Description
The attached code incorrectly (?) reports a call to an unsafe function.
This is only shown in-IDE (Zed or Helix). It is not shown with cargo check
or cargo clippy
.
The code in question is just a call to produce a new array, with populated values.
(There is no visible issue at runtime.)
I was able to get the code down to what looks like any vec of arrays.
In-IDE error:
rust-analyzer: call to unsafe function is unsafe and requires an unsafe function or block
Minimal-Example-Helix:
Helix:
Zed:
with Zed or Helix:
rust-analyzer 1.86.0-nightly (b3b368a1 2025-01-05)
rustc 1.86.0-nightly (b3b368a18 2025-01-05)
Zed 0.167.1 – /Applications/Zed.app
helix 25.1 (dabfb6ce)
fn main() {
let an_array: [bool; 3] = [false; 3];
let vec_of_arrays = vec![an_array];
print!("{:?}", vec_of_arrays);
}
Here's the minimal example as a cargo-script: dbg_incorrect-unsafe-error-minimal.rs
And (probably not needed) here's the orignating non-minimal example as a cargo-script: dbg_incorrect-unsafe-error.rs
(I realize that rust-analyzer doesn't yet work with cargo-script at the time of posting. But hopefully soon! Figured it would still be best practice. :)