Skip to content

ICE: loop match: broken mir encountered 'Assign' statement with overlapping memory #143806

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -Zlint-mir
#![feature(loop_match)]

fn main() {}

fn helper() -> u8 {
    let mut state = 0u8;
    #[loop_match]
    'a: loop {
        state = 'blk: {
            match state {
                _ => break 'blk state,
            }
        }
    }
}

original:

#![feature(loop_match)]

fn main() {
    assert_eq!(helper(), 1);
}

fn helper() -> u8 {
    let mut state = 0u8;
    #[loop_match]
    'a: loop {
        state = 'blk: {
            match state {
                0 => break 'blk 1,
                _ => break 'blk state,
            }
        }
    }
}

Version information

rustc 1.90.0-nightly (855e0fe46 2025-07-11)
binary: rustc
commit-hash: 855e0fe46e68d94e9f6147531b75ac2d488c548e
commit-date: 2025-07-11
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zlint-mir

Program output

warning: the feature `loop_match` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs: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.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:8:5
  |
8 |     'a: loop {
  |     ^^
  |
  = note: `#[warn(unused_labels)]` on by default

warning: function `helper` is never used
 --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:5:4
  |
5 | fn helper() -> u8 {
  |    ^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 3 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 Item(DefId(0:4 ~ mvce[77c1]::helper)) (after pass CheckForceInline) at bb2[0]:
                                encountered `Assign` statement with overlapping memory
  --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:11:33
   |
11 |                 _ => break 'blk state,
   |                                 ^^^^^
   |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:86:30
         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_mir_transform::lint::Lint>::fail::<&str>
         5: <rustc_mir_transform::lint::Lint as rustc_middle::mir::visit::Visitor>::visit_statement
         6: rustc_mir_transform::lint::lint_body
         7: rustc_mir_transform::mir_built
         8: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_built::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_built::get_query_non_incr::__rust_end_short_backtrace
        11: rustc_mir_build::check_unsafety::check_unsafety
        12: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        13: 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; 0]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        14: rustc_query_impl::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
        15: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
        16: rustc_interface::passes::analysis
        17: 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]>>
        18: 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>
        19: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        20: 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}
        21: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        22: 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}, ()>
        23: <<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}
        24: std::sys::pal::unix::thread::Thread::new::thread_start
        25: <unknown>
        26: <unknown>
  --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:11:33
   |
11 |                 _ => break 'blk state,
   |                                 ^^^^^

error: internal compiler error: broken MIR in Item(DefId(0:4 ~ mvce[77c1]::helper)) (after pass CheckCallRecursion) at bb2[0]:
                                encountered `Assign` statement with overlapping memory
  --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:11:33
   |
11 |                 _ => break 'blk state,
   |                                 ^^^^^
   |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:86:30
         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_mir_transform::lint::Lint>::fail::<&str>
         5: <rustc_mir_transform::lint::Lint as rustc_middle::mir::visit::Visitor>::visit_statement
         6: rustc_mir_transform::lint::lint_body
         7: rustc_mir_transform::mir_built
         8: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_built::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_built::get_query_non_incr::__rust_end_short_backtrace
        11: rustc_mir_build::check_unsafety::check_unsafety
        12: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        13: 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; 0]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        14: rustc_query_impl::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
        15: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
        16: rustc_interface::passes::analysis
        17: 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]>>
        18: 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>
        19: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        20: 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}
        21: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        22: 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}, ()>
        23: <<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}
        24: std::sys::pal::unix::thread::Thread::new::thread_start
        25: <unknown>
        26: <unknown>
  --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:11:33
   |
11 |                 _ => break 'blk state,
   |                                 ^^^^^

error: internal compiler error: broken MIR in Item(DefId(0:4 ~ mvce[77c1]::helper)) (after pass CheckPackedRef) at bb2[0]:
                                encountered `Assign` statement with overlapping memory
  --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:11:33
   |
11 |                 _ => break 'blk state,
   |                                 ^^^^^
   |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:86:30
         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_mir_transform::lint::Lint>::fail::<&str>
         5: <rustc_mir_transform::lint::Lint as rustc_middle::mir::visit::Visitor>::visit_statement
         6: rustc_mir_transform::lint::lint_body
         7: rustc_mir_transform::mir_built
         8: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_built::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_built::get_query_non_incr::__rust_end_short_backtrace
        11: rustc_mir_build::check_unsafety::check_unsafety
        12: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        13: 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; 0]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        14: rustc_query_impl::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
        15: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
        16: rustc_interface::passes::analysis
        17: 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]>>
        18: 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>
        19: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        20: 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}
        21: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        22: 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}, ()>
        23: <<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}
        24: std::sys::pal::unix::thread::Thread::new::thread_start
        25: <unknown>
        26: <unknown>
  --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:11:33
   |
11 |                 _ => break 'blk state,
   |                                 ^^^^^



< snip > 


  --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:11:33
   |
11 |                 _ => break 'blk state,
   |                                 ^^^^^

error: internal compiler error: broken MIR in Item(DefId(0:4 ~ mvce[77c1]::helper)) (after phase change to runtime-post-cleanup) at bb1[0]:
                                encountered `Assign` statement with overlapping memory
  --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:11:33
   |
11 |                 _ => break 'blk state,
   |                                 ^^^^^
   |
note: delayed at compiler/rustc_mir_transform/src/lint.rs:86:30
         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_mir_transform::lint::Lint>::fail::<&str>
         5: <rustc_mir_transform::lint::Lint as rustc_middle::mir::visit::Visitor>::visit_statement
         6: rustc_mir_transform::lint::lint_body
         7: rustc_mir_transform::run_analysis_to_runtime_passes
         8: rustc_mir_transform::mir_drops_elaborated_and_const_checked
         9: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        10: 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>
        11: rustc_query_impl::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
        12: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
        13: rustc_interface::passes::analysis
        14: 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]>>
        15: 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>
        16: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        17: 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}
        18: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        19: 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}, ()>
        20: <<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}
        21: std::sys::pal::unix::thread::Thread::new::thread_start
        22: <unknown>
        23: <unknown>
  --> /tmp/icemaker_global_tempdir.7LzmHSjvI9Dm/rustc_testrunner_tmpdir_reporting.0dtkccEbh5V9/mvce.rs:11:33
   |
11 |                 _ => break 'blk state,
   |                                 ^^^^^

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 (855e0fe46 2025-07-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z lint-mir -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
    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