Closed
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