rust-lang/rust

ICE "Mismatched open/close delims" with `derive` and multiple syntax errors

Closed this issue · 1 comments

Found with a modified fuzz-rustc

Code

#[derive(A)]
struct S {
    d: [u32; {
        #![cfg] {
            #![w,)

ICE

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Bracket`,
 right: `Brace`: Mismatched open/close delims: open=Bracket close=pe.rs:5:19: 5:19 (#0)', compiler/rustc_parse/src/parser/attr_wrapper.rs:410:17
Full output including backtrace
error: this file contains an unclosed delimiter
 --> pe.rs:5:19
  |
2 | struct S {
  |          - unclosed delimiter
3 |     d: [u32; {
  |        -     - unclosed delimiter
  |        |
  |        unclosed delimiter
4 |         #![cfg] {
  |                 - unclosed delimiter
5 |             #![w,)
  |                   ^

error: expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `,`
 --> pe.rs:5:15
  |
5 |             #![w,)
  |               ^ ^ help: `]` may belong here
  |               |
  |               unclosed delimiter

error: expected expression, found `,`
 --> pe.rs:5:17
  |
5 |             #![w,)
  |                 ^ expected expression

error: expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `,`
 --> pe.rs:5:17
  |
5 |             #![w,)
  |                 ^ expected one of `(`, `::`, `=`, `[`, `]`, or `{`

error: expected one of `.`, `?`, `]`, or an operator, found `}`
 --> pe.rs:5:19
  |
2 | struct S {
  |        - while parsing this struct
...
5 |             #![w,)
  |                   ^ expected one of `.`, `?`, `]`, or an operator

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Bracket`,
 right: `Brace`: Mismatched open/close delims: open=Bracket close=pe.rs:5:19: 5:19 (#0)', compiler/rustc_parse/src/parser/attr_wrapper.rs:410:17
stack backtrace:
   0:        0x104b6af12 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1b594e9bcc0c6898
   1:        0x104bc94ba - core::fmt::write::h7c6f83d024852aa9
   2:        0x104b5cfec - std::io::Write::write_fmt::h97d969d4aea1606d
   3:        0x104b6acda - std::sys_common::backtrace::print::h562dadf6028256bf
   4:        0x104b6e0b6 - std::panicking::default_hook::{{closure}}::hee367e24075678e4
   5:        0x104b6de07 - std::panicking::default_hook::hcce3553a0befadd1
   6:        0x113ad4f3d - rustc_driver[f93b8a3886cc8b65]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x104b6e8b5 - std::panicking::rust_panic_with_hook::h4f6feaafc55c56a2
   8:        0x104b6e643 - std::panicking::begin_panic_handler::{{closure}}::hde5e87cf8416de78
   9:        0x104b6b3a8 - std::sys_common::backtrace::__rust_end_short_backtrace::h06c292cffdb0bbc3
  10:        0x104b6e30d - _rust_begin_unwind
  11:        0x104bf6053 - core::panicking::panic_fmt::he51d66482c616f28
  12:        0x104bc6255 - core::panicking::assert_failed_inner::h61c1e02f13567a3b
  13:        0x11886a8de - core[322641b34a183a]::panicking::assert_failed::<rustc_ast[e82592d0ad019575]::token::Delimiter, rustc_ast[e82592d0ad019575]::token::Delimiter>
  14:        0x117dfdf4d - <rustc_parse[570b285c5a8296e1]::parser::attr_wrapper::LazyAttrTokenStreamImpl as rustc_ast[e82592d0ad019575]::tokenstream::ToAttrTokenStream>::to_attr_token_stream
  15:        0x116a03ebb - <rustc_expand[3365769f7608aa23]::config::StripUnconfigured>::configure::<rustc_ast[e82592d0ad019575]::ptr::P<rustc_ast[e82592d0ad019575]::ast::Item>>
  16:        0x1169e942f - rustc_builtin_macros[419da32eca7734ae]::cfg_eval::cfg_eval
  17:        0x116a13607 - <rustc_builtin_macros[419da32eca7734ae]::derive::Expander as rustc_expand[3365769f7608aa23]::base::MultiItemModifier>::expand::{closure#0}
  18:        0x116ae5815 - <rustc_resolve[39b6d331f013b4c1]::Resolver as rustc_expand[3365769f7608aa23]::base::ResolverExpand>::resolve_derives
  19:        0x116a133c1 - <rustc_builtin_macros[419da32eca7734ae]::derive::Expander as rustc_expand[3365769f7608aa23]::base::MultiItemModifier>::expand
  20:        0x117c0c92d - <rustc_expand[3365769f7608aa23]::expand::MacroExpander>::fully_expand_fragment
  21:        0x117c0ac46 - <rustc_expand[3365769f7608aa23]::expand::MacroExpander>::expand_crate
  22:        0x113b59591 - <rustc_session[304ed9bc7c986c94]::session::Session>::time::<core[322641b34a183a]::result::Result<rustc_ast[e82592d0ad019575]::ast::Crate, rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_interface[bab52cec3fba6e57]::passes::configure_and_expand::{closure#1}>
  23:        0x113b94025 - rustc_interface[bab52cec3fba6e57]::passes::configure_and_expand
  24:        0x113b76a51 - <rustc_interface[bab52cec3fba6e57]::queries::Queries>::expansion
  25:        0x113aa8560 - rustc_span[50ad8565b2f1bbfb]::with_source_map::<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  26:        0x113a985bc - <scoped_tls[5d80669e9829205e]::ScopedKey<rustc_span[50ad8565b2f1bbfb]::SessionGlobals>>::set::<rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>
  27:        0x113a6737a - std[38dd6138ba148cb2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[bab52cec3fba6e57]::util::run_in_thread_pool_with_globals<rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>
  28:        0x113a4db4b - <<std[38dd6138ba148cb2]::thread::Builder>::spawn_unchecked_<rustc_interface[bab52cec3fba6e57]::util::run_in_thread_pool_with_globals<rustc_interface[bab52cec3fba6e57]::interface::run_compiler<core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>, rustc_driver[f93b8a3886cc8b65]::run_compiler::{closure#1}>::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[322641b34a183a]::result::Result<(), rustc_errors[ef89fc2f19a46f90]::ErrorGuaranteed>>::{closure#1} as core[322641b34a183a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:        0x104b77967 - std::sys::unix::thread::Thread::new::thread_start::hae9a83a2ac729f3b
  30:     0x7ff80d84d4e1 - __pthread_start

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.67.0-nightly (e75aab045 2022-11-09) running on x86_64-apple-darwin

query stack during panic:
end of query stack
error: aborting due to 5 previous errors

Regression

Possibly a regression in nightly-2021-04-12, perhaps from #84023.

It's hard to tell with such a cursed testcase.

Version

rustc 1.67.0-nightly (e75aab045 2022-11-09)
binary: rustc
commit-hash: e75aab045fc476f176a58c408f6b06f0e275c6e1
commit-date: 2022-11-09
host: x86_64-apple-darwin
release: 1.67.0-nightly
LLVM version: 15.0.4