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

Panic: non-eager expansion without a parent scope #70624

Closed
zicklag opened this issue Mar 31, 2020 · 8 comments
Closed

Panic: non-eager expansion without a parent scope #70624

zicklag opened this issue Mar 31, 2020 · 8 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) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zicklag
Copy link

zicklag commented Mar 31, 2020

I tried this code:

macro_rules! breakme {
    ($config:stmt; $($tokens:literal)*) => {
        #[cfg($config)]
        $($tokens)*
    };
}

fn main() {
    macro_rules! unix {
        () => {
            not(unix)
        };
    }

    breakme!(unix!(); "test");
}

I didn't actually expect it to work ( yet ), but it shouldn't have panicked.

Meta

playground link.

Build using the Nightly version: 1.44.0-nightly

(2020-03-30 2113659479a82ea69633)
Backtrace

thread 'rustc' panicked at 'non-eager expansion without a parent scope', src/librustc_resolve/macros.rs:223:37
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1439
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:515
  12: rust_begin_unwind
             at src/libstd/panicking.rs:419
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:111
  14: core::option::expect_failed
             at src/libcore/option.rs:1260
  15: rustc_resolve::macros::<impl rustc_expand::base::Resolver for rustc_resolve::Resolver>::resolve_macro_invocation
  16: rustc_expand::expand::MacroExpander::fully_expand_fragment
  17: rustc_expand::expand::MacroExpander::expand_crate
  18: rustc_session::utils::<impl rustc_session::session::Session>::time
  19: rustc_interface::passes::configure_and_expand_inner
  20: rustc_interface::passes::configure_and_expand::{{closure}}
  21: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
  22: rustc_interface::passes::configure_and_expand
  23: rustc_interface::queries::Queries::expansion
  24: rustc_interface::interface::run_compiler_in_existing_thread_pool
  25: scoped_tls::ScopedKey<T>::set
  26: rustc_ast::attr::with_globals

@zicklag zicklag added the C-bug Category: This is a bug. label Mar 31, 2020
@jonas-schievink jonas-schievink added 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) ❄️ I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 31, 2020
@petrochenkov
Copy link
Contributor

Likely a duplicate of #55414.

@spastorino
Copy link
Member

spastorino commented Apr 1, 2020

This was discussed briefly on Zulip.

Removing I-nominated, prioritizing as P-medium.

@rustbot ping cleanup

Would be nice if we figure out if this is a dupe or not.

@rustbot
Copy link
Collaborator

rustbot commented Apr 1, 2020

Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3

cc @AminArria @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @jakevossen5 @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke

@rustbot rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label Apr 1, 2020
@spastorino spastorino added P-medium Medium priority and removed I-nominated labels Apr 1, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 3, 2020
@woshilapin
Copy link
Contributor

woshilapin commented Apr 5, 2020

I'm not sure how exactly to prove that this is the same bug but, at the very least, I've compiled both on rustc 1.42.0 (b8cedc004 2020-03-09) and they both produce the exact same stack backtrace. It seems the bug is both present on stable and nightly.

Stack backtrace stack backtrace: 0: ::fmt 1: core::fmt::write 2: std::io::Write::write_fmt 3: std::panicking::default_hook::{{closure}} 4: std::panicking::default_hook 5: rustc_driver::report_ice 6: std::panicking::rust_panic_with_hook 7: rust_begin_unwind 8: core::panicking::panic_fmt 9: core::option::expect_failed 10: rustc_resolve::macros::::resolve_macro_invocation 11: rustc_expand::expand::MacroExpander::fully_expand_fragment 12: rustc_expand::expand::MacroExpander::expand_crate 13: rustc_session::utils::::time 14: rustc_interface::passes::configure_and_expand_inner 15: rustc_interface::passes::configure_and_expand::{{closure}} 16: rustc_data_structures::box_region::PinnedGenerator::new 17: rustc_interface::passes::configure_and_expand 18: rustc_interface::queries::Queries::expansion 19: rustc_interface::interface::run_compiler_in_existing_thread_pool 20: scoped_tls::ScopedKey::set 21: syntax::with_globals

However, the following thing is a difference between both bugs.

No compiler message

In the case of #55414, the compiler doesn't show any message (except than rustc panic). However, for #70624, the following compiler message is displayed before rustc panics.

error: expected unsuffixed literal or identifier, found `unix!()`
  --> src/main.rs:3:23
   |
3  |                 #[cfg($config)]
   |                       ^^^^^^^
...
17 |     breakme!(unix!(); "test");
   |     -------------------------- in this macro invocation

@pickfire
Copy link
Contributor

pickfire commented May 7, 2020

I got the same error message with doc and building on top of another macro.

macro_rules! breakme {
    ( $name:ident ) => { breakme!($name, stringify!($name), $); };
    ( $name:ident, $name_str:expr, $d:tt ) => {
        #[doc = $name_str]
        #[macro_export]
        macro_rules! $name {
            ( $format:expr, $d( $arg:tt ),+ ) => {
                format!($format, $d( $arg ),+);
            }
        }
    }
}

breakme!(hello);

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=8026a63548ffa4560b31207d69a4dd67

Error log
thread 'rustc' panicked at 'non-eager expansion without a parent scope', src/librustc_resolve/macros.rs:223:37
note: run with `RUST_BACKTRACE=1` environment variable to display 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.45.0-nightly (1836e3b42 2020-05-06) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: could not compile `playground`.

To learn more, run the command again with --verbose.

@petrochenkov
Copy link
Contributor

Closing as a duplicate of #55414.

@pickfire
Copy link
Contributor

pickfire commented May 7, 2020

@petrochenkov But that have a different error.

@petrochenkov
Copy link
Contributor

Which one?
I only see the "non-eager expansion without a parent scope" one, which is a known issue with known reasons.

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) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-medium Medium priority 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

8 participants