Skip to content

ICE: Result::unwrap() on an Err value: InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(BoundsCheckFailed .. #151079

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -Zmir-opt-level=5 -Clink-dead-code=true
#![feature(min_generic_const_args)]
#![feature(adt_const_params, unsized_const_params, generic_const_parameter_types)]

use std::marker::ConstParamTy_;

fn foo<T: ConstParamTy_, const N: usize, const M: [T; N]>() -> [T; N] {
    M
}

fn main() {
    let a: [u8; 2] = foo::<u8, 2, { [0, 0, 0] }>();
}

original:

//@ check-pass

#![feature(adt_const_params, unsized_const_params, generic_const_parameter_types)]
#![allow(incomplete_features)]

use std::marker::ConstParamTy_;

fn foo<T: ConstParamTy_, const N: usize, const M: [T; N]>() -> [T; N] {
    M
}

fn main() {
    let a: [u8; 2] = foo::<u8, 2, { [0,0,0] }>();
}

Version information

rustc 1.94.0-nightly (9b8162963 2026-01-13)
binary: rustc
commit-hash: 9b81629631b382fd49ee3a20ac47797b1467e52d
commit-date: 2026-01-13
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Possibly related line of code:

// them recursively
for (i, inner_valtree) in branches.iter().enumerate() {
debug!(?i, ?inner_valtree);
let place_inner = match ty.kind() {
ty::Str | ty::Slice(_) | ty::Array(..) => {
ecx.project_index(place, i as u64).unwrap()
}
_ => ecx.project_field(&place_adjusted, FieldIdx::from_usize(i)).unwrap(),
};
debug!(?place_inner);
valtree_into_mplace(ecx, &place_inner, inner_valtree.to_value().valtree);

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 -Clink-dead-code=true -Zcrate-attr=feature(min_generic_const_args)

Program output

warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.wjemz51V43gv/rustc_testrunner_tmpdir_reporting.8FXotATA72YN/mvce.rs:1:30
  |
1 | #![feature(adt_const_params, unsized_const_params, generic_const_parameter_types)]
  |                              ^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: the feature `generic_const_parameter_types` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.wjemz51V43gv/rustc_testrunner_tmpdir_reporting.8FXotATA72YN/mvce.rs:1:52
  |
1 | #![feature(adt_const_params, unsized_const_params, generic_const_parameter_types)]
  |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #137626 <https://github.com/rust-lang/rust/issues/137626> for more information

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

warning: unused variable: `a`
  --> /tmp/icemaker_global_tempdir.wjemz51V43gv/rustc_testrunner_tmpdir_reporting.8FXotATA72YN/mvce.rs:10:9
   |
10 |     let a: [u8; 2] = foo::<u8, 2, { [0, 0, 0] }>();
   |         ^ help: if this is intentional, prefix it with an underscore: `_a`
   |
   = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default


thread 'rustc' (1941695) panicked at /rustc-dev/9b81629631b382fd49ee3a20ac47797b1467e52d/compiler/rustc_const_eval/src/const_eval/valtrees.rs:427:60:
called `Result::unwrap()` on an `Err` value: InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(BoundsCheckFailed { len: 2, index: 2 }), backtrace: InterpErrorBacktrace { backtrace: None } })
stack backtrace:
   0:     0x7fb14a635093 - <<std[2ade4c2364de62da]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[70014f3701156057]::fmt::Display>::fmt
   1:     0x7fb14ac0fb48 - core[70014f3701156057]::fmt::write
   2:     0x7fb14a64ba86 - <std[2ade4c2364de62da]::sys::stdio::unix::Stderr as std[2ade4c2364de62da]::io::Write>::write_fmt
   3:     0x7fb14a60b108 - std[2ade4c2364de62da]::panicking::default_hook::{closure#0}
   4:     0x7fb14a6287c3 - std[2ade4c2364de62da]::panicking::default_hook
   5:     0x7fb14960c68a - std[2ade4c2364de62da]::panicking::update_hook::<alloc[bf1f08ca38e38ea3]::boxed::Box<rustc_driver_impl[48bdb3468b385e51]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fb14a628aa2 - std[2ade4c2364de62da]::panicking::panic_with_hook
   7:     0x7fb14a60b1c8 - std[2ade4c2364de62da]::panicking::panic_handler::{closure#0}
   8:     0x7fb14a5ff679 - std[2ade4c2364de62da]::sys::backtrace::__rust_end_short_backtrace::<std[2ade4c2364de62da]::panicking::panic_handler::{closure#0}, !>
   9:     0x7fb14a60cc9d - __rustc[2d9923b8307f5353]::rust_begin_unwind
  10:     0x7fb14718318c - core[70014f3701156057]::panicking::panic_fmt
  11:     0x7fb146ef4ef2 - core[70014f3701156057]::result::unwrap_failed
  12:     0x7fb14b0ba94e - rustc_const_eval[7181a74e73bdfbc4]::const_eval::valtrees::valtree_into_mplace
  13:     0x7fb14bcefddc - rustc_const_eval[7181a74e73bdfbc4]::const_eval::valtrees::valtree_to_const_value
  14:     0x7fb14bcef7ab - <rustc_const_eval[7181a74e73bdfbc4]::provide::{closure#1} as core[70014f3701156057]::ops::function::FnOnce<(rustc_middle[a808b96dc0c8b39]::ty::context::TyCtxt, rustc_middle[a808b96dc0c8b39]::ty::consts::valtree::Value)>>::call_once
  15:     0x7fb14bcef756 - rustc_query_impl[d3207ad19da6bae6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d3207ad19da6bae6]::query_impl::valtree_to_const_val::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a808b96dc0c8b39]::query::erase::Erased<[u8; 24usize]>>
  16:     0x7fb14bcef71f - <rustc_query_impl[d3207ad19da6bae6]::query_impl::valtree_to_const_val::dynamic_query::{closure#2} as core[70014f3701156057]::ops::function::FnOnce<(rustc_middle[a808b96dc0c8b39]::ty::context::TyCtxt, rustc_middle[a808b96dc0c8b39]::ty::consts::valtree::Value)>>::call_once
  17:     0x7fb14bceed4c - rustc_query_system[ac97840b0086b723]::query::plumbing::try_execute_query::<rustc_query_impl[d3207ad19da6bae6]::DynamicConfig<rustc_query_system[ac97840b0086b723]::query::caches::DefaultCache<rustc_middle[a808b96dc0c8b39]::ty::consts::valtree::Value, rustc_middle[a808b96dc0c8b39]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[d3207ad19da6bae6]::plumbing::QueryCtxt, false>
  18:     0x7fb14bceea65 - rustc_query_impl[d3207ad19da6bae6]::query_impl::valtree_to_const_val::get_query_non_incr::__rust_end_short_backtrace
  19:     0x7fb14b9b5e0f - <rustc_const_eval[7181a74e73bdfbc4]::interpret::eval_context::InterpCx<rustc_const_eval[7181a74e73bdfbc4]::const_eval::dummy_machine::DummyMachine>>::eval_mir_constant
  20:     0x7fb14b9b6e3e - <rustc_mir_transform[60a44e365f7ed4e9]::gvn::VnState>::eval_to_const
  21:     0x7fb14b9c62d2 - <rustc_mir_transform[60a44e365f7ed4e9]::gvn::VnState as rustc_middle[a808b96dc0c8b39]::mir::visit::MutVisitor>::visit_assign
  22:     0x7fb14b9c5316 - <rustc_mir_transform[60a44e365f7ed4e9]::gvn::GVN as rustc_mir_transform[60a44e365f7ed4e9]::pass_manager::MirPass>::run_pass
  23:     0x7fb14ac0739d - rustc_mir_transform[60a44e365f7ed4e9]::run_optimization_passes
  24:     0x7fb14b416d4f - rustc_mir_transform[60a44e365f7ed4e9]::optimized_mir
  25:     0x7fb14b41696f - rustc_query_impl[d3207ad19da6bae6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d3207ad19da6bae6]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a808b96dc0c8b39]::query::erase::Erased<[u8; 8usize]>>
  26:     0x7fb14ac18386 - rustc_query_system[ac97840b0086b723]::query::plumbing::try_execute_query::<rustc_query_impl[d3207ad19da6bae6]::DynamicConfig<rustc_query_system[ac97840b0086b723]::query::caches::DefIdCache<rustc_middle[a808b96dc0c8b39]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d3207ad19da6bae6]::plumbing::QueryCtxt, false>
  27:     0x7fb14ac1795b - rustc_query_impl[d3207ad19da6bae6]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7fb1473cada1 - <rustc_middle[a808b96dc0c8b39]::ty::context::TyCtxt>::instance_mir
  29:     0x7fb14b67ac1f - rustc_monomorphize[a4e61b93c8fa6a66]::collector::items_of_instance
  30:     0x7fb14b67abbc - rustc_query_impl[d3207ad19da6bae6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d3207ad19da6bae6]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a808b96dc0c8b39]::query::erase::Erased<[u8; 32usize]>>
  31:     0x7fb14b8d7894 - rustc_query_system[ac97840b0086b723]::query::plumbing::try_execute_query::<rustc_query_impl[d3207ad19da6bae6]::DynamicConfig<rustc_query_system[ac97840b0086b723]::query::caches::DefaultCache<(rustc_middle[a808b96dc0c8b39]::ty::instance::Instance, rustc_middle[a808b96dc0c8b39]::mir::mono::CollectionMode), rustc_middle[a808b96dc0c8b39]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[d3207ad19da6bae6]::plumbing::QueryCtxt, false>
  32:     0x7fb14b8d74b3 - rustc_query_impl[d3207ad19da6bae6]::query_impl::items_of_instance::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7fb14c0e5c58 - rustc_monomorphize[a4e61b93c8fa6a66]::collector::collect_items_rec
  34:     0x7fb14af47eab - rustc_monomorphize[a4e61b93c8fa6a66]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
  35:     0x7fb14b2d8836 - rustc_monomorphize[a4e61b93c8fa6a66]::partitioning::collect_and_partition_mono_items
  36:     0x7fb14c0038a4 - rustc_query_impl[d3207ad19da6bae6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d3207ad19da6bae6]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a808b96dc0c8b39]::query::erase::Erased<[u8; 24usize]>>
  37:     0x7fb14c003889 - <rustc_query_impl[d3207ad19da6bae6]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[70014f3701156057]::ops::function::FnOnce<(rustc_middle[a808b96dc0c8b39]::ty::context::TyCtxt, ())>>::call_once
  38:     0x7fb14c0033de - rustc_query_system[ac97840b0086b723]::query::plumbing::try_execute_query::<rustc_query_impl[d3207ad19da6bae6]::DynamicConfig<rustc_query_system[ac97840b0086b723]::query::caches::SingleCache<rustc_middle[a808b96dc0c8b39]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[d3207ad19da6bae6]::plumbing::QueryCtxt, false>
  39:     0x7fb14c003183 - rustc_query_impl[d3207ad19da6bae6]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7fb14c00a508 - rustc_codegen_ssa[3d3f98e3151f9062]::base::codegen_crate::<rustc_codegen_llvm[5765bde0af8a4c1a]::LlvmCodegenBackend>
  41:     0x7fb14c007fc3 - <rustc_codegen_llvm[5765bde0af8a4c1a]::LlvmCodegenBackend as rustc_codegen_ssa[3d3f98e3151f9062]::traits::backend::CodegenBackend>::codegen_crate
  42:     0x7fb14bfb748c - <rustc_interface[372b2d608f466254]::queries::Linker>::codegen_and_build_linker
  43:     0x7fb14bfb4a9c - <rustc_interface[372b2d608f466254]::passes::create_and_enter_global_ctxt<core[70014f3701156057]::option::Option<rustc_interface[372b2d608f466254]::queries::Linker>, rustc_driver_impl[48bdb3468b385e51]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[70014f3701156057]::ops::function::FnOnce<(&rustc_session[4ad34451d848125f]::session::Session, rustc_middle[a808b96dc0c8b39]::ty::context::CurrentGcx, alloc[bf1f08ca38e38ea3]::sync::Arc<rustc_data_structures[de9cc80261963238]::jobserver::Proxy>, &std[2ade4c2364de62da]::sync::once_lock::OnceLock<rustc_middle[a808b96dc0c8b39]::ty::context::GlobalCtxt>, &rustc_data_structures[de9cc80261963238]::sync::worker_local::WorkerLocal<rustc_middle[a808b96dc0c8b39]::arena::Arena>, &rustc_data_structures[de9cc80261963238]::sync::worker_local::WorkerLocal<rustc_hir[d443c4a01af566e4]::Arena>, rustc_driver_impl[48bdb3468b385e51]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  44:     0x7fb14be7abd8 - rustc_interface[372b2d608f466254]::interface::run_compiler::<(), rustc_driver_impl[48bdb3468b385e51]::run_compiler::{closure#0}>::{closure#1}
  45:     0x7fb14bdae8ce - std[2ade4c2364de62da]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[372b2d608f466254]::util::run_in_thread_with_globals<rustc_interface[372b2d608f466254]::util::run_in_thread_pool_with_globals<rustc_interface[372b2d608f466254]::interface::run_compiler<(), rustc_driver_impl[48bdb3468b385e51]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  46:     0x7fb14bdae6a0 - <std[2ade4c2364de62da]::thread::lifecycle::spawn_unchecked<rustc_interface[372b2d608f466254]::util::run_in_thread_with_globals<rustc_interface[372b2d608f466254]::util::run_in_thread_pool_with_globals<rustc_interface[372b2d608f466254]::interface::run_compiler<(), rustc_driver_impl[48bdb3468b385e51]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[70014f3701156057]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:     0x7fb14bdb0446 - <std[2ade4c2364de62da]::sys::thread::unix::Thread>::new::thread_start
  48:     0x7fb14569698b - <unknown>
  49:     0x7fb14571a9cc - <unknown>
  50:                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.94.0-nightly (9b8162963 2026-01-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=5 -C link-dead-code=true -Z crate-attr=feature(min_generic_const_args) -Z dump-mir-dir=dir

query stack during panic:
#0 [valtree_to_const_val] converting type-level constant value to MIR constant value
#1 [optimized_mir] optimizing MIR for `main`
#2 [items_of_instance] collecting items used by `main`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
warning: 4 warnings emitted


@rustbot label +F-adt_const_params +F-unsized_const_params +F-generic_const_parameter_types +F-min_generic_const_args

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-adt_const_params`#![feature(adt_const_params)]`F-generic_const_parameter_types`#![feature(generic_const_parameter_types)]`F-min_generic_const_args`#![feature(min_generic_const_args)]`F-unsized_const_params`#![feature(unsized_const_params)]`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.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions