-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
Clippy wrongly suggests I can use the question mark operator when returning an error which matches a deep pattern.
The idea is that I'm manually matching an error and then returning, but my match is more specific than what ?
does, so it's a false positive
Lint Name
question_mark
Reproducer
I tried this code:
pub struct Error {
flag: bool,
}
fn foo() -> Result<(), Error> {
let res = Ok(());
if let Err(err @ Error { flag: true }) = res {
return Err(err);
}
res
}
I saw this happen:
warning: this block may be rewritten with the `?` operator
--> src/lib.rs:10:5
|
10 | / if let Err(err @ Error { flag: true }) = res {
11 | | return Err(err);
12 | | }
| |_____^ help: replace it with: `res?;`
|
= note: `#[warn(clippy::question_mark)]` on by default
I expected to see this happen:
No warning
Version
rustc 1.65.0-nightly (29e4a9ee0 2022-08-10)
binary: rustc
commit-hash: 29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6
commit-date: 2022-08-10
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 14.0.6
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Dont lint on match pattern-binding
Auto merge of #9348 - lukaslueg:issue9347, r=Alexendoo
Auto merge of #9348 - lukaslueg:issue9347, r=Alexendoo