Skip to content

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

Closed

Description

@lorepozo

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

Activity

  1. changed the title [-]compiler panic using macros: 'no entry found for key'[/-] [+]compiler panic using nested macros: 'no entry found for key'[/+] on Sep 25, 2017
  2. added
    I-ICE
    on Sep 25, 2017
  3. changed the title [-]compiler panic using nested macros: 'no entry found for key'[/-] [+]ICE when using nested macro calls: 'no entry found for key'[/+] on Sep 25, 2017
  4. kennytm commented on Sep 26, 2017

    @kennytm
    Member

    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).

  5. added
    A-macros
    C-bug
    on Sep 27, 2017
  6. added a commit that references this issue on Oct 23, 2017
    c0ccab4
  7. added a commit that references this issue on Oct 26, 2017
    56dc171
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosC-bugI-ICE

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions