Skip to content

[ICE]: called Result::unwrap() on an Err value: InvalidProgram(Layout(SizeOverflow)) #163904

Closed

Description

@matthiaskrgr

may be related to #162336

auto-reduced (treereduce-rust):

#![feature(gca_min_const_items)]
#![feature(gca_macroless_items)]

const X4: &[u8; 0x2468_ACF1_3579_BDFF_DB97_530E_CA86_420] = b"";
static Y4: u8 = X4[0];

original:

#![feature(gca_min_const_items)]
#![feature(gca_macroless_items)]
#![feature(unsized_const_params,adt_const_params)]
const X4: &[u8; 0x2468_ACF1_3579_BDFF_DB97_530E_CA86_420] = b"";
static Y4: u8 = X4[0];
fn main() {}

Version information

rustc 1.101.0-nightly (8d1a76430 2026-10-06)
binary: rustc
commit-hash: 8d1a76430406c877b35d0b627e7f796dcf0dfeca
commit-date: 2026-10-06
host: x86_64-unknown-linux-gnu
release: 1.101.0-nightly
LLVM version: 23.1.3

Possibly related line of code:

/// Put a valtree into memory and return a reference to that.
fn valtree_to_ref<'tcx>(
ecx: &mut CompileTimeInterpCx<'tcx>,
valtree: ty::ValTree<'tcx>,
pointee_ty: Ty<'tcx>,
) -> Immediate {
let pointee_place = create_valtree_place(ecx, ecx.layout_of(pointee_ty).unwrap(), valtree);
debug!(?pointee_place);
valtree_into_mplace(ecx, &pointee_place, valtree);
dump_place(ecx, &pointee_place);
intern_const_alloc_recursive(ecx, InternKind::Constant, &pointee_place).unwrap();

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

Program output

`--edition` is unspecified, defaulting to `2015` while the latest is `2024`; it must be one of: <2015|2018|2021|2024|future>

warning: the feature `gca_min_const_items` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.Q1hCm60aY6dW/rustc_testrunner_tmpdir_reporting.Aw9a5ddFnw4l/mvce.rs:1:12
  |
1 | #![feature(gca_min_const_items)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: the feature `gca_macroless_items` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.Q1hCm60aY6dW/rustc_testrunner_tmpdir_reporting.Aw9a5ddFnw4l/mvce.rs:2:12
  |
2 | #![feature(gca_macroless_items)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #162540 <https://github.com/rust-lang/rust/issues/162540> for more information

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.Q1hCm60aY6dW/rustc_testrunner_tmpdir_reporting.Aw9a5ddFnw4l/mvce.rs:5:23
  |
5 | static Y4: u8 = X4[0];
  |                       ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.Q1hCm60aY6dW/rustc_testrunner_tmpdir_reporting.Aw9a5ddFnw4l/mvce.rs`

error[E0658]: use of unstable library feature `unsized_const_params`
 --> /tmp/icemaker_global_tempdir.Q1hCm60aY6dW/rustc_testrunner_tmpdir_reporting.Aw9a5ddFnw4l/mvce.rs:4:1
  |
4 | const X4: &[u8; 0x2468_ACF1_3579_BDFF_DB97_530E_CA86_420] = b"";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: add `#![feature(unsized_const_params)]` to the crate attributes to enable
  = note: this compiler was built on 2026-10-06; consider upgrading it if it is out of date
  = note: required for `&'static [u8; 18282773015276577824]` to implement `ConstParamTy_`


thread 'rustc' (214065) panicked at /rustc-dev/8d1a76430406c877b35d0b627e7f796dcf0dfeca/compiler/rustc_const_eval/src/const_eval/valtrees.rs:395:77:
called `Result::unwrap()` on an `Err` value: InvalidProgram(Layout(SizeOverflow([u8; 18282773015276577824_usize])))
stack backtrace:
   0:     0x7f57316804c6 - <<std[4277eccd800b78b2]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[c462f097285717c3]::fmt::Display>::fmt
   1:     0x7f5731e06ddf - core[c462f097285717c3]::fmt::write
   2:     0x7f5731696aac - <std[4277eccd800b78b2]::sys::stdio::unix::Stderr as core[c462f097285717c3]::io::write::Write>::write_fmt
   3:     0x7f57316517aa - std[4277eccd800b78b2]::panicking::default_hook::{closure#0}
   4:     0x7f5731673d03 - std[4277eccd800b78b2]::panicking::default_hook
   5:     0x7f5730398ed5 - std[4277eccd800b78b2]::panicking::update_hook::<alloc[1d605d725c4adf04]::boxed::Box<rustc_driver_impl[6bc1d265902a538f]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f57316741a2 - std[4277eccd800b78b2]::panicking::panic_with_hook
   7:     0x7f5731651862 - std[4277eccd800b78b2]::panicking::panic_handler::{closure#0}
   8:     0x7f5731648de9 - std[4277eccd800b78b2]::sys::backtrace::__rust_end_short_backtrace::<std[4277eccd800b78b2]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f573165343d - __rustc[645588fcd52e2aab]::rust_begin_unwind
  10:     0x7f572e09069c - core[c462f097285717c3]::panicking::panic_fmt
  11:     0x7f572e523272 - core[c462f097285717c3]::result::unwrap_failed
  12:     0x7f57325a3dcb - rustc_const_eval[972e94427edec29e]::const_eval::valtrees::valtree_to_ref
  13:     0x7f572ed9d5bf - rustc_const_eval[972e94427edec29e]::const_eval::valtrees::valtree_to_const_value
  14:     0x7f5732df77eb - <rustc_const_eval[972e94427edec29e]::provide::{closure#1} as core[c462f097285717c3]::ops::function::FnOnce<(rustc_middle[48d26b50814b8eca]::ty::context::TyCtxt, rustc_middle[48d26b50814b8eca]::ty::consts::valtree::Value)>>::call_once
  15:     0x7f5732df7796 - rustc_query_impl[8cd92731ff675bd2]::query_vtables::valtree_to_const_val::invoke_provider_fn::__rust_begin_short_backtrace
  16:     0x7f5732df7001 - rustc_query_impl[8cd92731ff675bd2]::execution::try_execute_query::<rustc_middle[48d26b50814b8eca]::query::caches::DefaultCache<rustc_middle[48d26b50814b8eca]::ty::consts::valtree::Value, rustc_middle[48d26b50814b8eca]::query::erase::ErasedData<[u8; 24usize]>>, false>
  17:     0x7f5732df6d2a - rustc_query_impl[8cd92731ff675bd2]::query_vtables::valtree_to_const_val::execute_query_non_incr::__rust_end_short_backtrace
  18:     0x7f5732765200 - <rustc_middle[48d26b50814b8eca]::mir::consts::Const>::eval
  19:     0x7f5732764697 - <rustc_const_eval[972e94427edec29e]::interpret::eval_context::InterpCx<rustc_const_eval[972e94427edec29e]::const_eval::machine::CompileTimeMachine>>::push_stack_frame_raw
  20:     0x7f57335309e0 - rustc_const_eval[972e94427edec29e]::const_eval::eval_queries::eval_in_interpreter::<rustc_middle[48d26b50814b8eca]::mir::interpret::allocation::ConstAllocation>
  21:     0x7f57335302ef - rustc_const_eval[972e94427edec29e]::const_eval::eval_queries::eval_static_initializer_provider
  22:     0x7f57335301d9 - rustc_query_impl[8cd92731ff675bd2]::query_vtables::eval_static_initializer::invoke_provider_fn::__rust_begin_short_backtrace
  23:     0x7f57321f2fa3 - rustc_query_impl[8cd92731ff675bd2]::execution::try_execute_query::<rustc_middle[48d26b50814b8eca]::query::caches::DefIdCache<rustc_middle[48d26b50814b8eca]::query::erase::ErasedData<[u8; 16usize]>>, false>
  24:     0x7f5732563988 - rustc_query_impl[8cd92731ff675bd2]::query_vtables::eval_static_initializer::execute_query_non_incr::__rust_end_short_backtrace
  25:     0x7f573256490d - <rustc_middle[48d26b50814b8eca]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[14eb4f9c54c6df4e]::check_crate::{closure#1}>::{closure#0}
  26:     0x7f5732563ce5 - rustc_hir_analysis[14eb4f9c54c6df4e]::check_crate
  27:     0x7f57326a8479 - rustc_interface[3032bc8ff93305e7]::passes::analysis
  28:     0x7f5732ec0cdf - rustc_query_impl[8cd92731ff675bd2]::execution::try_execute_query::<rustc_middle[48d26b50814b8eca]::query::caches::SingleCache<rustc_middle[48d26b50814b8eca]::query::erase::ErasedData<[u8; 0usize]>>, false>
  29:     0x7f5732ec0ad3 - rustc_query_impl[8cd92731ff675bd2]::query_vtables::analysis::execute_query_non_incr::__rust_end_short_backtrace
  30:     0x7f5733063579 - rustc_interface[3032bc8ff93305e7]::interface::run_compiler::<(), rustc_driver_impl[6bc1d265902a538f]::compiler_entrypoint::{closure#0}>::{closure#2}
  31:     0x7f5733090742 - std[4277eccd800b78b2]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3032bc8ff93305e7]::util::run_in_thread_with_globals<rustc_interface[3032bc8ff93305e7]::util::run_in_thread_pool_with_globals<rustc_interface[3032bc8ff93305e7]::interface::run_compiler<(), rustc_driver_impl[6bc1d265902a538f]::compiler_entrypoint::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:     0x7f57330904ed - <std[4277eccd800b78b2]::thread::lifecycle::spawn_unchecked<rustc_interface[3032bc8ff93305e7]::util::run_in_thread_with_globals<rustc_interface[3032bc8ff93305e7]::util::run_in_thread_pool_with_globals<rustc_interface[3032bc8ff93305e7]::interface::run_compiler<(), rustc_driver_impl[6bc1d265902a538f]::compiler_entrypoint::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[c462f097285717c3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7f573308e65d - <std[4277eccd800b78b2]::sys::thread::unix::Thread>::new::thread_start
  34:     0x7f572be980a2 - <unknown>
  35:     0x7f572bf2080c - <unknown>
  36:                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.101.0-nightly (8d1a76430 2026-10-06) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [valtree_to_const_val] converting type-level constant value to MIR constant value
#1 [eval_static_initializer] evaluating initializer of static `Y4`
#2 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted

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

@rustbot label +F-gca_min_const_items +F-gca_macroless_items +F-unsized_const_params +F-adt_const_params

Activity

  1. added
    I-ICE
    T-compiler
    C-bug
    on Oct 6, 2026
  2. added
    needs-triage
    on Oct 6, 2026
  3. rustbot commented on Oct 6, 2026

    @rustbot
    Collaborator

    Error: Unknown labels: F-gca_macroless_items

    Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

  4. added
    F-gca_min_const_items
    on Oct 6, 2026
  5. removed
    needs-triage
    on Oct 7, 2026
  6. Suryansh-Dey commented on Oct 7, 2026

    @Suryansh-Dey
    Contributor

    After investigating, One thing is clear that panic is because of .unwrap() on line 395 and we can't make return type Result<> to remove that unwrap because the we will have to change function signature of almost entire code base. Because everybody will now need to return Result.

    let imm = valtree_to_ref(ecx, valtree, *inner_ty);

    Best way is to throw a compiler error saying size is exceeding limit. This check is already there for all types but because & is just an 8 byte pointer, our checker get's tricked there.

    I want to contribute here, could anybody help me what approach should I take to fix this? (Basically how to throw a compiler error for this?)

  7. oli-obk commented on Oct 7, 2026

    @oli-obk
    Contributor

    hmm... why does this even reach valtree_to_ref?. Shouldn't this already error during the evaluation of the body of X4? Ah, is this taking the fast path for literals, so const eval doesn't run, but there should still be some sanity checking of the literals against their type I'd think?

  8. oli-obk commented on Oct 7, 2026

    @oli-obk
    Contributor

    lmao yea the literal type checks are very bare bones:

    #![feature(gca_min_const_items)]
    #![feature(gca_macroless_items)]
    
    const X4: &[u32] = 5;
    error: type annotations needed for the literal
     --> src/lib.rs:4:20
      |
    4 | const X4: &[u32] = 5;
      |                    ^
    

    I think fixing this issue should also fix this suboptimal diagnostic. The checks for the literals should be exhaustive (so also check array lengths where applicable)

  9. Suryansh-Dey commented on Oct 9, 2026

    @Suryansh-Dey
    Contributor

    @rustbot claim

  10. added a commit that references this issue on Oct 16, 2026
    686a116
  11. added a commit that references this issue on Oct 16, 2026
    af734a9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugF-gca_min_const_itemsI-ICET-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions