-
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
New Lint: Use question mark instead of Option::and_then #6436
Comments
just checking if this is still good to be worked on? i am aware it has been a while since this was raised! if it is, i don't mind picking it up :)! cc: @flip1995 @Manishearth @giraffate (sorry if i've overtagged someone) |
Should be fine. We should figure out the name and the lint level but you can start work on it before we decide. I'm open to the level being |
yeah, that sounds good. as you said, both of those things shouldn't require a lot of re-work if i start on this now. will get a bit familiarised with the tool and we can continue the discussion either here or when i raise the pr (about naming and lint level). thanks again :). |
@rustbot claim |
I found myself rewriting: let select = paren_select(p);
match select {
Some(cm) => {
if p.at_ts(COMPOUND_SELECT_FIRST) {
opt_compound_select(p, cm)
} else {
Some(cm)
}
}
None => None,
} as paren_select(p).and_then(|cm| {
if p.at_ts(COMPOUND_SELECT_FIRST) {
opt_compound_select(p, cm)
} else {
Some(cm)
}
}) before switching to the question mark: let cm = paren_select(p)?;
if p.at_ts(COMPOUND_SELECT_FIRST) {
opt_compound_select(p, cm)
} else {
Some(cm)
} |
@rustbot claim |
What it does
Detect functions that end with
Option::and_then
orResult::and_then
and suggest using a question mark instead.Categories
It is simpler and more idiomatic.
Drawbacks
None.
Example
Could be written as:
The
and_then
call should be the very last expression of the function (not inside anif
block, for example).More Questionable Cases
Single expression lambda (no block)
At the end of a call chain
Personally I think those cases should still be linted. Maybe it can be configurable.
The text was updated successfully, but these errors were encountered: