@@ -3,7 +3,6 @@ use clippy_utils::ty::is_type_diagnostic_item;
3
3
use clippy_utils:: { is_refutable, peel_hir_pat_refs, recurse_or_patterns} ;
4
4
use rustc_errors:: Applicability ;
5
5
use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
6
- use rustc_hir:: def_id:: DefId ;
7
6
use rustc_hir:: { Arm , Expr , PatKind , PathSegment , QPath , Ty , TyKind } ;
8
7
use rustc_lint:: LateContext ;
9
8
use rustc_middle:: ty:: { self , VariantDef } ;
@@ -46,11 +45,12 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
46
45
47
46
// Accumulate the variants which should be put in place of the wildcard because they're not
48
47
// already covered.
49
- let has_hidden_external = adt_def. variants ( ) . iter ( ) . any ( |x| is_external_and_hidden ( cx, x) ) ;
48
+ let is_external = adt_def. did ( ) . as_local ( ) . is_none ( ) ;
49
+ let has_external_hidden = is_external && adt_def. variants ( ) . iter ( ) . any ( |x| is_hidden ( cx, x) ) ;
50
50
let mut missing_variants: Vec < _ > = adt_def
51
51
. variants ( )
52
52
. iter ( )
53
- . filter ( |x| !is_external_and_hidden ( cx, x) )
53
+ . filter ( |x| !( is_external && is_hidden ( cx, x) ) )
54
54
. collect ( ) ;
55
55
56
56
let mut path_prefix = CommonPrefixSearcher :: None ;
@@ -138,7 +138,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
138
138
139
139
match missing_variants. as_slice ( ) {
140
140
[ ] => ( ) ,
141
- [ x] if !adt_def. is_variant_list_non_exhaustive ( ) && !has_hidden_external => span_lint_and_sugg (
141
+ [ x] if !adt_def. is_variant_list_non_exhaustive ( ) && !has_external_hidden => span_lint_and_sugg (
142
142
cx,
143
143
MATCH_WILDCARD_FOR_SINGLE_VARIANTS ,
144
144
wildcard_span,
@@ -149,7 +149,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
149
149
) ,
150
150
variants => {
151
151
let mut suggestions: Vec < _ > = variants. iter ( ) . copied ( ) . map ( format_suggestion) . collect ( ) ;
152
- let message = if adt_def. is_variant_list_non_exhaustive ( ) || has_hidden_external {
152
+ let message = if adt_def. is_variant_list_non_exhaustive ( ) || has_external_hidden {
153
153
suggestions. push ( "_" . into ( ) ) ;
154
154
"wildcard matches known variants and will also match future added variants"
155
155
} else {
@@ -196,14 +196,6 @@ impl<'a> CommonPrefixSearcher<'a> {
196
196
}
197
197
}
198
198
199
- fn is_external_and_hidden ( cx : & LateContext < ' _ > , variant_def : & VariantDef ) -> bool {
200
- is_external ( variant_def. def_id ) && is_hidden ( cx, variant_def)
201
- }
202
-
203
199
fn is_hidden ( cx : & LateContext < ' _ > , variant_def : & VariantDef ) -> bool {
204
200
cx. tcx . is_doc_hidden ( variant_def. def_id ) || cx. tcx . has_attr ( variant_def. def_id , sym:: unstable)
205
201
}
206
-
207
- fn is_external ( def_id : DefId ) -> bool {
208
- def_id. as_local ( ) . is_none ( )
209
- }
0 commit comments