Skip to content

Add a check for some followed by filter - #15745

Merged
ada4a merged 1 commit into
rust-lang:masterfrom
ceptontech:filter-some
May 4, 2026
Merged

Add a check for some followed by filter#15745
ada4a merged 1 commit into
rust-lang:masterfrom
ceptontech:filter-some

Conversation

@qmwrygdxpzc

@qmwrygdxpzc qmwrygdxpzc commented Sep 23, 2025

Copy link
Copy Markdown

View all comments

Add a check for some followed by filter.

The program will suggest using the then_some method.

changelog: [filter_some]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_some

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 23, 2025
@rustbot

rustbot commented Sep 23, 2025

Copy link
Copy Markdown
Collaborator

r? @llogiq

rustbot has assigned @llogiq.
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

@github-actions

github-actions Bot commented Sep 23, 2025

Copy link
Copy Markdown

No changes for 436aad4

@samueltardieu samueltardieu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution. However, the lint cannot be considered for merging as-is:

  • It should include autofixes suggestions when possible.
  • It should cover more complex cases.

For example, with the following code

fn with_side_effect(x: u32) -> u32 {
    println!("In `with_side_effect()`");
    x * 10 + 30
}

fn f(x: u32) -> Option<u32> {
    Some(with_side_effect(x)).filter(|&x| x > 40)
}

the lint suggests using then_some() inside f(). However, I don't see what would be the replacement code here.

You should include tests for the most complicated situations you can think of, as the lint should not fail, don't just cover the simplest case where it is obvious it will work. For example, what is part of the expression comes from a macro? Also, bool::then_some() has been introduced in Rust 1.62.0, so the MSRV must be checked as well.

Hope this review will help you go forward.

View changes since this review

@qmwrygdxpzc

Copy link
Copy Markdown
Author

In the example with the 2 functions, what should the linter do?

@samueltardieu

Copy link
Copy Markdown
Member

In the example with the 2 functions, what should the linter do?

Probably nothing.

@qmwrygdxpzc

Copy link
Copy Markdown
Author

It has been about 2 weeks. Can someone take a look?

@qmwrygdxpzc

Copy link
Copy Markdown
Author

@samueltardieu Now there are some less trivial tests involving macros. Please take another look.

@rustbot

This comment has been minimized.

Comment thread clippy_lints/src/methods/filter_some.rs Outdated
Comment thread clippy_lints/src/methods/filter_some.rs Outdated
Comment thread clippy_lints/src/methods/filter_some.rs Outdated
@rustbot rustbot added the needs-fcp PRs that add, remove, or rename lints and need an FCP label Oct 13, 2025
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Oct 13, 2025
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) has-merge-commits PR has merge commits, merge with caution. labels Oct 13, 2025
Comment thread clippy_lints/src/methods/some_filter.rs Outdated
@qmwrygdxpzc

Copy link
Copy Markdown
Author

I used the reindent_multiline function because the check that I used as an example has it. I noticed that some checks don't use it. When should it be used?

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@qmwrygdxpzc

Copy link
Copy Markdown
Author

I used the reindent_multiline function because the check that I used as an example has it. I noticed that some checks don't use it. When should it be used?

@rustbot

This comment has been minimized.

@rustbot rustbot added the needs-fcp PRs that add, remove, or rename lints and need an FCP label Apr 3, 2026
@qmwrygdxpzc

Copy link
Copy Markdown
Author

@rustbot ready

@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 Apr 3, 2026

@ada4a ada4a left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some last comments^^

View changes since this review

Comment thread clippy_lints/src/methods/some_filter.rs Outdated
Comment thread tests/ui/some_filter.stderr Outdated
@rustbot rustbot 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 Apr 4, 2026
Comment thread tests/ui/some_filter.fixed
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@qmwrygdxpzc

Copy link
Copy Markdown
Author

@rustbot ready

@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 Apr 7, 2026
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@ada4a ada4a left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One last change, then let's merge

View changes since this review

Comment thread clippy_lints/src/methods/mod.rs Outdated
The program will suggest using the `then_some` method.

changelog: add [`some_filter`]
@rustbot

rustbot commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

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.

@ada4a ada4a left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ada4a
ada4a added this pull request to the merge queue May 4, 2026
Merged via the queue into rust-lang:master with commit 6310134 May 4, 2026
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 4, 2026
@qmwrygdxpzc
qmwrygdxpzc deleted the filter-some branch May 4, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lint-nominated Create an FCP-thread on Zulip for this PR needs-fcp PRs that add, remove, or rename lints and need an FCP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants