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

Compile panic in nested empty proc_macro #99173

Open
mjul opened this issue Jul 12, 2022 · 0 comments
Open

Compile panic in nested empty proc_macro #99173

mjul opened this issue Jul 12, 2022 · 0 comments
Labels
A-proc-macros Area: Procedural 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

@mjul
Copy link

mjul commented Jul 12, 2022

I wrote two proc_macros in the same crate, one calling the other.
When the inner macro, named ignore in the example below, is invoked by the outer macro in the
example, this_fails, the build panics.

Code

File metamodel_macros/src/lib.rs in a proc_macro crate named metamodel_macros:

// these proc_macros cause the failure (the ignore macro called from the this_fails macro)
// this code is in root of a crate named metamodel_macros 

#[proc_macro]
pub fn ignore(input: TokenStream) -> TokenStream {
    let mut result : TokenStream = TokenStream::new();
    result.into()
}

#[proc_macro]
pub fn this_fails(input: TokenStream) -> TokenStream {
    let mut result : TokenStream = TokenStream::new();
    result.extend::<TokenStream>("metamodel_macros::ignore!(42).into()".parse().unwrap());
    result.into()
}

File metamodel_tests/src/lib.rs in a normal library crate named metamodel_tests:

       // This test using the nested macros fails (
        #[test]
        pub fn bug_report() {
            metamodel_macros::this_fails!(1*2*3*7);
        }

Meta

rustc --version --verbose:

rustc 1.59.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.1

This is the vanilla Ubuntu rust-all and rust-src packages.

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_resolve/src/late.rs:2406:52
stack backtrace:
   0:     0x7f05fe4c8db6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc764e6c306839a24
   1:     0x7f05fe540f1c - core::fmt::write::h6c6063682136d3f7
   2:     0x7f05fe4ad445 - <unknown>
   3:     0x7f05fe4bdf51 - <unknown>
   4:     0x7f05fe4bdb51 - <unknown>
   5:     0x7f05feca1b09 - <unknown>
   6:     0x7f05e8c99093 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h15d19db900bf691c
                               at /build/rustc-60tkWq/rustc-1.59.0+dfsg1/library/alloc/src/boxed.rs:1868:9
   7:     0x7f05e8c986bd - proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}::{{closure}}::hb14332fef47f4396
                               at /build/rustc-60tkWq/rustc-1.59.0+dfsg1/library/proc_macro/src/bridge/client.rs:320:21
   8:     0x7f05fe4be616 - std::panicking::rust_panic_with_hook::hb626f56f9705169d
   9:     0x7f05fe4c9762 - <unknown>
  10:     0x7f05fe4c8ee4 - <unknown>
  11:     0x7f05fe4be172 - rust_begin_unwind
  12:     0x7f05fe495fb1 - core::panicking::panic_fmt::h9ddcb63ac904a529
  13:     0x7f05fe495efd - core::panicking::panic::hd3f4ff0add4e700c
  14:     0x7f05ff7c98e4 - <unknown>
  15:     0x7f05ff7b2b79 - <rustc_resolve[c1d81ea7e97dfba6]::late::LateResolutionVisitor as rustc_ast[59dd777c9703ec89]::visit::Visitor>::visit_block
  16:     0x7f05ff7b450e - <rustc_resolve[c1d81ea7e97dfba6]::late::LateResolutionVisitor as rustc_ast[59dd777c9703ec89]::visit::Visitor>::visit_fn
  17:     0x7f05ff7945c1 - <unknown>
  18:     0x7f05ff7b8a89 - <unknown>
  19:     0x7f05ff79461b - <unknown>
  20:     0x7f05ff7b66e9 - <unknown>
  21:     0x7f05ff76bedc - <unknown>
  22:     0x7f05ff6dfd4b - <unknown>
  23:     0x7f05fed9bb53 - <unknown>
  24:     0x7f05feda071a - <rustc_interface[e82d985b74efe81f]::queries::Queries>::expansion
  25:     0x7f05fec475e1 - <unknown>
  26:     0x7f05fec13d13 - <unknown>
  27:     0x7f05fec44e19 - <unknown>
  28:     0x7f05fec1ee23 - <unknown>
  29:     0x7f05fec18919 - <unknown>
  30:     0x7f05fec914f0 - <unknown>
  31:     0x7f05fe4b4893 - <unknown>
  32:     0x7f05fe2a0b43 - start_thread
                               at ./nptl/./nptl/pthread_create.c:442:8
  33:     0x7f05fe332a00 - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  34:                0x0 - <unknown>

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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

warning: `metaprogramming_lab` (lib) generated 6 warnings
note: rustc 1.59.0 running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental

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

query stack during panic:
end of query stack
For more information about this error, try `rustc --explain E0433`.
error: could not compile `metamodel_test` due to previous error
Backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_resolve/src/late.rs:2406:52
stack backtrace:
   0:     0x7f05fe4c8db6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc764e6c306839a24
   1:     0x7f05fe540f1c - core::fmt::write::h6c6063682136d3f7
   2:     0x7f05fe4ad445 - <unknown>
   3:     0x7f05fe4bdf51 - <unknown>
   4:     0x7f05fe4bdb51 - <unknown>
   5:     0x7f05feca1b09 - <unknown>
   6:     0x7f05e8c99093 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h15d19db900bf691c
                               at /build/rustc-60tkWq/rustc-1.59.0+dfsg1/library/alloc/src/boxed.rs:1868:9
   7:     0x7f05e8c986bd - proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}::{{closure}}::hb14332fef47f4396
                               at /build/rustc-60tkWq/rustc-1.59.0+dfsg1/library/proc_macro/src/bridge/client.rs:320:21
   8:     0x7f05fe4be616 - std::panicking::rust_panic_with_hook::hb626f56f9705169d
   9:     0x7f05fe4c9762 - <unknown>
  10:     0x7f05fe4c8ee4 - <unknown>
  11:     0x7f05fe4be172 - rust_begin_unwind
  12:     0x7f05fe495fb1 - core::panicking::panic_fmt::h9ddcb63ac904a529
  13:     0x7f05fe495efd - core::panicking::panic::hd3f4ff0add4e700c
  14:     0x7f05ff7c98e4 - <unknown>
  15:     0x7f05ff7b2b79 - <rustc_resolve[c1d81ea7e97dfba6]::late::LateResolutionVisitor as rustc_ast[59dd777c9703ec89]::visit::Visitor>::visit_block
  16:     0x7f05ff7b450e - <rustc_resolve[c1d81ea7e97dfba6]::late::LateResolutionVisitor as rustc_ast[59dd777c9703ec89]::visit::Visitor>::visit_fn
  17:     0x7f05ff7945c1 - <unknown>
  18:     0x7f05ff7b8a89 - <unknown>
  19:     0x7f05ff79461b - <unknown>
  20:     0x7f05ff7b66e9 - <unknown>
  21:     0x7f05ff76bedc - <unknown>
  22:     0x7f05ff6dfd4b - <unknown>
  23:     0x7f05fed9bb53 - <unknown>
  24:     0x7f05feda071a - <rustc_interface[e82d985b74efe81f]::queries::Queries>::expansion
  25:     0x7f05fec475e1 - <unknown>
  26:     0x7f05fec13d13 - <unknown>
  27:     0x7f05fec44e19 - <unknown>
  28:     0x7f05fec1ee23 - <unknown>
  29:     0x7f05fec18919 - <unknown>
  30:     0x7f05fec914f0 - <unknown>
  31:     0x7f05fe4b4893 - <unknown>
  32:     0x7f05fe2a0b43 - start_thread
                               at ./nptl/./nptl/pthread_create.c:442:8
  33:     0x7f05fe332a00 - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  34:                0x0 - <unknown>

@mjul mjul added C-bug Category: This is a bug. 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. labels Jul 12, 2022
@pnkfelix pnkfelix added the A-proc-macros Area: Procedural macros label Jan 13, 2023
JohnTitor added a commit to JohnTitor/glacier that referenced this issue Jan 14, 2023
- rust-lang/rust#99173
- rust-lang/rust#103708
- rust-lang/rust#104827
- rust-lang/rust#105209
- rust-lang/rust#106298
- rust-lang/rust#106423

Signed-off-by: Yuki Okushi <jtitor@2k36.org>

rust-lang/rust#99173
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macros Area: Procedural 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

3 participants