Open
Description
The following example fails to compile on the latest nightly.
#![feature(core_intrinsics)]
#![feature(const_int_unchecked_arith)]
fn main() {
let _ = unsafe { [0i32; std::intrinsics::unchecked_add(4, 2)] };
}
Output:
warning: unnecessary `unsafe` block
--> src/main.rs:5:13
|
5 | let _ = unsafe { [0i32; std::intrinsics::unchecked_add(4, 2)] };
| ^^^^^^ unnecessary `unsafe` block
|
= note: `#[warn(unused_unsafe)]` on by default
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> src/main.rs:5:29
|
5 | let _ = unsafe { [0i32; std::intrinsics::unchecked_add(4, 2)] };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to previous error; 1 warning emitted
I would have expected this to compile successfully, but it seems that unsafe
is not applied to array length expressions. The nightly features are only needed because there are no stable const unsafe
functions. A user-defined const unsafe fn
runs into the same error on stable.
This arose from discussion in rust-lang/rfcs#2920.