-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed as duplicate of#117304
Closed as duplicate of#117304
Copy link
Labels
A-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsRelating to exhaustiveness / usefulness checking of patternsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.F-non_exhaustive_omitted_patterns_lint`#![feature(non_exhaustive_omitted_patterns_lint)]``#![feature(non_exhaustive_omitted_patterns_lint)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
#![feature(non_exhaustive_omitted_patterns_lint)]
#![warn(non_exhaustive_omitted_patterns)]
use core::sync::atomic::Ordering;
pub fn is_relaxed(ordering: Ordering) -> bool {
matches!(ordering, Ordering::Relaxed)
}warning: some variants are not matched explicitly
--> src/lib.rs:7:14
|
7 | matches!(ordering, Ordering::Relaxed)
| ^^^^^^^^ patterns `std::sync::atomic::Ordering::Release`, `std::sync::atomic::Ordering::Acquire`, `std::sync::atomic::Ordering::AcqRel` and 1 more 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
note: the lint level is defined here
--> src/lib.rs:2:9
|
2 | #![warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^I believe the lint should not trigger on this code. For comparison, it correctly does not trigger on this alternative implementation of the same function:
pub fn is_relaxed(ordering: Ordering) -> bool {
if let Ordering::Relaxed = ordering {
true
} else {
false
}
}Conceptually, for the purpose of exhaustiveness, matches! more closely resembles if let than match, even if the standard library implementation currently involves match internally in order to support guard expressions.
The non_exhaustive_omitted_patterns should only trigger on this variation of this function.
pub fn is_relaxed(ordering: Ordering) -> bool {
match ordering {
Ordering::Relaxed => true,
_ => false, // warning: non exhaustive omitted patterns
}
}Metadata
Metadata
Assignees
Labels
A-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsRelating to exhaustiveness / usefulness checking of patternsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.F-non_exhaustive_omitted_patterns_lint`#![feature(non_exhaustive_omitted_patterns_lint)]``#![feature(non_exhaustive_omitted_patterns_lint)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.