Skip to content

[ICE]: mir_const_qualif should only be called on const fns and const items #153891

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

trait Tr {
    const fn test() {
        (const || {})()
    }
}

original:

#![feature(const_closures)]
trait Tr {
  const fn test() { (const || {})() }
}

fn main() {}

Version information

rustc 1.96.0-nightly (35f1109ec 2026-03-14)
binary: rustc
commit-hash: 35f1109ece895199e4b8d755b101e9a481d18243
commit-date: 2026-03-14
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

Possibly related line of code:

// performing the steal.
let body = &tcx.mir_built(def).borrow();
let ccx = check_consts::ConstCx::new(tcx, body);
// No need to const-check a non-const `fn`.
match ccx.const_kind {
Some(ConstContext::Const { .. } | ConstContext::Static(_) | ConstContext::ConstFn) => {}
None => span_bug!(
tcx.def_span(def),
"`mir_const_qualif` should only be called on const fns and const items"
),
}
if body.return_ty().references_error() {

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0379]: functions in traits cannot be declared const
 --> /tmp/icemaker_global_tempdir.n0SNzQ7KNFjU/rustc_testrunner_tmpdir_reporting.fXzkkXSIWyr5/mvce.rs:2:5
  |
2 |     const fn test() {
  |     ^^^^^-
  |     |
  |     functions in traits cannot be const
  |     help: remove the `const`

error[E0658]: const closures are experimental
 --> /tmp/icemaker_global_tempdir.n0SNzQ7KNFjU/rustc_testrunner_tmpdir_reporting.fXzkkXSIWyr5/mvce.rs:3:10
  |
3 |         (const || {})()
  |          ^^^^^
  |
  = note: see issue #106003 <https://github.com/rust-lang/rust/issues/106003> for more information
  = help: add `#![feature(const_closures)]` to the crate attributes to enable
  = note: this compiler was built on 2026-03-14; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.n0SNzQ7KNFjU/rustc_testrunner_tmpdir_reporting.fXzkkXSIWyr5/mvce.rs:5:2
  |
5 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.n0SNzQ7KNFjU/rustc_testrunner_tmpdir_reporting.fXzkkXSIWyr5/mvce.rs`

error: internal compiler error: /rustc-dev/35f1109ece895199e4b8d755b101e9a481d18243/compiler/rustc_mir_transform/src/lib.rs:366:17: `mir_const_qualif` should only be called on const fns and const items
 --> /tmp/icemaker_global_tempdir.n0SNzQ7KNFjU/rustc_testrunner_tmpdir_reporting.fXzkkXSIWyr5/mvce.rs:3:10
  |
3 |         (const || {})()
  |          ^^^^^^^^


thread 'rustc' (541342) panicked at /rustc-dev/35f1109ece895199e4b8d755b101e9a481d18243/compiler/rustc_mir_transform/src/lib.rs:366:17:
Box<dyn Any>
stack backtrace:
   0:     0x7f5b99d213eb - <<std[61fe9fb7598c59ec]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[4d6fecf5427e9877]::fmt::Display>::fmt
   1:     0x7f5b9a41d688 - core[4d6fecf5427e9877]::fmt::write
   2:     0x7f5b99d383f6 - <std[61fe9fb7598c59ec]::sys::stdio::unix::Stderr as std[61fe9fb7598c59ec]::io::Write>::write_fmt
   3:     0x7f5b99cf74d8 - std[61fe9fb7598c59ec]::panicking::default_hook::{closure#0}
   4:     0x7f5b99d14863 - std[61fe9fb7598c59ec]::panicking::default_hook
   5:     0x7f5b98d1097c - std[61fe9fb7598c59ec]::panicking::update_hook::<alloc[f42d5cfb2491bc0e]::boxed::Box<rustc_driver_impl[4f72d89ade9facad]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f5b99d14b42 - std[61fe9fb7598c59ec]::panicking::panic_with_hook
   7:     0x7f5b98d40001 - std[61fe9fb7598c59ec]::panicking::begin_panic::<rustc_errors[134bc766e4a63093]::ExplicitBug>::{closure#0}
   8:     0x7f5b98d38bd6 - std[61fe9fb7598c59ec]::sys::backtrace::__rust_end_short_backtrace::<std[61fe9fb7598c59ec]::panicking::begin_panic<rustc_errors[134bc766e4a63093]::ExplicitBug>::{closure#0}, !>
   9:     0x7f5b98d38a4b - std[61fe9fb7598c59ec]::panicking::begin_panic::<rustc_errors[134bc766e4a63093]::ExplicitBug>
  10:     0x7f5b98d4b671 - <rustc_errors[134bc766e4a63093]::diagnostic::BugAbort as rustc_errors[134bc766e4a63093]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f5b9930142c - <rustc_errors[134bc766e4a63093]::DiagCtxtHandle>::span_bug::<rustc_span[32b7adb4652d268b]::span_encoding::Span, alloc[f42d5cfb2491bc0e]::string::String>
  12:     0x7f5b99328b06 - rustc_middle[a02619f756b66d19]::util::bug::opt_span_bug_fmt::<rustc_span[32b7adb4652d268b]::span_encoding::Span>::{closure#0}
  13:     0x7f5b99328cb2 - rustc_middle[a02619f756b66d19]::ty::context::tls::with_opt::<rustc_middle[a02619f756b66d19]::util::bug::opt_span_bug_fmt<rustc_span[32b7adb4652d268b]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f5b9931978b - rustc_middle[a02619f756b66d19]::ty::context::tls::with_context_opt::<rustc_middle[a02619f756b66d19]::ty::context::tls::with_opt<rustc_middle[a02619f756b66d19]::util::bug::opt_span_bug_fmt<rustc_span[32b7adb4652d268b]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f5b97698dc8 - rustc_middle[a02619f756b66d19]::util::bug::span_bug_fmt::<rustc_span[32b7adb4652d268b]::span_encoding::Span>
  16:     0x7f5b9b3718d7 - rustc_mir_transform[9a5d8df70c249596]::mir_const_qualif
  17:     0x7f5b9ad78d09 - rustc_query_impl[93b176b1fd053a9]::execution::try_execute_query::<rustc_middle[a02619f756b66d19]::query::caches::DefIdCache<rustc_middle[a02619f756b66d19]::query::erase::ErasedData<[u8; 4usize]>>, false>
  18:     0x7f5b9ad78a40 - rustc_query_impl[93b176b1fd053a9]::query_impl::mir_const_qualif::execute_query_non_incr::__rust_end_short_backtrace
  19:     0x7f5b9ae6fbe2 - rustc_mir_transform[9a5d8df70c249596]::mir_promoted
  20:     0x7f5b9ae6e8d2 - rustc_query_impl[93b176b1fd053a9]::query_impl::mir_promoted::invoke_provider_fn::__rust_begin_short_backtrace
  21:     0x7f5b9ac992b9 - rustc_query_impl[93b176b1fd053a9]::execution::try_execute_query::<rustc_data_structures[56575bac38d6f7b0]::vec_cache::VecCache<rustc_span[32b7adb4652d268b]::def_id::LocalDefId, rustc_middle[a02619f756b66d19]::query::erase::ErasedData<[u8; 16usize]>, rustc_middle[a02619f756b66d19]::dep_graph::graph::DepNodeIndex>, false>
  22:     0x7f5b9ac98e4b - rustc_query_impl[93b176b1fd053a9]::query_impl::mir_promoted::execute_query_non_incr::__rust_end_short_backtrace
  23:     0x7f5b9b3cb5fa - <rustc_borrowck[9c30ced49c092f0]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  24:     0x7f5b9b3c546f - rustc_borrowck[9c30ced49c092f0]::mir_borrowck
  25:     0x7f5b9b3c52a5 - rustc_query_impl[93b176b1fd053a9]::query_impl::mir_borrowck::invoke_provider_fn::__rust_begin_short_backtrace
  26:     0x7f5b9a548ee6 - rustc_query_impl[93b176b1fd053a9]::execution::try_execute_query::<rustc_data_structures[56575bac38d6f7b0]::vec_cache::VecCache<rustc_span[32b7adb4652d268b]::def_id::LocalDefId, rustc_middle[a02619f756b66d19]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[a02619f756b66d19]::dep_graph::graph::DepNodeIndex>, false>
  27:     0x7f5b9a54afc9 - rustc_query_impl[93b176b1fd053a9]::query_impl::mir_borrowck::execute_query_non_incr::__rust_end_short_backtrace
  28:     0x7f5b9a54b194 - <rustc_middle[a02619f756b66d19]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[5823a45d1c8a071a]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  29:     0x7f5b9a54a733 - rustc_interface[5823a45d1c8a071a]::passes::analysis
  30:     0x7f5b9b628e49 - rustc_query_impl[93b176b1fd053a9]::execution::try_execute_query::<rustc_middle[a02619f756b66d19]::query::caches::SingleCache<rustc_middle[a02619f756b66d19]::query::erase::ErasedData<[u8; 0usize]>>, false>
  31:     0x7f5b9b628ab5 - rustc_query_impl[93b176b1fd053a9]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  32:     0x7f5b9b5d2838 - rustc_interface[5823a45d1c8a071a]::interface::run_compiler::<(), rustc_driver_impl[4f72d89ade9facad]::run_compiler::{closure#0}>::{closure#1}
  33:     0x7f5b9b6073fe - std[61fe9fb7598c59ec]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5823a45d1c8a071a]::util::run_in_thread_with_globals<rustc_interface[5823a45d1c8a071a]::util::run_in_thread_pool_with_globals<rustc_interface[5823a45d1c8a071a]::interface::run_compiler<(), rustc_driver_impl[4f72d89ade9facad]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  34:     0x7f5b9b607ca0 - <std[61fe9fb7598c59ec]::thread::lifecycle::spawn_unchecked<rustc_interface[5823a45d1c8a071a]::util::run_in_thread_with_globals<rustc_interface[5823a45d1c8a071a]::util::run_in_thread_pool_with_globals<rustc_interface[5823a45d1c8a071a]::interface::run_compiler<(), rustc_driver_impl[4f72d89ade9facad]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[4d6fecf5427e9877]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7f5b9b608b2c - <std[61fe9fb7598c59ec]::sys::thread::unix::Thread>::new::thread_start
  36:     0x7f5b950a597a - <unknown>
  37:     0x7f5b951292bc - <unknown>
  38:                0x0 - <unknown>

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.96.0-nightly (35f1109ec 2026-03-14) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_const_qualif] const checking `Tr::test::{closure#0}`
#1 [mir_promoted] promoting constants in MIR for `Tr::test::{closure#0}`
#2 [mir_borrowck] borrow-checking `Tr::test`
#3 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0379, E0601, E0658.
For more information about an error, try `rustc --explain E0379`.

@rustbot label +F-const_closures

Metadata

Metadata

Assignees

No one assigned

    Labels

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