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

False positive in match_same_arms + non_exhaustive_omitted_patterns #10327

Closed
dtolnay opened this issue Feb 12, 2023 · 0 comments · Fixed by #10946
Closed

False positive in match_same_arms + non_exhaustive_omitted_patterns #10327

dtolnay opened this issue Feb 12, 2023 · 0 comments · Fixed by #10946
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@dtolnay
Copy link
Member

dtolnay commented Feb 12, 2023

Summary

Clippy's suggestion makes the code not compile when non_exhaustive_omitted_patterns is in use.

Lint Name

match_same_arms

Reproducer

#![feature(non_exhaustive_omitted_patterns_lint)]
#![deny(clippy::match_same_arms)]

use std::sync::atomic::Ordering; // #[non_exhaustive] enum

pub fn f(x: Ordering) {
    match x {
        Ordering::Relaxed => println!("relaxed"),
        Ordering::Release => println!("release"),
        Ordering::Acquire => println!("acquire"),
        Ordering::AcqRel | Ordering::SeqCst => unsupported(x),
        #[deny(non_exhaustive_omitted_patterns)]
        _ => unsupported(x),
    }
}

fn unsupported(x: Ordering) {
    dbg!(x);
}
$ cargo clippy
error: this match arm has an identical body to the `_` wildcard arm
  --> src/lib.rs:11:9
   |
11 |         Ordering::AcqRel | Ordering::SeqCst => unsupported(x),
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the arm
   |
   = help: or try changing either arm body
note: `_` wildcard arm here
  --> src/lib.rs:13:9
   |
13 |         _ => unsupported(x),
   |         ^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms

The original code compiles. Clippy's suggested code (remove line 11) does not compile.

error: some variants are not matched explicitly
  --> src/lib.rs:13:9
   |
13 |         _ => unsupported(x),
   |         ^ patterns `std::sync::atomic::Ordering::AcqRel` and `std::sync::atomic::Ordering::SeqCst` not covered
   |
   = help: ensure that all variants are matched explicitly by adding the suggested match arms
   = note: the matched value is of type `std::sync::atomic::Ordering` and the `non_exhaustive_omitted_patterns` attribute was found

Version

rustc 1.69.0-nightly (585f3eef2 2023-02-11)
binary: rustc
commit-hash: 585f3eef26f04440bca726c29193af7b4fa90e54
commit-date: 2023-02-11
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

@rustbot label +I-suggestion-causes-error

@dtolnay dtolnay 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 Feb 12, 2023
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Feb 12, 2023
dtolnay added a commit to dtolnay/cargo-expand that referenced this issue Mar 23, 2023
rust-lang/rust-clippy#10327

    error: this match arm has an identical body to the `_` wildcard arm
       --> src/edit.rs:103:9
        |
    103 |         Expr::Verbatim(_) => None,
        |         ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the arm
        |
        = help: or try changing either arm body
    note: `_` wildcard arm here
       --> src/edit.rs:106:9
        |
    106 |         _ => None,
        |         ^^^^^^^^^
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
        = note: `-D clippy::match-same-arms` implied by `-D clippy::pedantic`
@bors bors closed this as completed in cda13a8 Jun 15, 2023
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants