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: match arm generation using macros + paste crate #94850

Closed
abocquet opened this issue Mar 11, 2022 · 2 comments
Closed

ICE: match arm generation using macros + paste crate #94850

abocquet opened this issue Mar 11, 2022 · 2 comments
Labels
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.

Comments

@abocquet
Copy link

abocquet commented Mar 11, 2022

Code

use paste::paste;

enum MyEnum {
    A,
    B,
}

macro_rules! my_macro {
    ($t: ty, $x: ident) => {
        paste! {
            match x {
                [< "MyEnum::" $x>] => "there",
                _ => "world"
            }
        }
    };
}

fn main() {
    let x = MyEnum::A;
    let y = my_macro!(A, x);
    println!("Hello {}", y);
}

Meta

paste crate (imported on top): https://docs.rs/paste/latest/paste/

rustc --version --verbose:

rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-apple-darwin
release: 1.59.0
LLVM version: 13.0.0

The error also occurs in beta and nightly

Error output

thread 'rustc' panicked at '`"MyEnum::x"` is not a valid identifier', compiler/rustc_expand/src/proc_macro_server.rs:337:13
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.59.0 (9d1b2106e 2022-02-23) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
end of query stack
error: `"MyEnum::x"` is not a valid identifier
  --> src/main.rs:12:17
   |
12 |                 [< "MyEnum::" $x>] => "there",
   |                 ^^^^^^^^^^^^^^^^^^
...
20 |     let y = my_macro!(A, x);
   |             --------------- in this macro invocation
   |
   = note: this error originates in the macro `my_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `paste_error` due to previous error
Backtrace

   Compiling paste_error v0.1.0 (/Users/johndoe/paste_error)
thread 'rustc' panicked at '`"MyEnum::x"` is not a valid identifier', compiler/rustc_expand/src/proc_macro_server.rs:337:13
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_expand::proc_macro_server::Ident>::new
   3: std::panic::catch_unwind::<core::panic::unwind_safe::AssertUnwindSafe<<proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<rustc_expand::proc_macro_server::Rustc>> as proc_macro::bridge::server::DispatcherTrait>::dispatch::{closure#33}>, proc_macro::bridge::Marked<rustc_expand::proc_macro_server::Ident, proc_macro::bridge::client::Ident>>
   4: <proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<rustc_expand::proc_macro_server::Rustc>> as proc_macro::bridge::server::DispatcherTrait>::dispatch
   5: <proc_macro::bridge::closure::Closure<_, _> as core::convert::From<&mut _>>::from::call::<proc_macro::bridge::buffer::Buffer<u8>, proc_macro::bridge::buffer::Buffer<u8>, <proc_macro::bridge::server::SameThread as proc_macro::bridge::server::ExecutionStrategy>::run_bridge_and_client<fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream, proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<rustc_expand::proc_macro_server::Rustc>>>::{closure#0}>
   6: proc_macro::bridge::closure::Closure<A,R>::call
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/closure.rs:27:18
   7: proc_macro::bridge::client::Ident::new::{{closure}}
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:244:25
   8: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::with::{{closure}}
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:336:47
   9: proc_macro::bridge::client::BridgeState::with::{{closure}}::{{closure}}
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:293:17
  10: proc_macro::bridge::scoped_cell::ScopedCell<T>::replace
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/scoped_cell.rs:75:9
  11: proc_macro::bridge::client::BridgeState::with::{{closure}}
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:291:13
  12: std::thread::local::LocalKey<T>::try_with
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/thread/local.rs:412:16
  13: std::thread::local::LocalKey<T>::with
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/thread/local.rs:388:9
  14: proc_macro::bridge::client::BridgeState::with
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:290:9
  15: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::with
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:329:9
  16: proc_macro::bridge::client::Ident::new
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:237:17
  17: paste::pasted_to_tokens::{{closure}}
             at /Users/johndoe/.cargo/registry/src/github.com-1ecc6299db9ec823/paste-1.0.6/src/lib.rs:390:46
  18: std::panicking::try::do_call
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:406:40
  19: <unknown>
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/alloc/layout.rs:30:21
  20: std::panicking::try
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:370:19
  21: std::panic::catch_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panic.rs:133:14
  22: paste::pasted_to_tokens
             at /Users/johndoe/.cargo/registry/src/github.com-1ecc6299db9ec823/paste-1.0.6/src/lib.rs:390:23
  23: paste::expand
             at /Users/johndoe/.cargo/registry/src/github.com-1ecc6299db9ec823/paste-1.0.6/src/lib.rs:214:34
  24: paste::expand
             at /Users/johndoe/.cargo/registry/src/github.com-1ecc6299db9ec823/paste-1.0.6/src/lib.rs:227:38
  25: paste::paste
             at /Users/johndoe/.cargo/registry/src/github.com-1ecc6299db9ec823/paste-1.0.6/src/lib.rs:164:11
  26: core::ops::function::FnOnce::call_once
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/ops/function.rs:227:5
  27: proc_macro::bridge::client::Client<fn(proc_macro::TokenStream) .> proc_macro::TokenStream>::expand1::run::{{closure}}
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:410:40
  28: proc_macro::bridge::client::run_client::{{closure}}::{{closure}}
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:377:26
  29: proc_macro::bridge::scoped_cell::ScopedCell<T>::set::{{closure}}
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/scoped_cell.rs:80:33
  30: proc_macro::bridge::scoped_cell::ScopedCell<T>::replace
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/scoped_cell.rs:75:9
  31: proc_macro::bridge::scoped_cell::ScopedCell<T>::set
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/scoped_cell.rs:80:9
  32: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:325:35
  33: std::thread::local::LocalKey<T>::try_with
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/thread/local.rs:412:16
  34: std::thread::local::LocalKey<T>::with
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/thread/local.rs:388:9
  35: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:325:9
  36: proc_macro::bridge::client::run_client::{{closure}}
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:370:9
  37: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panic/unwind_safe.rs:271:9
  38: std::panicking::try::do_call
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:406:40
  39: <unknown>
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/alloc/layout.rs:30:21
  40: std::panicking::try
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:370:19
  41: std::panic::catch_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panic.rs:133:14
  42: proc_macro::bridge::client::run_client
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:369:5
  43: proc_macro::bridge::client::Client<fn(proc_macro::TokenStream) .> proc_macro::TokenStream>::expand1::run
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/proc_macro/src/bridge/client.rs:410:13
  44: proc_macro::bridge::server::run_server::<rustc_expand::proc_macro_server::Rustc, proc_macro::bridge::Marked<rustc_ast::tokenstream::TokenStream, proc_macro::bridge::client::TokenStream>, proc_macro::bridge::Marked<rustc_ast::tokenstream::TokenStream, proc_macro::bridge::client::TokenStream>, fn(proc_macro::TokenStream) -> proc_macro::TokenStream, proc_macro::bridge::server::SameThread>
  45: <rustc_expand::proc_macro::BangProcMacro as rustc_expand::base::ProcMacro>::expand
  46: <rustc_expand::expand::MacroExpander>::fully_expand_fragment
  47: <rustc_expand::expand::MacroExpander>::expand_crate
  48: <rustc_session::session::Session>::time::<core::result::Result<rustc_ast::ast::Crate, rustc_errors::ErrorReported>, rustc_interface::passes::configure_and_expand::{closure#1}>
  49: rustc_interface::passes::configure_and_expand
  50: <rustc_interface::queries::Queries>::expansion
  51: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  52: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  53: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  54: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.59.0 (9d1b2106e 2022-02-23) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
end of query stack
error: `"MyEnum::x"` is not a valid identifier
  --> src/main.rs:12:17
   |
12 |                 [< "MyEnum::" $x>] => "there",
   |                 ^^^^^^^^^^^^^^^^^^
...
20 |     let y = my_macro!(A, x);
   |             --------------- in this macro invocation
   |
   = note: this error originates in the macro `my_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `paste_error` due to previous error

@abocquet abocquet 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 Mar 11, 2022
@abocquet abocquet changed the title ICE: match arm generation using macros + paste! crate ICE: match arm generation using macros + paste crate Mar 11, 2022
@SNCPlay42
Copy link
Contributor

This doesn't ICE on the playground, which makes me suspect this is a duplicate of #59998.

Also FYI the use of paste is not necessary to create a path from :: - separated identifiers, i.e. this works:

enum MyEnum {
    A,
    B,
}

macro_rules! my_macro {
    ($variant:ident, $x:expr) => {
        match $x {
            MyEnum::$variant => "there",
            _ => "world"
        }
    };
}

fn main() {
    let x = MyEnum::A;
    let y = my_macro!(A, x);
    println!("Hello {}", y);
}

@dtolnay
Copy link
Member

dtolnay commented Mar 11, 2022

Closing as a duplicate of #59998.

@dtolnay dtolnay closed this as completed Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

3 participants