Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match_overlapping_arm false positive when ranges have negative starts #7829

Closed
ghost opened this issue Oct 17, 2021 · 1 comment · Fixed by #7847
Closed

match_overlapping_arm false positive when ranges have negative starts #7829

ghost opened this issue Oct 17, 2021 · 1 comment · Fixed by #7847
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@ghost
Copy link

ghost commented Oct 17, 2021

Lint name: match_overlapping_arm

I tried this code:

#[warn(clippy::match_overlapping_arm)]

fn main() {
    match 0 {
        -1..=1 => (),
        -2..=2 => (),
        _ => (),
    }
}

I expected to see this happen: No warning. Although it's not documented, the lint should not warn when a range is 'completely included' in another one.

Instead, this happened:

warning: some ranges overlap
 --> src/main.rs:5:9
  |
5 |         -1..=1 => (),
  |         ^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:8
  |
1 | #[warn(clippy::match_overlapping_arm)]
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: overlaps with this
 --> src/main.rs:6:9
  |
6 |         -2..=2 => (),
  |         ^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_overlapping_arm

Meta

Clippy 0.1.57 (2021-10-15 c102653) on the playground

playground

@ghost ghost added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 17, 2021
@ghost
Copy link
Author

ghost commented Oct 17, 2021

@rustbot claim

@rustbot rustbot assigned ghost Oct 17, 2021
bors added a commit that referenced this issue Oct 28, 2021
Fix false positive in `match_overlapping_arm`

Fixes #7829

changelog: Fix false positive in [`match_overlapping_arm`].
@bors bors closed this as completed in 1ede540 Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant
and others