-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messages
Description
Summary
There's no point to wrapping expression? in parenthesis, since (expression?).call() and expression?.call() work the same, and the latter is... Well, simply better.
Lint Name
redundant_pattern_matching
Reproducer
I tried this code:
use std::io;
struct FailableIterator {}
impl FailableIterator {
fn next_result(&mut self) -> Result<Option<usize>, io::Error> {
Ok(None)
}
}
fn main() -> Result<(), io::Error> {
let mut fiter = FailableIterator {};
while let Some(_) = fiter.next_result()? {}
Ok(())
}I saw this happen:
Checking playground v0.0.1 (/playground)
warning: redundant pattern matching, consider using `is_some()`
--> src/main.rs:13:15
|
13 | while let Some(_) = fiter.next_result()? {}
| ----------^^^^^^^----------------------- help: try: `while (fiter.next_result()?).is_some()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#redundant_pattern_matching
= note: `#[warn(clippy::redundant_pattern_matching)]` on by default
I expected to see this happen:
Checking playground v0.0.1 (/playground)
warning: redundant pattern matching, consider using `is_some()`
--> src/main.rs:13:15
|
13 | while let Some(_) = fiter.next_result()? {}
| ----------^^^^^^^----------------------- help: try: `while fiter.next_result()?.is_some()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#redundant_pattern_matching
= note: `#[warn(clippy::redundant_pattern_matching)]` on by default
Version
rustc 1.91.0 (f8297e351 2025-10-28)
binary: rustc
commit-hash: f8297e351a40c1439a467bbbb6879088047f50b3
commit-date: 2025-10-28
host: x86_64-unknown-linux-gnu
release: 1.91.0
LLVM version: 21.1.2
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messages