-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[question_mark
]: also trigger on return
statements
#11994
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
Conversation
r? @xFrednet (rustbot has picked a reviewer for you, use r? to override) |
I like how it immediately flagged 3 instances in Clippy sources. I wonder how many will trigger in popular crates. |
From the top 500 crates, only 4 crates triggered this lint, totaling a number of 72 instances (most of them in the plotters-backend crate). |
Nice. This comment made me think that this would cause us to lint in a lot more cases due to rustfmt adding the semicolon and suppressing the lint that way for correctly-formatted code, but double-checking now, it doesn't seem to be case that it does that. Hopefully those 4 are legit warnings and not FPs? Also thanks for running lintcheck, I meant to do that myself but forgot 😅 |
Looks like it. I'm currently submitting a PR for the libc crate, and may submit others as well. |
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.
LGTM, small NIT and then we can r+ this :D
clippy_lints/src/question_mark.rs
Outdated
expr: Some(els), | ||
.. | ||
} = els | ||
&& let Some(els) = find_let_else_ret_expression(els) |
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 change looks good to me. Could you also add a check for comments, with span_contains_comment
and a test?
let Some(x) = y else {
// Roses are red,
// violets are blue,
// please keep this comment,
// it's art, you know?
return None;
};
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 idea! Fixed. (also love that quote)
Perfection! And what a masterpiece. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Simplify build.rs by using the question mark operator The `question_mark` clippy lint currently overlooks some patterns that could be replaced by the question mark operator. This will be fixed shortly by rust-lang/rust-clippy#11994.
This fixes the false negative mentioned in #11993: the lint only used to check for
return
expressions, and not a statement containing areturn
expression (doesn't close the issue tho since there's still a useful suggestion that we could make, which is to suggest.ok_or()?
/.ok_or_else()?
forelse { return Err(..) }
)changelog: [
question_mark
]: also trigger onreturn
statements