Skip to content

[ICE]: invalid field access on immediate #154748

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(min_generic_const_args)]

type const S: bool = 1i32;
type const T: bool = -1i32;

fn main() {
    T;
    S;
    S;
}

original:

//@ incremental//!                     <https://github.com/rust-lang/rust/issues/154636>
//@ incremental
#![feature(min_generic_const_args)]
type const U: usize = -1_i32; //~ ERROR: the constant `1` is not of type `usize`
type const U: usize = -1_i32;
type const S: bool = 1i32; //~ ERROR: the constant `1` is not of type `bool`
type const T: bool = -1i32; //~ ERROR: the constant `-1` is not of type `bool`

fn main() {
    T;
    S;
    S;

}

Version information

rustc 1.96.0-nightly (5bbdeaa9a 2026-04-03)
binary: rustc
commit-hash: 5bbdeaa9a8dc563185f40e99f96704cbcc7a6e6e
commit-date: 2026-04-03
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2

Possibly related line of code:

} else {
assert_eq!(offset, a.size(cx).align_to(b.align(cx).abi));
b_val
})
}
// everything else is a bug
_ => bug!(
"invalid field access on immediate {} at offset {}, original layout {:#?}",
self,
offset.bytes(),
self.layout
),
};

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.VcGEzXc6B2mO/rustc_testrunner_tmpdir_reporting.unbVhMZfucFM/mvce.rs:1:12
  |
1 | #![feature(min_generic_const_args)]
  |            ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
  = note: `#[warn(incomplete_features)]` on by default

error: the constant `1` is not of type `bool`
 --> /tmp/icemaker_global_tempdir.VcGEzXc6B2mO/rustc_testrunner_tmpdir_reporting.unbVhMZfucFM/mvce.rs:3:1
  |
3 | type const S: bool = 1i32;
  | ^^^^^^^^^^^^^^^^^^ expected `bool`, found `i32`

error: the constant `-1` is not of type `bool`
 --> /tmp/icemaker_global_tempdir.VcGEzXc6B2mO/rustc_testrunner_tmpdir_reporting.unbVhMZfucFM/mvce.rs:4:1
  |
4 | type const T: bool = -1i32;
  | ^^^^^^^^^^^^^^^^^^ expected `bool`, found `i32`

error: internal compiler error: /rustc-dev/5bbdeaa9a8dc563185f40e99f96704cbcc7a6e6e/compiler/rustc_const_eval/src/interpret/operand.rs:430:18: invalid field access on immediate -1_i32 at offset 0, original layout TyAndLayout {
                                    ty: i32,
                                    layout: Layout {
                                        size: Size(4 bytes),
                                        align: AbiAlign {
                                            abi: Align(4 bytes),
                                        },
                                        backend_repr: Scalar(
                                            Initialized {
                                                value: Int(
                                                    I32,
                                                    true,
                                                ),
                                                valid_range: 0..=4294967295,
                                            },
                                        ),
                                        fields: Primitive,
                                        largest_niche: None,
                                        uninhabited: false,
                                        variants: Single {
                                            index: 0,
                                        },
                                        max_repr_align: None,
                                        unadjusted_abi_align: Align(4 bytes),
                                        randomization_seed: 18446462603027873795,
                                    },
                                }


thread 'rustc' (903782) panicked at /rustc-dev/5bbdeaa9a8dc563185f40e99f96704cbcc7a6e6e/compiler/rustc_const_eval/src/interpret/operand.rs:430:18:
Box<dyn Any>
stack backtrace:
   0:     0x7f26427c8d7b - <<std[55fbeb01ec93ae41]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[6b09cf77c14f6d64]::fmt::Display>::fmt
   1:     0x7f2642e1db88 - core[6b09cf77c14f6d64]::fmt::write
   2:     0x7f26427dfd86 - <std[55fbeb01ec93ae41]::sys::stdio::unix::Stderr as std[55fbeb01ec93ae41]::io::Write>::write_fmt
   3:     0x7f264279ed88 - std[55fbeb01ec93ae41]::panicking::default_hook::{closure#0}
   4:     0x7f26427bc183 - std[55fbeb01ec93ae41]::panicking::default_hook
   5:     0x7f26417c00bc - std[55fbeb01ec93ae41]::panicking::update_hook::<alloc[371bb832da918502]::boxed::Box<rustc_driver_impl[948c84815bc57e07]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f26427bc462 - std[55fbeb01ec93ae41]::panicking::panic_with_hook
   7:     0x7f26417ef981 - std[55fbeb01ec93ae41]::panicking::begin_panic::<rustc_errors[1fe80c445c0af38b]::ExplicitBug>::{closure#0}
   8:     0x7f26417e8666 - std[55fbeb01ec93ae41]::sys::backtrace::__rust_end_short_backtrace::<std[55fbeb01ec93ae41]::panicking::begin_panic<rustc_errors[1fe80c445c0af38b]::ExplicitBug>::{closure#0}, !>
   9:     0x7f26417e6228 - std[55fbeb01ec93ae41]::panicking::begin_panic::<rustc_errors[1fe80c445c0af38b]::ExplicitBug>
  10:     0x7f26417fafc1 - <rustc_errors[1fe80c445c0af38b]::diagnostic::BugAbort as rustc_errors[1fe80c445c0af38b]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f2641ddd699 - rustc_middle[39fdeca766187dd]::util::bug::opt_span_bug_fmt::<rustc_span[a1f4f8c3615135ef]::span_encoding::Span>::{closure#0}
  12:     0x7f2641ddd822 - rustc_middle[39fdeca766187dd]::ty::context::tls::with_opt::<rustc_middle[39fdeca766187dd]::util::bug::opt_span_bug_fmt<rustc_span[a1f4f8c3615135ef]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7f2641dce2db - rustc_middle[39fdeca766187dd]::ty::context::tls::with_context_opt::<rustc_middle[39fdeca766187dd]::ty::context::tls::with_opt<rustc_middle[39fdeca766187dd]::util::bug::opt_span_bug_fmt<rustc_span[a1f4f8c3615135ef]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7f263ef2d044 - rustc_middle[39fdeca766187dd]::util::bug::bug_fmt
  15:     0x7f2644c3d37d - <rustc_const_eval[943d02374ec5aa24]::interpret::operand::ImmTy>::offset_::<rustc_const_eval[943d02374ec5aa24]::interpret::eval_context::InterpCx<rustc_const_eval[943d02374ec5aa24]::const_eval::dummy_machine::DummyMachine>>.cold
  16:     0x7f2643636d65 - <rustc_mir_transform[821c4539e524a24d]::known_panics_lint::ConstPropagator as rustc_middle[39fdeca766187dd]::mir::visit::Visitor>::visit_assign
  17:     0x7f2643630bc0 - <rustc_mir_transform[821c4539e524a24d]::known_panics_lint::ConstPropagator as rustc_middle[39fdeca766187dd]::mir::visit::Visitor>::visit_body
  18:     0x7f264362de8f - <rustc_mir_transform[821c4539e524a24d]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[821c4539e524a24d]::pass_manager::MirLint>::run_lint
  19:     0x7f2642e0d03c - rustc_mir_transform[821c4539e524a24d]::run_analysis_to_runtime_passes
  20:     0x7f2643ac56b7 - rustc_mir_transform[821c4539e524a24d]::mir_drops_elaborated_and_const_checked
  21:     0x7f2643ac5159 - rustc_query_impl[2232f359ced67f13]::query_impl::mir_drops_elaborated_and_const_checked::invoke_provider_fn::__rust_begin_short_backtrace
  22:     0x7f2642eb9f26 - rustc_query_impl[2232f359ced67f13]::execution::try_execute_query::<rustc_data_structures[4cf2110bba7d42f2]::vec_cache::VecCache<rustc_span[a1f4f8c3615135ef]::def_id::LocalDefId, rustc_middle[39fdeca766187dd]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[39fdeca766187dd]::dep_graph::graph::DepNodeIndex>, false>
  23:     0x7f2642eb7555 - rustc_query_impl[2232f359ced67f13]::query_impl::mir_drops_elaborated_and_const_checked::execute_query_non_incr::__rust_end_short_backtrace
  24:     0x7f2642eb7988 - <rustc_middle[39fdeca766187dd]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[2f488dcf8b7ae4e4]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  25:     0x7f2642eb6ac2 - rustc_interface[2f488dcf8b7ae4e4]::passes::analysis
  26:     0x7f264402e849 - rustc_query_impl[2232f359ced67f13]::execution::try_execute_query::<rustc_middle[39fdeca766187dd]::query::caches::SingleCache<rustc_middle[39fdeca766187dd]::query::erase::ErasedData<[u8; 0usize]>>, false>
  27:     0x7f264402e529 - rustc_query_impl[2232f359ced67f13]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  28:     0x7f2644001194 - rustc_interface[2f488dcf8b7ae4e4]::interface::run_compiler::<(), rustc_driver_impl[948c84815bc57e07]::run_compiler::{closure#0}>::{closure#1}
  29:     0x7f2643fdbc3e - std[55fbeb01ec93ae41]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[2f488dcf8b7ae4e4]::util::run_in_thread_with_globals<rustc_interface[2f488dcf8b7ae4e4]::util::run_in_thread_pool_with_globals<rustc_interface[2f488dcf8b7ae4e4]::interface::run_compiler<(), rustc_driver_impl[948c84815bc57e07]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  30:     0x7f2643fdc4e0 - <std[55fbeb01ec93ae41]::thread::lifecycle::spawn_unchecked<rustc_interface[2f488dcf8b7ae4e4]::util::run_in_thread_with_globals<rustc_interface[2f488dcf8b7ae4e4]::util::run_in_thread_pool_with_globals<rustc_interface[2f488dcf8b7ae4e4]::interface::run_compiler<(), rustc_driver_impl[948c84815bc57e07]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[6b09cf77c14f6d64]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x7f2643fdd36c - <std[55fbeb01ec93ae41]::sys::thread::unix::Thread>::new::thread_start
  32:     0x7f263da5e97a - <unknown>
  33:     0x7f263dae22bc - <unknown>
  34:                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.96.0-nightly (5bbdeaa9a 2026-04-03) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `main`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted


@rustbot label +F-min_generic_const_args

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions