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 when using nested macro calls: 'no entry found for key' #44851

Closed
lorepozo opened this issue Sep 25, 2017 · 1 comment
Closed

ICE when using nested macro calls: 'no entry found for key' #44851

lorepozo opened this issue Sep 25, 2017 · 1 comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@lorepozo
Copy link
Contributor

This issue probably needs a better title, perhaps someone more familiar with the compiler's handling of macros can suggest a better one.

Code

playground

macro_rules! make_foodoc {
    ($outer:ident, $inner:ident) => {
        concat!("outer: ", stringify!($outer), " ; inner: ", stringify!($inner))
    }
}

macro_rules! make_foo {
    ($doc:expr, $outer:ident, $inner:ident) => {
        #[doc = $doc ]
        #[derive(Debug)]
        pub struct $outer($inner);
    }
}

make_foo!(make_foodoc!(MyFoo, i32), MyFoo, i32);

fn main() {
    let f = MyFoo(0);
    println!("{:?}", f);
}

Version

# rustc --version --verbose
rustc 1.20.0 (f3d6973f4 2017-08-27)
binary: rustc
commit-hash: f3d6973f41a7d1fb83029c9c0ceaf0f5d4fd7208
commit-date: 2017-08-27
host: x86_64-apple-darwin
release: 1.20.0
LLVM version: 4.0

Expected Behavior

Some kind of error message, at least.

Actual Behavior

panic with exit code 101:

$ RUST_BACKTRACE=full rustc main.rs
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

note: rustc 1.20.0 (f3d6973f4 2017-08-27) running on x86_64-apple-darwin

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'no entry found for key', src/libcore/option.rs:819:4
stack backtrace:
   0:        0x10c7de6c3 - std::sys::imp::backtrace::tracing::imp::unwind_backtrace::h5d6b821bcccc8af3
   1:        0x10c7eb73a - std::panicking::default_hook::{{closure}}::haca53f8b96e15b81
   2:        0x10c7eb238 - std::panicking::default_hook::h0029f59c1ec97ffc
   3:        0x10c7eda02 - std::panicking::rust_panic_with_hook::hb8eae939c3fcaf9c
   4:        0x10c7ed864 - std::panicking::begin_panic_new::h3c5f9a0be81106be
   5:        0x10c7ed7b2 - std::panicking::begin_panic_fmt::hf585b6224c51a06c
   6:        0x10c7ed71a - rust_begin_unwind
   7:        0x10c82eb73 - core::panicking::panic_fmt::h13ed235e8f32b1d5
   8:        0x10c82ebdd - core::option::expect_failed::hcda4f7b77532dbdc
   9:        0x1077ca622 - rustc_resolve::macros::<impl rustc_resolve::Resolver<'a>>::resolve_macro_to_def::hfdf39b9e743bd0a1
  10:        0x1077c945d - rustc_resolve::macros::<impl syntax::ext::base::Resolver for rustc_resolve::Resolver<'a>>::resolve_invoc::h6533cd14622b0f6e
  11:        0x10c1461a0 - syntax::ext::expand::MacroExpander::expand::h14f5532b993820a5
  12:        0x10c145182 - syntax::ext::expand::MacroExpander::expand_crate::h0ee7fed5f1132fa4
  13:        0x1075f13cc - rustc_driver::driver::phase_2_configure_and_expand::{{closure}}::h87fe884b6ee57e81
  14:        0x1075eb807 - rustc_driver::driver::phase_2_configure_and_expand::h8b4927fdd561d907
  15:        0x1075e4c83 - rustc_driver::driver::compile_input::hed13f3a0f9e4f9ca
  16:        0x1076246b0 - rustc_driver::run_compiler::h08be8ddbdb667b6f
  17:        0x107551e30 - std::sys_common::backtrace::__rust_begin_short_backtrace::h2887c3163846925d
  18:        0x10c81da4c - __rust_maybe_catch_panic
  19:        0x10758596f - <F as alloc::boxed::FnBox<A>>::call_box::h4c5af747e717c038
  20:        0x10c7ea71b - std::sys::imp::thread::Thread::new::thread_start::h823686b907c11c46
  21:     0x7fff4f0b56c0 - _pthread_body
  22:     0x7fff4f0b556c - _pthread_start
@lorepozo lorepozo changed the title compiler panic using macros: 'no entry found for key' compiler panic using nested macros: 'no entry found for key' Sep 25, 2017
@sfackler sfackler added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 25, 2017
@lorepozo lorepozo changed the title compiler panic using nested macros: 'no entry found for key' ICE when using nested macro calls: 'no entry found for key' Sep 25, 2017
@kennytm
Copy link
Member

kennytm commented Sep 26, 2017

Simplified:

macro_rules! a {
    () => { "a" }
}

macro_rules! b {
    ($doc:expr) => {
        #[doc = $doc]
        pub struct B;
    }
}

b!(a!());

Same ICE will happen if expr is changed to stmt/pat/item/block.


Update: Panic happens at this line:

let invocation = self.invocations[&scope];

self.invocations has keys Mark(0) and Mark(1), but the scope is Mark(2).

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, ..) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants