Skip to content

[ICE]: interpret: assertion failed: layout.is_sized() #151880

@matthiaskrgr

Description

@matthiaskrgr

mutation of #144719 which ICES instead of stack overflowing

auto-reduced (treereduce-rust):

//@compile-flags: --edition=2021
struct Thing(<&[fn()] as ::core::ops::Deref>::Target);

static X: Thing = Thing(&X);

const Y: &Thing = &X;

original:

#[derive(PartialEq)]
struct Thing(<&[fn()] as ::core::ops::Deref>::Target);

static X: Thing = Thing(&X);

const Y: &Thing = &X;

fn main() {
    if let Y = Y {}
}

Version information

rustc 1.95.0-nightly (a293cc4af 2026-01-30)
binary: rustc
commit-hash: a293cc4af8b26701c42738381c0c6f9d2ba881e0
commit-date: 2026-01-30
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0

Possibly related line of code:

// * be able to get information on extern statics.
let ty = tcx
.type_of(def_id)
.no_bound_vars()
.expect("statics should not have generic parameters");
let layout = tcx.layout_of(typing_env.as_query_input(ty)).unwrap();
assert!(layout.is_sized());
// Take over-alignment from attributes into account.
let align = match tcx.codegen_fn_attrs(def_id).alignment {
Some(align_from_attribute) => {
Ord::max(align_from_attribute, layout.align.abi)
}

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2021

Program output

error[E0106]: missing lifetime specifier
 --> /tmp/icemaker_global_tempdir.iMa6q0Z2ZI23/rustc_testrunner_tmpdir_reporting.BHAvUFGKsE2L/mvce.rs:1:15
  |
1 | struct Thing(<&[fn()] as ::core::ops::Deref>::Target);
  |               ^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
1 | struct Thing<'a>(<&'a [fn()] as ::core::ops::Deref>::Target);
  |             ++++   ++

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.iMa6q0Z2ZI23/rustc_testrunner_tmpdir_reporting.BHAvUFGKsE2L/mvce.rs:5:22
  |
5 | const Y: &Thing = &X;
  |                      ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.iMa6q0Z2ZI23/rustc_testrunner_tmpdir_reporting.BHAvUFGKsE2L/mvce.rs`


thread 'rustc' (74536) panicked at /rustc-dev/a293cc4af8b26701c42738381c0c6f9d2ba881e0/compiler/rustc_middle/src/mir/interpret/mod.rs:388:21:
assertion failed: layout.is_sized()
stack backtrace:
   0:     0x7ffbaae44ebb - <<std[b56300d62699629]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[1940e17cfe77f04e]::fmt::Display>::fmt
   1:     0x7ffbab40ef88 - core[1940e17cfe77f04e]::fmt::write
   2:     0x7ffbaae5bd96 - <std[b56300d62699629]::sys::stdio::unix::Stderr as std[b56300d62699629]::io::Write>::write_fmt
   3:     0x7ffbaae1af68 - std[b56300d62699629]::panicking::default_hook::{closure#0}
   4:     0x7ffbaae38283 - std[b56300d62699629]::panicking::default_hook
   5:     0x7ffba9e0da0d - std[b56300d62699629]::panicking::update_hook::<alloc[77e06c05b3e1163]::boxed::Box<rustc_driver_impl[306165e0f22ac3b8]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7ffbaae38562 - std[b56300d62699629]::panicking::panic_with_hook
   7:     0x7ffbaae1b05a - std[b56300d62699629]::panicking::panic_handler::{closure#0}
   8:     0x7ffbaae0f599 - std[b56300d62699629]::sys::backtrace::__rust_end_short_backtrace::<std[b56300d62699629]::panicking::panic_handler::{closure#0}, !>
   9:     0x7ffbaae1ca8d - __rustc[dff7bba7b93d99f5]::rust_begin_unwind
  10:     0x7ffba7ac973c - core[1940e17cfe77f04e]::panicking::panic_fmt
  11:     0x7ffba75c2e32 - core[1940e17cfe77f04e]::panicking::panic
  12:     0x7ffbacee4826 - <rustc_middle[4fbddfd8361bbe31]::mir::interpret::GlobalAlloc>::size_and_align.cold
  13:     0x7ffbac4a5054 - <rustc_const_eval[de22eaac5c78cdba]::interpret::eval_context::InterpCx<rustc_const_eval[de22eaac5c78cdba]::const_eval::machine::CompileTimeMachine>>::eval_rvalue_into_place
  14:     0x7ffbac49c053 - rustc_const_eval[de22eaac5c78cdba]::const_eval::eval_queries::eval_to_allocation_raw_provider
  15:     0x7ffbac499dc0 - rustc_query_impl[de8dc5dcbfafa282]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[de8dc5dcbfafa282]::query_impl::eval_to_allocation_raw::make_query_vtable::{closure#1}::{closure#0}, rustc_middle[4fbddfd8361bbe31]::query::erase::ErasedData<[u8; 24usize]>>
  16:     0x7ffbac499091 - rustc_query_system[47e010d69cf1376c]::query::plumbing::try_execute_query::<rustc_query_impl[de8dc5dcbfafa282]::SemiDynamicQueryDispatcher<rustc_query_system[47e010d69cf1376c]::query::caches::DefaultCache<rustc_middle[4fbddfd8361bbe31]::ty::PseudoCanonicalInput<rustc_middle[4fbddfd8361bbe31]::mir::interpret::GlobalId>, rustc_middle[4fbddfd8361bbe31]::query::erase::ErasedData<[u8; 24usize]>>, false, false, false>, false>
  17:     0x7ffbac498c33 - rustc_query_impl[de8dc5dcbfafa282]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  18:     0x7ffbac493f4b - rustc_const_eval[de22eaac5c78cdba]::const_eval::eval_queries::eval_to_const_value_raw_provider
  19:     0x7ffbac493ad2 - rustc_query_impl[de8dc5dcbfafa282]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[de8dc5dcbfafa282]::query_impl::eval_to_const_value_raw::make_query_vtable::{closure#1}::{closure#0}, rustc_middle[4fbddfd8361bbe31]::query::erase::ErasedData<[u8; 24usize]>>
  20:     0x7ffbac49267a - rustc_query_system[47e010d69cf1376c]::query::plumbing::try_execute_query::<rustc_query_impl[de8dc5dcbfafa282]::SemiDynamicQueryDispatcher<rustc_query_system[47e010d69cf1376c]::query::caches::DefaultCache<rustc_middle[4fbddfd8361bbe31]::ty::PseudoCanonicalInput<rustc_middle[4fbddfd8361bbe31]::mir::interpret::GlobalId>, rustc_middle[4fbddfd8361bbe31]::query::erase::ErasedData<[u8; 24usize]>>, false, true, false>, false>
  21:     0x7ffbac4921fd - rustc_query_impl[de8dc5dcbfafa282]::query_impl::eval_to_const_value_raw::get_query_non_incr::__rust_end_short_backtrace
  22:     0x7ffbaba40a77 - <rustc_middle[4fbddfd8361bbe31]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[281f645d6dd33d26]::check_crate::{closure#2}>::{closure#0}
  23:     0x7ffbaba40004 - rustc_hir_analysis[281f645d6dd33d26]::check_crate
  24:     0x7ffbab52e11b - rustc_interface[c33df4e5b4e639ae]::passes::analysis
  25:     0x7ffbab52dd75 - rustc_query_impl[de8dc5dcbfafa282]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[de8dc5dcbfafa282]::query_impl::analysis::make_query_vtable::{closure#1}::{closure#0}, rustc_middle[4fbddfd8361bbe31]::query::erase::ErasedData<[u8; 0usize]>>
  26:     0x7ffbac56dfe6 - rustc_query_system[47e010d69cf1376c]::query::plumbing::try_execute_query::<rustc_query_impl[de8dc5dcbfafa282]::SemiDynamicQueryDispatcher<rustc_query_system[47e010d69cf1376c]::query::caches::SingleCache<rustc_middle[4fbddfd8361bbe31]::query::erase::ErasedData<[u8; 0usize]>>, false, false, false>, false>
  27:     0x7ffbac56ddce - rustc_query_impl[de8dc5dcbfafa282]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7ffbac706b6c - <rustc_interface[c33df4e5b4e639ae]::passes::create_and_enter_global_ctxt<core[1940e17cfe77f04e]::option::Option<rustc_interface[c33df4e5b4e639ae]::queries::Linker>, rustc_driver_impl[306165e0f22ac3b8]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[1940e17cfe77f04e]::ops::function::FnOnce<(&rustc_session[1d337842f56cc0a6]::session::Session, rustc_middle[4fbddfd8361bbe31]::ty::context::CurrentGcx, alloc[77e06c05b3e1163]::sync::Arc<rustc_data_structures[66bcb0d8d60a0708]::jobserver::Proxy>, &std[b56300d62699629]::sync::once_lock::OnceLock<rustc_middle[4fbddfd8361bbe31]::ty::context::GlobalCtxt>, &rustc_data_structures[66bcb0d8d60a0708]::sync::worker_local::WorkerLocal<rustc_middle[4fbddfd8361bbe31]::arena::Arena>, &rustc_data_structures[66bcb0d8d60a0708]::sync::worker_local::WorkerLocal<rustc_hir[5322f89bbdf6d77c]::Arena>, rustc_driver_impl[306165e0f22ac3b8]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  29:     0x7ffbac595748 - rustc_interface[c33df4e5b4e639ae]::interface::run_compiler::<(), rustc_driver_impl[306165e0f22ac3b8]::run_compiler::{closure#0}>::{closure#1}
  30:     0x7ffbac5d25be - std[b56300d62699629]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c33df4e5b4e639ae]::util::run_in_thread_with_globals<rustc_interface[c33df4e5b4e639ae]::util::run_in_thread_pool_with_globals<rustc_interface[c33df4e5b4e639ae]::interface::run_compiler<(), rustc_driver_impl[306165e0f22ac3b8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  31:     0x7ffbac5d2ae0 - <std[b56300d62699629]::thread::lifecycle::spawn_unchecked<rustc_interface[c33df4e5b4e639ae]::util::run_in_thread_with_globals<rustc_interface[c33df4e5b4e639ae]::util::run_in_thread_pool_with_globals<rustc_interface[c33df4e5b4e639ae]::interface::run_compiler<(), rustc_driver_impl[306165e0f22ac3b8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[1940e17cfe77f04e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7ffbac5d396c - <std[b56300d62699629]::sys::thread::unix::Thread>::new::thread_start
  33:     0x7ffba5e9698b - <unknown>
  34:     0x7ffba5f1a9cc - <unknown>
  35:                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 (a293cc4af 2026-01-30) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `Y`
#1 [eval_to_const_value_raw] simplifying constant for the type system `Y`
#2 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 2 previous errors

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.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