Skip to content

ICE expected ConstKind::Value, got N/#1 #150354

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: --edition=2024
#![feature(min_generic_const_args, adt_const_params)]

enum Option<T> {
    Some(T),
    None,
}

fn foo<const N: Option<u32>>() {}

fn bar<T, const N: u32>() {
    foo::<{ Some::<u32> { 0: N } }>;
}
original code

original:

#![feature(min_generic_const_args, adt_const_params)]


#[derive(Eq, PartialEq, std::marker::ConstParamTy)]
enum Option<T> {
    Some(T),
    None,
}
use Option::Some;

fn foo<const N: Option<u32>>() {}

trait Trait {
    #[type_const]
    const ASSOC: usize;
}

fn bar<T, const N: u32>() {
    // the initializer of `_0` is a `N` which is a legal const argument
    // so this is ok.
    foo::<{ Some::<u32> { 0: N } }>;

    // this is allowed as mgca supports uses of assoc consts in the
    // type system. ie `<T as Trait>::ASSOC` is a legal const argument
    foo::<{ Some::<u32> { 0: <T as Trait>::ASSOC } }>();

    // this on the other hand is not allowed as `N + 1` is not a legal
    // const argument
    foo::<{ Some::<u32> { 0: N + 1 } }>();
    //~^ ERROR: complex const arguments must be placed inside of a `const` block

    // this also is not allowed as generic parameters cannot be used
    // in anon const const args
    foo::<{ Some::<u32> { 0: const { N + 1 } } }>();
    //~^ ERROR: generic parameters may not be used in const operations
}

fn main() {}

Version information

rustc 1.94.0-nightly (efa32de15 2025-12-24)
binary: rustc
commit-hash: efa32de15b394620520f24781d8c55d4df6fa106
commit-date: 2025-12-24
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Possibly related line of code:

}
/// Panics if `self.kind != ty::ConstKind::Value`.
pub fn to_value(self) -> ty::Value<'tcx> {
match self.kind() {
ty::ConstKind::Value(cv) => cv,
_ => bug!("expected ConstKind::Value, got {:?}", self.kind()),
}
}
/// Attempts to convert to a value.
///
/// Note that this does not normalize the constant.

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2024

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.co1336ymRBvg/rustc_testrunner_tmpdir_reporting.HBliNFcGkwUu/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

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

error[E0741]: `Option<u32>` must implement `ConstParamTy` to be used as the type of a const generic parameter
 --> /tmp/icemaker_global_tempdir.co1336ymRBvg/rustc_testrunner_tmpdir_reporting.HBliNFcGkwUu/mvce.rs:8:17
  |
8 | fn foo<const N: Option<u32>>() {}
  |                 ^^^^^^^^^^^
  |
help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the enum
  |
3 + #[derive(ConstParamTy, PartialEq, Eq)]
4 | enum Option<T> {
  |

error: internal compiler error: /rustc-dev/efa32de15b394620520f24781d8c55d4df6fa106/compiler/rustc_middle/src/ty/consts.rs:258:18: expected ConstKind::Value, got N/#1


thread 'rustc' (3462691) panicked at /rustc-dev/efa32de15b394620520f24781d8c55d4df6fa106/compiler/rustc_middle/src/ty/consts.rs:258:18:
Box<dyn Any>
stack backtrace:
   0:     0x7fee48c5fda3 - <<std[8a52549f710fb415]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[9df9debe8b3ae22c]::fmt::Display>::fmt
   1:     0x7fee49410648 - core[9df9debe8b3ae22c]::fmt::write
   2:     0x7fee48c764f6 - <std[8a52549f710fb415]::sys::stdio::unix::Stderr as std[8a52549f710fb415]::io::Write>::write_fmt
   3:     0x7fee48c36548 - std[8a52549f710fb415]::panicking::default_hook::{closure#0}
   4:     0x7fee48c53c13 - std[8a52549f710fb415]::panicking::default_hook
   5:     0x7fee47c2d377 - std[8a52549f710fb415]::panicking::update_hook::<alloc[d3a84aa4019980d4]::boxed::Box<rustc_driver_impl[84ab8a953ff30580]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fee48c53ef2 - std[8a52549f710fb415]::panicking::panic_with_hook
   7:     0x7fee47c6a4c1 - std[8a52549f710fb415]::panicking::begin_panic::<rustc_errors[699e0d49929a30bc]::ExplicitBug>::{closure#0}
   8:     0x7fee47c5aa06 - std[8a52549f710fb415]::sys::backtrace::__rust_end_short_backtrace::<std[8a52549f710fb415]::panicking::begin_panic<rustc_errors[699e0d49929a30bc]::ExplicitBug>::{closure#0}, !>
   9:     0x7fee47c57da9 - std[8a52549f710fb415]::panicking::begin_panic::<rustc_errors[699e0d49929a30bc]::ExplicitBug>
  10:     0x7fee47c884b1 - <rustc_errors[699e0d49929a30bc]::diagnostic::BugAbort as rustc_errors[699e0d49929a30bc]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fee48237099 - rustc_middle[6c8ebc09c5dee75c]::util::bug::opt_span_bug_fmt::<rustc_span[f43d92d060b6ef6a]::span_encoding::Span>::{closure#0}
  12:     0x7fee48237222 - rustc_middle[6c8ebc09c5dee75c]::ty::context::tls::with_opt::<rustc_middle[6c8ebc09c5dee75c]::util::bug::opt_span_bug_fmt<rustc_span[f43d92d060b6ef6a]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7fee482280fb - rustc_middle[6c8ebc09c5dee75c]::ty::context::tls::with_context_opt::<rustc_middle[6c8ebc09c5dee75c]::ty::context::tls::with_opt<rustc_middle[6c8ebc09c5dee75c]::util::bug::opt_span_bug_fmt<rustc_span[f43d92d060b6ef6a]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7fee45c3a3c4 - rustc_middle[6c8ebc09c5dee75c]::util::bug::bug_fmt
  15:     0x7fee48246a3d - <rustc_middle[6c8ebc09c5dee75c]::ty::consts::Const>::to_value
  16:     0x7fee48badca9 - rustc_ty_utils[4ecae0266dc2b209]::consts::destructure_const
  17:     0x7fee48634546 - rustc_query_impl[741bec1d205ed836]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[741bec1d205ed836]::query_impl::destructure_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6c8ebc09c5dee75c]::query::erase::Erased<[u8; 24usize]>>
  18:     0x7fee48737e49 - <rustc_query_impl[741bec1d205ed836]::query_impl::destructure_const::dynamic_query::{closure#2} as core[9df9debe8b3ae22c]::ops::function::FnOnce<(rustc_middle[6c8ebc09c5dee75c]::ty::context::TyCtxt, rustc_middle[6c8ebc09c5dee75c]::ty::consts::Const)>>::call_once
  19:     0x7fee4865c4ca - rustc_query_system[d1e761e268b8884b]::query::plumbing::try_execute_query::<rustc_query_impl[741bec1d205ed836]::DynamicConfig<rustc_query_system[d1e761e268b8884b]::query::caches::DefaultCache<rustc_middle[6c8ebc09c5dee75c]::ty::consts::Const, rustc_middle[6c8ebc09c5dee75c]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[741bec1d205ed836]::plumbing::QueryCtxt, false>
  20:     0x7fee486d11c9 - rustc_query_impl[741bec1d205ed836]::query_impl::destructure_const::get_query_non_incr::__rust_end_short_backtrace
  21:     0x7fee482cded2 - <rustc_middle[6c8ebc09c5dee75c]::ty::print::pretty::FmtPrinter as rustc_middle[6c8ebc09c5dee75c]::ty::print::pretty::PrettyPrinter>::pretty_print_const_valtree
  22:     0x7fee48a26c7f - <rustc_trait_selection[5e395e029186e477]::error_reporting::TypeErrCtxt>::report_selection_error
  23:     0x7fee47565dfa - <rustc_trait_selection[5e395e029186e477]::error_reporting::TypeErrCtxt>::report_fulfillment_errors
  24:     0x7fee49dd7256 - rustc_hir_typeck[8cc08117c3dde91c]::typeck_with_inspect::{closure#0}
  25:     0x7fee49dcccf4 - rustc_query_impl[741bec1d205ed836]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[741bec1d205ed836]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6c8ebc09c5dee75c]::query::erase::Erased<[u8; 8usize]>>
  26:     0x7fee497251f7 - rustc_query_system[d1e761e268b8884b]::query::plumbing::try_execute_query::<rustc_query_impl[741bec1d205ed836]::DynamicConfig<rustc_data_structures[ededeb3d82402ac5]::vec_cache::VecCache<rustc_span[f43d92d060b6ef6a]::def_id::LocalDefId, rustc_middle[6c8ebc09c5dee75c]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[d1e761e268b8884b]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[741bec1d205ed836]::plumbing::QueryCtxt, false>
  27:     0x7fee49724ac9 - rustc_query_impl[741bec1d205ed836]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7fee49b9b0f1 - <rustc_middle[6c8ebc09c5dee75c]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[6d86651e35dd2117]::check_crate::{closure#2}>::{closure#0}
  29:     0x7fee49b9ab03 - rustc_hir_analysis[6d86651e35dd2117]::check_crate
  30:     0x7fee4a2dee9b - rustc_interface[f52ab86d5a555b2e]::passes::analysis
  31:     0x7fee4a2deaf5 - rustc_query_impl[741bec1d205ed836]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[741bec1d205ed836]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6c8ebc09c5dee75c]::query::erase::Erased<[u8; 0usize]>>
  32:     0x7fee4a60e766 - rustc_query_system[d1e761e268b8884b]::query::plumbing::try_execute_query::<rustc_query_impl[741bec1d205ed836]::DynamicConfig<rustc_query_system[d1e761e268b8884b]::query::caches::SingleCache<rustc_middle[6c8ebc09c5dee75c]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[741bec1d205ed836]::plumbing::QueryCtxt, false>
  33:     0x7fee4a60e336 - rustc_query_impl[741bec1d205ed836]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7fee4a785011 - <rustc_interface[f52ab86d5a555b2e]::passes::create_and_enter_global_ctxt<core[9df9debe8b3ae22c]::option::Option<rustc_interface[f52ab86d5a555b2e]::queries::Linker>, rustc_driver_impl[84ab8a953ff30580]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[9df9debe8b3ae22c]::ops::function::FnOnce<(&rustc_session[4724149daa9f2ace]::session::Session, rustc_middle[6c8ebc09c5dee75c]::ty::context::CurrentGcx, alloc[d3a84aa4019980d4]::sync::Arc<rustc_data_structures[ededeb3d82402ac5]::jobserver::Proxy>, &std[8a52549f710fb415]::sync::once_lock::OnceLock<rustc_middle[6c8ebc09c5dee75c]::ty::context::GlobalCtxt>, &rustc_data_structures[ededeb3d82402ac5]::sync::worker_local::WorkerLocal<rustc_middle[6c8ebc09c5dee75c]::arena::Arena>, &rustc_data_structures[ededeb3d82402ac5]::sync::worker_local::WorkerLocal<rustc_hir[d3cd5594ffcae9cc]::Arena>, rustc_driver_impl[84ab8a953ff30580]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  35:     0x7fee4a5ce48a - rustc_interface[f52ab86d5a555b2e]::interface::run_compiler::<(), rustc_driver_impl[84ab8a953ff30580]::run_compiler::{closure#0}>::{closure#1}
  36:     0x7fee4a54c3ce - std[8a52549f710fb415]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[f52ab86d5a555b2e]::util::run_in_thread_with_globals<rustc_interface[f52ab86d5a555b2e]::util::run_in_thread_pool_with_globals<rustc_interface[f52ab86d5a555b2e]::interface::run_compiler<(), rustc_driver_impl[84ab8a953ff30580]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  37:     0x7fee4a54c1a0 - <std[8a52549f710fb415]::thread::lifecycle::spawn_unchecked<rustc_interface[f52ab86d5a555b2e]::util::run_in_thread_with_globals<rustc_interface[f52ab86d5a555b2e]::util::run_in_thread_pool_with_globals<rustc_interface[f52ab86d5a555b2e]::interface::run_compiler<(), rustc_driver_impl[84ab8a953ff30580]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[9df9debe8b3ae22c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7fee4a54a578 - <std[8a52549f710fb415]::sys::thread::unix::Thread>::new::thread_start
  39:     0x7fee43c9698b - <unknown>
  40:     0x7fee43d1a9cc - <unknown>
  41:                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.94.0-nightly (efa32de15 2025-12-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

query stack during panic:
#0 [destructure_const] destructuring type level constant
#1 [typeck] type-checking `bar`
#2 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

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

@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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions