Skip to content

redundant_pattern_matching applies redundant parenthesis to expression with ? #16045

@mks-h

Description

@mks-h

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

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=2b291bbdcdecba2e6fd1f2dd16434242

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

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions