Skip to content

[ICE]: macro inside const #153198

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(min_generic_const_args)]
macro_rules! y {
    ( $($matcher:tt)*) => {
        _
    };
}

const y: A<
    {
        y! {
            x

        }
    },
>;

fn y() {}

original:

// Regression test for #131915 where we did not handle macro calls as
// statements correctly when determining if a const argument should
// have a `DefId` created or not.

macro_rules! y {
    ( $($matcher:tt)*) => {
        _
        //~^ ERROR: free constant item without body
    };
}

const y: A<
    //~^ ERROR: free constant item without body
    //~| ERROR: cannot find type `A` in this scope
    {
        y! {
        x
        //~^ ERROR: cannot find value `x` in this scope
    }
    },
>;

fn y() {}

Version information

rustc 1.95.0-nightly (3a70d0349 2026-02-27)
binary: rustc
commit-hash: 3a70d0349fa378a10c3748f1a48742e61505020f
commit-date: 2026-02-27
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0

Possibly related line of code:

}
_ => {}
}
GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
}
ast::GenericArg::Const(ct) => GenericArg::Const(
self.lower_anon_const_to_const_arg_and_alloc(ct).try_as_ambig_ct().unwrap(),
),
}
}
#[instrument(level = "debug", skip(self))]
fn lower_ty_alloc(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(min_generic_const_args)

Program output

error[E0428]: the name `y` is defined multiple times
  --> /tmp/icemaker_global_tempdir.cq95d7U6lefs/rustc_testrunner_tmpdir_reporting.IFiUVm8Brbnr/mvce.rs:16:1
   |
 7 | const y: A<
   | ----------- previous definition of the value `y` here
...
16 | fn y() {}
   | ^^^^^^ `y` redefined here
   |
   = note: `y` must be defined only once in the value namespace of this module

error: free constant item without body
  --> /tmp/icemaker_global_tempdir.cq95d7U6lefs/rustc_testrunner_tmpdir_reporting.IFiUVm8Brbnr/mvce.rs:7:1
   |
 7 | / const y: A<
 8 | |     {
 9 | |         y! {
10 | |             x
...  |
13 | |     },
14 | | >;
   | |  ^ help: provide a definition for the constant: `= <expr>;`
   | |__|
   |

error[E0425]: cannot find type `A` in this scope
 --> /tmp/icemaker_global_tempdir.cq95d7U6lefs/rustc_testrunner_tmpdir_reporting.IFiUVm8Brbnr/mvce.rs:7:10
  |
7 | const y: A<
  |          ^ not found in this scope

warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
 --> <crate attribute>:1:12
  |
1 | #![feature(min_generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
  = note: `#[warn(incomplete_features)]` on by default


thread 'rustc' (1615394) panicked at /rustc-dev/3a70d0349fa378a10c3748f1a48742e61505020f/compiler/rustc_ast_lowering/src/lib.rs:1257:84:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f7113d8edbb - <<std[31ff84e99a7a8ead]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[541fdf89a9632946]::fmt::Display>::fmt
   1:     0x7f7114420308 - core[541fdf89a9632946]::fmt::write
   2:     0x7f7113da5dc6 - <std[31ff84e99a7a8ead]::sys::stdio::unix::Stderr as std[31ff84e99a7a8ead]::io::Write>::write_fmt
   3:     0x7f7113d64e98 - std[31ff84e99a7a8ead]::panicking::default_hook::{closure#0}
   4:     0x7f7113d82223 - std[31ff84e99a7a8ead]::panicking::default_hook
   5:     0x7f7112d64f10 - std[31ff84e99a7a8ead]::panicking::update_hook::<alloc[650d1a802a99d584]::boxed::Box<rustc_driver_impl[d9c9a532171ebae0]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f7113d82502 - std[31ff84e99a7a8ead]::panicking::panic_with_hook
   7:     0x7f7113d64f8a - std[31ff84e99a7a8ead]::panicking::panic_handler::{closure#0}
   8:     0x7f7113d5bc89 - std[31ff84e99a7a8ead]::sys::backtrace::__rust_end_short_backtrace::<std[31ff84e99a7a8ead]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f7113d669bd - __rustc[8af5c0f5c54b39df]::rust_begin_unwind
  10:     0x7f711091b2cc - core[541fdf89a9632946]::panicking::panic_fmt
  11:     0x7f711042c042 - core[541fdf89a9632946]::panicking::panic
  12:     0x7f7110fa4249 - core[541fdf89a9632946]::option::unwrap_failed
  13:     0x7f7114b12aae - <rustc_ast_lowering[2c97d6b2d3e28664]::LoweringContext>::lower_qpath
  14:     0x7f7114b0c4f3 - <rustc_ast_lowering[2c97d6b2d3e28664]::LoweringContext>::lower_ty
  15:     0x7f7114b24bdd - <rustc_ast_lowering[2c97d6b2d3e28664]::LoweringContext>::lower_item_kind
  16:     0x7f71149d4784 - <rustc_ast_lowering[2c97d6b2d3e28664]::item::ItemLowerer>::lower_node
  17:     0x7f71149d317b - rustc_ast_lowering[2c97d6b2d3e28664]::lower_to_hir
  18:     0x7f7115685ce0 - rustc_query_impl[10c474e00055ca18]::query_impl::hir_crate::invoke_provider_fn::__rust_begin_short_backtrace
  19:     0x7f711568102e - rustc_query_impl[10c474e00055ca18]::execution::try_execute_query::<rustc_middle[f47881f46f7915ce]::query::caches::SingleCache<rustc_middle[f47881f46f7915ce]::query::erase::ErasedData<[u8; 8usize]>>, false>
  20:     0x7f7115680c8f - rustc_query_impl[10c474e00055ca18]::query_impl::hir_crate::execute_query_non_incr::__rust_end_short_backtrace
  21:     0x7f71145682b9 - rustc_query_impl[10c474e00055ca18]::query_impl::opt_hir_owner_nodes::invoke_provider_fn::__rust_begin_short_backtrace
  22:     0x7f711456748a - rustc_query_impl[10c474e00055ca18]::execution::try_execute_query::<rustc_data_structures[6b769a1dd6b8c594]::vec_cache::VecCache<rustc_span[99e019a6fa3a3929]::def_id::LocalDefId, rustc_middle[f47881f46f7915ce]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[f47881f46f7915ce]::dep_graph::graph::DepNodeIndex>, false>
  23:     0x7f7114567105 - rustc_query_impl[10c474e00055ca18]::query_impl::opt_hir_owner_nodes::execute_query_non_incr::__rust_end_short_backtrace
  24:     0x7f7114c2f126 - <rustc_middle[f47881f46f7915ce]::ty::context::TyCtxt>::hir_owner_node
  25:     0x7f71156870d7 - rustc_middle[f47881f46f7915ce]::hir::map::hir_crate_items
  26:     0x7f71156845dd - rustc_query_impl[10c474e00055ca18]::query_impl::hir_crate_items::invoke_provider_fn::__rust_begin_short_backtrace
  27:     0x7f711568102e - rustc_query_impl[10c474e00055ca18]::execution::try_execute_query::<rustc_middle[f47881f46f7915ce]::query::caches::SingleCache<rustc_middle[f47881f46f7915ce]::query::erase::ErasedData<[u8; 8usize]>>, false>
  28:     0x7f7115680839 - rustc_query_impl[10c474e00055ca18]::query_impl::hir_crate_items::execute_query_non_incr::__rust_end_short_backtrace
  29:     0x7f7114563dd8 - rustc_interface[4731d672126a0531]::passes::analysis
  30:     0x7f711567fd1a - rustc_query_impl[10c474e00055ca18]::execution::try_execute_query::<rustc_middle[f47881f46f7915ce]::query::caches::SingleCache<rustc_middle[f47881f46f7915ce]::query::erase::ErasedData<[u8; 0usize]>>, false>
  31:     0x7f711567fae9 - rustc_query_impl[10c474e00055ca18]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  32:     0x7f711565e1ad - rustc_interface[4731d672126a0531]::interface::run_compiler::<(), rustc_driver_impl[d9c9a532171ebae0]::run_compiler::{closure#0}>::{closure#1}
  33:     0x7f71156442be - std[31ff84e99a7a8ead]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4731d672126a0531]::util::run_in_thread_with_globals<rustc_interface[4731d672126a0531]::util::run_in_thread_pool_with_globals<rustc_interface[4731d672126a0531]::interface::run_compiler<(), rustc_driver_impl[d9c9a532171ebae0]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  34:     0x7f7115644920 - <std[31ff84e99a7a8ead]::thread::lifecycle::spawn_unchecked<rustc_interface[4731d672126a0531]::util::run_in_thread_with_globals<rustc_interface[4731d672126a0531]::util::run_in_thread_pool_with_globals<rustc_interface[4731d672126a0531]::interface::run_compiler<(), rustc_driver_impl[d9c9a532171ebae0]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[541fdf89a9632946]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7f71156457ac - <std[31ff84e99a7a8ead]::sys::thread::unix::Thread>::new::thread_start
  36:     0x7f710f0a598b - <unknown>
  37:     0x7f710f129a0c - <unknown>
  38:                0x0 - <unknown>

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: rustc 1.95.0-nightly (3a70d0349 2026-02-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(min_generic_const_args) -Z dump-mir-dir=dir

query stack during panic:
#0 [hir_crate] getting the crate HIR
#1 [opt_hir_owner_nodes] getting HIR owner items in ``
#2 [hir_crate_items] getting HIR crate items
#3 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

Some errors have detailed explanations: E0425, E0428.
For more information about an error, try `rustc --explain E0425`.

@rustbot label +F-min_generic_const_args

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-min_generic_const_args`#![feature(min_generic_const_args)]`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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions