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 on wrong macro #51173

Closed
llogiq opened this issue May 29, 2018 · 4 comments
Closed

ICE on wrong macro #51173

llogiq opened this issue May 29, 2018 · 4 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@llogiq
Copy link
Contributor

llogiq commented May 29, 2018

Repro:

$ rustc ice.rs 
thread 'main' panicked at 'no entry found for key', libcore/option.rs:960:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

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.28.0-nightly (990d8aa74 2018-05-25) running on x86_64-unknown-linux-gnu

Compiling the following:

// ice.rs
pub trait Letter {
    fn l(self) -> Self;
}

macro_rules! l_impl {
    ($ty: ty, $ex: expr) => {
        impl Letter for $ty {
            #[doc = concat!(
            "```
use std::{env, exor::*, fmt};
let _x : ", stringify!($ty), " = ", stringify!($ex), ";
```")]
                fn l(self) -> Self { self }
            }
    };
}

l_impl!(std::string::FromUtf8Error, String::from_utf8(vec![193u8]).unwrap_err());

fn main() { }
@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label May 29, 2018
@llogiq
Copy link
Contributor Author

llogiq commented May 29, 2018

running with RUST_BACKTRACE=1 gives the following trace:

thread 'main' panicked at 'no entry found for key', libcore/option.rs:960:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:467
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:350
   7: rust_begin_unwind
             at libstd/panicking.rs:328
   8: core::panicking::panic_fmt
             at libcore/panicking.rs:71
   9: core::option::expect_failed
             at libcore/option.rs:960
  10: rustc_resolve::macros::<impl rustc_resolve::Resolver<'a>>::resolve_macro_to_def_inner
  11: rustc_resolve::macros::<impl rustc_resolve::Resolver<'a>>::resolve_macro_to_def
  12: rustc_resolve::macros::<impl syntax::ext::base::Resolver for rustc_resolve::Resolver<'a>>::resolve_invoc
  13: syntax::ext::expand::MacroExpander::expand
  14: syntax::ext::expand::MacroExpander::expand_crate
  15: rustc_driver::driver::phase_2_configure_and_expand_inner::{{closure}}
  16: rustc::util::common::time
  17: rustc_driver::driver::phase_2_configure_and_expand
  18: rustc_driver::driver::compile_input
  19: rustc_driver::run_compiler_with_pool
  20: syntax::with_globals
  21: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  22: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  23: rustc_driver::run
  24: rustc_driver::main
  25: std::rt::lang_start::{{closure}}
  26: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  27: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  28: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:374
             at libstd/rt.rs:58
  29: main
  30: __libc_start_main
  31: <unknown>
query stack during panic:
end of query stack

@cuviper cuviper added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 29, 2018
@stevecheckoway
Copy link

Here's a smaller reproducer.

macro_rules! bug {
    ( $doc:expr ) => { #[doc = $doc] enum Bug {} }
}

bug! { (stringify!(bug)) }

fn main() { }

Interestingly, this similar example compiles.

macro_rules! working {
    ( $doc:expr, $item:item ) => { #[doc = $doc] $item }
}

working! {
    stringify!(Working),
    enum Working { }
}
fn main() {}

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@Centril
Copy link
Contributor

Centril commented Mar 10, 2020

Smaller reproducer reproduces in 2020, cc @petrochenkov

@petrochenkov
Copy link
Contributor

Duplicate of #55414.

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. glacier ICE tracked in rust-lang/glacier. 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

No branches or pull requests

7 participants