@@ -45,8 +45,12 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
45
45
46
46
// Accumulate the variants which should be put in place of the wildcard because they're not
47
47
// already covered.
48
- let has_hidden = adt_def. variants ( ) . iter ( ) . any ( |x| is_hidden ( cx, x) ) ;
49
- let mut missing_variants: Vec < _ > = adt_def. variants ( ) . iter ( ) . filter ( |x| !is_hidden ( cx, x) ) . collect ( ) ;
48
+ let has_hidden_external = adt_def. variants ( ) . iter ( ) . any ( |x| is_hidden_and_external ( cx, x) ) ;
49
+ let mut missing_variants: Vec < _ > = adt_def
50
+ . variants ( )
51
+ . iter ( )
52
+ . filter ( |x| !is_hidden_and_external ( cx, x) )
53
+ . collect ( ) ;
50
54
51
55
let mut path_prefix = CommonPrefixSearcher :: None ;
52
56
for arm in arms {
@@ -133,7 +137,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
133
137
134
138
match missing_variants. as_slice ( ) {
135
139
[ ] => ( ) ,
136
- [ x] if !adt_def. is_variant_list_non_exhaustive ( ) && !has_hidden => span_lint_and_sugg (
140
+ [ x] if !adt_def. is_variant_list_non_exhaustive ( ) && !has_hidden_external => span_lint_and_sugg (
137
141
cx,
138
142
MATCH_WILDCARD_FOR_SINGLE_VARIANTS ,
139
143
wildcard_span,
@@ -144,7 +148,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
144
148
) ,
145
149
variants => {
146
150
let mut suggestions: Vec < _ > = variants. iter ( ) . copied ( ) . map ( format_suggestion) . collect ( ) ;
147
- let message = if adt_def. is_variant_list_non_exhaustive ( ) || has_hidden {
151
+ let message = if adt_def. is_variant_list_non_exhaustive ( ) || has_hidden_external {
148
152
suggestions. push ( "_" . into ( ) ) ;
149
153
"wildcard matches known variants and will also match future added variants"
150
154
} else {
@@ -191,6 +195,7 @@ impl<'a> CommonPrefixSearcher<'a> {
191
195
}
192
196
}
193
197
194
- fn is_hidden ( cx : & LateContext < ' _ > , variant_def : & VariantDef ) -> bool {
195
- cx. tcx . is_doc_hidden ( variant_def. def_id ) || cx. tcx . has_attr ( variant_def. def_id , sym:: unstable)
198
+ fn is_hidden_and_external ( cx : & LateContext < ' _ > , variant_def : & VariantDef ) -> bool {
199
+ ( cx. tcx . is_doc_hidden ( variant_def. def_id ) || cx. tcx . has_attr ( variant_def. def_id , sym:: unstable) )
200
+ && variant_def. def_id . as_local ( ) . is_none ( )
196
201
}
0 commit comments