Skip to content

redundant_pattern_matching failes to check whether contained value are used. #12329

@S-K-Tiger

Description

@S-K-Tiger

Summary

I found a example of redundant pattern matching in my code that wasn't picked up by clippy.

Lint Name

redundant_pattern_matching

Reproducer

I tried this code:

#[deny(clippy::redundant_pattern_matching)]
pub fn missing_warning(input: &str) -> bool {
    // This is the match I expected 'redundant_pattern_matching' to warn me about.
    let _result = match input.parse::<u32>() {
        Ok(_) => input,
        Err(_) => return false
    };
    true
}

I expected to see this happen:
Running cargo clippy should trigger an error and provide a suggestion in the form of:

pub fn expected_fix(input: &str) -> bool {
    let _result = if input.parse::<u32>().is_ok() { input } else { return false }
}

Instead, this happened:
Running cargo clippy did not report any errors.

Version

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02e
commit-date: 2024-02-04
host: x86_64-pc-windows-msvc
release: 1.76.0
LLVM version: 17.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions