-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestionsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
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)
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestionsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy