Skip to content

ICE: loop match: broken MIR: bad assignment #144492

@matthiaskrgr

Description

@matthiaskrgr

snippet:

#![feature(loop_match)]
#![crate_type = "lib"]

fn test(mut state: u8) {
    #[loop_match]
    loop {
        state = 'blk: {
            match state {
                ARRAY => dbg!(ARRAY),
            }
        }
    }
}

Version information

rustc 1.90.0-nightly (f32b23204 2025-07-26)
binary: rustc
commit-hash: f32b23204a0efe2fe8383ed4be1a30b56c1bbf94
commit-date: 2025-07-26
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

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

Program output

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

warning: unused label
 --> /tmp/icemaker_global_tempdir.Mh0izylGtxSo/rustc_testrunner_tmpdir_reporting.mzbHvU9juaja/mvce.rs:6:17
  |
6 |         state = 'blk: {
  |                 ^^^^
  |
  = note: `#[warn(unused_labels)]` on by default

warning: variable does not need to be mutable
 --> /tmp/icemaker_global_tempdir.Mh0izylGtxSo/rustc_testrunner_tmpdir_reporting.mzbHvU9juaja/mvce.rs:3:9
  |
3 | fn test(mut state: u8) {
  |         ----^^^^^
  |         |
  |         help: remove this `mut`
  |
  = note: `#[warn(unused_mut)]` on by default

warning: function `test` is never used
 --> /tmp/icemaker_global_tempdir.Mh0izylGtxSo/rustc_testrunner_tmpdir_reporting.mzbHvU9juaja/mvce.rs:3:4
  |
3 | fn test(mut state: u8) {
  |    ^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: variable `ARRAY` should have a snake case name
 --> /tmp/icemaker_global_tempdir.Mh0izylGtxSo/rustc_testrunner_tmpdir_reporting.mzbHvU9juaja/mvce.rs:8:17
  |
8 |                 ARRAY => dbg!(ARRAY),
  |                 ^^^^^ help: convert the identifier to snake case: `array`
  |
  = note: `#[warn(non_snake_case)]` on by default

warning: 5 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: broken MIR in DefId(0:3 ~ mvce[7ffe]::test) (_2 = copy _4): bad assignment (! = u8): NoSolution
 --> /tmp/icemaker_global_tempdir.Mh0izylGtxSo/rustc_testrunner_tmpdir_reporting.mzbHvU9juaja/mvce.rs:8:26
  |
8 |                 ARRAY => dbg!(ARRAY),
  |                          ^^^^^^^^^^^
  |
note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:662:21
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         4: <rustc_borrowck::type_check::TypeChecker as rustc_middle::mir::visit::Visitor>::visit_body
         5: rustc_borrowck::type_check::type_check
         6: rustc_borrowck::do_mir_borrowck
         7: rustc_borrowck::mir_borrowck
         8: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        10: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
        11: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
        12: rustc_interface::passes::analysis
        13: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        15: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        16: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
        17: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        18: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        19: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        20: std::sys::pal::unix::thread::Thread::new::thread_start
        21: <unknown>
        22: <unknown>
 --> /tmp/icemaker_global_tempdir.Mh0izylGtxSo/rustc_testrunner_tmpdir_reporting.mzbHvU9juaja/mvce.rs:8:26
  |
8 |                 ARRAY => dbg!(ARRAY),
  |                          ^^^^^^^^^^^
  = note: this error: internal compiler error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)

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.90.0-nightly (f32b23204 2025-07-26) running on x86_64-unknown-linux-gnu

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

query stack during panic:
end of query stack

@rustbot label +F-loop_match

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-loop_matchwhen you match up with someone and they really throw you for a loopI-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