-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add single_option_map
lint
#14033
base: master
Are you sure you want to change the base?
Add single_option_map
lint
#14033
Conversation
r? @Manishearth rustbot has assigned @Manishearth. Use |
r? @llogiq |
It is also necessary to check that the receiver of fn f(x: &str) -> Option<u32> {
x.parse::<u32>().ok().map(|x| x+1)
} |
da10dc2
to
609541b
Compare
f89506e
to
4df6872
Compare
dc114ee
to
a2283e0
Compare
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.
This test case should be added, to reflect one problem the lint had in its earlier form:
// No lint: maps other than the receiver
fn map_not_arg(arg: Option<u32>) -> Option<u32> {
maps_static_option().map(|_| arg.unwrap())
}
Also, wrapping a function can be done more explicitly than with just the function name:
// No lint: wrapper function with η-expanded form
fn manipulate_opt_explicit(opt_i: Option<i32>) -> Option<i32> {
opt_i.map(|x| manipulate(x))
}
It would be great not to lint here too. But it can always be done later if this proves cumbersome.
Co-authored-by: Samuel Tardieu <[email protected]>
This ensures lints aren't accidentally lost during future refactoring, as they will be checked by uitest Co-authored-by: Samuel Tardieu <[email protected]>
Co-authored-by: Samuel Tardieu <[email protected]>
Thanks, I've added it. |
maps_static_option().map(|_| arg.unwrap()) | ||
} | ||
|
||
// No lint: wrapper function with η-expanded form |
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.
It looks like it lints in the current case (look at the stderr
file).
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.
Yes, I just noticed that. For future reference, is there a way to change status of the PR to WIP, in case I find a problem I urgently need to resolve.
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.
You have two ways of doing this:
- Use rustbot with "@rustbot author" to indicate that your PR waits for an action on your side, and "@rustbot review" when you want to switch it back to ready to review.
- Using the GitHub interface, you can at any point set the PR to "Draft", then set it back to "Ready" when you're done. This has the disadvantage of not changing the status in the TriageBot dashboard AFAICT.
Checks for functions with method calls to
.map(_)
on an arg of typeOption
as the outermost expression.Fixes #774