@@ -45,8 +45,12 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
4545
4646 // Accumulate the variants which should be put in place of the wildcard because they're not
4747 // 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 ( ) ;
5054
5155 let mut path_prefix = CommonPrefixSearcher :: None ;
5256 for arm in arms {
@@ -133,7 +137,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
133137
134138 match missing_variants. as_slice ( ) {
135139 [ ] => ( ) ,
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 (
137141 cx,
138142 MATCH_WILDCARD_FOR_SINGLE_VARIANTS ,
139143 wildcard_span,
@@ -144,7 +148,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
144148 ) ,
145149 variants => {
146150 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 {
148152 suggestions. push ( "_" . into ( ) ) ;
149153 "wildcard matches known variants and will also match future added variants"
150154 } else {
@@ -191,6 +195,7 @@ impl<'a> CommonPrefixSearcher<'a> {
191195 }
192196}
193197
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 ( )
196201}
0 commit comments