-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Lint name: vec_init_then_push
I tried this code:
let mut arg_strings: Vec<Box<str>> = Vec::new();
arg_strings.push(name.to_owned().into_boxed_str());
for arg in args {
arg_strings.push(
arg.as_ref()
.to_os_string()
.into_string()
.unwrap()
.into_boxed_str(),
);
}
I expected to see this happen: The lint doesn't trigger, because using vec![]
and then immediately pushing doesn't improve the code any, it uses two different styles of initializing the vector.
Instead, this happened:
warning: calls to `push` immediately after creation
--> tests/mock/clitools.rs:613:5
|
613 | / let mut arg_strings: Vec<Box<str>> = Vec::new();
614 | | arg_strings.push(name.to_owned().into_boxed_str());
| |_______________________________________________________^ help: consider using the `vec![]` macro: `let mut arg_strings: Vec<Box<str>> = vec![..];`
cc rust-lang/rustup#2718, @kinnison
Meta
wchargin
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have