Skip to content

manual_range_contains doesn't catch multiple range checks in && expressions #8745

Closed
@xTibor

Description

@xTibor

Summary

When there are two or more range checks in && expressions Clippy only catches the first instance of them. Similar || expressions are not affected by this issue.

Lint Name

manual_range_contains

Reproducer

fn main() {
    let (a, b) = (0, 0);

    let _test_or = (a >= 0) && (a <= 10) || (b >= 0) && (b <= 10);
    //             ^^^^^^^^^^^^^^^^^^^^^    ^^^^^^^^^^^^^^^^^^^^^
    //             (0..=10).contains(&a)    (0..=10).contains(&b)

    let _test_and = (a >= 0) && (a <= 10) && (b >= 0) && (b <= 10);
    //              ^^^^^^^^^^^^^^^^^^^^^    ^^^^^^^^^^^^^^^^^^^^^
    //              (0..=10).contains(&a)    Missing suggestion
}

Version

rustc 1.62.0-nightly (311e2683e 2022-04-18)
binary: rustc
commit-hash: 311e2683e1bad87715b1558f7900e294d24ce491
commit-date: 2022-04-18
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

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