Skip to content

False positive in unsafe_vector_initialization: nonintegral vector element type #3477

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

Closed
dtolnay opened this issue Dec 2, 2018 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing good first issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@dtolnay
Copy link
Member

dtolnay commented Dec 2, 2018

unsafe fn f<T: Copy, R: std::io::Read>(len: usize, io: R) -> Result<Vec<T>, ()> {
    let mut vec = Vec::<T>::with_capacity(len);
    vec.set_len(len);

    /* io.read_exact... */

    Ok(vec)
}
error: unsafe vector initialization
 --> src/main.rs:3:5
  |
2 |     let mut vec = Vec::<T>::with_capacity(len);
  |                   ---------------------------- help: consider replace allocation with: `vec![0; len]`
3 |     vec.set_len(len);
  |     ^^^^^^^^^^^^^^^^
  |

The suggested replacement of vec![0; len] is not a viable replacement because the vector element type is not something that can be "0".


clippy 0.0.212 (b2601be 2018-11-27)

@phansch phansch added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions labels Dec 2, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Dec 3, 2018

We should just stop emitting this lint for set_len entirely.

@oli-obk oli-obk added the good first issue These issues are a good way to get started with Clippy label Dec 3, 2018
@dtolnay
Copy link
Member Author

dtolnay commented Dec 3, 2018

I deleted this lint in #3478.

@dtolnay dtolnay closed this as completed Dec 3, 2018
@rustbot rustbot added the I-false-positive Issue: The lint was triggered on code it shouldn't have label Sep 13, 2021
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 good first issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

No branches or pull requests

4 participants