Skip to content

ICE:rustc panicked at compiler\rustc_const_eval\src\interpret\operand.rs:416:18 #139259

Open
@sososopy

Description

@sososopy

Similar to #139258 code, except that there is an extra 'a:i32' in struct A, B
And the Bug Trace is different, so I report this issue

Code

#![feature(generic_const_exprs)]
#![feature(min_generic_const_args)]

struct A {
    arr: usize,
    a:i32
}
struct B<const N: A> {
    arr: [u8; N.arr],
    a:i32
}
struct Struct(u32);
const C: Struct = Struct(42);
fn main() {
    let b = B::<C> {};
    assert_eq!(b.arr.len(), 5);
}

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (e2014e876 2025-04-01)
binary: rustc
commit-hash: e2014e876e3efaa69bf51c19579adb16c3df5f81
commit-date: 2025-04-01
host: x86_64-pc-windows-msvc
release: 1.88.0-nightly
LLVM version: 20.1.1

Error output

error: overly complex generic constant
   --> ./ttt/test.rs:183:15
    |
183 |     arr: [u8; N.arr],
    |               ^^^^^ field access is not supported in generic constants
    |
    = help: consider moving this anonymous constant into a `const` function
    = note: this operation may be supported in the future

error: `A` is forbidden as the type of a const generic parameter
   --> ./ttt/test.rs:181:19
    |
181 | struct B<const N: A> {
    |                   ^
    |
    = note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
    |
177 + #![feature(adt_const_params)]
    |

error[E0063]: missing fields `a` and `arr` in initializer of `B<C>`
   --> ./ttt/test.rs:189:13
    |
189 |     let b = B::<C> {};
    |             ^^^^^^ missing `a` and `arr`

error: the constant `C` is not of type `A`
   --> ./ttt/test.rs:189:17
    |
189 |     let b = B::<C> {};
    |                 ^ expected `A`, found `Struct`
    |
note: required by a const generic parameter in `B`
   --> ./ttt/test.rs:181:10
    |
181 | struct B<const N: A> {
    |          ^^^^^^^^^^ required by this const generic parameter in `B`

error: internal compiler error: compiler\rustc_const_eval\src\interpret\operand.rs:416:18: invalid field access on immediate {transmute(0x0000002a): A} at offset 0, original layout TyAndLayout {
                                    ty: A,
                                    layout: Layout {
                                        size: Size(16 bytes),
                                        align: AbiAndPrefAlign {
                                            abi: Align(8 bytes),
                                            pref: Align(8 bytes),
                                        },
                                        backend_repr: ScalarPair(
                                            Initialized {
                                                value: Int(
                                                    I64,
                                                    false,
                                                ),
                                                valid_range: 0..=18446744073709551615,
                                            },
                                            Initialized {
                                                value: Int(
                                                    I32,
                                                    true,
                                                ),
                                                valid_range: 0..=4294967295,
                                            },
                                        ),
                                        fields: Arbitrary {
                                            offsets: [
                                                Size(0 bytes),
                                                Size(8 bytes),
                                            ],
                                            memory_index: [
                                                0,
                                                1,
                                            ],
                                        },
                                        largest_niche: None,
                                        uninhabited: false,
                                        variants: Single {
                                            index: 0,
                                        },
                                        max_repr_align: None,
                                        unadjusted_abi_align: Align(8 bytes),
                                        randomization_seed: 2541587965537135706,
                                    },
                                }


Backtrace

thread 'rustc' panicked at compiler\rustc_const_eval\src\interpret\operand.rs:416:18:
Box<dyn Any>
stack backtrace:
   0:     0x7ff8ceb402f2 - std::backtrace_rs::backtrace::win64::trace
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\..\..\backtrace\src\backtrace\win64.rs:85
   1:     0x7ff8ceb402f2 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff8ceb402f2 - std::sys::backtrace::_print_fmt
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\sys\backtrace.rs:66
   3:     0x7ff8ceb402f2 - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\sys\backtrace.rs:39
   4:     0x7ff8ceb7364b - core::fmt::rt::Argument::fmt
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\core\src\fmt\rt.rs:178
   5:     0x7ff8ceb7364b - core::fmt::write
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\core\src\fmt\mod.rs:1480
   6:     0x7ff8ceb36777 - std::io::default_write_fmt
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\io\mod.rs:639
   7:     0x7ff8ceb36777 - std::io::Write::write_fmt<std::sys::stdio::windows::Stderr>
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\io\mod.rs:1914
   8:     0x7ff8ceb40135 - std::sys::backtrace::BacktraceLock::print
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\sys\backtrace.rs:42
   9:     0x7ff8ceb46ffa - std::panicking::default_hook::closure$0
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\panicking.rs:300
  10:     0x7ff8ceb46d90 - std::panicking::default_hook
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\panicking.rs:327
  11:     0x7ff8d0210d67 - core[6d088d7b265a6e22]::slice::sort::unstable::heapsort::heapsort::<((rustc_lint_defs[2e317b48e3d2ebdb]::Level, &str), usize), <((rustc_lint_defs[2e317b48e3d2ebdb]::Level, &str), usize) as core[6d088d7b265a6e22]::cmp::PartialOrd>::lt>
  12:     0x7ff8ceb47c8e - std::panicking::rust_panic_with_hook
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\panicking.rs:841
  13:     0x7ff8d1a23b53 - RINvNtNtNtNtCs9mnHtfphvnG_4core5slice4sort6stable9quicksort9quicksortTjRNtNtCslBZCZaLskxK_12rustc_errors7snippet10AnnotationENCINvMNtCsa2p6rIrRCRF_5alloc5sliceSB15_11sort_by_keyTINtNtBa_3cmp7ReversejEbENCNCNvMs5_NtB1c_7emitterNtB3o_12HumanEmitter18render_s
  14:     0x7ff8d1a16e09 - std[2b19152666764cb3]::sys::backtrace::__rust_end_short_backtrace::<std[2b19152666764cb3]::panicking::begin_panic<rustc_errors[fbbcdbab4d048c8e]::ExplicitBug>::{closure#0}, !>
  15:     0x7ff8d1a11b53 - std[2b19152666764cb3]::panicking::begin_panic::<rustc_errors[fbbcdbab4d048c8e]::ExplicitBug>
  16:     0x7ff8d1a30bd5 - <rustc_errors[fbbcdbab4d048c8e]::diagnostic::BugAbort as rustc_errors[fbbcdbab4d048c8e]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  17:     0x7ff8d1977df9 - rustc_middle[aacb0f4b714b863e]::util::bug::span_bug_fmt::<rustc_span[d3576ee5acc9c9de]::span_encoding::Span>
  18:     0x7ff8d194d33d - <rustc_middle[aacb0f4b714b863e]::ty::consts::Const>::to_value
  19:     0x7ff8d194d106 - <rustc_middle[aacb0f4b714b863e]::ty::consts::Const>::to_value
  20:     0x7ff8d1977cf2 - rustc_middle[aacb0f4b714b863e]::util::bug::bug_fmt
  21:     0x7ff8cf444d38 - <rustc_const_eval[cdeb1530e4b9f185]::interpret::eval_context::InterpCx<_>>::storage_live_dyn::is_very_trivially_sized
  22:     0x7ff8cf563c6e - rustc_const_eval[cdeb1530e4b9f185]::const_eval::eval_queries::eval_to_allocation_raw_provider
  23:     0x7ff8cfa276d8 - rustc_query_impl[56f20a7905ba520b]::plumbing::query_key_hash_verify_all
  24:     0x7ff8cf91f4b8 - RINvNtNtCsd292uDN0rBR_18rustc_query_system5query8plumbing17try_execute_queryINtCs7sO8FYcisaZ_16rustc_query_impl13DynamicConfigINtNtB4_6caches12DefaultCacheINtNtCseF7WPnEfXL6_12rustc_middle2ty20PseudoCanonicalInputNtNtNtB2y_3mir9interpret8GlobalIdEINtNtNtB2
  25:     0x7ff8cfa31093 - rustc_query_impl[56f20a7905ba520b]::plumbing::query_key_hash_verify_all
  26:     0x7ff8ce4a1783 - rustc_const_eval[cdeb1530e4b9f185]::const_eval::valtrees::eval_to_valtree
  27:     0x7ff8cb4a2ae7 - <alloc[74ed9035c15269e1]::sync::Arc<std[2b19152666764cb3]::sync::poison::mutex::Mutex<core[6d088d7b265a6e22]::option::Option<()>>>>::drop_slow
  28:     0x7ff8ce6c6dc8 - RINvNtNtCsd292uDN0rBR_18rustc_query_system5query8plumbing17try_execute_queryINtCs7sO8FYcisaZ_16rustc_query_impl13DynamicConfigINtNtCs6OLjYz5jF8a_21rustc_data_structures9vec_cache8VecCacheNtNtCsi8XTrxUbIbW_10rustc_span6def_id8CrateNumINtNtNtCseF7WPnEfXL6_12
  29:     0x7ff8ce69d0ab - RINvNtNtCsd292uDN0rBR_18rustc_query_system5query8plumbing17try_execute_queryINtCs7sO8FYcisaZ_16rustc_query_impl13DynamicConfigINtNtCs6OLjYz5jF8a_21rustc_data_structures9vec_cache8VecCacheNtNtCsi8XTrxUbIbW_10rustc_span6def_id8CrateNumINtNtNtCseF7WPnEfXL6_12
  30:     0x7ff8cf91f5f6 - RINvNtNtCsd292uDN0rBR_18rustc_query_system5query8plumbing17try_execute_queryINtCs7sO8FYcisaZ_16rustc_query_impl13DynamicConfigINtNtB4_6caches12DefaultCacheINtNtCseF7WPnEfXL6_12rustc_middle2ty20PseudoCanonicalInputNtNtNtB2y_3mir9interpret8GlobalIdEINtNtNtB2
  31:     0x7ff8ce6ddc23 - rustc_query_impl[56f20a7905ba520b]::query_system
  32:     0x7ff8ce9cd5db - <rustc_middle[aacb0f4b714b863e]::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  33:     0x7ff8ce9c9d6f - <rustc_middle[aacb0f4b714b863e]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  34:     0x7ff8ce7e43bf - rustc_trait_selection[3fe63704279140bd]::traits::try_evaluate_const
  35:     0x7ff8ce7bff50 - <rustc_trait_selection[3fe63704279140bd]::traits::query::normalize::QueryNormalizer as rustc_type_ir[9d33fc60d68d2dcf]::fold::FallibleTypeFolder<rustc_middle[aacb0f4b714b863e]::ty::context::TyCtxt>>::try_fold_const
  36:     0x7ff8ceba6ede - <tracing_subscriber[1d72ba99e274072e]::registry::sharded::Registry as core[6d088d7b265a6e22]::default::Default>::default
  37:     0x7ff8cfa282f5 - rustc_query_impl[56f20a7905ba520b]::plumbing::query_key_hash_verify_all
  38:     0x7ff8cf91a783 - RINvNtNtCsd292uDN0rBR_18rustc_query_system5query8plumbing17try_execute_queryINtCs7sO8FYcisaZ_16rustc_query_impl13DynamicConfigINtNtB4_6caches12DefaultCacheINtNtCseF7WPnEfXL6_12rustc_middle2ty20PseudoCanonicalInputNtNtB2w_12generic_args10GenericArgEINtNtNtB
  39:     0x7ff8cfa39113 - rustc_query_impl[56f20a7905ba520b]::plumbing::query_key_hash_verify_all
  40:     0x7ff8ce9985de - <rustc_middle[aacb0f4b714b863e]::ty::normalize_erasing_regions::TryNormalizeAfterErasingRegionsFolder as rustc_type_ir[9d33fc60d68d2dcf]::fold::FallibleTypeFolder<rustc_middle[aacb0f4b714b863e]::ty::context::TyCtxt>>::try_fold_const
  41:     0x7ff8d066066b - <rustc_hir_typeck[9044826a83b93224]::writeback::EagerlyNormalizeConsts as rustc_type_ir[9d33fc60d68d2dcf]::fold::TypeFolder<rustc_middle[aacb0f4b714b863e]::ty::context::TyCtxt>>::fold_const
  42:     0x7ff8d051353f - RINvNtNtNtNtCs9mnHtfphvnG_4core5slice4sort8unstable8heapsort8heapsortTRNtNtCsi8XTrxUbIbW_10rustc_span6def_id10LocalDefIdRINtNtCsNjHbSUiwjI_8indexmap3map8IndexMapNtNtCsdoLqZK1Fple_9rustc_hir6hir_id5HirIdINtNtCsa2p6rIrRCRF_5alloc3vec3VecNtNtNtCseF7WPnEfXL6_1
  43:     0x7ff8d051359b - RINvNtNtNtNtCs9mnHtfphvnG_4core5slice4sort8unstable8heapsort8heapsortTRNtNtCsi8XTrxUbIbW_10rustc_span6def_id10LocalDefIdRINtNtCsNjHbSUiwjI_8indexmap3map8IndexMapNtNtCsdoLqZK1Fple_9rustc_hir6hir_id5HirIdINtNtCsa2p6rIrRCRF_5alloc3vec3VecNtNtNtCseF7WPnEfXL6_1
  44:     0x7ff8cede2597 - <rustc_hir_typeck[9044826a83b93224]::upvar::InferBorrowKind as rustc_hir_typeck[9044826a83b93224]::expr_use_visitor::Delegate>::borrow
  45:     0x7ff8ced8fe3f - <rustc_hir_typeck[9044826a83b93224]::writeback::WritebackCx as rustc_hir[9c124fbbc18ac5d2]::intravisit::Visitor>::visit_expr
  46:     0x7ff8ced9025c - <rustc_hir_typeck[9044826a83b93224]::writeback::WritebackCx as rustc_hir[9c124fbbc18ac5d2]::intravisit::Visitor>::visit_expr
  47:     0x7ff8ced8ff1e - <rustc_hir_typeck[9044826a83b93224]::writeback::WritebackCx as rustc_hir[9c124fbbc18ac5d2]::intravisit::Visitor>::visit_expr
  48:     0x7ff8ced8ff04 - <rustc_hir_typeck[9044826a83b93224]::writeback::WritebackCx as rustc_hir[9c124fbbc18ac5d2]::intravisit::Visitor>::visit_expr
  49:     0x7ff8ced904e9 - <rustc_hir_typeck[9044826a83b93224]::writeback::WritebackCx as rustc_hir[9c124fbbc18ac5d2]::intravisit::Visitor>::visit_expr
  50:     0x7ff8ced90201 - <rustc_hir_typeck[9044826a83b93224]::writeback::WritebackCx as rustc_hir[9c124fbbc18ac5d2]::intravisit::Visitor>::visit_expr
  51:     0x7ff8ced8578a - <rustc_hir_typeck[9044826a83b93224]::upvar::InferBorrowKindVisitor as rustc_hir[9c124fbbc18ac5d2]::intravisit::Visitor>::visit_expr
  52:     0x7ff8cede7386 - <rustc_hir_typeck[9044826a83b93224]::upvar::InferBorrowKind as rustc_hir_typeck[9044826a83b93224]::expr_use_visitor::Delegate>::borrow
  53:     0x7ff8ced9512f - rustc_hir_typeck[9044826a83b93224]::typeck
  54:     0x7ff8cfa283fb - rustc_query_impl[56f20a7905ba520b]::plumbing::query_key_hash_verify_all
  55:     0x7ff8cf96a4bb - RINvNtNtCsd292uDN0rBR_18rustc_query_system5query8plumbing17try_execute_queryINtCs7sO8FYcisaZ_16rustc_query_impl13DynamicConfigINtNtCs6OLjYz5jF8a_21rustc_data_structures9vec_cache8VecCacheNtNtCsi8XTrxUbIbW_10rustc_span6def_id10LocalDefIdINtNtNtCseF7WPnEfXL6
  56:     0x7ff8cfa30942 - rustc_query_impl[56f20a7905ba520b]::plumbing::query_key_hash_verify_all
  57:     0x7ff8cee1eb3d - RINvMs6_NtCs9GUOe0vHTal_9hashbrown3rawINtB6_8RawTablejE14reserve_rehashNCINvNtNtCsNjHbSUiwjI_8indexmap3map4core8get_hashTNtNtNtCseF7WPnEfXL6_12rustc_middle2ty9predicate6ClauseNtNtCsi8XTrxUbIbW_10rustc_span13span_encoding4SpanEuE0ECs7279yv5bpcP_18rustc_hir_
  58:     0x7ff8ceeb8ce7 - rustc_hir_analysis[51ee44c3c3f46e99]::check_crate
  59:     0x7ff8cebb0abf - rustc_interface[75012607f30e9760]::passes::resolver_for_lowering_raw
  60:     0x7ff8cb4b6237 - rustc_interface[75012607f30e9760]::passes::analysis
  61:     0x7ff8ce6ca91a - RINvNtNtCsd292uDN0rBR_18rustc_query_system5query8plumbing17try_execute_queryINtCs7sO8FYcisaZ_16rustc_query_impl13DynamicConfigINtNtCs6OLjYz5jF8a_21rustc_data_structures9vec_cache8VecCacheNtNtCsi8XTrxUbIbW_10rustc_span6def_id8CrateNumINtNtNtCseF7WPnEfXL6_12
  62:     0x7ff8ce5d42ce - RINvNtNtCsd292uDN0rBR_18rustc_query_system5query8plumbing17try_execute_queryINtCs7sO8FYcisaZ_16rustc_query_impl13DynamicConfigINtNtB4_6caches11SingleCacheINtNtNtCseF7WPnEfXL6_12rustc_middle5query5erase6ErasedAhj0_EEKb0_KB3s_KB3s_ENtNtB1f_8plumbing9QueryCtx
  63:     0x7ff8ce6d0b43 - rustc_query_impl[56f20a7905ba520b]::query_system
  64:     0x7ff8cb479eef - RINvNtNtCs3HpoeEqdUFH_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCsa2p6rIrRCRF_5alloc5boxed3BoxDINtNtNtCs9mnHtfphvnG_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECskVE
  65:     0x7ff8cb473e23 - RINvNtNtCs3HpoeEqdUFH_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCsa2p6rIrRCRF_5alloc5boxed3BoxDINtNtNtCs9mnHtfphvnG_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECskVE
  66:     0x7ff8cb46ebd3 - RINvNtNtCs3HpoeEqdUFH_3std3sys9backtrace28___rust_begin_short_backtraceNCNCINvNtCsa2OlQQRayV8_15rustc_interface4util26run_in_thread_with_globalsNCINvB1e_31run_in_thread_pool_with_globalsNCINvNtB1g_9interface12run_compileruNCNvCskVEWmdzkxyR_17rustc_driver_i
  67:     0x7ff8cb47e4d0 - RINvNtNtCs3HpoeEqdUFH_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCsa2p6rIrRCRF_5alloc5boxed3BoxDINtNtNtCs9mnHtfphvnG_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECskVE
  68:     0x7ff8ceb4c9ad - alloc::boxed::impl$28::call_once
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\alloc\src\boxed.rs:1966
  69:     0x7ff8ceb4c9ad - alloc::boxed::impl$28::call_once
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\alloc\src\boxed.rs:1966
  70:     0x7ff8ceb4c9ad - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/e2014e876e3efaa69bf51c19579adb16c3df5f81/library\std\src\sys\pal\windows\thread.rs:56
  71:     0x7ff9ae2d7374 - BaseThreadInitThunk
  72:     0x7ff9ae7bcc91 - RtlUserThreadStart

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: please attach the file at `D:\rust_test\test1\src\rustc-ice-2025-04-02T14_05_16-26960.txt` to your bug report

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `B::arr::{constant#0}`
#1 [eval_to_valtree] evaluating type-level constant
... and 3 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
error: aborting due to 5 previous errors; 2 warnings emitted

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`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.requires-incomplete-featuresThis issue requires the use of incomplete features.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions