Skip to content

ICE expression is not a valid constant NeverToAny #143165

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

fn main() {
    let mut state;
    'a: loop {
        state = 'state: 
        #[const_continue]
        break break;
    }
}

original:

#![feature(stmt_expr_attributes)]
#![feature(loop_match)]
fn main() {
    let mut state;
    'a: loop {
        state = 'state: 
        #[const_continue]
        break break;
    }
}

Version information

rustc 1.90.0-nightly (7ba34c704 2025-06-28)
binary: rustc
commit-hash: 7ba34c704529e7fcab80130c3fe40efe415d61b5
commit-date: 2025-06-28
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Possibly related line of code:

ExprKind::StaticRef { alloc_id, ty, .. } => {
let const_val = ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &tcx));
let const_ = Const::Val(const_val, ty);
ConstOperand { span, user_ty: None, const_ }
}
_ => span_bug!(span, "expression is not a valid constant {:?}", kind),
}
}
#[instrument(skip(tcx, lit_input))]
fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>) -> Const<'tcx> {
let LitToConstInput { lit, ty, neg } = lit_input;

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

Program output

error: expected `while`, `for`, `loop` or `{` after a label
 --> /tmp/icemaker_global_tempdir.DI8OPfL1Gi3q/rustc_testrunner_tmpdir_reporting.kcIqqKt2mcz1/mvce.rs:7:9
  |
7 |         #[const_continue]
  |         ^ expected `while`, `for`, `loop` or `{` after a label
  |
help: consider removing the label
  |
6 -         state = 'state: 
7 -         #[const_continue]
8 -         break break;
6 +         state = break break;
  |

error[E0658]: attributes on expressions are experimental
 --> /tmp/icemaker_global_tempdir.DI8OPfL1Gi3q/rustc_testrunner_tmpdir_reporting.kcIqqKt2mcz1/mvce.rs:7:9
  |
7 |         #[const_continue]
  |         ^^^^^^^^^^^^^^^^^
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
  = note: this compiler was built on 2025-06-28; consider upgrading it if it is out of date

error[E0658]: the `#[const_continue]` attribute is an experimental feature
 --> /tmp/icemaker_global_tempdir.DI8OPfL1Gi3q/rustc_testrunner_tmpdir_reporting.kcIqqKt2mcz1/mvce.rs:7:9
  |
7 |         #[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-06-28; consider upgrading it if it is out of date

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

warning: unreachable expression
 --> /tmp/icemaker_global_tempdir.DI8OPfL1Gi3q/rustc_testrunner_tmpdir_reporting.kcIqqKt2mcz1/mvce.rs:8:9
  |
8 |         break break;
  |         ^^^^^^-----
  |         |     |
  |         |     any code following this expression is unreachable
  |         unreachable expression
  |
  = note: `#[warn(unreachable_code)]` on by default

warning: unused variable: `state`
 --> /tmp/icemaker_global_tempdir.DI8OPfL1Gi3q/rustc_testrunner_tmpdir_reporting.kcIqqKt2mcz1/mvce.rs:4:13
  |
4 |     let mut state;
  |             ^^^^^ help: if this is intentional, prefix it with an underscore: `_state`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: value assigned to `state` is never read
 --> /tmp/icemaker_global_tempdir.DI8OPfL1Gi3q/rustc_testrunner_tmpdir_reporting.kcIqqKt2mcz1/mvce.rs:6:9
  |
6 |         state = 'state: 
  |         ^^^^^
  |
  = help: maybe it is overwritten before being read?
  = note: `#[warn(unused_assignments)]` on by default

error: internal compiler error: compiler/rustc_mir_build/src/builder/expr/as_constant.rs:96:14: expression is not a valid constant NeverToAny { source: e2 }
 --> /tmp/icemaker_global_tempdir.DI8OPfL1Gi3q/rustc_testrunner_tmpdir_reporting.kcIqqKt2mcz1/mvce.rs:8:15
  |
8 |         break break;
  |               ^^^^^


thread 'rustc' panicked at compiler/rustc_mir_build/src/builder/expr/as_constant.rs:96:14:
Box<dyn Any>
stack backtrace:
   0:     0x71cc4bac68e3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3e894326f8a7c11c
   1:     0x71cc4c20283f - core::fmt::write::h6eeadbb9ea260f9c
   2:     0x71cc4babc513 - std::io::Write::write_fmt::h35e5f3d60ec3f32d
   3:     0x71cc4bac6742 - std::sys::backtrace::BacktraceLock::print::habb074c516ea140b
   4:     0x71cc4baca23a - std::panicking::default_hook::{{closure}}::h9257677f6ec58979
   5:     0x71cc4bac9dbf - std::panicking::default_hook::h333afff20a3a1afe
   6:     0x71cc4ab8bc23 - std[ccb05a0eb3ad2d9e]::panicking::update_hook::<alloc[373d9532891f4aec]::boxed::Box<rustc_driver_impl[425c3dc064231476]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x71cc4bacaa8b - std::panicking::rust_panic_with_hook::h66ec27a7afe51f34
   8:     0x71cc4abc5721 - std[ccb05a0eb3ad2d9e]::panicking::begin_panic::<rustc_errors[383d557f6d132d72]::ExplicitBug>::{closure#0}
   9:     0x71cc4abb9df6 - std[ccb05a0eb3ad2d9e]::sys::backtrace::__rust_end_short_backtrace::<std[ccb05a0eb3ad2d9e]::panicking::begin_panic<rustc_errors[383d557f6d132d72]::ExplicitBug>::{closure#0}, !>
  10:     0x71cc4abb67f5 - std[ccb05a0eb3ad2d9e]::panicking::begin_panic::<rustc_errors[383d557f6d132d72]::ExplicitBug>
  11:     0x71cc4abcf201 - <rustc_errors[383d557f6d132d72]::diagnostic::BugAbort as rustc_errors[383d557f6d132d72]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x71cc4b1062ec - <rustc_errors[383d557f6d132d72]::DiagCtxtHandle>::span_bug::<rustc_span[16362823c931f6]::span_encoding::Span, alloc[373d9532891f4aec]::string::String>
  13:     0x71cc4b19b097 - rustc_middle[412f90b70c87e60]::util::bug::opt_span_bug_fmt::<rustc_span[16362823c931f6]::span_encoding::Span>::{closure#0}
  14:     0x71cc4b17ac0a - rustc_middle[412f90b70c87e60]::ty::context::tls::with_opt::<rustc_middle[412f90b70c87e60]::util::bug::opt_span_bug_fmt<rustc_span[16362823c931f6]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x71cc4b17aa7b - rustc_middle[412f90b70c87e60]::ty::context::tls::with_context_opt::<rustc_middle[412f90b70c87e60]::ty::context::tls::with_opt<rustc_middle[412f90b70c87e60]::util::bug::opt_span_bug_fmt<rustc_span[16362823c931f6]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x71cc49207f57 - rustc_middle[412f90b70c87e60]::util::bug::span_bug_fmt::<rustc_span[16362823c931f6]::span_encoding::Span>
  17:     0x71cc4c6ea7cd - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::as_constant
  18:     0x71cc4c717933 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::stmt_expr
  19:     0x71cc4c702c67 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::expr_into_dest
  20:     0x71cc4c6f43b5 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::as_temp::{closure#0}
  21:     0x71cc4c7020d8 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::expr_into_dest
  22:     0x71cc4c6eca91 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::as_operand
  23:     0x71cc4c6e6834 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::as_rvalue
  24:     0x71cc4c6e6d6d - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::as_rvalue
  25:     0x71cc4c71661c - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::stmt_expr
  26:     0x71cc4c715f13 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::stmt_expr
  27:     0x71cc4d1c15a0 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::ast_block_stmts
  28:     0x71cc4d1c0885 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::ast_block
  29:     0x71cc4c701043 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::expr_into_dest
  30:     0x71cc4c703ff9 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::expr_into_dest
  31:     0x71cc4c7007af - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::expr_into_dest
  32:     0x71cc4d1c2b03 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::ast_block_stmts
  33:     0x71cc4d1c0885 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::ast_block
  34:     0x71cc4c701043 - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::expr_into_dest
  35:     0x71cc4c7007af - <rustc_mir_build[1d5862d1f154bcbe]::builder::Builder>::expr_into_dest
  36:     0x71cc4c71bc4f - rustc_mir_build[1d5862d1f154bcbe]::builder::build_mir
  37:     0x71cc4c208576 - rustc_mir_transform[f0878ee077d7cc6c]::mir_built
  38:     0x71cc4c208547 - rustc_query_impl[f5161839cfb48de0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f5161839cfb48de0]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[412f90b70c87e60]::query::erase::Erased<[u8; 8usize]>>
  39:     0x71cc4c473fae - rustc_query_system[5e749f836759c0de]::query::plumbing::try_execute_query::<rustc_query_impl[f5161839cfb48de0]::DynamicConfig<rustc_data_structures[de5ffd1caefd334d]::vec_cache::VecCache<rustc_span[16362823c931f6]::def_id::LocalDefId, rustc_middle[412f90b70c87e60]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[5e749f836759c0de]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[f5161839cfb48de0]::plumbing::QueryCtxt, false>
  40:     0x71cc4c473a09 - rustc_query_impl[f5161839cfb48de0]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  41:     0x71cc4cc4de6a - rustc_mir_build[1d5862d1f154bcbe]::check_unsafety::check_unsafety
  42:     0x71cc4cc4dbe3 - rustc_query_impl[f5161839cfb48de0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f5161839cfb48de0]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[412f90b70c87e60]::query::erase::Erased<[u8; 0usize]>>
  43:     0x71cc4cc4d1f9 - rustc_query_system[5e749f836759c0de]::query::plumbing::try_execute_query::<rustc_query_impl[f5161839cfb48de0]::DynamicConfig<rustc_data_structures[de5ffd1caefd334d]::vec_cache::VecCache<rustc_span[16362823c931f6]::def_id::LocalDefId, rustc_middle[412f90b70c87e60]::query::erase::Erased<[u8; 0usize]>, rustc_query_system[5e749f836759c0de]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[f5161839cfb48de0]::plumbing::QueryCtxt, false>
  44:     0x71cc4cc4ced1 - rustc_query_impl[f5161839cfb48de0]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  45:     0x71cc4c4727e1 - <rustc_middle[412f90b70c87e60]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[529e108fd7de8268]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  46:     0x71cc4c4701e4 - rustc_interface[529e108fd7de8268]::passes::analysis
  47:     0x71cc4c46f6a5 - rustc_query_impl[f5161839cfb48de0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f5161839cfb48de0]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[412f90b70c87e60]::query::erase::Erased<[u8; 0usize]>>
  48:     0x71cc4d271cb0 - rustc_query_system[5e749f836759c0de]::query::plumbing::try_execute_query::<rustc_query_impl[f5161839cfb48de0]::DynamicConfig<rustc_query_system[5e749f836759c0de]::query::caches::SingleCache<rustc_middle[412f90b70c87e60]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[f5161839cfb48de0]::plumbing::QueryCtxt, false>
  49:     0x71cc4d271988 - rustc_query_impl[f5161839cfb48de0]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  50:     0x71cc4d5a3056 - rustc_interface[529e108fd7de8268]::passes::create_and_enter_global_ctxt::<core[f57c8a2dc663c78e]::option::Option<rustc_interface[529e108fd7de8268]::queries::Linker>, rustc_driver_impl[425c3dc064231476]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  51:     0x71cc4d44166f - rustc_interface[529e108fd7de8268]::interface::run_compiler::<(), rustc_driver_impl[425c3dc064231476]::run_compiler::{closure#0}>::{closure#1}
  52:     0x71cc4d3c8e78 - std[ccb05a0eb3ad2d9e]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[529e108fd7de8268]::util::run_in_thread_with_globals<rustc_interface[529e108fd7de8268]::util::run_in_thread_pool_with_globals<rustc_interface[529e108fd7de8268]::interface::run_compiler<(), rustc_driver_impl[425c3dc064231476]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  53:     0x71cc4d3c8b56 - <<std[ccb05a0eb3ad2d9e]::thread::Builder>::spawn_unchecked_<rustc_interface[529e108fd7de8268]::util::run_in_thread_with_globals<rustc_interface[529e108fd7de8268]::util::run_in_thread_pool_with_globals<rustc_interface[529e108fd7de8268]::interface::run_compiler<(), rustc_driver_impl[425c3dc064231476]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[f57c8a2dc663c78e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  54:     0x71cc4d3cedfd - std::sys::pal::unix::thread::Thread::new::thread_start::h284bc444b5f92f17
  55:     0x71cc46ea57eb - <unknown>
  56:     0x71cc46f2918c - <unknown>
  57:                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.90.0-nightly (7ba34c704 2025-06-28) running on x86_64-unknown-linux-gnu

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

For more information about this error, try `rustc --explain E0658`.

@rustbot label +F-stmt_expr_attributes +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 loopF-stmt_expr_attributes`#![feature(stmt_expr_attributes)]`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