@@ -602,7 +602,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
602
602
}
603
603
}
604
604
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]`.
606
606
crate fn is_foreign_non_exhaustive_enum ( & self , ty : Ty < ' tcx > ) -> bool {
607
607
match ty. kind {
608
608
ty:: Adt ( def, ..) => {
@@ -612,8 +612,8 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
612
612
}
613
613
}
614
614
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]`.
617
617
fn is_foreign_non_exhaustive_variant ( & self , ty : Ty < ' tcx > , variant : & VariantDef ) -> bool {
618
618
match ty. kind {
619
619
ty:: Adt ( def, ..) => variant. is_field_list_non_exhaustive ( ) && !def. did . is_local ( ) ,
@@ -733,8 +733,8 @@ impl Slice {
733
733
734
734
#[ derive( Clone , Debug , PartialEq ) ]
735
735
enum 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.
738
738
Single ,
739
739
/// Enum variants.
740
740
Variant ( DefId ) ,
@@ -2349,12 +2349,17 @@ fn specialize_one_pattern<'p, 'tcx>(
2349
2349
2350
2350
PatKind :: Variant { adt_def, variant_index, ref subpatterns, .. } => {
2351
2351
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
+ }
2358
2363
}
2359
2364
2360
2365
PatKind :: Leaf { ref subpatterns } => {
0 commit comments