rust-lang / rust-lang/rust

[ICE]: `invalid immediate for given destination place: scalar value has wrong size`

Open
#161,510 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-generic_const_args F-generic_const_items F-min_generic_const_args I-ICE needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

#![feature(generic_const_args)]

trait Owner {
    const K<const N : u16>: u16;
}
impl Owner for () {
    const K<const N : u32> : u32 = N;
}
fn take1(_: impl Owner<K<9> = 0>) {
    take1(())
}

original:

#![feature(generic_const_args)]
#![feature(min_generic_const_args)]
#![feature(generic_const_items)]


trait Owner {
    const K<const N : u16>: u16;
}
impl Owner for () {
    const K<const N : u32> : u32 = N;
}
fn take1(_: impl Owner<K<9> = 0>) {
    take1(())
}

fn main() {}

Version information

rustc 1.100.0-nightly (8536f4de9 2026-08-22)
binary: rustc
commit-hash: 8536f4de90e5e781c06e584f8a88de860adc798b
commit-date: 2026-08-22
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.0

Possibly related line of code:
https://github.com/rust-lang/rust/blob/8536f4de90e5e781c06e584f8a88de860adc798b/compiler/rustc_const_eval/src/interpret/operand.rs#L116-L128

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

Program output

error: `generic_const_args` requires `min_generic_const_args` to be enabled
 --> /tmp/icemaker_global_tempdir.o4FI5rQou7VT/rustc_testrunner_tmpdir_reporting.0AJls2wI4xES/mvce.rs:1:12
  |
1 | #![feature(generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^
  |
  = help: enable all of these features

error[E0658]: generic const items are experimental
 --> /tmp/icemaker_global_tempdir.o4FI5rQou7VT/rustc_testrunner_tmpdir_reporting.0AJls2wI4xES/mvce.rs:4:12
  |
4 |     const K<const N : u16>: u16;
  |            ^^^^^^^^^^^^^^^
  |
  = note: see issue #113521 <https://github.com/rust-lang/rust/issues/113521> for more information
  = help: add `#![feature(generic_const_items)]` to the crate attributes to enable
  = note: this compiler was built on 2026-08-22; consider upgrading it if it is out of date

error[E0658]: generic const items are experimental
 --> /tmp/icemaker_global_tempdir.o4FI5rQou7VT/rustc_testrunner_tmpdir_reporting.0AJls2wI4xES/mvce.rs:7:12
  |
7 |     const K<const N : u32> : u32 = N;
  |            ^^^^^^^^^^^^^^^
  |
  = note: see issue #113521 <https://github.com/rust-lang/rust/issues/113521> for more information
  = help: add `#![feature(generic_const_items)]` to the crate attributes to enable
  = note: this compiler was built on 2026-08-22; consider upgrading it if it is out of date

error[E0658]: associated const equality is incomplete
 --> /tmp/icemaker_global_tempdir.o4FI5rQou7VT/rustc_testrunner_tmpdir_reporting.0AJls2wI4xES/mvce.rs:9:24
  |
9 | fn take1(_: impl Owner<K<9> = 0>) {
  |                        ^^^^^^^^
  |
  = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
  = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable
  = note: this compiler was built on 2026-08-22; consider upgrading it if it is out of date

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

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

error[E0053]: associated constant `K` has an incompatible generic parameter for trait `Owner`
 --> /tmp/icemaker_global_tempdir.o4FI5rQou7VT/rustc_testrunner_tmpdir_reporting.0AJls2wI4xES/mvce.rs:7:13
  |
3 | trait Owner {
  |       -----
4 |     const K<const N : u16>: u16;
  |             ------------- expected const parameter of type `u16`
5 | }
6 | impl Owner for () {
  | -----------------
7 |     const K<const N : u32> : u32 = N;
  |             ^^^^^^^^^^^^^ found const parameter of type `u32`


thread 'rustc' (3624088) panicked at /rustc-dev/8536f4de90e5e781c06e584f8a88de860adc798b/compiler/rustc_const_eval/src/interpret/operand.rs:122:17:
assertion `left == right` failed: invalid immediate for given destination place: scalar value has wrong size
  left: Size(2 bytes)
 right: Size(4 bytes)
stack backtrace:
   0:     0x7f1c36fef966 - <<std[6a2a162ccd49bd24]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[34df38ed1aeeb409]::fmt::Display>::fmt
   1:     0x7f1c3760b063 - core[34df38ed1aeeb409]::fmt::write
   2:     0x7f1c37004e4c - <std[6a2a162ccd49bd24]::sys::stdio::unix::Stderr as core[34df38ed1aeeb409]::io::write::Write>::write_fmt
   3:     0x7f1c36fc2bea - std[6a2a162ccd49bd24]::panicking::default_hook::{closure#0}
   4:     0x7f1c36fe3c03 - std[6a2a162ccd49bd24]::panicking::default_hook
   5:     0x7f1c35f9f25a - std[6a2a162ccd49bd24]::panicking::update_hook::<alloc[d780ca98ca945870]::boxed::Box<rustc_driver_impl[914da1ef5f0db717]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f1c36fe40a2 - std[6a2a162ccd49bd24]::panicking::panic_with_hook
   7:     0x7f1c36fc2ca2 - std[6a2a162ccd49bd24]::panicking::panic_handler::{closure#0}
   8:     0x7f1c36fbadd9 - std[6a2a162ccd49bd24]::sys::backtrace::__rust_end_short_backtrace::<std[6a2a162ccd49bd24]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f1c36fc46ad - __rustc[8236491043d97613]::rust_begin_unwind
  10:     0x7f1c33c2f00c - core[34df38ed1aeeb409]::panicking::panic_fmt
  11:     0x7f1c359332b3 - core[34df38ed1aeeb409]::panicking::assert_failed_inner
  12:     0x7f1c36527f00 - core[34df38ed1aeeb409]::panicking::assert_failed::<rustc_abi[a860a93160536fb1]::Size, rustc_abi[a860a93160536fb1]::Size>
  13:     0x7f1c37d6466c - <rustc_const_eval[972a1eb05da00dbd]::interpret::eval_context::InterpCx<rustc_const_eval[972a1eb05da00dbd]::const_eval::machine::CompileTimeMachine>>::copy_op_no_validate::<rustc_const_eval[972a1eb05da00dbd]::interpret::operand::OpTy, rustc_const_eval[972a1eb05da00dbd]::interpret::place::PlaceTy>
  14:     0x7f1c351027d7 - rustc_const_eval[972a1eb05da00dbd]::const_eval::eval_queries::eval_to_allocation_raw_provider
  15:     0x7f1c3763bcd6 - rustc_query_impl[7883aff223ddbf83]::query_vtables::eval_to_allocation_raw::invoke_provider_fn::__rust_begin_short_backtrace
  16:     0x7f1c3865bdfa - rustc_query_impl[7883aff223ddbf83]::execution::try_execute_query::<rustc_middle[e13af1fab9e07cac]::query::caches::DefaultCache<rustc_middle[e13af1fab9e07cac]::ty::PseudoCanonicalInput<rustc_middle[e13af1fab9e07cac]::mir::interpret::GlobalId>, rustc_middle[e13af1fab9e07cac]::query::erase::ErasedData<[u8; 24usize]>>, false>
  17:     0x7f1c3865b367 - rustc_query_impl[7883aff223ddbf83]::query_vtables::eval_to_allocation_raw::execute_query_non_incr::__rust_end_short_backtrace
  18:     0x7f1c350ffc9a - rustc_const_eval[972a1eb05da00dbd]::const_eval::eval_queries::eval_to_allocation_raw_provider
  19:     0x7f1c3763bcd6 - rustc_query_impl[7883aff223ddbf83]::query_vtables::eval_to_allocation_raw::invoke_provider_fn::__rust_begin_short_backtrace
  20:     0x7f1c3865bdfa - rustc_query_impl[7883aff223ddbf83]::execution::try_execute_query::<rustc_middle[e13af1fab9e07cac]::query::caches::DefaultCache<rustc_middle[e13af1fab9e07cac]::ty::PseudoCanonicalInput<rustc_middle[e13af1fab9e07cac]::mir::interpret::GlobalId>, rustc_middle[e13af1fab9e07cac]::query::erase::ErasedData<[u8; 24usize]>>, false>
  21:     0x7f1c3865b367 - rustc_query_impl[7883aff223ddbf83]::query_vtables::eval_to_allocation_raw::execute_query_non_incr::__rust_end_short_backtrace
  22:     0x7f1c3474d8d6 - rustc_const_eval[972a1eb05da00dbd]::const_eval::valtrees::eval_to_valtree
  23:     0x7f1c383a7fe6 - <rustc_const_eval[972a1eb05da00dbd]::provide::{closure#0} as core[34df38ed1aeeb409]::ops::function::FnOnce<(rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt, rustc_middle[e13af1fab9e07cac]::ty::PseudoCanonicalInput<rustc_middle[e13af1fab9e07cac]::mir::interpret::GlobalId>)>>::call_once
  24:     0x7f1c383a7fa2 - rustc_query_impl[7883aff223ddbf83]::query_vtables::eval_to_valtree::invoke_provider_fn::__rust_begin_short_backtrace
  25:     0x7f1c383a7676 - rustc_query_impl[7883aff223ddbf83]::execution::try_execute_query::<rustc_middle[e13af1fab9e07cac]::query::caches::DefaultCache<rustc_middle[e13af1fab9e07cac]::ty::PseudoCanonicalInput<rustc_middle[e13af1fab9e07cac]::mir::interpret::GlobalId>, rustc_middle[e13af1fab9e07cac]::query::erase::ErasedData<[u8; 16usize]>>, false>
  26:     0x7f1c383a733f - rustc_query_impl[7883aff223ddbf83]::query_vtables::eval_to_valtree::execute_query_non_incr::__rust_end_short_backtrace
  27:     0x7f1c3773fef1 - <rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  28:     0x7f1c3773f9f2 - <rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  29:     0x7f1c3773ecbe - <rustc_next_trait_solver[71fb316e451aa38c]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[c751c4991df8534b]::solve::delegate::SolverDelegate, rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>>::evaluate_const
  30:     0x7f1c3772b2f5 - <rustc_next_trait_solver[71fb316e451aa38c]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[c751c4991df8534b]::solve::delegate::SolverDelegate, rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>>::evaluate_const_and_instantiate_projection_term
  31:     0x7f1c38da7ede - <rustc_next_trait_solver[71fb316e451aa38c]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[c751c4991df8534b]::solve::delegate::SolverDelegate, rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>>::assemble_and_evaluate_candidates::<rustc_type_ir[277fd484b88c078f]::predicate::NormalizesTo<rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>>
  32:     0x7f1c344e7520 - <rustc_type_ir[277fd484b88c078f]::search_graph::SearchGraph<rustc_next_trait_solver[71fb316e451aa38c]::solve::search_graph::SearchGraphDelegate<rustc_trait_selection[c751c4991df8534b]::solve::delegate::SolverDelegate>, rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>>::evaluate_goal::{closure#0}
  33:     0x7f1c38561928 - <rustc_next_trait_solver[71fb316e451aa38c]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[c751c4991df8534b]::solve::delegate::SolverDelegate, rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>>::evaluate_goal_raw
  34:     0x7f1c344e6a07 - <rustc_type_ir[277fd484b88c078f]::search_graph::SearchGraph<rustc_next_trait_solver[71fb316e451aa38c]::solve::search_graph::SearchGraphDelegate<rustc_trait_selection[c751c4991df8534b]::solve::delegate::SolverDelegate>, rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>>::evaluate_goal::{closure#0}
  35:     0x7f1c383e5430 - <rustc_next_trait_solver[71fb316e451aa38c]::solve::eval_ctxt::EvalCtxt<rustc_trait_selection[c751c4991df8534b]::solve::delegate::SolverDelegate, rustc_middle[e13af1fab9e07cac]::ty::context::TyCtxt>>::evaluate_goal_no_fast_paths
  36:     0x7f1c3760c001 - <rustc_trait_selection[c751c4991df8534b]::traits::engine::FulfillmentEngine<rustc_trait_selection[c751c4991df8534b]::traits::FulfillmentError> as rustc_infer[d9cb6d70c198d788]::traits::engine::TraitEngine<rustc_trait_selection[c751c4991df8534b]::traits::FulfillmentError>>::try_evaluate_obligations
  37:     0x7f1c377adbe1 - <rustc_hir_typeck[794a63979e72c52d]::fn_ctxt::FnCtxt>::check_expr_call
  38:     0x7f1c37fe6675 - <rustc_hir_typeck[794a63979e72c52d]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  39:     0x7f1c37fdf7fd - <rustc_hir_typeck[794a63979e72c52d]::fn_ctxt::FnCtxt>::check_expr_block
  40:     0x7f1c37fe6692 - <rustc_hir_typeck[794a63979e72c52d]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  41:     0x7f1c37766861 - rustc_hir_typeck[794a63979e72c52d]::check::check_fn
  42:     0x7f1c381184d8 - rustc_hir_typeck[794a63979e72c52d]::typeck_with_inspect::{closure#0}
  43:     0x7f1c38116a4a - rustc_query_impl[7883aff223ddbf83]::query_vtables::typeck_root::invoke_provider_fn::__rust_begin_short_backtrace
  44:     0x7f1c380f0f35 - rustc_query_impl[7883aff223ddbf83]::execution::try_execute_query::<rustc_data_structures[f27dd378dd25622a]::vec_cache::VecCache<rustc_span[e5991a1499837571]::def_id::LocalDefId, rustc_middle[e13af1fab9e07cac]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[e13af1fab9e07cac]::dep_graph::graph::DepNodeIndex>, false>
  45:     0x7f1c380f0ba7 - rustc_query_impl[7883aff223ddbf83]::query_vtables::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
  46:     0x7f1c37eb8914 - rustc_hir_analysis[6c6705371eee3cd0]::check_crate
  47:     0x7f1c380f243a - rustc_interface[4cb4cba335c0809d]::passes::analysis
  48:     0x7f1c3882ef4a - rustc_query_impl[7883aff223ddbf83]::execution::try_execute_query::<rustc_middle[e13af1fab9e07cac]::query::caches::SingleCache<rustc_middle[e13af1fab9e07cac]::query::erase::ErasedData<[u8; 0usize]>>, false>
  49:     0x7f1c3882ecd3 - rustc_query_impl[7883aff223ddbf83]::query_vtables::analysis::execute_query_non_incr::__rust_end_short_backtrace
  50:     0x7f1c389afb6b - rustc_interface[4cb4cba335c0809d]::interface::run_compiler::<(), rustc_driver_impl[914da1ef5f0db717]::run_compiler::{closure#0}>::{closure#2}
  51:     0x7f1c389da7e4 - std[6a2a162ccd49bd24]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4cb4cba335c0809d]::util::run_in_thread_with_globals<rustc_interface[4cb4cba335c0809d]::util::run_in_thread_pool_with_globals<rustc_interface[4cb4cba335c0809d]::interface::run_compiler<(), rustc_driver_impl[914da1ef5f0db717]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  52:     0x7f1c389da5ad - <std[6a2a162ccd49bd24]::thread::lifecycle::spawn_unchecked<rustc_interface[4cb4cba335c0809d]::util::run_in_thread_with_globals<rustc_interface[4cb4cba335c0809d]::util::run_in_thread_pool_with_globals<rustc_interface[4cb4cba335c0809d]::interface::run_compiler<(), rustc_driver_impl[914da1ef5f0db717]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[34df38ed1aeeb409]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  53:     0x7f1c389d82c7 - <std[6a2a162ccd49bd24]::sys::thread::unix::Thread>::new::thread_start
  54:     0x7f1c31c97739 - <unknown>
  55:     0x7f1c31d1bedc - <unknown>
  56:                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.100.0-nightly (8536f4de9 2026-08-22) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `<impl at /tmp/icemaker_global_tempdir.o4FI5rQou7VT/rustc_testrunner_tmpdir_reporting.0AJls2wI4xES/mvce.rs:6:1: 6:18>::K`
#1 [eval_to_allocation_raw] const-evaluating + checking `<impl at /tmp/icemaker_global_tempdir.o4FI5rQou7VT/rustc_testrunner_tmpdir_reporting.0AJls2wI4xES/mvce.rs:6:1: 6:18>::K`
#2 [eval_to_valtree] evaluating type-level constant
#3 [typeck_root] type-checking `take1`
#4 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 6 previous errors; 1 warning emitted

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

@rustbot label +F-generic_const_args +F-min_generic_const_args +F-generic_const_items

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the reduced b.rs reproducer with the nightly rustc version reported in the issue. Then inspect compiler/rustc_const_eval/src/interpret/operand.rs around lines 116-128 and trace the const-evaluation path shown in the backtrace. Done means the reproducer no longer causes the scalar-size assertion ICE and instead produces an appropriate compiler result or diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.