Code
#![feature(const_index, const_trait_impl)]
const ARRAY: [u32; 5] = [1, 2, 3, 4, 5];
const OUT_OF_BOUNDS: &u32 = unsafe { ARRAY.get_unchecked(9) };
Current output
error[E0080]: `assume` called with `false`
--> src/lib.rs:4:38
|
4 | const OUT_OF_BOUNDS: &u32 = unsafe { ARRAY.get_unchecked(9) };
| ^^^^^^^^^^^^^^^^^^^^^^ evaluation of `OUT_OF_BOUNDS` failed here
For more information about this error, try `rustc --explain E0080`.
error: could not compile `playground` (lib) due to 1 previous error
Desired output
error[E0080]: evaluation panicked: unsafe precondition(s) violated: slice::get_unchecked requires that the index is within the slice
This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
--> src/lib.rs:4:38
|
4 | const OUT_OF_BOUNDS: &u32 = unsafe { ARRAY.get_unchecked(9) };
| ^^^^^^^^^^^^^^^^^^^^^^ evaluation of `OUT_OF_BOUNDS` failed here
For more information about this error, try `rustc --explain E0080`.
error: could not compile `playground` (lib) due to 1 previous error
Rationale and extra context
No response
Other cases
#![feature(const_index, const_trait_impl)]
const MUT: () = unsafe {
let mut array: [u32; 5] = [1, 2, 3, 4, 5];
let _ = array.get_unchecked_mut(9);
};
correctly errors with:
error[E0080]: evaluation panicked: unsafe precondition(s) violated: slice::get_unchecked_mut requires that the index is within the slice
This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
--> src/lib.rs:5:13
|
5 | let _ = array.get_unchecked_mut(9);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `MUT` failed here
For more information about this error, try `rustc --explain E0080`.
error: could not compile `playground` (lib) due to 1 previous error
Rust Version
Nightly version: 1.100.0-nightly (2026-08-22 c54751567b19c4ceb08b)
Anything else?
Ref #143775
Code
Current output
Desired output
error[E0080]: evaluation panicked: unsafe precondition(s) violated: slice::get_unchecked requires that the index is within the slice This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety. --> src/lib.rs:4:38 | 4 | const OUT_OF_BOUNDS: &u32 = unsafe { ARRAY.get_unchecked(9) }; | ^^^^^^^^^^^^^^^^^^^^^^ evaluation of `OUT_OF_BOUNDS` failed here For more information about this error, try `rustc --explain E0080`. error: could not compile `playground` (lib) due to 1 previous errorRationale and extra context
No response
Other cases
correctly errors with:
error[E0080]: evaluation panicked: unsafe precondition(s) violated: slice::get_unchecked_mut requires that the index is within the slice This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety. --> src/lib.rs:5:13 | 5 | let _ = array.get_unchecked_mut(9); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `MUT` failed here For more information about this error, try `rustc --explain E0080`. error: could not compile `playground` (lib) due to 1 previous errorRust Version
Anything else?
Ref #143775