-
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
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
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.
Thanks, I've added it. |
993f5b3
to
40edb89
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.
I think we may want to look into the the closure and not lint when it's anything but a function call.
This also applies to function arguments, which should be paths to lint. We shouldn't lint arg1.map(|a1| f(a1, arg2 + 1))
. Edit: I'm confused, we should certainly lint that.
214b37b
to
4d4ef00
Compare
Checks for functions with method calls to
.map(_)
on an arg of typeOption
as the outermost expression.Fixes #774