Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser crashes after encountering invalid variable declaration in macro call #103529

Closed
fmease opened this issue Oct 25, 2022 · 7 comments · Fixed by #105141
Closed

Parser crashes after encountering invalid variable declaration in macro call #103529

fmease opened this issue Oct 25, 2022 · 7 comments · Fixed by #105141
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Oct 25, 2022

Code

macro_rules! m { ($s:stmt) => {} }
m! { var x }

Meta

rustc --Vv:

rustc 1.66.0-nightly (9062b780b 2022-09-21)
binary: rustc
commit-hash: 9062b780b32d2eab060b4432863e085d9504ca5c
commit-date: 2022-09-21
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.0

Error output

error: invalid variable declaration
 --> t.rs:2:6
  |
2 | m! { var x }
  |      ^^^
  |
help: write `let` instead of `var` to introduce a new variable
  |
2 | m! { let x }
  |      ~~~
Backtrace

thread 'rustc' panicked at 'Missing tokens for nt NtStmt(..) at t.rs:2:6: 2:11 (#0): "let x;"', /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/compiler/rustc_parse/src/parser/nonterminal.rs:187:13
stack backtrace:
   0:     0x7f963a96e010 - std::backtrace_rs::backtrace::libunwind::trace::hb70cd2c4f10319c4
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f963a96e010 - std::backtrace_rs::backtrace::trace_unsynchronized::h6a235690bde8066a
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f963a96e010 - std::sys_common::backtrace::_print_fmt::hf423a9f93de17924
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f963a96e010 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h81fafbb534b53ab7
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f963a9c8e5e - core::fmt::write::h91215ed98af09b40
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/core/src/fmt/mod.rs:1202:17
   5:     0x7f963a95eb15 - std::io::Write::write_fmt::h9d32a42fc3233c10
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/io/mod.rs:1679:15
   6:     0x7f963a970d93 - std::sys_common::backtrace::_print::hebe110643c78e1a1
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f963a970d93 - std::sys_common::backtrace::print::h544b1b31fddff6eb
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f963a970d93 - std::panicking::default_hook::{{closure}}::hf97dcba6b32ea332
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/panicking.rs:267:22
   9:     0x7f963a970a7f - std::panicking::default_hook::h3f82dc02801e0576
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/panicking.rs:286:9
  10:     0x7f963d1748d1 - <rustc_driver[610c3dabcb482a3]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[c7389bc70673082e]::ops::function::FnOnce<(&core[c7389bc70673082e]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f963a9715cb - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1442642a89018d6d
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/alloc/src/boxed.rs:1954:9
  12:     0x7f963a9715cb - std::panicking::rust_panic_with_hook::hb8c8dca0bdad40db
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/panicking.rs:673:13
  13:     0x7f963a971427 - std::panicking::begin_panic_handler::{{closure}}::hd6686af6943caeb9
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/panicking.rs:560:13
  14:     0x7f963a96e4bc - std::sys_common::backtrace::__rust_end_short_backtrace::h83dd31235af00771
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/sys_common/backtrace.rs:138:18
  15:     0x7f963a971142 - rust_begin_unwind
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/panicking.rs:556:5
  16:     0x7f963a9c5a33 - core::panicking::panic_fmt::h261ed3d4efd89943
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/core/src/panicking.rs:142:14
  17:     0x7f963be7c627 - <rustc_expand[f42067b102e05961]::mbe::macro_parser::TtParser>::parse_tt
  18:     0x7f963be76c43 - <rustc_expand[f42067b102e05961]::mbe::macro_rules::MacroRulesMacroExpander as rustc_expand[f42067b102e05961]::base::TTMacroExpander>::expand
  19:     0x7f963c872ed2 - <rustc_expand[f42067b102e05961]::expand::MacroExpander>::fully_expand_fragment
  20:     0x7f963bf4cc13 - <rustc_expand[f42067b102e05961]::expand::MacroExpander>::expand_crate
  21:     0x7f963bf4be24 - <rustc_session[40303a05d79b8f9]::session::Session>::time::<core[c7389bc70673082e]::result::Result<rustc_ast[8659774c93938f42]::ast::Crate, rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>, rustc_interface[121647ee48321f2a]::passes::configure_and_expand::{closure#1}>
  22:     0x7f963bf14083 - rustc_interface[121647ee48321f2a]::passes::configure_and_expand
  23:     0x7f963bf0ac85 - <rustc_interface[121647ee48321f2a]::queries::Queries>::expansion
  24:     0x7f963bf0764c - rustc_interface[121647ee48321f2a]::interface::create_compiler_and_run::<core[c7389bc70673082e]::result::Result<(), rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>, rustc_driver[610c3dabcb482a3]::run_compiler::{closure#1}>
  25:     0x7f963bf06072 - <scoped_tls[d2720ff23ff3c466]::ScopedKey<rustc_span[d840d66cf15b0e9]::SessionGlobals>>::set::<rustc_interface[121647ee48321f2a]::interface::run_compiler<core[c7389bc70673082e]::result::Result<(), rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>, rustc_driver[610c3dabcb482a3]::run_compiler::{closure#1}>::{closure#0}, core[c7389bc70673082e]::result::Result<(), rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>>
  26:     0x7f963bf05d5f - std[2c19137f19a9cec7]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[121647ee48321f2a]::util::run_in_thread_pool_with_globals<rustc_interface[121647ee48321f2a]::interface::run_compiler<core[c7389bc70673082e]::result::Result<(), rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>, rustc_driver[610c3dabcb482a3]::run_compiler::{closure#1}>::{closure#0}, core[c7389bc70673082e]::result::Result<(), rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>>::{closure#0}, core[c7389bc70673082e]::result::Result<(), rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>>
  27:     0x7f963cfda9d0 - <<std[2c19137f19a9cec7]::thread::Builder>::spawn_unchecked_<rustc_interface[121647ee48321f2a]::util::run_in_thread_pool_with_globals<rustc_interface[121647ee48321f2a]::interface::run_compiler<core[c7389bc70673082e]::result::Result<(), rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>, rustc_driver[610c3dabcb482a3]::run_compiler::{closure#1}>::{closure#0}, core[c7389bc70673082e]::result::Result<(), rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>>::{closure#0}, core[c7389bc70673082e]::result::Result<(), rustc_errors[275d4fb119ffacfb]::ErrorGuaranteed>>::{closure#1} as core[c7389bc70673082e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x7f963a97b3b3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he225f53d02ef001f
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/alloc/src/boxed.rs:1940:9
  29:     0x7f963a97b3b3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1d16365b1f15b7b7
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/alloc/src/boxed.rs:1940:9
  30:     0x7f963a97b3b3 - std::sys::unix::thread::Thread::new::thread_start::h91bd867cccfe281f
                               at /rustc/9062b780b32d2eab060b4432863e085d9504ca5c/library/std/src/sys/unix/thread.rs:108:17
  31:     0x7f963a71f78d - <unknown>
  32:     0x7f963a7a08e4 - clone
  33:                0x0 - <unknown>

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.66.0-nightly (9062b780b 2022-09-21) running on x86_64-unknown-linux-gnu

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

@rustbot label A-parser A-macros

@fmease fmease added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 25, 2022
@rustbot rustbot added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-parser Area: The parsing of Rust source code to an AST. labels Oct 25, 2022
@chenyukang
Copy link
Member

@rustbot claim

@compiler-errors
Copy link
Member

compiler-errors commented Oct 26, 2022

cc @Nilstrieb this should probably be gated with your "may eagerly recover" work as well

@fmease
Copy link
Member Author

fmease commented Oct 27, 2022

This code is actually already mentioned in #103534 ;)

@chenyukang chenyukang removed their assignment Nov 3, 2022
@ohno418
Copy link
Contributor

ohno418 commented Nov 19, 2022

@rustbot claim

@Noratrieb
Copy link
Member

Yeah, gating this recovery behind a self.may_recover() is the correct fix here.

@Noratrieb
Copy link
Member

Also very fun that these things can ICE sometimes.

@ohno418
Copy link
Contributor

ohno418 commented Nov 26, 2022

Found these also panic:

m! { mut x }
m! { auto x }

Since these are highly related to the var case, one pull request can fix all of these (maybe).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants