Closed
Description
Summary
Basic examples of uninit_vec
seem to be broken. I think this is a regression but I'm not positive. In particular the example from #10407 is also broken. In short, the lint is supposed to not fire if the element type is MaybeUninit<T>
or similar types based on it which allow uninit values, but it doesn't seem to work.
Lint Name
uninit_vec
Reproducer
I tried this code:
#![warn(clippy::uninit_vec)]
use std::mem::MaybeUninit;
pub fn new_uninit<T>(size: usize) -> Box<[MaybeUninit<T>]> {
let mut res = Vec::<MaybeUninit<T>>::with_capacity(size);
unsafe { res.set_len(size) };
res.into_boxed_slice()
}
I saw this happen:
warning: calling `set_len()` immediately after reserving a buffer creates uninitialized values
--> src/main.rs:6:5
|
6 | let mut res = Vec::<MaybeUninit<T>>::with_capacity(size);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 | unsafe { res.set_len(size) };
| ^^^^^^^^^^^^^^^^^
|
= help: initialize the buffer or wrap the content in `MaybeUninit`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninit_vec
I expected to see this happen: no error
Version
rustc 1.70.0-nightly (478cbb42b 2023-03-28)
binary: rustc
commit-hash: 478cbb42b730ba4739351b72ce2aa928e78e2f81
commit-date: 2023-03-28
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 16.0.0
Additional Labels
No response