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

ICE: Macro parser: Error message, then compiler panic. #33569

Closed
matthewhammer opened this issue May 11, 2016 · 0 comments · Fixed by #33870
Closed

ICE: Macro parser: Error message, then compiler panic. #33569

matthewhammer opened this issue May 11, 2016 · 0 comments · Fixed by #33870
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@matthewhammer
Copy link

Nightly compiler panics on a silly macro pattern that uses a double dollar sign ($$).

I tried this code:
https://play.rust-lang.org/?gist=0aafe97edc13def2e090e3a09527dcc6&version=nightly&backtrace=0

macro_rules! foo {
  { $a:expr $$ $b:expr } => {{ 0 }};
}

fn main() {
    println!("Hello, world!");
}

I expected either a compiler error, or for the macro to be legally definable, and for the compiler to accept this silly definition. Instead, the compiler complains and then panics.

Here's the output, which seems reasonable, up until the panic:

error: expected identifier, found `$`
 --> <anon>:2:14
2 |>   { $a:expr $$ $b:expr } => {{ 0 }};
  |>              ^
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/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 'internal error: entered unreachable code', ../src/libsyntax/parse/parser.rs:2848
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Backtrace

thread 'rustc' panicked at 'internal error: entered unreachable code', ../src/libsyntax/parse/parser.rs:2848
stack backtrace:
   1:        0x10fb10f38 - std::sys::backtrace::tracing::imp::write::h9fb600083204ae7f
   2:        0x10fb1d475 - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hca543c34f11229ac
   3:        0x10fb1cfaf - std::panicking::default_hook::hc2c969e7453d080c
   4:        0x10fae23d6 - std::sys_common::unwind::begin_unwind_inner::h30e12d15ce2b2e25
   5:        0x10cc95ef4 - std::sys_common::unwind::begin_unwind::h65390c63b501d6ed
   6:        0x10cd94009 - syntax::parse::parser::Parser::parse_token_tree::hd7887691a0224788
   7:        0x10cfa95b1 - syntax::ext::tt::macro_parser::parse_nt::h9776ef73ddf4d14c
   8:        0x10ccfd1c4 - syntax::ext::tt::macro_parser::parse::hf8420386b1b7feca
   9:        0x10ced4280 - syntax::ext::tt::macro_rules::compile::h21c8262e7bf89324
  10:        0x10ced3850 - syntax::ext::base::ExtCtxt::insert_macro::h393439bf035c459e
  11:        0x10cf2b567 - syntax::ext::expand::expand_item_mac::hb51c73877df56a79
  12:        0x10cf18797 - syntax::ext::expand::expand_annotatable::hc0f78f406615b5e1
  13:        0x10cf15e8c - syntax::ext::expand::expand_item::hb99af7e0c910686e
  14:        0x10cf23af1 - _<ext..expand..MacroExpander<'a, 'b> as fold..Folder>::fold_item::h8c27a95378ad2c28
  15:        0x10cf237a0 - syntax::fold::noop_fold_mod::hc2718611fc479597
  16:        0x10cf1d343 - syntax::ext::expand::expand_item_kind::h0b21c6d930b6a1e4
  17:        0x10cf5c7ad - syntax::fold::Folder::fold_item_simple::ha749d2ae63b235ad
  18:        0x10cf5c396 - _<ptr..P<T>>::map::he640c72a9f20f0a4
  19:        0x10cf19f23 - syntax::ext::expand::expand_annotatable::hc0f78f406615b5e1
  20:        0x10cf15e8c - syntax::ext::expand::expand_item::hb99af7e0c910686e
  21:        0x10cf23d37 - _<ext..expand..MacroExpander<'a, 'b> as fold..Folder>::fold_item::h8c27a95378ad2c28
  22:        0x10cf699b1 - _<ext..expand..MacroExpander<'a, 'b> as fold..Folder>::fold_crate::h072fa0f078d6fae0
  23:        0x10cf6adf6 - syntax::ext::expand::expand_crate::h7e9f12d49472476d
  24:        0x10b05b6c4 - rustc_driver::driver::phase_2_configure_and_expand::_$u7b$$u7b$closure$u7d$$u7d$::hcc02923f666dd3df
  25:        0x10b00b393 - rustc_driver::driver::phase_2_configure_and_expand::h70a47be7bf475f39
  26:        0x10afe6e40 - rustc_driver::driver::compile_input::h0629572e6f316b31
  27:        0x10afdca91 - rustc_driver::run_compiler::h8902aebf8b1849a8
  28:        0x10afd9c65 - std::sys_common::unwind::try::try_fn::h4c74456035d0fcc7
  29:        0x10fb0e75b - __rust_try
  30:        0x10fb0e6e3 - std::sys_common::unwind::inner_try::h47a4d9cd4a369dcd
  31:        0x10afda6f9 - _<F as std..boxed..FnBox<A>>::call_box::h27f542a39f1d61ef
  32:        0x10fb1c348 - std::sys::thread::Thread::new::thread_start::h6f266e069bf4ec2b
  33:     0x7fff932e9059 - _pthread_body
  34:     0x7fff932e8fd6 - _pthread_start
@nagisa nagisa added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels May 11, 2016
c4rlo added a commit to c4rlo/rust that referenced this issue May 18, 2016
A "token tree" is how the contents of a macro_rules! definition is parsed,
before expanding it.  This is a very permissive form of parsing.

Fixes rust-lang#33569.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 27, 2016
Fix ICE on parsing a bad metavariable in a macro definition

Fixes rust-lang#33569, fixes rust-lang#33728.
r? @pnkfelix
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, ..) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
2 participants