Skip to content

Invalid warning on redundant_pattern_matching #11174

@nurmohammed840

Description

@nurmohammed840

Summary

This example should not yield any warning.

Lint Name

redundant_pattern_matching

Reproducer

I tried this code:

fn _test<T>(boolean: bool, maybe_some: Option<T>) -> bool {
    matches!(maybe_some, None if !boolean)
}

I saw this happen:

warning: redundant pattern matching, consider using `is_none()`
 --> src/lib.rs:2:5
  |
2 |     matches!(maybe_some, None if !boolean)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `maybe_some.is_none()`
  |

Expected:

fn _test<T>(boolean: bool, maybe_some: Option<T>) -> bool {
    // matches!(maybe_some, None if !boolean)
    maybe_some.is_none() && !boolean
}

Version

rustc 1.73.0-nightly (33a2c2487 2023-07-12)

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions