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

Vec extend to append #7270

Merged
merged 1 commit into from
Jun 14, 2021
Merged

Conversation

Valentine-Mario
Copy link
Contributor

@Valentine-Mario Valentine-Mario commented May 25, 2021

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

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @flip1995 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 25, 2021
@flip1995
Copy link
Member

r? @xFrednet This seems to be a good PR to review.

@Valentine-Mario
Copy link
Contributor Author

r? @xFrednet This seems to be a good PR to review.

The test keeps failing. Not sure what I'm doing wrong. I'm pretty new to the repo 😪

@flip1995
Copy link
Member

You can update the tests with cargo dev bless. Also see CI:

Not all lints defined properly. Please run `cargo dev update_lints` to make sure all lints are defined properly.

To get started with working on Clippy, make sure to read our documentation in doc/. Especially adding_lints.md and basics.md should help you out.

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Valentine-Mario, you've come to the right place to ask :). I've added some comments to your code with explanations, how it can be improved.

The test keeps failing. Not sure what I'm doing wrong. I'm pretty new to the repo 😪

You have two tests which are failing:

  1. UI tests: these tests run Clippy on the .rs files inside tests/ui/ directory and then compare the output with the .stderr file with the same name. You've correctly written the tests/ui/vec_extend_to_append.rs file but the corresponding tests/ui/vec_extend_to_append.stderr is missing. Our dev tool can copy it to the correct location with cargo dev bless.
  2. Test update_lints: This test verifies that cargo dev update_lints produces no changes. Your merge from master most likely altered something that results in a new output. You can simply rerun cargo dev update_lints.
  3. Test fmt: This test didn't run, but it's likely that it would fail. You can simply fix this by running cargo dev fmt (Note: The dev is required because we're using a slightly different version than cargo fmt)

It's usually good to run a few commands before every commit. This is roughly my procedure:

# Formatting the code base and tests
cargo dev fmt
# Running Clippy's tests
cargo test
# Updating UI test outputs if anything failed
cargo dev bless
# I usually only run this if `Test update_lints` fails but you can also run it every time as it's quite fast
cargo dev update_lints

# git add -A
# git commit -m "Your awesome commit message"
# git push

All of this might be a lot to take in, but your effort is appreciated, everyone started out like this. Feel free to ask if you're stuck or something is unclear 🙃

clippy_lints/src/vec_extend_to_append.rs Outdated Show resolved Hide resolved
clippy_lints/src/vec_extend_to_append.rs Outdated Show resolved Hide resolved
clippy_lints/src/vec_extend_to_append.rs Outdated Show resolved Hide resolved
Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I've added a comment with guidance for the next steps.

In regard to commits. You've now overridden your previous commits with a force push. This can be useful to clean up at the end but right now complicates the review and destroys links from previous comments. Could you please add the next changes in a new commit and also describe a bit better what you're doing in the message itself 🙃

clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
@Valentine-Mario Valentine-Mario marked this pull request as ready for review May 27, 2021 21:07
Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Valentine-Mario, I've reviewed your recent changes and added some suggestions. Don't let them overwhelm you, the implementation is getting better each time.

clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
tests/ui/append_instead_of_extend.rs Show resolved Hide resolved
@Valentine-Mario
Copy link
Contributor Author

Hey @Valentine-Mario, I've reviewed your recent changes and added some suggestions. Don't let them overwhelm you, the implementation is getting better each time.

Added the updates. Sorry for the delay. It was weekend

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thank you for the changes. You've also added the automatic applicability of the suggestion correctly. 👍

Here are some last annotations. You can fix the red pipeline by adjusting the lint description. I'll do a final review when you've addressed these comments.

Added the updates. Sorry for the delay. It was weekend

That's totally okay, you can take your time with these changes 🙃

clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
clippy_lints/src/append_instead_of_extend.rs Outdated Show resolved Hide resolved
tests/ui/append_instead_of_extend.rs Show resolved Hide resolved
@giraffate
Copy link
Contributor

Can you do a rebase, not merge? We follow a no-merge commit policy: https://github.com/rust-lang/rust-clippy/blob/master/doc/basics.md#pr

clippy_lints/src/methods/mod.rs Show resolved Hide resolved
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rebase gone wrong: You have to force push after a rebase, instead of merging the rebased branch. You should be able to fix this by running:

$ git fetch upstream # assuming upstream is the remote of this repo
$ git rebase upstream/master
$ git diff origin/vec_extend_to_append  # < This should be empty
$ git push --force-with-lease

clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
tests/ui/append_instead_of_extend.rs Show resolved Hide resolved
tests/ui/append_instead_of_extend.fixed Show resolved Hide resolved
clippy_lints/src/methods/append_instead_of_extend.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
@Valentine-Mario Valentine-Mario force-pushed the vec_extend_to_append branch 2 times, most recently from 0497dd1 to c1dd158 Compare June 7, 2021 07:57
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Please squash your commit and this should be ready to go.

@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 8, 2021
@Valentine-Mario
Copy link
Contributor Author

Thanks! Please squash your commit and this should be ready to go.

Done

@flip1995
Copy link
Member

flip1995 commented Jun 9, 2021

There are some dogfood errors and you have to run cargo dev update_lints

@Valentine-Mario
Copy link
Contributor Author

There are some dogfood errors and you have to run cargo dev update_lints

done

@flip1995
Copy link
Member

flip1995 commented Jun 9, 2021

There are still 2 dogfood errors.

@bors
Copy link
Contributor

bors commented Jun 10, 2021

☔ The latest upstream changes (presumably #7315) made this pull request unmergeable. Please resolve the merge conflicts.

@Valentine-Mario
Copy link
Contributor Author

There are still 2 dogfood errors.

Done

@flip1995
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Jun 14, 2021

📌 Commit 44608b1 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jun 14, 2021

⌛ Testing commit 44608b1 with merge a36a7c8...

@bors
Copy link
Contributor

bors commented Jun 14, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing a36a7c8 to master...

@bors bors merged commit a36a7c8 into rust-lang:master Jun 14, 2021
@0969397110

This comment has been minimized.

@0969397110

This comment has been minimized.

@Valentine-Mario
Copy link
Contributor Author

closes #7209

@xFrednet
Copy link
Member

It has to be in the PR description before the merge. It's setup that way to allow the maintainers to double-check it beforehand. You can add it to future PRs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants