Don't suggest unstable and doc(hidden) variants.
This commit is contained in:
parent
3e59563394
commit
38569c03eb
@ -992,9 +992,9 @@ fn with_prefix(&mut self, path: &'a [PathSegment<'a>]) {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_doc_hidden(cx: &LateContext<'_>, variant_def: &VariantDef) -> bool {
|
||||
fn is_hidden(cx: &LateContext<'_>, variant_def: &VariantDef) -> bool {
|
||||
let attrs = cx.tcx.get_attrs(variant_def.def_id);
|
||||
clippy_utils::attrs::is_doc_hidden(attrs)
|
||||
clippy_utils::attrs::is_doc_hidden(attrs) || clippy_utils::attrs::is_unstable(attrs)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
@ -1033,7 +1033,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
|
||||
|
||||
// Accumulate the variants which should be put in place of the wildcard because they're not
|
||||
// already covered.
|
||||
let mut missing_variants: Vec<_> = adt_def.variants.iter().collect();
|
||||
let mut missing_variants: Vec<_> = adt_def.variants.iter().filter(|x| !is_hidden(cx, x)).collect();
|
||||
|
||||
let mut path_prefix = CommonPrefixSearcher::None;
|
||||
for arm in arms {
|
||||
@ -1118,7 +1118,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
|
||||
|
||||
match missing_variants.as_slice() {
|
||||
[] => (),
|
||||
[x] if !adt_def.is_variant_list_non_exhaustive() && !is_doc_hidden(cx, x) => span_lint_and_sugg(
|
||||
[x] if !adt_def.is_variant_list_non_exhaustive() => span_lint_and_sugg(
|
||||
cx,
|
||||
MATCH_WILDCARD_FOR_SINGLE_VARIANTS,
|
||||
wildcard_span,
|
||||
|
@ -157,3 +157,8 @@ pub fn is_doc_hidden(attrs: &[ast::Attribute]) -> bool {
|
||||
.filter_map(ast::Attribute::meta_item_list)
|
||||
.any(|l| attr::list_contains_name(&l, sym::hidden))
|
||||
}
|
||||
|
||||
/// Return true if the attributes contain `#[unstable]`
|
||||
pub fn is_unstable(attrs: &[ast::Attribute]) -> bool {
|
||||
attrs.iter().any(|attr| attr.has_name(sym::unstable))
|
||||
}
|
||||
|
@ -20,4 +20,6 @@ pub enum ErrorKind {
|
||||
UnexpectedEof,
|
||||
Unsupported,
|
||||
OutOfMemory,
|
||||
#[doc(hidden)]
|
||||
Uncategorized,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user