Skip to content

ICE: expected branch, got Leaf #150712

@matthiaskrgr

Description

@matthiaskrgr

snippet:

#![feature(min_generic_const_args, adt_const_params)]
use std::marker::ConstParamTy;
#[derive(Eq, PartialEq, ConstParamTy)]
struct Inner(u32);
#[derive(Eq, PartialEq, ConstParamTy)]
enum Container<T> {
    Wrap(T),
}
fn with_container<const C: Container<Inner>>() -> Container<Inner> {
    C
}
fn test<const N: u32>() {
    with_container::<{ Container::Wrap::<Inner>(N) }>();
}
fn main() {
    test::<5>()
}

Version information

rustc 1.94.0-nightly (bd33b83cf 2026-01-05)
binary: rustc
commit-hash: bd33b83cfdbac9bffa3b04aaef95ec97827909a9
commit-date: 2026-01-05
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Possibly related line of code:

/// Converts to a `ValTreeKind::Branch` value, `panic`'ing
/// if this valtree is some other kind.
#[inline]
pub fn to_branch(&self) -> &[I::Const] {
match self {
ValTreeKind::Branch(branch) => &**branch,
ValTreeKind::Leaf(..) => panic!("expected branch, got {:?}", self),
}
}
/// Attempts to convert to a `ValTreeKind::Leaf` value.
pub fn try_to_leaf(&self) -> Option<I::ScalarInt> {
match self {

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

Program output

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


thread 'rustc' (1772566) panicked at /rustc-dev/bd33b83cfdbac9bffa3b04aaef95ec97827909a9/compiler/rustc_type_ir/src/const_kind.rs:183:38:
expected branch, got Leaf(0x00000005)
stack backtrace:
   0:     0x7f9da2420fc3 - <<std[6810ad95c09a1f38]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[8c39a0108b8da36b]::fmt::Display>::fmt
   1:     0x7f9da2a0e348 - core[8c39a0108b8da36b]::fmt::write
   2:     0x7f9da2437246 - <std[6810ad95c09a1f38]::sys::stdio::unix::Stderr as std[6810ad95c09a1f38]::io::Write>::write_fmt
   3:     0x7f9da23f6df8 - std[6810ad95c09a1f38]::panicking::default_hook::{closure#0}
   4:     0x7f9da2414853 - std[6810ad95c09a1f38]::panicking::default_hook
   5:     0x7f9da13fb1da - std[6810ad95c09a1f38]::panicking::update_hook::<alloc[c78df5de1e68b592]::boxed::Box<rustc_driver_impl[4e21432d7c76ef67]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f9da2414b32 - std[6810ad95c09a1f38]::panicking::panic_with_hook
   7:     0x7f9da23f6eb8 - std[6810ad95c09a1f38]::panicking::panic_handler::{closure#0}
   8:     0x7f9da23edb79 - std[6810ad95c09a1f38]::sys::backtrace::__rust_end_short_backtrace::<std[6810ad95c09a1f38]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f9da23f898d - __rustc[a475064d16802d7f]::rust_begin_unwind
  10:     0x7f9d9f558fec - core[8c39a0108b8da36b]::panicking::panic_fmt
  11:     0x7f9da2f2fd3e - rustc_const_eval[6fc806a0c4979697]::const_eval::valtrees::valtree_into_mplace
  12:     0x7f9da2f2f90e - rustc_const_eval[6fc806a0c4979697]::const_eval::valtrees::valtree_into_mplace
  13:     0x7f9da3af295c - rustc_const_eval[6fc806a0c4979697]::const_eval::valtrees::valtree_to_const_value
  14:     0x7f9da3af232b - <rustc_const_eval[6fc806a0c4979697]::provide::{closure#1} as core[8c39a0108b8da36b]::ops::function::FnOnce<(rustc_middle[42237da0a4c7601]::ty::context::TyCtxt, rustc_middle[42237da0a4c7601]::ty::consts::valtree::Value)>>::call_once
  15:     0x7f9da3af22d6 - rustc_query_impl[4d93b3b10c7f5167]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[4d93b3b10c7f5167]::query_impl::valtree_to_const_val::dynamic_query::{closure#2}::{closure#0}, rustc_middle[42237da0a4c7601]::query::erase::Erased<[u8; 24usize]>>
  16:     0x7f9da3af229f - <rustc_query_impl[4d93b3b10c7f5167]::query_impl::valtree_to_const_val::dynamic_query::{closure#2} as core[8c39a0108b8da36b]::ops::function::FnOnce<(rustc_middle[42237da0a4c7601]::ty::context::TyCtxt, rustc_middle[42237da0a4c7601]::ty::consts::valtree::Value)>>::call_once
  17:     0x7f9da3af18cc - rustc_query_system[747dc01c13837c3b]::query::plumbing::try_execute_query::<rustc_query_impl[4d93b3b10c7f5167]::DynamicConfig<rustc_query_system[747dc01c13837c3b]::query::caches::DefaultCache<rustc_middle[42237da0a4c7601]::ty::consts::valtree::Value, rustc_middle[42237da0a4c7601]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[4d93b3b10c7f5167]::plumbing::QueryCtxt, false>
  18:     0x7f9da3af15e5 - rustc_query_impl[4d93b3b10c7f5167]::query_impl::valtree_to_const_val::get_query_non_incr::__rust_end_short_backtrace
  19:     0x7f9da34aed87 - rustc_monomorphize[df187732e26b04b8]::collector::items_of_instance
  20:     0x7f9da34aaff2 - rustc_query_impl[4d93b3b10c7f5167]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[4d93b3b10c7f5167]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[42237da0a4c7601]::query::erase::Erased<[u8; 32usize]>>
  21:     0x7f9da36c0b95 - rustc_query_system[747dc01c13837c3b]::query::plumbing::try_execute_query::<rustc_query_impl[4d93b3b10c7f5167]::DynamicConfig<rustc_query_system[747dc01c13837c3b]::query::caches::DefaultCache<(rustc_middle[42237da0a4c7601]::ty::instance::Instance, rustc_middle[42237da0a4c7601]::mir::mono::CollectionMode), rustc_middle[42237da0a4c7601]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[4d93b3b10c7f5167]::plumbing::QueryCtxt, false>
  22:     0x7f9da36c07b3 - rustc_query_impl[4d93b3b10c7f5167]::query_impl::items_of_instance::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7f9da3edaf54 - rustc_monomorphize[df187732e26b04b8]::collector::collect_items_rec
  24:     0x7f9da3edcea7 - rustc_monomorphize[df187732e26b04b8]::collector::collect_items_rec
  25:     0x7f9da3edcea7 - rustc_monomorphize[df187732e26b04b8]::collector::collect_items_rec
  26:     0x7f9da2ebb3ed - rustc_monomorphize[df187732e26b04b8]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
  27:     0x7f9da32822ba - rustc_monomorphize[df187732e26b04b8]::partitioning::collect_and_partition_mono_items
  28:     0x7f9da3e28764 - rustc_query_impl[4d93b3b10c7f5167]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[4d93b3b10c7f5167]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[42237da0a4c7601]::query::erase::Erased<[u8; 24usize]>>
  29:     0x7f9da3e28749 - <rustc_query_impl[4d93b3b10c7f5167]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[8c39a0108b8da36b]::ops::function::FnOnce<(rustc_middle[42237da0a4c7601]::ty::context::TyCtxt, ())>>::call_once
  30:     0x7f9da3e2829e - rustc_query_system[747dc01c13837c3b]::query::plumbing::try_execute_query::<rustc_query_impl[4d93b3b10c7f5167]::DynamicConfig<rustc_query_system[747dc01c13837c3b]::query::caches::SingleCache<rustc_middle[42237da0a4c7601]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[4d93b3b10c7f5167]::plumbing::QueryCtxt, false>
  31:     0x7f9da3e28043 - rustc_query_impl[4d93b3b10c7f5167]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f9da3e2fa20 - rustc_codegen_ssa[e1295ddd32952513]::base::codegen_crate::<rustc_codegen_llvm[443ddb3aab83af46]::LlvmCodegenBackend>
  33:     0x7f9da3e2d4fd - <rustc_codegen_llvm[443ddb3aab83af46]::LlvmCodegenBackend as rustc_codegen_ssa[e1295ddd32952513]::traits::backend::CodegenBackend>::codegen_crate
  34:     0x7f9da3d6b40f - <rustc_interface[5d1daf306103d6d4]::queries::Linker>::codegen_and_build_linker
  35:     0x7f9da3d68a1c - <rustc_interface[5d1daf306103d6d4]::passes::create_and_enter_global_ctxt<core[8c39a0108b8da36b]::option::Option<rustc_interface[5d1daf306103d6d4]::queries::Linker>, rustc_driver_impl[4e21432d7c76ef67]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[8c39a0108b8da36b]::ops::function::FnOnce<(&rustc_session[b55a0c80c17f87]::session::Session, rustc_middle[42237da0a4c7601]::ty::context::CurrentGcx, alloc[c78df5de1e68b592]::sync::Arc<rustc_data_structures[b6e1d723e783a0f9]::jobserver::Proxy>, &std[6810ad95c09a1f38]::sync::once_lock::OnceLock<rustc_middle[42237da0a4c7601]::ty::context::GlobalCtxt>, &rustc_data_structures[b6e1d723e783a0f9]::sync::worker_local::WorkerLocal<rustc_middle[42237da0a4c7601]::arena::Arena>, &rustc_data_structures[b6e1d723e783a0f9]::sync::worker_local::WorkerLocal<rustc_hir[570d9ac2d5177df8]::Arena>, rustc_driver_impl[4e21432d7c76ef67]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  36:     0x7f9da3c140d8 - rustc_interface[5d1daf306103d6d4]::interface::run_compiler::<(), rustc_driver_impl[4e21432d7c76ef67]::run_compiler::{closure#0}>::{closure#1}
  37:     0x7f9da3b8cbce - std[6810ad95c09a1f38]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5d1daf306103d6d4]::util::run_in_thread_with_globals<rustc_interface[5d1daf306103d6d4]::util::run_in_thread_pool_with_globals<rustc_interface[5d1daf306103d6d4]::interface::run_compiler<(), rustc_driver_impl[4e21432d7c76ef67]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  38:     0x7f9da3b8c9a0 - <std[6810ad95c09a1f38]::thread::lifecycle::spawn_unchecked<rustc_interface[5d1daf306103d6d4]::util::run_in_thread_with_globals<rustc_interface[5d1daf306103d6d4]::util::run_in_thread_pool_with_globals<rustc_interface[5d1daf306103d6d4]::interface::run_compiler<(), rustc_driver_impl[4e21432d7c76ef67]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[8c39a0108b8da36b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7f9da3b8e744 - <std[6810ad95c09a1f38]::sys::thread::unix::Thread>::new::thread_start
  40:     0x7f9d9d49698b - <unknown>
  41:     0x7f9d9d51a9cc - <unknown>
  42:                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 (bd33b83cf 2026-01-05) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [valtree_to_const_val] converting type-level constant value to MIR constant value
#1 [items_of_instance] collecting items used by `with_container::<ValTree(Branch([ValTree(Leaf(0x00000000): u32), ValTree(Leaf(0x00000005): u32)]): Container<Inner>)>`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
warning: 1 warning emitted


@rustbot label +F-min_generic_const_args +F-adt_const_params

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-adt_const_params`#![feature(adt_const_params)]`F-min_generic_const_args`#![feature(min_generic_const_args)]`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