Skip to content

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

Closed
@zicklag

Description

@zicklag

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

Activity

added
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 31, 2020
petrochenkov

petrochenkov commented on Mar 31, 2020

@petrochenkov
Contributor

Likely a duplicate of #55414.

spastorino

spastorino commented on Apr 1, 2020

@spastorino
Member

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

rustbot commented on Apr 1, 2020

@rustbot
Collaborator

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

woshilapin

woshilapin commented on Apr 5, 2020

@woshilapin
Contributor

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

pickfire commented on May 7, 2020

@pickfire
Contributor

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

petrochenkov commented on May 7, 2020

@petrochenkov
Contributor

Closing as a duplicate of #55414.

pickfire

pickfire commented on May 7, 2020

@pickfire
Contributor

@petrochenkov But that have a different error.

petrochenkov

petrochenkov commented on May 7, 2020

@petrochenkov
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ICEBreaker-Cleanup-CrewHelping to "clean up" bugs with minimal examples and bisectionsP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @spastorino@jonas-schievink@woshilapin@pickfire@petrochenkov

        Issue actions

          Panic: non-eager expansion without a parent scope · Issue #70624 · rust-lang/rust