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

New Lint: needless_for_each #6706

Merged
merged 14 commits into from
Mar 31, 2021
Merged

New Lint: needless_for_each #6706

merged 14 commits into from
Mar 31, 2021

Conversation

Y-Nak
Copy link
Contributor

@Y-Nak Y-Nak commented Feb 9, 2021

resolves: #6543

changelog: Added pedantic lint: needless_for_each

@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 Feb 9, 2021
@Y-Nak Y-Nak force-pushed the excessive-for-each branch from 0cbec62 to 7acb8f8 Compare February 9, 2021 12:20
@Y-Nak
Copy link
Contributor Author

Y-Nak commented Feb 9, 2021

Changes:

  1. Change a category from style to restriction.
  2. Remove a redundant condition: if !match_trait_method(cx, for_each_receiver, &paths::ITERATOR);.

@Y-Nak
Copy link
Contributor Author

Y-Nak commented Feb 9, 2021

Changes:

  1. Trigger the lint if closure's body is ExprKind::Block.

@camsteffen
Copy link
Contributor

I'm a little iffy on the return within inner loop case (should not lint). There's an argument to be made that it is better style to avoid multi-level control flow (continue 'label) if possible.

@Y-Nak
Copy link
Contributor Author

Y-Nak commented Feb 9, 2021

Yes, I think so too... if for_each is used to avoid multi-level control flow, it should be acceptable.
@llogiq what do you think about this?

@bors
Copy link
Contributor

bors commented Feb 10, 2021

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

@llogiq
Copy link
Contributor

llogiq commented Feb 10, 2021

I completely agree. Requiring adding a label is likely bad style, and I've seen compiler code introducing a closure that is directly called to avoid labels.

@Y-Nak Y-Nak force-pushed the excessive-for-each branch from 8f50346 to ffcd033 Compare February 11, 2021 03:51
@Y-Nak
Copy link
Contributor Author

Y-Nak commented Feb 11, 2021

Changes:

  1. Skip the lint if return is used in Loop.
  2. Resolve conflicts.

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.

impl LGTM, but code duplication can be reduced.

clippy_lints/src/methods/excessive_for_each.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/excessive_for_each.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/excessive_for_each.rs Outdated Show resolved Hide resolved
@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 Feb 21, 2021
@Y-Nak
Copy link
Contributor Author

Y-Nak commented Feb 22, 2021

Changes:

  1. Rewrite is_target_ty to utils::has_iter_method.
  2. Format codes inside then block of if_chain
  3. Remove unnecessary format usage.

@Y-Nak
Copy link
Contributor Author

Y-Nak commented Feb 23, 2021

Changes: Add comments to clarify why RetCollector is needed.

@Y-Nak
Copy link
Contributor Author

Y-Nak commented Feb 25, 2021

@rustbot label -S-waiting-on-author +S-waiting-on-review

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

bors commented Feb 27, 2021

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

@Y-Nak Y-Nak force-pushed the excessive-for-each branch 2 times, most recently from 3bdbe72 to dbadac7 Compare February 27, 2021 04:58
@Y-Nak
Copy link
Contributor Author

Y-Nak commented Feb 27, 2021

Changes:

  1. Improve document (including typo fix).
  2. Change to use .. as the default value of snippet.
  3. Resolve conflicts.

Copy link
Contributor

@camsteffen camsteffen left a comment

Choose a reason for hiding this comment

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

Filling in for @flip1995 with a review!

Need to remove the empty file clippy_lints/src/iter_for_each.rs.

clippy_lints/src/methods/excessive_for_each.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/excessive_for_each.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/excessive_for_each.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/excessive_for_each.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/excessive_for_each.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/mod.rs Outdated Show resolved Hide resolved
tests/ui/excessive_for_each.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/excessive_for_each.rs Outdated Show resolved Hide resolved
@Y-Nak
Copy link
Contributor Author

Y-Nak commented Mar 10, 2021

@camsteffen Thanks for your review! Reviewed points make perfect sense to me, I'll fix them.

@giraffate
Copy link
Contributor

ping from triage @flip1995 @camsteffen. Can we need to review this further?

@flip1995
Copy link
Member

Thanks! I didn't follow this PR, so I just

@bors r=camsteffen

Skimming over it, I couldn't find any obvious flaws, so I trust your review.

@bors
Copy link
Contributor

bors commented Mar 31, 2021

📌 Commit 0e42112 has been approved by camsteffen

bors added a commit that referenced this pull request Mar 31, 2021
New Lint: needless_for_each

resolves: #6543

changelog: Added pedantic lint: `needless_for_each`
@bors
Copy link
Contributor

bors commented Mar 31, 2021

⌛ Testing commit 0e42112 with merge a743553...

@bors
Copy link
Contributor

bors commented Mar 31, 2021

💔 Test failed - checks-action_test

@flip1995
Copy link
Member

flip1995 commented Mar 31, 2021

The CI failures are because crate::utils::* are clippy_utils::* now.

@Y-Nak Y-Nak force-pushed the excessive-for-each branch from 0e42112 to e61f978 Compare March 31, 2021 15:10
@Y-Nak
Copy link
Contributor Author

Y-Nak commented Mar 31, 2021

Fixed!

@flip1995
Copy link
Member

@bors r=camsteffen

Thanks!

@bors
Copy link
Contributor

bors commented Mar 31, 2021

📌 Commit e61f978 has been approved by camsteffen

@bors
Copy link
Contributor

bors commented Mar 31, 2021

⌛ Testing commit e61f978 with merge c1021b8...

@bors
Copy link
Contributor

bors commented Mar 31, 2021

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

@bors bors merged commit c1021b8 into rust-lang:master Mar 31, 2021
@bors
Copy link
Contributor

bors commented Mar 31, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint .iter().for_each()
9 participants