Skip to content

[ICE]: attempting to project to field at offset 0 with size 8 into immediate #152653

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

type const CONST: usize = 1i32;

fn uses_const() {
    CONST;
}

original:

//@ check-pass
// This test should compile without an ICE.
#![expect(incomplete_features)]
#![Debug(min_generic_const_args)]

type const CONST: usize = 1i32;

fn uses_const() {
    CONST;
}

fn main() { (1i32, 'a') }

Version information

rustc 1.95.0-nightly (75b9d89c6 2026-02-15)
binary: rustc
commit-hash: 75b9d89c68a4a92758349272aa4e35a8eb7a6708
commit-date: 2026-02-15
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0

Possibly related line of code:

cx,
);
}
// `ImmTy` have already been checked to be in-bounds, so we can just check directly if this
// remains in-bounds. This cannot actually be violated since projections are type-checked
// and bounds-checked.
assert!(
offset + layout.size <= self.layout.size,
"attempting to project to field at offset {} with size {} into immediate with layout {:#?}",
offset.bytes(),
layout.size.bytes(),
self.layout,
);

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

Program output

error[E0658]: `type const` syntax is experimental
 --> /tmp/icemaker_global_tempdir.jrAx15H5Wv2o/rustc_testrunner_tmpdir_reporting.lglgTxuY3juB/mvce.rs:1:1
  |
1 | type const CONST: usize = 1i32;
  | ^^^^^^^^^^
  |
  = 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-02-15; consider upgrading it if it is out of date

error[E0658]: top-level `type const` are unstable
 --> /tmp/icemaker_global_tempdir.jrAx15H5Wv2o/rustc_testrunner_tmpdir_reporting.lglgTxuY3juB/mvce.rs:1:1
  |
1 | type const CONST: usize = 1i32;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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-02-15; consider upgrading it if it is out of date

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

error: the constant `1` is not of type `usize`
 --> /tmp/icemaker_global_tempdir.jrAx15H5Wv2o/rustc_testrunner_tmpdir_reporting.lglgTxuY3juB/mvce.rs:1:1
  |
1 | type const CONST: usize = 1i32;
  | ^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `i32`

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.jrAx15H5Wv2o/rustc_testrunner_tmpdir_reporting.lglgTxuY3juB/mvce.rs:1:27
  |
1 | type const CONST: usize = 1i32;
  |                           ^^^^ expected `usize`, found `i32`
  |
help: change the type of the numeric literal from `i32` to `usize`
  |
1 - type const CONST: usize = 1i32;
1 + type const CONST: usize = 1usize;
  |


thread 'rustc' (2715739) panicked at /rustc-dev/75b9d89c68a4a92758349272aa4e35a8eb7a6708/compiler/rustc_const_eval/src/interpret/operand.rs:387:9:
attempting to project to field at offset 0 with size 8 into immediate with 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,
    },
}
stack backtrace:
   0:     0x7f6ae47c8a8b - <<std[2d1308c35637467a]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[59b75ac17867df2]::fmt::Display>::fmt
   1:     0x7f6ae4e110e0 - core[59b75ac17867df2]::fmt::write
   2:     0x7f6ae47dfd06 - <std[2d1308c35637467a]::sys::stdio::unix::Stderr as std[2d1308c35637467a]::io::Write>::write_fmt
   3:     0x7f6ae479eb38 - std[2d1308c35637467a]::panicking::default_hook::{closure#0}
   4:     0x7f6ae47bbef3 - std[2d1308c35637467a]::panicking::default_hook
   5:     0x7f6ae378b61f - std[2d1308c35637467a]::panicking::update_hook::<alloc[b4f9b4e27dddabf5]::boxed::Box<rustc_driver_impl[e294da4906e6dc96]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f6ae47bc1d2 - std[2d1308c35637467a]::panicking::panic_with_hook
   7:     0x7f6ae479ebf8 - std[2d1308c35637467a]::panicking::panic_handler::{closure#0}
   8:     0x7f6ae4793169 - std[2d1308c35637467a]::sys::backtrace::__rust_end_short_backtrace::<std[2d1308c35637467a]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f6ae47a065d - __rustc[67c75c4a30db75ac]::rust_begin_unwind
  10:     0x7f6ae147e82c - core[59b75ac17867df2]::panicking::panic_fmt
  11:     0x7f6ae6c82e20 - <rustc_const_eval[e33c05d851da09de]::interpret::operand::ImmTy>::offset_::<rustc_const_eval[e33c05d851da09de]::interpret::eval_context::InterpCx<rustc_const_eval[e33c05d851da09de]::const_eval::dummy_machine::DummyMachine>>.cold
  12:     0x7f6ae5648f70 - <rustc_mir_transform[262394a36fc8ebcd]::known_panics_lint::ConstPropagator as rustc_middle[8dc6b2453706b250]::mir::visit::Visitor>::visit_assign
  13:     0x7f6ae5642cc5 - <rustc_mir_transform[262394a36fc8ebcd]::known_panics_lint::ConstPropagator as rustc_middle[8dc6b2453706b250]::mir::visit::Visitor>::visit_body
  14:     0x7f6ae56401b2 - <rustc_mir_transform[262394a36fc8ebcd]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[262394a36fc8ebcd]::pass_manager::MirLint>::run_lint
  15:     0x7f6ae4e0c94c - rustc_mir_transform[262394a36fc8ebcd]::run_analysis_to_runtime_passes
  16:     0x7f6ae5b89203 - rustc_mir_transform[262394a36fc8ebcd]::mir_drops_elaborated_and_const_checked
  17:     0x7f6ae5b88c21 - rustc_query_impl[ae97bbfaef5cf938]::query_impl::mir_drops_elaborated_and_const_checked::invoke_provider_fn::__rust_begin_short_backtrace
  18:     0x7f6ae58618fe - rustc_query_impl[ae97bbfaef5cf938]::execution::try_execute_query::<rustc_data_structures[7f8c3356a540b3ba]::vec_cache::VecCache<rustc_span[d1cb45c887057336]::def_id::LocalDefId, rustc_middle[8dc6b2453706b250]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[8dc6b2453706b250]::dep_graph::graph::DepNodeIndex>, {rustc_query_impl[ae97bbfaef5cf938]::QueryFlags { is_anon: false, is_depth_limit: false, is_feedable: false }}, false>
  19:     0x7f6ae5861289 - rustc_query_impl[ae97bbfaef5cf938]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  20:     0x7f6ae585f56a - <rustc_middle[8dc6b2453706b250]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[14454cc610ccaaa5]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  21:     0x7f6ae585e96c - rustc_interface[14454cc610ccaaa5]::passes::analysis
  22:     0x7f6ae608b999 - rustc_query_impl[ae97bbfaef5cf938]::execution::try_execute_query::<rustc_middle[8dc6b2453706b250]::query::caches::SingleCache<rustc_middle[8dc6b2453706b250]::query::erase::ErasedData<[u8; 0usize]>>, {rustc_query_impl[ae97bbfaef5cf938]::QueryFlags { is_anon: false, is_depth_limit: false, is_feedable: false }}, false>
  23:     0x7f6ae608b6d4 - rustc_query_impl[ae97bbfaef5cf938]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7f6ae6124867 - <rustc_interface[14454cc610ccaaa5]::passes::create_and_enter_global_ctxt<core[59b75ac17867df2]::option::Option<rustc_interface[14454cc610ccaaa5]::queries::Linker>, rustc_driver_impl[e294da4906e6dc96]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[59b75ac17867df2]::ops::function::FnOnce<(&rustc_session[df95067a6cb94e78]::session::Session, rustc_middle[8dc6b2453706b250]::ty::context::CurrentGcx, alloc[b4f9b4e27dddabf5]::sync::Arc<rustc_data_structures[7f8c3356a540b3ba]::jobserver::Proxy>, &std[2d1308c35637467a]::sync::once_lock::OnceLock<rustc_middle[8dc6b2453706b250]::ty::context::GlobalCtxt>, &rustc_data_structures[7f8c3356a540b3ba]::sync::worker_local::WorkerLocal<rustc_middle[8dc6b2453706b250]::arena::Arena>, &rustc_data_structures[7f8c3356a540b3ba]::sync::worker_local::WorkerLocal<rustc_hir[2ea25bfe832ed195]::Arena>, rustc_driver_impl[e294da4906e6dc96]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  25:     0x7f6ae6069337 - rustc_interface[14454cc610ccaaa5]::interface::run_compiler::<(), rustc_driver_impl[e294da4906e6dc96]::run_compiler::{closure#0}>::{closure#1}
  26:     0x7f6ae604c5fe - std[2d1308c35637467a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[14454cc610ccaaa5]::util::run_in_thread_with_globals<rustc_interface[14454cc610ccaaa5]::util::run_in_thread_pool_with_globals<rustc_interface[14454cc610ccaaa5]::interface::run_compiler<(), rustc_driver_impl[e294da4906e6dc96]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  27:     0x7f6ae604cce0 - <std[2d1308c35637467a]::thread::lifecycle::spawn_unchecked<rustc_interface[14454cc610ccaaa5]::util::run_in_thread_with_globals<rustc_interface[14454cc610ccaaa5]::util::run_in_thread_pool_with_globals<rustc_interface[14454cc610ccaaa5]::interface::run_compiler<(), rustc_driver_impl[e294da4906e6dc96]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[59b75ac17867df2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x7f6ae604db6c - <std[2d1308c35637467a]::sys::thread::unix::Thread>::new::thread_start
  29:     0x7f6ae78d698b - <unknown>
  30:     0x7f6ae795aa0c - <unknown>
  31:                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.95.0-nightly (75b9d89c6 2026-02-15) running on x86_64-unknown-linux-gnu

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

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

Metadata

Metadata

Assignees

No one assigned

    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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions