Repository: rust
Issue: ICE: `InvalidProgram(Layout(SizeOverflow`
Labels: I-ICE,T-compiler,C-bug,needs-triage

<!--
[31mICE[0m: Rustc ./a.rs '-Zmir-opt-level=5 -Zvalidate-mir -ooutputfile -Zdump-mir-dir=dir' 'thread 'rustc' panicked at compiler/rustc_const_eval/src/const_eval/valtrees.rs:375:77: 'called `Result::unwrap()` on an `Err` value: InvalidProgram(Layout(SizeOverflow([u8; 13554212585355425205_usize])))'', 'thread 'rustc' panicked at compiler/rustc_const_eval/src/const_eval/valtrees.rs:375:77: 'called `Result::unwrap()` on an `Err` value: InvalidProgram(Layout(SizeOverflow([u8; 13554212585355425205_usize])))''
File: /tmp/im/a.rs
-->

auto-reduced (treereduce-rust):
````rust
//@compile-flags: -Zmir-opt-level=5 -Zvalidate-mir
fn function_with_bytes<const BYTES: &'static [u8; 0xc7b889180b67b07d_bc1a3c88783d35b5_u128]>(
) -> &'static [u8] {
    BYTES
}

fn main() {
    function_with_bytes::<b"aa">() == &[];
}

````

original:
````rust
fn function_with_bytes<const BYTES: &'static [u8; 0xc7b889180b67b07d_bc1a3c88783d35b5_u128]>() -> &'static [u8] {
    BYTES
}

fn main() {
    function_with_bytes::<b"aa">() == &[];
}

````

Version information
````
rustc 1.86.0-nightly (5cd16b7f2 2025-01-16)
binary: rustc
commit-hash: 5cd16b7f2bc3624f2d658aa87151279878d2652a
commit-date: 2025-01-16
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6

````

Possibly related line of code:
https://github.com/rust-lang/rust/blob/5cd16b7f2bc3624f2d658aa87151279878d2652a/compiler/rustc_const_eval/src/const_eval/valtrees.rs#L369-L381

Command:
`/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 -Zvalidate-mir`

<details><summary><strong>Program output</strong></summary>
<p>

```
error: `&'static [u8; 13554212585355425205]` is forbidden as the type of a const generic parameter
 --> /tmp/icemaker_global_tempdir.FIw1XfCIbDrc/rustc_testrunner_tmpdir_reporting.ijfwCzlkhntL/mvce.rs:1:37
  |
1 | fn function_with_bytes<const BYTES: &'static [u8; 0xc7b889180b67b07d_bc1a3c88783d35b5_u128]>(
  |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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
  |
1 + #![feature(adt_const_params)]
  |
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
  |
1 + #![feature(unsized_const_params)]
  |

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.FIw1XfCIbDrc/rustc_testrunner_tmpdir_reporting.ijfwCzlkhntL/mvce.rs:1:51
  |
1 | fn function_with_bytes<const BYTES: &'static [u8; 0xc7b889180b67b07d_bc1a3c88783d35b5_u128]>(
  |                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `u128`
  |
help: change the type of the numeric literal from `u128` to `usize`
  |
1 | fn function_with_bytes<const BYTES: &'static [u8; 0xc7b889180b67b07d_bc1a3c88783d35b5_usize]>(
  |                                                                                       ~~~~~

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.FIw1XfCIbDrc/rustc_testrunner_tmpdir_reporting.ijfwCzlkhntL/mvce.rs:7:27
  |
7 |     function_with_bytes::<b"aa">() == &[];
  |                           ^^^^^ expected an array with a size of 13554212585355425205, found one with a size of 2


thread 'rustc' panicked at compiler/rustc_const_eval/src/const_eval/valtrees.rs:375:77:
called `Result::unwrap()` on an `Err` value: InvalidProgram(Layout(SizeOverflow([u8; 13554212585355425205_usize])))
stack backtrace:
   0:     0x7e0bedef66aa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h0e5f1585bfffb19f
   1:     0x7e0bee612da6 - core::fmt::write::hb4406e0cc18cab0a
   2:     0x7e0bef57f451 - std::io::Write::write_fmt::hbfb92718103b7507
   3:     0x7e0bedef6502 - std::sys::backtrace::BacktraceLock::print::he782f6d80c255a43
   4:     0x7e0bedef8982 - std::panicking::default_hook::{{closure}}::h7927be4c4a7836a0
   5:     0x7e0bedef880a - std::panicking::default_hook::hce8a4e7a77e5c861
   6:     0x7e0bed059a3b - std[5eed3342ae415129]::panicking::update_hook::<alloc[d9cc840343b62059]::boxed::Box<rustc_driver_impl[d6b89c31630ac8e2]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7e0bedef9503 - std::panicking::rust_panic_with_hook::hc6e72cdac3b94dca
   8:     0x7e0bedef91fa - std::panicking::begin_panic_handler::{{closure}}::h7f7a407352c9fced
   9:     0x7e0bedef6b89 - std::sys::backtrace::__rust_end_short_backtrace::h7f36a8d1fa9d1d9e
  10:     0x7e0bedef8ebd - rust_begin_unwind
  11:     0x7e0beaba6950 - core::panicking::panic_fmt::hca9dd5375a399d1d
  12:     0x7e0beb0ce966 - core::result::unwrap_failed::hb1947dc54d635233
  13:     0x7e0beee8b97f - rustc_const_eval[d8aeece37abbbffc]::const_eval::valtrees::valtree_to_ref
  14:     0x7e0bef1630f9 - rustc_const_eval[d8aeece37abbbffc]::const_eval::valtrees::valtree_to_const_value
  15:     0x7e0bef162eb6 - <rustc_const_eval[d8aeece37abbbffc]::provide::{closure#1} as core[ced015e6fc2a4da0]::ops::function::FnOnce<(rustc_middle[7623bb75c8b82ad6]::ty::context::TyCtxt, (rustc_middle[7623bb75c8b82ad6]::ty::Ty, rustc_middle[7623bb75c8b82ad6]::ty::consts::valtree::ValTree))>>::call_once
  16:     0x7e0bef162e72 - rustc_query_impl[22732cf2fa73812a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[22732cf2fa73812a]::query_impl::valtree_to_const_val::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7623bb75c8b82ad6]::query::erase::Erased<[u8; 24usize]>>
  17:     0x7e0bef162e3b - <rustc_query_impl[22732cf2fa73812a]::query_impl::valtree_to_const_val::dynamic_query::{closure#2} as core[ced015e6fc2a4da0]::ops::function::FnOnce<(rustc_middle[7623bb75c8b82ad6]::ty::context::TyCtxt, (rustc_middle[7623bb75c8b82ad6]::ty::Ty, rustc_middle[7623bb75c8b82ad6]::ty::consts::valtree::ValTree))>>::call_once
  18:     0x7e0bef162009 - rustc_query_system[ce3a0679b26f255f]::query::plumbing::try_execute_query::<rustc_query_impl[22732cf2fa73812a]::DynamicConfig<rustc_query_system[ce3a0679b26f255f]::query::caches::DefaultCache<(rustc_middle[7623bb75c8b82ad6]::ty::Ty, rustc_middle[7623bb75c8b82ad6]::ty::consts::valtree::ValTree), rustc_middle[7623bb75c8b82ad6]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[22732cf2fa73812a]::plumbing::QueryCtxt, false>
  19:     0x7e0bef161d45 - rustc_query_impl[22732cf2fa73812a]::query_impl::valtree_to_const_val::get_query_non_incr::__rust_end_short_backtrace
  20:     0x7e0bef127767 - <rustc_mir_transform[1ba400a67d95abf]::gvn::VnState>::insert
  21:     0x7e0bef11e34b - <rustc_mir_transform[1ba400a67d95abf]::gvn::VnState>::simplify_operand
  22:     0x7e0bef11fe90 - <rustc_mir_transform[1ba400a67d95abf]::gvn::VnState>::simplify_rvalue
  23:     0x7e0bec203dd6 - <rustc_mir_transform[1ba400a67d95abf]::gvn::GVN as rustc_mir_transform[1ba400a67d95abf]::pass_manager::MirPass>::run_pass
  24:     0x7e0bee6046f3 - rustc_mir_transform[1ba400a67d95abf]::pass_manager::run_passes_inner
  25:     0x7e0bee731b74 - rustc_mir_transform[1ba400a67d95abf]::optimized_mir
  26:     0x7e0bee73141d - rustc_query_impl[22732cf2fa73812a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[22732cf2fa73812a]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7623bb75c8b82ad6]::query::erase::Erased<[u8; 8usize]>>
  27:     0x7e0bee8d30df - rustc_query_system[ce3a0679b26f255f]::query::plumbing::try_execute_query::<rustc_query_impl[22732cf2fa73812a]::DynamicConfig<rustc_query_system[ce3a0679b26f255f]::query::caches::DefIdCache<rustc_middle[7623bb75c8b82ad6]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[22732cf2fa73812a]::plumbing::QueryCtxt, false>
  28:     0x7e0bee8d24f3 - rustc_query_impl[22732cf2fa73812a]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7e0beb71a024 - <rustc_middle[7623bb75c8b82ad6]::ty::context::TyCtxt>::instance_mir
  30:     0x7e0bee917792 - rustc_interface[8d12bef601c5487]::passes::run_required_analyses
  31:     0x7e0bef57ac5e - rustc_interface[8d12bef601c5487]::passes::analysis
  32:     0x7e0bef57ac2f - rustc_query_impl[22732cf2fa73812a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[22732cf2fa73812a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7623bb75c8b82ad6]::query::erase::Erased<[u8; 0usize]>>
  33:     0x7e0bef5dc2d5 - rustc_query_system[ce3a0679b26f255f]::query::plumbing::try_execute_query::<rustc_query_impl[22732cf2fa73812a]::DynamicConfig<rustc_query_system[ce3a0679b26f255f]::query::caches::SingleCache<rustc_middle[7623bb75c8b82ad6]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[22732cf2fa73812a]::plumbing::QueryCtxt, false>
  34:     0x7e0bef5dc00e - rustc_query_impl[22732cf2fa73812a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7e0bef637fa9 - rustc_interface[8d12bef601c5487]::passes::create_and_enter_global_ctxt::<core[ced015e6fc2a4da0]::option::Option<rustc_interface[8d12bef601c5487]::queries::Linker>, rustc_driver_impl[d6b89c31630ac8e2]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  36:     0x7e0bef62b1d6 - rustc_interface[8d12bef601c5487]::interface::run_compiler::<(), rustc_driver_impl[d6b89c31630ac8e2]::run_compiler::{closure#0}>::{closure#1}
  37:     0x7e0bef479ec7 - std[5eed3342ae415129]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[8d12bef601c5487]::util::run_in_thread_with_globals<rustc_interface[8d12bef601c5487]::util::run_in_thread_pool_with_globals<rustc_interface[8d12bef601c5487]::interface::run_compiler<(), rustc_driver_impl[d6b89c31630ac8e2]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  38:     0x7e0bef479b99 - <<std[5eed3342ae415129]::thread::Builder>::spawn_unchecked_<rustc_interface[8d12bef601c5487]::util::run_in_thread_with_globals<rustc_interface[8d12bef601c5487]::util::run_in_thread_pool_with_globals<rustc_interface[8d12bef601c5487]::interface::run_compiler<(), rustc_driver_impl[d6b89c31630ac8e2]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ced015e6fc2a4da0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7e0bef47932f - std::sys::pal::unix::thread::Thread::new::thread_start::h6a23afa4b51367f7
  40:     0x7e0be98a339d - <unknown>
  41:     0x7e0be992849c - <unknown>
  42:                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.86.0-nightly (5cd16b7f2 2025-01-16) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=5 -Z validate-mir -Z dump-mir-dir=dir

query stack during panic:
#0 [valtree_to_const_val] converting type-level constant value to mir constant value
#1 [optimized_mir] optimizing MIR for `main`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.

```

</p>
</details>

<!--
query stack:
#0 [valtree_to_const_val] converting type-level constant value to mir constant value
#1 [optimized_mir] optimizing MIR for `main`
#2 [analysis] running analysis passes on this crate

-->