Skip to content

ICE loop match: None in compiler/rustc_mir_build/src/builder/scope.rs #144051

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

fn unsupported_type() {
    let mut state = 0;

    'a: loop {
        || {
            #[loop_match]
            'a: loop {
                state = 'blk: {
                    match state {
                        -1 => {
                            #[const_continue]
                            break 'blk 2;
                        }

                        _ => unreachable!("weird value {:?}", state),
                    }
                }
            }

            state
        };
    }
}

original:

// Test that the right error is emitted when the `#[loop_match]` state is an
// unsupported type.

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

fn unsupported_type() {
    let mut state = 0;
    #[loop_match]
    'a: loop {
    #[inline(never)] //~ ERROR should be applied to a loop
    #[const_continue] //~ ERROR should be applied to a break expression
    || {
    #[loop_match]
    'a: loop {
        state = 'blk: {
            match state {
                -1 => {
                    #[const_continue]
                    break 'blk 2;
                }
                0 => {
                    #[const_continue]
                    break 'blk -1;
                }
                2 => break 'a,
                _ => unreachable!("weird value {:?}", state),
            }
        }
    }

    state
};

    {
        #[repr(C)] //~ ERROR should be applied to a loop
        #[const_continue] //~ ERROR should be applied to a break expression
        5
    };
}
}

Version information

rustc 1.90.0-nightly (014bd8290 2025-07-17)
binary: rustc
commit-hash: 014bd8290f084c714995205a9116e6c035419ae6
commit-date: 2025-07-17
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

Possibly related line of code:

.iter()
.rposition(|const_continuable_scope| const_continuable_scope.region_scope == scope)
.unwrap_or_else(|| span_bug!(span, "no enclosing const-continuable scope found"));
let scope = &self.scopes.const_continuable_scopes[break_index];
let state_decl = &self.local_decls[scope.state_place.as_local().unwrap()];
let state_ty = state_decl.ty;
let (discriminant_ty, rvalue) = match state_ty.kind() {
ty::Adt(adt_def, _) if adt_def.is_enum() => {
(state_ty.discriminant_ty(self.tcx), Rvalue::Discriminant(scope.state_place))
}
ty::Uint(_) | ty::Int(_) | ty::Float(_) | ty::Bool | ty::Char => {

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

Program output

error[E0658]: the `#[loop_match]` attribute is an experimental feature
 --> /tmp/icemaker_global_tempdir.GMTN35g214QG/rustc_testrunner_tmpdir_reporting.9UjlcKRKmu2D/mvce.rs:6:13
  |
6 |             #[loop_match]
  |             ^^^^^^^^^^^^^
  |
  = note: see issue #132306 <https://github.com/rust-lang/rust/issues/132306> for more information
  = help: add `#![feature(loop_match)]` to the crate attributes to enable
  = note: this compiler was built on 2025-07-17; consider upgrading it if it is out of date

error[E0658]: the `#[const_continue]` attribute is an experimental feature
  --> /tmp/icemaker_global_tempdir.GMTN35g214QG/rustc_testrunner_tmpdir_reporting.9UjlcKRKmu2D/mvce.rs:11:29
   |
11 | ...                   #[const_continue]
   |                       ^^^^^^^^^^^^^^^^^
   |
   = note: see issue #132306 <https://github.com/rust-lang/rust/issues/132306> for more information
   = help: add `#![feature(loop_match)]` to the crate attributes to enable
   = note: this compiler was built on 2025-07-17; consider upgrading it if it is out of date

warning: unused label
 --> /tmp/icemaker_global_tempdir.GMTN35g214QG/rustc_testrunner_tmpdir_reporting.9UjlcKRKmu2D/mvce.rs:4:5
  |
4 |     'a: loop {
  |     ^^
  |
  = note: `#[warn(unused_labels)]` on by default

warning: unused label
 --> /tmp/icemaker_global_tempdir.GMTN35g214QG/rustc_testrunner_tmpdir_reporting.9UjlcKRKmu2D/mvce.rs:7:13
  |
7 |             'a: loop {
  |             ^^

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

warning: unreachable expression
  --> /tmp/icemaker_global_tempdir.GMTN35g214QG/rustc_testrunner_tmpdir_reporting.9UjlcKRKmu2D/mvce.rs:20:13
   |
7  | /             'a: loop {
8  | |                 state = 'blk: {
9  | |                     match state {
10 | |                         -1 => {
...  |
18 | |             }
   | |_____________- any code following this expression is unreachable
19 |
20 |               state
   |               ^^^^^ unreachable expression
   |
   = note: `#[warn(unreachable_code)]` on by default


thread 'rustc' panicked at compiler/rustc_mir_build/src/builder/scope.rs:902:73:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7c98b17e2293 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h0b28cdcfe78a5ed3
   1:     0x7c98b2002877 - core::fmt::write::hbea9847360c231be
   2:     0x7c98b17d7ed3 - std::io::Write::write_fmt::hf711e490e13f00b9
   3:     0x7c98b17e20f2 - std::sys::backtrace::BacktraceLock::print::h4d82bcc7f74e1ec5
   4:     0x7c98b17e5b97 - std::panicking::default_hook::{{closure}}::hd61b8464e725f852
   5:     0x7c98b17e56fb - std::panicking::default_hook::h87cb98537b3cffb8
   6:     0x7c98b087bf83 - std[e5f5c135a89762ee]::panicking::update_hook::<alloc[3c5006027e39d139]::boxed::Box<rustc_driver_impl[a76be0c1fdc9e07a]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7c98b17e63de - std::panicking::rust_panic_with_hook::h4cd7989e10b76f46
   8:     0x7c98b17e60a6 - std::panicking::begin_panic_handler::{{closure}}::h47a4dc5160afbc0a
   9:     0x7c98b17e2769 - std::sys::backtrace::__rust_end_short_backtrace::heeea59ebc1b8935f
  10:     0x7c98b17e5dbd - __rustc[47d9f7d1488e7ed5]::rust_begin_unwind
  11:     0x7c98adecbb60 - core::panicking::panic_fmt::h742212fe4d5ce251
  12:     0x7c98ae01c28c - core::panicking::panic::h898b2fade62ed74a
  13:     0x7c98adecd599 - core::option::unwrap_failed::hb4bec956bfc85846
  14:     0x7c98b25c5cee - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::stmt_expr
  15:     0x7c98b25c374e - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::stmt_expr
  16:     0x7c98b2ff4910 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::ast_block_stmts
  17:     0x7c98b2ff3c05 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::ast_block
  18:     0x7c98b25ae983 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::expr_into_dest
  19:     0x7c98b25a1267 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::as_temp::{closure#0}
  20:     0x7c98b25af92a - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::expr_into_dest
  21:     0x7c98b25ae0e1 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::expr_into_dest
  22:     0x7c98b25be6ff - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::lower_match_arms
  23:     0x7c98b0f2eaf3 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::in_breakable_scope::<<rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::expr_into_dest::{closure#4}>
  24:     0x7c98b25b6d66 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::expr_into_dest
  25:     0x7c98b25a1267 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::as_temp::{closure#0}
  26:     0x7c98b25af92a - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::expr_into_dest
  27:     0x7c98b25a1267 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::as_temp::{closure#0}
  28:     0x7c98b25c3872 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::stmt_expr
  29:     0x7c98b25c374e - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::stmt_expr
  30:     0x7c98b2ff4910 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::ast_block_stmts
  31:     0x7c98b2ff3c05 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::ast_block
  32:     0x7c98b25ae983 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::expr_into_dest
  33:     0x7c98b25ae0e1 - <rustc_mir_build[1f2b9a1109db338f]::builder::Builder>::expr_into_dest
  34:     0x7c98b25c9464 - rustc_mir_build[1f2b9a1109db338f]::builder::build_mir
  35:     0x7c98b2008546 - rustc_mir_transform[3ceaf87cab08db3e]::mir_built
  36:     0x7c98b2008517 - rustc_query_impl[492fefb9a5fae053]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[492fefb9a5fae053]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4ee2656344169b3]::query::erase::Erased<[u8; 8usize]>>
  37:     0x7c98b225f56e - rustc_query_system[438c9ee495de13ef]::query::plumbing::try_execute_query::<rustc_query_impl[492fefb9a5fae053]::DynamicConfig<rustc_data_structures[d0add7e5346d7c92]::vec_cache::VecCache<rustc_span[8bf0c24e8c30bc02]::def_id::LocalDefId, rustc_middle[4ee2656344169b3]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[438c9ee495de13ef]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[492fefb9a5fae053]::plumbing::QueryCtxt, false>
  38:     0x7c98b225efc9 - rustc_query_impl[492fefb9a5fae053]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7c98b2aecb3a - <rustc_mir_build[1f2b9a1109db338f]::check_unsafety::UnsafetyVisitor>::visit_inner_body
  40:     0x7c98b2aee0a4 - <rustc_mir_build[1f2b9a1109db338f]::check_unsafety::UnsafetyVisitor as rustc_middle[4ee2656344169b3]::thir::visit::Visitor>::visit_expr
  41:     0x7c98b2aeda96 - <rustc_mir_build[1f2b9a1109db338f]::check_unsafety::UnsafetyVisitor as rustc_middle[4ee2656344169b3]::thir::visit::Visitor>::visit_block
  42:     0x7c98b2aee0a4 - <rustc_mir_build[1f2b9a1109db338f]::check_unsafety::UnsafetyVisitor as rustc_middle[4ee2656344169b3]::thir::visit::Visitor>::visit_expr
  43:     0x7c98b2aee0a4 - <rustc_mir_build[1f2b9a1109db338f]::check_unsafety::UnsafetyVisitor as rustc_middle[4ee2656344169b3]::thir::visit::Visitor>::visit_expr
  44:     0x7c98b295768b - rustc_mir_build[1f2b9a1109db338f]::check_unsafety::check_unsafety
  45:     0x7c98b29570f3 - rustc_query_impl[492fefb9a5fae053]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[492fefb9a5fae053]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4ee2656344169b3]::query::erase::Erased<[u8; 0usize]>>
  46:     0x7c98b294fdc7 - rustc_query_system[438c9ee495de13ef]::query::plumbing::try_execute_query::<rustc_query_impl[492fefb9a5fae053]::DynamicConfig<rustc_data_structures[d0add7e5346d7c92]::vec_cache::VecCache<rustc_span[8bf0c24e8c30bc02]::def_id::LocalDefId, rustc_middle[4ee2656344169b3]::query::erase::Erased<[u8; 0usize]>, rustc_query_system[438c9ee495de13ef]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[492fefb9a5fae053]::plumbing::QueryCtxt, false>
  47:     0x7c98b294fabd - rustc_query_impl[492fefb9a5fae053]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7c98b225dd2c - <rustc_middle[4ee2656344169b3]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[e9a632fb96b6dab3]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  49:     0x7c98b225b7f5 - rustc_interface[e9a632fb96b6dab3]::passes::analysis
  50:     0x7c98b225acb7 - rustc_query_impl[492fefb9a5fae053]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[492fefb9a5fae053]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4ee2656344169b3]::query::erase::Erased<[u8; 0usize]>>
  51:     0x7c98b307553c - rustc_query_system[438c9ee495de13ef]::query::plumbing::try_execute_query::<rustc_query_impl[492fefb9a5fae053]::DynamicConfig<rustc_query_system[438c9ee495de13ef]::query::caches::SingleCache<rustc_middle[4ee2656344169b3]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[492fefb9a5fae053]::plumbing::QueryCtxt, false>
  52:     0x7c98b3075104 - rustc_query_impl[492fefb9a5fae053]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  53:     0x7c98b347c38b - rustc_interface[e9a632fb96b6dab3]::passes::create_and_enter_global_ctxt::<core[847d6dda7f01e6ef]::option::Option<rustc_interface[e9a632fb96b6dab3]::queries::Linker>, rustc_driver_impl[a76be0c1fdc9e07a]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  54:     0x7c98b3312dd4 - rustc_interface[e9a632fb96b6dab3]::interface::run_compiler::<(), rustc_driver_impl[a76be0c1fdc9e07a]::run_compiler::{closure#0}>::{closure#1}
  55:     0x7c98b31cf0b8 - std[e5f5c135a89762ee]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[e9a632fb96b6dab3]::util::run_in_thread_with_globals<rustc_interface[e9a632fb96b6dab3]::util::run_in_thread_pool_with_globals<rustc_interface[e9a632fb96b6dab3]::interface::run_compiler<(), rustc_driver_impl[a76be0c1fdc9e07a]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  56:     0x7c98b31ced96 - <<std[e5f5c135a89762ee]::thread::Builder>::spawn_unchecked_<rustc_interface[e9a632fb96b6dab3]::util::run_in_thread_with_globals<rustc_interface[e9a632fb96b6dab3]::util::run_in_thread_pool_with_globals<rustc_interface[e9a632fb96b6dab3]::interface::run_compiler<(), rustc_driver_impl[a76be0c1fdc9e07a]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[847d6dda7f01e6ef]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  57:     0x7c98b31d4e7d - std::sys::pal::unix::thread::Thread::new::thread_start::h77dfd11f2b6c80ba
  58:     0x7c98aca5f7eb - <unknown>
  59:     0x7c98acae318c - <unknown>
  60:                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.90.0-nightly (014bd8290 2025-07-17) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_built] building MIR for `unsupported_type::{closure#0}`
#1 [check_unsafety] unsafety-checking `unsupported_type`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors; 3 warnings emitted

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

@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) ❄️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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions