Skip to content

ICE: invalid immediate for given destination place: scalar value has wrong size #131406

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

trait Owner {
    const C<const N: u32>: u32 = N;
}

fn take0<const N: u64>(_: impl Owner<C<N> = { N }>) {}

fn main() {
    take0::<128>(());
}

impl Owner for () {
    ;
}


original:

trait Owner {
    const C<const N: u32>: u32 = N;
}

fn take0<const N: u64>(_: impl Owner<C<N> = { N }>) {}

fn main() {
    take0::<128>(());
}

impl Owner for () {
    const C<const N: u32>: u32 = N;
}

fn take0<const N: u64>(_: impl <128>) {}

fn main(_: impl Owner<C<N> = { N }>) {
    take0::<128>(());
}

Version information

rustc 1.83.0-nightly (6a3c45e1c 2024-10-08)
binary: rustc
commit-hash: 6a3c45e1c65e61b298fd6eaceac6d8ef4d973b66
commit-date: 2024-10-08
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.1

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

Program output

error: non-item in item list
  --> /tmp/icemaker_global_tempdir.2w6assLgpoXM/rustc_testrunner_tmpdir_reporting.CKpee9Fi7WqK/mvce.rs:12:5
   |
11 | impl Owner for () {
   |                   - item list starts here
12 |     ;
   |     ^ non-item starts here
13 | }
   | - item list ends here

error[E0658]: associated const equality is incomplete
 --> /tmp/icemaker_global_tempdir.2w6assLgpoXM/rustc_testrunner_tmpdir_reporting.CKpee9Fi7WqK/mvce.rs:5:38
  |
5 | fn take0<const N: u64>(_: impl Owner<C<N> = { N }>) {}
  |                                      ^^^^^^^^^^^^
  |
  = note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
  = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
  = note: this compiler was built on 2024-10-08; consider upgrading it if it is out of date

error[E0658]: generic const items are experimental
 --> /tmp/icemaker_global_tempdir.2w6assLgpoXM/rustc_testrunner_tmpdir_reporting.CKpee9Fi7WqK/mvce.rs:2:12
  |
2 |     const C<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 2024-10-08; consider upgrading it if it is out of date

error: the constant `N` is not of type `u32`
 --> /tmp/icemaker_global_tempdir.2w6assLgpoXM/rustc_testrunner_tmpdir_reporting.CKpee9Fi7WqK/mvce.rs:5:38
  |
5 | fn take0<const N: u64>(_: impl Owner<C<N> = { N }>) {}
  |                                      ^^^^^^^^^^^^ expected `u32`, found `u64`
  |
note: required by a const generic parameter in `Owner::C`
 --> /tmp/icemaker_global_tempdir.2w6assLgpoXM/rustc_testrunner_tmpdir_reporting.CKpee9Fi7WqK/mvce.rs:2:13
  |
2 |     const C<const N: u32>: u32 = N;
  |             ^^^^^^^^^^^^ required by this const generic parameter in `Owner::C`

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/operand.rs:119:17:
assertion `left == right` failed: invalid immediate for given destination place: scalar value has wrong size
  left: Size(8 bytes)
 right: Size(4 bytes)
stack backtrace:
   0:     0x7e41bbb3791a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3a851883c61e7981
   1:     0x7e41bc203466 - core::fmt::write::h71e264ea650e601d
   2:     0x7e41bd422b51 - std::io::Write::write_fmt::h627c59d250fe240c
   3:     0x7e41bbb37772 - std::sys::backtrace::BacktraceLock::print::h44906e04748e3e02
   4:     0x7e41bbb39c46 - std::panicking::default_hook::{{closure}}::he278d98c128c4a9d
   5:     0x7e41bbb39a90 - std::panicking::default_hook::h9cfc75667ebedffd
   6:     0x7e41babea8df - std[584ae1ac58580d89]::panicking::update_hook::<alloc[ea383159db73a253]::boxed::Box<rustc_driver_impl[6a0c09598ae9c08a]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7e41bbb3a358 - std::panicking::rust_panic_with_hook::hb2fe5d026efb466f
   8:     0x7e41bbb3a12a - std::panicking::begin_panic_handler::{{closure}}::h559274bc7def08cd
   9:     0x7e41bbb37dc9 - std::sys::backtrace::__rust_end_short_backtrace::hd9444e85474e39c0
  10:     0x7e41bbb39dec - rust_begin_unwind
  11:     0x7e41b94dbe70 - core::panicking::panic_fmt::h7d898ac73934d0c0
  12:     0x7e41ba5ed256 - core::panicking::assert_failed_inner::h3fd5e0c9c8a24468
  13:     0x7e41bab45cde - core[12ec0f185bbc53d2]::panicking::assert_failed::<rustc_abi[81e5ba8ae6f0eb2a]::Size, rustc_abi[81e5ba8ae6f0eb2a]::Size>
  14:     0x7e41bc998f01 - <rustc_const_eval[bcbc4c0dac6d4403]::interpret::eval_context::InterpCx<rustc_const_eval[bcbc4c0dac6d4403]::const_eval::machine::CompileTimeMachine>>::write_immediate_no_validate::<rustc_const_eval[bcbc4c0dac6d4403]::interpret::place::MPlaceTy>
  15:     0x7e41bc992a14 - <rustc_const_eval[bcbc4c0dac6d4403]::interpret::eval_context::InterpCx<rustc_const_eval[bcbc4c0dac6d4403]::const_eval::machine::CompileTimeMachine>>::return_from_current_stack_frame
  16:     0x7e41b9bdd4c9 - rustc_const_eval[bcbc4c0dac6d4403]::const_eval::eval_queries::eval_to_allocation_raw_provider
  17:     0x7e41bc9a1236 - rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 24usize]>>
  18:     0x7e41bc9a0a5a - rustc_query_system[847c6ad2b9dd3ac1]::query::plumbing::try_execute_query::<rustc_query_impl[3daeaa2f12c0dbc5]::DynamicConfig<rustc_query_system[847c6ad2b9dd3ac1]::query::caches::DefaultCache<rustc_middle[6c2a42b363ada80b]::ty::ParamEnvAnd<rustc_middle[6c2a42b363ada80b]::mir::interpret::GlobalId>, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::QueryCtxt, false>
  19:     0x7e41bc9a062f - rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  20:     0x7e41bc9ba6ab - rustc_const_eval[bcbc4c0dac6d4403]::const_eval::valtrees::eval_to_valtree
  21:     0x7e41bc9ba4bf - <rustc_const_eval[bcbc4c0dac6d4403]::provide::{closure#0} as core[12ec0f185bbc53d2]::ops::function::FnOnce<(rustc_middle[6c2a42b363ada80b]::ty::context::TyCtxt, rustc_middle[6c2a42b363ada80b]::ty::ParamEnvAnd<rustc_middle[6c2a42b363ada80b]::mir::interpret::GlobalId>)>>::call_once
  22:     0x7e41bc9ba476 - rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::eval_to_valtree::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 24usize]>>
  23:     0x7e41bc9ba435 - <rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::eval_to_valtree::dynamic_query::{closure#2} as core[12ec0f185bbc53d2]::ops::function::FnOnce<(rustc_middle[6c2a42b363ada80b]::ty::context::TyCtxt, rustc_middle[6c2a42b363ada80b]::ty::ParamEnvAnd<rustc_middle[6c2a42b363ada80b]::mir::interpret::GlobalId>)>>::call_once
  24:     0x7e41bc9a0b2e - rustc_query_system[847c6ad2b9dd3ac1]::query::plumbing::try_execute_query::<rustc_query_impl[3daeaa2f12c0dbc5]::DynamicConfig<rustc_query_system[847c6ad2b9dd3ac1]::query::caches::DefaultCache<rustc_middle[6c2a42b363ada80b]::ty::ParamEnvAnd<rustc_middle[6c2a42b363ada80b]::mir::interpret::GlobalId>, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::QueryCtxt, false>
  25:     0x7e41bc9a044a - rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7e41bcc18437 - rustc_middle[6c2a42b363ada80b]::query::plumbing::query_get_at::<rustc_query_system[847c6ad2b9dd3ac1]::query::caches::DefaultCache<rustc_middle[6c2a42b363ada80b]::ty::ParamEnvAnd<rustc_middle[6c2a42b363ada80b]::mir::interpret::GlobalId>, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 24usize]>>>
  27:     0x7e41bcc17eaa - <rustc_middle[6c2a42b363ada80b]::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  28:     0x7e41bcc16dbe - <rustc_middle[6c2a42b363ada80b]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  29:     0x7e41bcc16a05 - <rustc_middle[6c2a42b363ada80b]::ty::consts::Const>::normalize
  30:     0x7e41bcab6d26 - rustc_trait_selection[1c2265ed8fe6d14c]::traits::project::opt_normalize_projection_term
  31:     0x7e41bca9cfdc - rustc_trait_selection[1c2265ed8fe6d14c]::traits::project::poly_project_and_unify_term
  32:     0x7e41bc2662a8 - <rustc_trait_selection[1c2265ed8fe6d14c]::traits::select::SelectionContext>::evaluate_root_obligation
  33:     0x7e41bc264292 - rustc_traits[e9b239c6de819adf]::evaluate_obligation::evaluate_obligation
  34:     0x7e41bc263d29 - rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::evaluate_obligation::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 2usize]>>
  35:     0x7e41bc2632d3 - rustc_query_system[847c6ad2b9dd3ac1]::query::plumbing::try_execute_query::<rustc_query_impl[3daeaa2f12c0dbc5]::DynamicConfig<rustc_query_system[847c6ad2b9dd3ac1]::query::caches::DefaultCache<rustc_type_ir[c34a23cd41056f95]::canonical::Canonical<rustc_middle[6c2a42b363ada80b]::ty::context::TyCtxt, rustc_middle[6c2a42b363ada80b]::ty::ParamEnvAnd<rustc_middle[6c2a42b363ada80b]::ty::predicate::Predicate>>, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 2usize]>>, false, false, false>, rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::QueryCtxt, false>
  36:     0x7e41bc262f24 - rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::evaluate_obligation::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7e41b8a3c01e - <rustc_infer[a418d8929ad58d0a]::infer::InferCtxt as rustc_trait_selection[1c2265ed8fe6d14c]::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  38:     0x7e41b88c32b9 - <rustc_trait_selection[1c2265ed8fe6d14c]::traits::fulfill::FulfillProcessor>::process_projection_obligation
  39:     0x7e41b88ab544 - <rustc_trait_selection[1c2265ed8fe6d14c]::traits::fulfill::FulfillProcessor as rustc_data_structures[71eb2d5d27abd3bf]::obligation_forest::ObligationProcessor>::process_obligation
  40:     0x7e41bc20f112 - <rustc_data_structures[71eb2d5d27abd3bf]::obligation_forest::ObligationForest<rustc_trait_selection[1c2265ed8fe6d14c]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[1c2265ed8fe6d14c]::traits::fulfill::FulfillProcessor>
  41:     0x7e41b89d1939 - <rustc_hir_typeck[5f24e1131155eb7]::fn_ctxt::FnCtxt>::confirm_builtin_call
  42:     0x7e41bcea85cf - <rustc_hir_typeck[5f24e1131155eb7]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  43:     0x7e41bcea1a3e - <rustc_hir_typeck[5f24e1131155eb7]::fn_ctxt::FnCtxt>::check_block_with_expected
  44:     0x7e41bcea92e9 - <rustc_hir_typeck[5f24e1131155eb7]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  45:     0x7e41bc549ae1 - rustc_hir_typeck[5f24e1131155eb7]::check::check_fn
  46:     0x7e41bc53e861 - rustc_hir_typeck[5f24e1131155eb7]::typeck
  47:     0x7e41bc53e1cf - rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 8usize]>>
  48:     0x7e41bc64dfba - rustc_query_system[847c6ad2b9dd3ac1]::query::plumbing::try_execute_query::<rustc_query_impl[3daeaa2f12c0dbc5]::DynamicConfig<rustc_query_system[847c6ad2b9dd3ac1]::query::caches::VecCache<rustc_span[ff2bb122df6010f7]::def_id::LocalDefId, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::QueryCtxt, false>
  49:     0x7e41bc64cd1b - rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  50:     0x7e41bc64c9a1 - <rustc_middle[6c2a42b363ada80b]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[944f64ea10dfd453]::check_crate::{closure#4}>::{closure#0}
  51:     0x7e41bc64a8db - rustc_hir_analysis[944f64ea10dfd453]::check_crate
  52:     0x7e41bc647317 - rustc_interface[6c180d597a38bbca]::passes::run_required_analyses
  53:     0x7e41bcf4b41e - rustc_interface[6c180d597a38bbca]::passes::analysis
  54:     0x7e41bcf4b3f1 - rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 1usize]>>
  55:     0x7e41bd1041ee - rustc_query_system[847c6ad2b9dd3ac1]::query::plumbing::try_execute_query::<rustc_query_impl[3daeaa2f12c0dbc5]::DynamicConfig<rustc_query_system[847c6ad2b9dd3ac1]::query::caches::SingleCache<rustc_middle[6c2a42b363ada80b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[3daeaa2f12c0dbc5]::plumbing::QueryCtxt, false>
  56:     0x7e41bd103ecf - rustc_query_impl[3daeaa2f12c0dbc5]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  57:     0x7e41bcf610de - rustc_interface[6c180d597a38bbca]::interface::run_compiler::<core[12ec0f185bbc53d2]::result::Result<(), rustc_span[ff2bb122df6010f7]::ErrorGuaranteed>, rustc_driver_impl[6a0c09598ae9c08a]::run_compiler::{closure#0}>::{closure#1}
  58:     0x7e41bd00b790 - std[584ae1ac58580d89]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[6c180d597a38bbca]::util::run_in_thread_with_globals<rustc_interface[6c180d597a38bbca]::util::run_in_thread_pool_with_globals<rustc_interface[6c180d597a38bbca]::interface::run_compiler<core[12ec0f185bbc53d2]::result::Result<(), rustc_span[ff2bb122df6010f7]::ErrorGuaranteed>, rustc_driver_impl[6a0c09598ae9c08a]::run_compiler::{closure#0}>::{closure#1}, core[12ec0f185bbc53d2]::result::Result<(), rustc_span[ff2bb122df6010f7]::ErrorGuaranteed>>::{closure#0}, core[12ec0f185bbc53d2]::result::Result<(), rustc_span[ff2bb122df6010f7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[12ec0f185bbc53d2]::result::Result<(), rustc_span[ff2bb122df6010f7]::ErrorGuaranteed>>
  59:     0x7e41bd00be57 - <<std[584ae1ac58580d89]::thread::Builder>::spawn_unchecked_<rustc_interface[6c180d597a38bbca]::util::run_in_thread_with_globals<rustc_interface[6c180d597a38bbca]::util::run_in_thread_pool_with_globals<rustc_interface[6c180d597a38bbca]::interface::run_compiler<core[12ec0f185bbc53d2]::result::Result<(), rustc_span[ff2bb122df6010f7]::ErrorGuaranteed>, rustc_driver_impl[6a0c09598ae9c08a]::run_compiler::{closure#0}>::{closure#1}, core[12ec0f185bbc53d2]::result::Result<(), rustc_span[ff2bb122df6010f7]::ErrorGuaranteed>>::{closure#0}, core[12ec0f185bbc53d2]::result::Result<(), rustc_span[ff2bb122df6010f7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[12ec0f185bbc53d2]::result::Result<(), rustc_span[ff2bb122df6010f7]::ErrorGuaranteed>>::{closure#1} as core[12ec0f185bbc53d2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  60:     0x7e41bd00cd41 - std::sys::pal::unix::thread::Thread::new::thread_start::h54d489bd9073b86f
  61:     0x7e41be75139d - <unknown>
  62:     0x7e41be7d649c - <unknown>
  63:                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.83.0-nightly (6a3c45e1c 2024-10-08) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `Owner::C`
#1 [eval_to_valtree] evaluating type-level constant
end of query stack
error: aborting due to 4 previous errors

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-associated_const_equality`#![feature(associated_const_equality)]`F-generic_const_items`#![feature(generic_const_items)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

Status

No status

Status

Can Do

Status

Can Do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions