Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninit_vec FP on Vec<MaybeUninit<T>> #10565

Closed
digama0 opened this issue Mar 29, 2023 · 0 comments · Fixed by #10553
Closed

uninit_vec FP on Vec<MaybeUninit<T>> #10565

digama0 opened this issue Mar 29, 2023 · 0 comments · Fixed by #10553
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@digama0
Copy link
Contributor

digama0 commented Mar 29, 2023

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

@digama0 digama0 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 29, 2023
@Alexendoo Alexendoo linked a pull request Mar 29, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant