Skip to content
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

Prefer vec.append(vec) over vec.extend(vec.drain(..)) #7209

Closed
seritools opened this issue May 11, 2021 · 3 comments
Closed

Prefer vec.append(vec) over vec.extend(vec.drain(..)) #7209

seritools opened this issue May 11, 2021 · 3 comments
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@seritools
Copy link

seritools commented May 11, 2021

What it does

This lint would suggest using the specialized Vec::append instead of vec.extend(other_vec.drain(..)).

Categories (optional)

  • Kind: clippy::style

What is the advantage of the recommended code over the original code

  • Slightly more succinct code
  • Potentially better perf?
  • Helps raise awareness of append even existing :)

Drawbacks

None that I could come up with

Example

let mut a = vec![0u8; 1024];
let mut b = Vec::new();

b.extend(a.drain(..));

Could be written as:

let mut a = vec![0u8; 1024];
let mut b = Vec::new();

b.append(&mut a);
@seritools seritools added the A-lint Area: New lints label May 11, 2021
@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label May 13, 2021
@Valentine-Mario
Copy link
Contributor

@rustbot claim

bors added a commit that referenced this issue Jun 14, 2021
Vec extend to append

This PR adds a check to suggest changes of vector from

```
vec.extend(other_vec.drain(..))
```

could be written as

```
vec![].append(&mut vec![]);
```

changelog: Add vec_extend_to_append lint
issue: #7209
@xFrednet
Copy link
Member

Hey, I've noticed that this issue is still open after the implementation was merged in #7270. @Valentine-Mario here is a neat-trick for the next time: you can close issues when a PR is merged by including a closes #<id> in the PR description. (GitHub documentation for more keywords) 🙃

cc: @flip1995 could you close this issue?

@Valentine-Mario
Copy link
Contributor

Hey, I've noticed that this issue is still open after the implementation was merged in #7270. @Valentine-Mario here is a neat-trick for the next time: you can close issues when a PR is merged by including a closes #<id> in the PR description. (GitHub documentation for more keywords)

cc: @flip1995 could you close this issue?

Oh. Was looking for the close issue button. Lol. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

5 participants