Skip to content

ICE: None in compiler/rustc_builtin_macros/src/cfg_eval.rs #148891

Description

@cushionbadak

Code

pub struct Char3(pub [i8; 3]);

macro_rules! values {
    ($($token:ident($value:literal) $(as $inner:ty)? => $attr:meta,)*) => {
        #[derive(Debug)]
        pub enum TokenKind {
            $(
                #[$attr]
                $token $(Char3([$inner, -3, $inner]))? = $value,
            )*
        }
    };
}

values!(STRING(1) as (String) => cfg(test),);

pub fn main() {}

A mutant of glacier2's fixed/96818.rs

Meta

rustc --version --verbose:

rustc 1.93.0-nightly (01867557c 2025-11-12)
binary: rustc
commit-hash: 01867557cd7dbe256a031a7b8e28d05daecd75ab
commit-date: 2025-11-12
host: x86_64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.5

Error output

Command: rustc

error: expected `;` or `]`, found `,`
  --> 04.rs:9:39
   |
 6 |         pub enum TokenKind {
   |                  --------- while parsing this enum
...
 9 |                 $token $(Char3([$inner, -3, $inner]))? = $value,
   |                                       ^ expected `;` or `]`
...
15 | values!(STRING(1) as (String) => cfg(test),);
   | -------------------------------------------- in this macro invocation
   |
   = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
   = note: this error originates in the macro `values` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected one of `(`, `,`, `=`, `{`, or `}`, found `Char3`
  --> 04.rs:9:26
   |
 9 |                 $token $(Char3([$inner, -3, $inner]))? = $value,
   |                       -  ^^^^^ expected one of `(`, `,`, `=`, `{`, or `}`
   |                       |
   |                       help: missing `,`
...
15 | values!(STRING(1) as (String) => cfg(test),);
   | -------------------------------------------- in this macro invocation
   |
   = note: this error originates in the macro `values` (in Nightly builds, run with -Z macro-backtrace for more info)

error: macro expansion ignores `)` and any tokens following
  --> 04.rs:9:52
   |
 9 |                 $token $(Char3([$inner, -3, $inner]))? = $value,
   |                                                    ^
...
15 | values!(STRING(1) as (String) => cfg(test),);
   | -------------------------------------------- caused by the macro expansion here
   |
   = note: the usage of `values!` is likely invalid in item context


thread 'rustc' (303421) panicked at compiler/rustc_builtin_macros/src/cfg_eval.rs:116:70:
called `Option::unwrap()` on a `None` value
Backtrace

thread 'rustc' (303421) panicked at compiler/rustc_builtin_macros/src/cfg_eval.rs:116:70:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: core::option::unwrap_failed
   4: rustc_builtin_macros::cfg_eval::cfg_eval
   5: <rustc_builtin_macros::derive::Expander as rustc_expand::base::MultiItemModifier>::expand::{closure#0}
   6: <rustc_resolve::Resolver as rustc_expand::base::ResolverExpand>::resolve_derives
   7: <rustc_builtin_macros::derive::Expander as rustc_expand::base::MultiItemModifier>::expand
   8: <rustc_expand::expand::MacroExpander>::expand_invoc
   9: <rustc_expand::expand::MacroExpander>::fully_expand_fragment
  10: <rustc_expand::expand::MacroExpander>::expand_crate
  11: rustc_interface::passes::configure_and_expand
  12: rustc_interface::passes::resolver_for_lowering_raw
      [... omitted 2 frames ...]
  13: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  14: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: 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: please make sure that you have updated to the latest nightly

note: please attach the file at `/Users/jb/Library/CloudStorage/Dropbox/Desk/2503_rustc_ice/251109 ice 보고용/rustc-ice-2025-11-13T04_40_58-76926.txt` to your bug report

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack
error: aborting due to 3 previous errors

Notes

  • ICE location: compiler/rustc_builtin_macros/src/cfg_eval.rs Line-116
    let mut parser = Parser::new(&self.0.sess.psess, orig_tokens, None);
    parser.capture_cfg = true;
    let res: PResult<'_, Annotatable> = try {
    match annotatable {
    Annotatable::Item(_) => {
    let item = parser.parse_item(ForceCollect::Yes)?.unwrap();
    Annotatable::Item(self.flat_map_item(item).pop().unwrap())
    }
    Annotatable::AssocItem(_, ctxt) => {

Duplication Check

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions