@@ -602,7 +602,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
602602 }
603603 }
604604
605- // Returns whether the given type is an enum from another crate declared `#[non_exhaustive]`.
605+ /// Returns whether the given type is an enum from another crate declared `#[non_exhaustive]`.
606606 crate fn is_foreign_non_exhaustive_enum ( & self , ty : Ty < ' tcx > ) -> bool {
607607 match ty. kind {
608608 ty:: Adt ( def, ..) => {
@@ -612,8 +612,8 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
612612 }
613613 }
614614
615- // Returns whether the given variant is from another crate and has its fields declared
616- // `#[non_exhaustive]`.
615+ /// Returns whether the given variant is from another crate and has its fields declared
616+ /// `#[non_exhaustive]`.
617617 fn is_foreign_non_exhaustive_variant ( & self , ty : Ty < ' tcx > , variant : & VariantDef ) -> bool {
618618 match ty. kind {
619619 ty:: Adt ( def, ..) => variant. is_field_list_non_exhaustive ( ) && !def. did . is_local ( ) ,
@@ -733,8 +733,8 @@ impl Slice {
733733
734734#[ derive( Clone , Debug , PartialEq ) ]
735735enum Constructor < ' tcx > {
736- /// The constructor of all patterns that don't vary by constructor,
737- /// e.g., struct patterns and fixed-length arrays.
736+ /// The constructor for patterns that have a single constructor, like tuples, struct patterns
737+ /// and fixed-length arrays.
738738 Single ,
739739 /// Enum variants.
740740 Variant ( DefId ) ,
@@ -2349,12 +2349,17 @@ fn specialize_one_pattern<'p, 'tcx>(
23492349
23502350 PatKind :: Variant { adt_def, variant_index, ref subpatterns, .. } => {
23512351 let variant = & adt_def. variants [ variant_index] ;
2352- let is_non_exhaustive = cx. is_foreign_non_exhaustive_variant ( pat. ty , variant) ;
2353- Some ( Variant ( variant. def_id ) )
2354- . filter ( |variant_constructor| variant_constructor == constructor)
2355- . map ( |_| {
2356- patterns_for_variant ( cx, subpatterns, ctor_wild_subpatterns, is_non_exhaustive)
2357- } )
2352+ if constructor == Variant ( variant. def_id ) {
2353+ let is_non_exhaustive = cx. is_foreign_non_exhaustive_variant ( pat. ty , variant) ;
2354+ Some ( patterns_for_variant (
2355+ cx,
2356+ subpatterns,
2357+ ctor_wild_subpatterns,
2358+ is_non_exhaustive,
2359+ ) )
2360+ } else {
2361+ None
2362+ }
23582363 }
23592364
23602365 PatKind :: Leaf { ref subpatterns } => {
0 commit comments