We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
needless_vec
Vec::append
Vec::extend
vec!
Detects code that uses Vec::append or Vec::extend with a newly-created vec!.
push
append
extend
Should there be a separate lint for some_vec.extend([single_elem]) to use push instead? This lint could create code that would require linting again.
some_vec.extend([single_elem])
some_vec.append(&mut vec![elem]); // 1 some_vec.extend(vec![elem]); // 2 some_vec.append(&mut vec![elem1, elem2]); // 3 some_vec.extend(vec![elem1, elem2]); // 4 // 5: let mut v = vec![elem1, elem2]; some_vec.append(&mut v);
Could be written as:
some_vec.push(elem); // 1 and 2 some_vec.extend([elem1, elem2]); // 3 and 4 // 5 let v = [elem1, elem2]; some_vec.extend(v);
The text was updated successfully, but these errors were encountered:
don't forget extend_from_slice.
Sorry, something went wrong.
No branches or pull requests
What it does
Detects code that uses
Vec::append
orVec::extend
with a newly-createdvec!
.Advantage
push
instead ofappend
/extend
Drawbacks
Should there be a separate lint for
some_vec.extend([single_elem])
to usepush
instead? This lint could create code that would require linting again.Example
Could be written as:
The text was updated successfully, but these errors were encountered: