Skip to content

Conversation

@qmwrygdxpzc
Copy link

Now the linter checks for calling the iter or into_iter method
followed by calling the all or any method.

We have used these methods by mistake ourselves. The developer was not
familiar with the is_some_and method. He tried to use the any
method on an option. The compiler suggested using iter first. The
developer did not get to learn about the idiomatic method.

The lint search_is_some involves converting a closure that takes the
reference into one that takes the value. The code is split between the
function for the lint and a shared function. The new feature that we
are adding involves the same transformation. To do so it needs some of
the same code that is currently in the search_is_some lint. So it is
moved from the lint into the shared function.

Before this patch, line 799 in the file clippy_utils/src/sugg.rs had a
check. It made the function return none in case the closure did not
dereference the argument. However, the code for the lint
search_is_some would then fall back to using the original closure.
That achieved the same effect as the check not existing. So the check
is now removed.

changelog: [manual_is_variant]: check for calling the iter or
into_iter method followed by calling the all or any method

changelog: [manual_is_variant]: skip the check when the MSRV is before
1.70

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2025

r? @Alexendoo

rustbot has assigned @Alexendoo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@qmwrygdxpzc
Copy link
Author

If the input uses .iter().any() on a value that is not Copy, the current version of the patch makes the linter suggest using .as_ref().is_some_and(). The suggestion is longer than the original code. Should the linter skip it instead?

@rustbot

This comment has been minimized.

ceptontech added 3 commits November 3, 2025 09:03
The lint `search_is_some` involves converting a closure that takes the
reference into one that takes the value.  The code is split between the
function for the lint and a shared function.  The new feature that we
are adding involves the same transformation.  To do so it needs some of
the same code that is currently in the `search_is_some` lint.  So it is
moved from the lint into the shared function.

Before this patch, line 799 in the file `clippy_utils/src/sugg.rs` had a
check.  It made the function return none in case the closure did not
dereference the argument.  However, the code for the lint
`search_is_some` would then fall back to using the original closure.
That achieved the same effect as the check not existing.  So the check
is now removed.
Now the linter checks for calling the `iter` or `into_iter` method
followed by calling the `all` or `any` method.

We have used these methods by mistake ourselves.  The developer was not
familiar with the `is_some_and` method.  He tried to use the `any`
method on an option.  The compiler suggested using `iter` first.  The
developer did not get to learn about the idiomatic method.

changelog: [`manual_is_variant`]: check for calling the `iter` or
`into_iter` method followed by calling the `all` or `any` method
changelog: [`manual_is_variant`]: skip the check when the MSRV is before
1.70
@rustbot
Copy link
Collaborator

rustbot commented Nov 3, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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.

3 participants