-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Activity
#![feature(non_exhaustive_omitted_patterns_lint)]
rust-lang/rust#89554Ignore match_same_arms clippy false positive
match_same_arms
]: don't lint ifnon_exhaustive_omitted_patterns
#10946Auto merge of #10946 - Centri3:match_same_arms, r=blyxyas,xFrednet