Skip to content

Commit 38569c0

Browse files
committed
Don't suggest unstable and doc(hidden) variants.
1 parent 3e59563 commit 38569c0

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

clippy_lints/src/matches.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,9 @@ impl CommonPrefixSearcher<'a> {
992992
}
993993
}
994994

995-
fn is_doc_hidden(cx: &LateContext<'_>, variant_def: &VariantDef) -> bool {
995+
fn is_hidden(cx: &LateContext<'_>, variant_def: &VariantDef) -> bool {
996996
let attrs = cx.tcx.get_attrs(variant_def.def_id);
997-
clippy_utils::attrs::is_doc_hidden(attrs)
997+
clippy_utils::attrs::is_doc_hidden(attrs) || clippy_utils::attrs::is_unstable(attrs)
998998
}
999999

10001000
#[allow(clippy::too_many_lines)]
@@ -1033,7 +1033,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
10331033

10341034
// Accumulate the variants which should be put in place of the wildcard because they're not
10351035
// already covered.
1036-
let mut missing_variants: Vec<_> = adt_def.variants.iter().collect();
1036+
let mut missing_variants: Vec<_> = adt_def.variants.iter().filter(|x| !is_hidden(cx, x)).collect();
10371037

10381038
let mut path_prefix = CommonPrefixSearcher::None;
10391039
for arm in arms {
@@ -1118,7 +1118,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
11181118

11191119
match missing_variants.as_slice() {
11201120
[] => (),
1121-
[x] if !adt_def.is_variant_list_non_exhaustive() && !is_doc_hidden(cx, x) => span_lint_and_sugg(
1121+
[x] if !adt_def.is_variant_list_non_exhaustive() => span_lint_and_sugg(
11221122
cx,
11231123
MATCH_WILDCARD_FOR_SINGLE_VARIANTS,
11241124
wildcard_span,

clippy_utils/src/attrs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,8 @@ pub fn is_doc_hidden(attrs: &[ast::Attribute]) -> bool {
157157
.filter_map(ast::Attribute::meta_item_list)
158158
.any(|l| attr::list_contains_name(&l, sym::hidden))
159159
}
160+
161+
/// Return true if the attributes contain `#[unstable]`
162+
pub fn is_unstable(attrs: &[ast::Attribute]) -> bool {
163+
attrs.iter().any(|attr| attr.has_name(sym::unstable))
164+
}

tests/ui/auxiliary/non-exhaustive-enum.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ pub enum ErrorKind {
2020
UnexpectedEof,
2121
Unsupported,
2222
OutOfMemory,
23+
#[doc(hidden)]
24+
Uncategorized,
2325
}

0 commit comments

Comments
 (0)