-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
manual_filter: don't eat comments in the and_then suggestion
#17377
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
Merged
llogiq
merged 1 commit into
rust-lang:master
from
costajohnt:fix/17376-manual-filter-eats-comments
Jul 16, 2026
+39
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //@no-rustfix: the suggestion drops the closure's comment, so it is not machine-applicable | ||
|
|
||
| #![warn(clippy::manual_filter)] | ||
|
|
||
| fn issue17376(opt: Option<u32>) { | ||
| // Rewriting to `filter` would drop the comment below, so the suggestion must not be | ||
| // machine-applicable here. Otherwise `clippy --fix` would silently eat the comment (#17376). | ||
| opt.and_then(|x| { | ||
| //~^ manual_filter | ||
| // keep this explanation | ||
| if x < 10 { Some(x) } else { None } | ||
| }); | ||
| } | ||
|
|
||
| fn main() {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| error: manual implementation of `Option::filter` | ||
| --> tests/ui/manual_filter_unfixable.rs:8:9 | ||
| | | ||
| LL | opt.and_then(|x| { | ||
| | _________^ | ||
| LL | | | ||
| LL | | // keep this explanation | ||
| LL | | if x < 10 { Some(x) } else { None } | ||
| LL | | }); | ||
| | |______^ help: try: `filter(|&x| x < 10)` | ||
| | | ||
| = note: `-D clippy::manual-filter` implied by `-D warnings` | ||
| = help: to override `-D warnings` add `#[allow(clippy::manual_filter)]` | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't
//@no-rustfixhere defeat the purpose of what you are trying to achieve? If you disable rustfix, the test would still pass even if the suggestion accidentally remainsMachineApplicableView changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, but rustfix wouldn't actually guard that here. clippy's UI tests run with
RustfixMode::Everything, which applies every suggestion regardless of applicability, soMaybeIncorrectgets applied too. The.fixedwould come out identical either way (comment dropped), so it can't tellMachineApplicablefromMaybeIncorrect, and turning rustfix on would just bless a.fixedshowing the comment eaten.So
//@no-rustfixhere, same asmanual_unwrap_or_default_unfixable.rs. The comment-free path is still rustfix-tested over inmanual_filter.rs. You're right that a regression back toMachineApplicablewouldn't be caught, but I don't think the harness exposes applicability anywhere to assert on. Open to it if you know a way.