Skip to content

Conversation

@y21
Copy link
Member

@y21 y21 commented May 23, 2023

Closes #10743.
This adds a lint that looks for .into_iter() calls in a call expression to a function that already expects an IntoIterator. In those cases, explicitly calling .into_iter() is unnecessary.
There were a few instances of this in clippy itself so I fixed those as well in this PR.

changelog: new lint [explicit_into_iter_fn_arg]

@rustbot
Copy link
Collaborator

rustbot commented May 23, 2023

r? @llogiq

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 23, 2023
Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

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

This looks good in general, I only have a scant few suggestions.

@bors
Copy link
Contributor

bors commented May 23, 2023

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

@llogiq
Copy link
Contributor

llogiq commented Jun 3, 2023

One small idea for improvement: If there are multiple .into_iter() calls, you could make the suggestion text "remove the `into_iter()`s" (note the s). But I'll have this merged now, so if you want to tackle that, feel free to open a followup PR and r? me. Thanks for seeing this through!

@bors r+

@bors
Copy link
Contributor

bors commented Jun 3, 2023

📌 Commit d816eba has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jun 3, 2023

⌛ Testing commit d816eba with merge 8a30f2f...

@rust-lang rust-lang deleted a comment from rustbot Jun 3, 2023
@bors
Copy link
Contributor

bors commented Jun 3, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 8a30f2f to master...

@bors bors merged commit 8a30f2f into rust-lang:master Jun 3, 2023
bors added a commit that referenced this pull request Jun 3, 2023
[`useless_conversion`]: pluralize if there are multiple `.into_iter()` calls

context: #10814 (comment)

changelog: [`useless_conversion`]: pluralize if there are multiple `.into_iter()` calls in the chain

r? `@llogiq`
bors added a commit that referenced this pull request Aug 17, 2023
[`useless_conversion`]: only lint on paths to fn items and fix FP in macro

Fixes #11065 (which is actually two issues: an ICE and a false positive)

It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes #11065 (comment)).
It *also* makes sure that the expression is not part of a macro call (fixes #11065 (comment)). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore)

changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item
changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP)

r? `@llogiq` (reviewed #10814, which introduced these issues)
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Aug 24, 2023
[`useless_conversion`]: only lint on paths to fn items and fix FP in macro

Fixes rust-lang#11065 (which is actually two issues: an ICE and a false positive)

It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes rust-lang#11065 (comment)).
It *also* makes sure that the expression is not part of a macro call (fixes rust-lang#11065 (comment)). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore)

changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item
changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP)

r? `@llogiq` (reviewed rust-lang#10814, which introduced these issues)
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 unnecessary .into_iter() in function arguments

4 participants