Repository: rust
Issue: ICE: `InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(BoundsCheckFailed`
Labels: I-ICE,T-compiler,C-bug,A-mir-opt,F-adt_const_params,S-bug-has-test,F-unsized_const_params,A-mir-opt-GVN

<!--
[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:433:60: 'called `Result::unwrap()` on an `Err` value: InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(BoundsCheckFailed { len: 4, index: 4 }), backtrace: InterpErrorBacktrace { backtrace: None } })'', 'thread 'rustc' panicked at compiler/rustc_const_eval/src/const_eval/valtrees.rs:433:60: 'called `Result::unwrap()` on an `Err` value: InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(BoundsCheckFailed { len: 4, index: 4 }), backtrace: InterpErrorBacktrace { backtrace: None } })''
File: /tmp/im/a.rs
-->

auto-reduced (treereduce-rust):
````rust
pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
    BYTES
}

pub fn main() {
    assert_eq!(function_with_bytes::<b"AAAAb">(), &[0x41, 0x41, 0x41, 0x41]);
}


````

original:
````rust
// skip-filecheck
// EMIT_MIR_FOR_EACH_BIT_WIDTH

#![feature(adt_const_params, unsized_const_params)]
#![allow(incomplete_features)]

pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
    BYTES
}

// EMIT_MIR_FOR_EACH_BIT_WIDTH
pub fn main() {
    assert_eq!(function_with_bytes::<b"AAAAb">(), &[0x41, 0x41, 0x41, 0x41]);
    assert_eq!(function_with_bytes::<{ &[0x41, 0x41, 0x41, 0x41] }>(), b"AAAA");
}

````

Version information
````
rustc 1.82.0-nightly (fbce03b19 2024-08-14)
binary: rustc
commit-hash: fbce03b195c02e425fbb12276b8f02349048a75f
commit-date: 2024-08-14
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

````

Command:
`/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 -Zvalidate-mir`

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Program output</strong></summary>
<p>

```
error: `&'static [u8; 4]` is forbidden as the type of a const generic parameter
 --> /tmp/icemaker_global_tempdir.UIvWXNcW58ZC/rustc_testrunner_tmpdir_reporting.bReUy5HRdRlL/mvce.rs:1:41
  |
1 | pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
  |                                         ^^^^^^^^^^^^^^^^
  |
  = 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.UIvWXNcW58ZC/rustc_testrunner_tmpdir_reporting.bReUy5HRdRlL/mvce.rs:6:38
  |
6 |     assert_eq!(function_with_bytes::<b"AAAAb">(), &[0x41, 0x41, 0x41, 0x41]);
  |                                      ^^^^^^^^ expected an array with a fixed size of 4 elements, found one with 5 elements

thread 'rustc' panicked at compiler/rustc_const_eval/src/const_eval/valtrees.rs:433:60:
called `Result::unwrap()` on an `Err` value: InterpErrorInfo(InterpErrorInfoInner { kind: UndefinedBehavior(BoundsCheckFailed { len: 4, index: 4 }), backtrace: InterpErrorBacktrace { backtrace: None } })
stack backtrace:
   0:     0x73319a7b666d - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h560b4d28c137b093
   1:     0x73319b004f2f - core::fmt::write::h99766545c4efef9d
   2:     0x73319bfb0ed1 - std::io::Write::write_fmt::h8e3cbf6208612263
   3:     0x73319a7b8d4b - std::panicking::default_hook::{{closure}}::h6bf6ccd32e88a7b7
   4:     0x73319a7b89be - std::panicking::default_hook::ha56d0025017107a4
   5:     0x733199946299 - std[265a0665abe5e043]::panicking::update_hook::<alloc[f7eab8ff756c9dca]::boxed::Box<rustc_driver_impl[18c1de8e11281817]::install_ice_hook::{closure#0}>>::{closure#0}
   6:     0x73319a7b9667 - std::panicking::rust_panic_with_hook::h53b891e816ad5807
   7:     0x73319a7b9327 - std::panicking::begin_panic_handler::{{closure}}::h3012610e5c310f7d
   8:     0x73319a7b6b29 - std::sys::backtrace::__rust_end_short_backtrace::h66811dbaa784350e
   9:     0x73319a7b8ff4 - rust_begin_unwind
  10:     0x733197699b63 - core::panicking::panic_fmt::he2d7dd7c7f53990c
  11:     0x733197772286 - core::result::unwrap_failed::h5d31905b634d5ea8
  12:     0x73319bd23d85 - rustc_const_eval[4703571d7d15c956]::const_eval::valtrees::valtree_into_mplace
  13:     0x73319bd2381b - rustc_const_eval[4703571d7d15c956]::const_eval::valtrees::valtree_to_ref
  14:     0x73319bc017a6 - rustc_const_eval[4703571d7d15c956]::const_eval::valtrees::valtree_to_const_value
  15:     0x73319bc01561 - <rustc_const_eval[4703571d7d15c956]::provide::{closure#1} as core[12164080e42249fc]::ops::function::FnOnce<(rustc_middle[d7f4792719c666e4]::ty::context::TyCtxt, (rustc_middle[d7f4792719c666e4]::ty::Ty, rustc_middle[d7f4792719c666e4]::ty::consts::valtree::ValTree))>>::call_once
  16:     0x73319bc0152e - rustc_query_impl[c2f5f95cecf69337]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c2f5f95cecf69337]::query_impl::valtree_to_const_val::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d7f4792719c666e4]::query::erase::Erased<[u8; 24usize]>>
  17:     0x73319bc014e7 - <rustc_query_impl[c2f5f95cecf69337]::query_impl::valtree_to_const_val::dynamic_query::{closure#2} as core[12164080e42249fc]::ops::function::FnOnce<(rustc_middle[d7f4792719c666e4]::ty::context::TyCtxt, (rustc_middle[d7f4792719c666e4]::ty::Ty, rustc_middle[d7f4792719c666e4]::ty::consts::valtree::ValTree))>>::call_once
  18:     0x73319bc005ba - rustc_query_system[f8c10878fe801c76]::query::plumbing::try_execute_query::<rustc_query_impl[c2f5f95cecf69337]::DynamicConfig<rustc_query_system[f8c10878fe801c76]::query::caches::DefaultCache<(rustc_middle[d7f4792719c666e4]::ty::Ty, rustc_middle[d7f4792719c666e4]::ty::consts::valtree::ValTree), rustc_middle[d7f4792719c666e4]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[c2f5f95cecf69337]::plumbing::QueryCtxt, false>
  19:     0x73319bc0030a - rustc_query_impl[c2f5f95cecf69337]::query_impl::valtree_to_const_val::get_query_non_incr::__rust_end_short_backtrace
  20:     0x73319bab3781 - <rustc_mir_transform[4b24bac2940eeb7a]::gvn::VnState>::insert
  21:     0x73319baab3fd - <rustc_mir_transform[4b24bac2940eeb7a]::gvn::VnState>::simplify_operand
  22:     0x73319baa9718 - <rustc_mir_transform[4b24bac2940eeb7a]::gvn::VnState>::simplify_rvalue
  23:     0x733198b21d20 - <rustc_mir_transform[4b24bac2940eeb7a]::gvn::GVN as rustc_middle[d7f4792719c666e4]::mir::MirPass>::run_pass
  24:     0x73319b002151 - rustc_mir_transform[4b24bac2940eeb7a]::pass_manager::run_passes_inner
  25:     0x73319bb2ccb3 - rustc_mir_transform[4b24bac2940eeb7a]::optimized_mir
  26:     0x73319bb5039b - rustc_query_impl[c2f5f95cecf69337]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c2f5f95cecf69337]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d7f4792719c666e4]::query::erase::Erased<[u8; 8usize]>>
  27:     0x73319b02af27 - rustc_query_system[f8c10878fe801c76]::query::plumbing::try_execute_query::<rustc_query_impl[c2f5f95cecf69337]::DynamicConfig<rustc_query_system[f8c10878fe801c76]::query::caches::DefIdCache<rustc_middle[d7f4792719c666e4]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c2f5f95cecf69337]::plumbing::QueryCtxt, false>
  28:     0x73319b02a4df - rustc_query_impl[c2f5f95cecf69337]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  29:     0x733197984814 - <rustc_middle[d7f4792719c666e4]::ty::context::TyCtxt>::instance_mir
  30:     0x73319b3b63f9 - rustc_interface[8b2190a255f69c87]::passes::run_required_analyses
  31:     0x73319bb663de - rustc_interface[8b2190a255f69c87]::passes::analysis
  32:     0x73319bb663b1 - rustc_query_impl[c2f5f95cecf69337]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c2f5f95cecf69337]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d7f4792719c666e4]::query::erase::Erased<[u8; 1usize]>>
  33:     0x73319bf706ee - rustc_query_system[f8c10878fe801c76]::query::plumbing::try_execute_query::<rustc_query_impl[c2f5f95cecf69337]::DynamicConfig<rustc_query_system[f8c10878fe801c76]::query::caches::SingleCache<rustc_middle[d7f4792719c666e4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c2f5f95cecf69337]::plumbing::QueryCtxt, false>
  34:     0x73319bf7044f - rustc_query_impl[c2f5f95cecf69337]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  35:     0x73319bddd169 - rustc_interface[8b2190a255f69c87]::interface::run_compiler::<core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>, rustc_driver_impl[18c1de8e11281817]::run_compiler::{closure#0}>::{closure#1}
  36:     0x73319bd025d0 - std[265a0665abe5e043]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[8b2190a255f69c87]::util::run_in_thread_with_globals<rustc_interface[8b2190a255f69c87]::util::run_in_thread_pool_with_globals<rustc_interface[8b2190a255f69c87]::interface::run_compiler<core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>, rustc_driver_impl[18c1de8e11281817]::run_compiler::{closure#0}>::{closure#1}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#0}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>
  37:     0x73319bd02c3a - <<std[265a0665abe5e043]::thread::Builder>::spawn_unchecked_<rustc_interface[8b2190a255f69c87]::util::run_in_thread_with_globals<rustc_interface[8b2190a255f69c87]::util::run_in_thread_pool_with_globals<rustc_interface[8b2190a255f69c87]::interface::run_compiler<core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>, rustc_driver_impl[18c1de8e11281817]::run_compiler::{closure#0}>::{closure#1}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#0}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#1} as core[12164080e42249fc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x73319bd02fab - std::sys::pal::unix::thread::Thread::new::thread_start::hbf34cdaead1142d4
  39:     0x73319d45539d - <unknown>
  40:     0x73319d4da49c - <unknown>
  41:                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.82.0-nightly (fbce03b19 2024-08-14) 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`
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.

```

</p>
</details>

<!--
query stack:
1 | pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
#0 [valtree_to_const_val] converting type-level constant value to mir constant value
#1 [optimized_mir] optimizing MIR for `main`

-->
@rustbot label +F-adt_const_params +F-unsized_const_params