@@ -33,13 +33,8 @@ pub(crate) struct Pat<'tcx> {
3333pub ( crate ) enum PatKind < ' tcx > {
3434 Wild ,
3535
36- Variant {
37- adt_def : AdtDef < ' tcx > ,
38- variant_index : VariantIdx ,
39- subpatterns : Vec < FieldPat < ' tcx > > ,
40- } ,
41-
42- Leaf {
36+ StructLike {
37+ enum_info : EnumInfo < ' tcx > ,
4338 subpatterns : Vec < FieldPat < ' tcx > > ,
4439 } ,
4540
@@ -67,8 +62,8 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
6762 match self . kind {
6863 PatKind :: Wild => write ! ( f, "_" ) ,
6964 PatKind :: Never => write ! ( f, "!" ) ,
70- PatKind :: Variant { ref subpatterns , .. } | PatKind :: Leaf { ref subpatterns } => {
71- write_struct_like ( f, self . ty , & self . kind , subpatterns)
65+ PatKind :: StructLike { ref enum_info , ref subpatterns } => {
66+ write_struct_like ( f, self . ty , enum_info , subpatterns)
7267 }
7368 PatKind :: Deref { ref subpattern } => write_ref_like ( f, self . ty , subpattern) ,
7469 PatKind :: Constant { value } => write ! ( f, "{value}" ) ,
@@ -95,14 +90,20 @@ fn start_or_comma() -> impl FnMut() -> &'static str {
9590 }
9691}
9792
93+ #[ derive( Clone , Debug ) ]
94+ pub ( crate ) enum EnumInfo < ' tcx > {
95+ Enum { adt_def : AdtDef < ' tcx > , variant_index : VariantIdx } ,
96+ NotEnum ,
97+ }
98+
9899fn write_struct_like < ' tcx > (
99100 f : & mut impl fmt:: Write ,
100101 ty : Ty < ' tcx > ,
101- kind : & PatKind < ' tcx > ,
102+ enum_info : & EnumInfo < ' tcx > ,
102103 subpatterns : & [ FieldPat < ' tcx > ] ,
103104) -> fmt:: Result {
104- let variant_and_name = match * kind {
105- PatKind :: Variant { adt_def, variant_index, .. } => ty:: tls:: with ( |tcx| {
105+ let variant_and_name = match * enum_info {
106+ EnumInfo :: Enum { adt_def, variant_index } => ty:: tls:: with ( |tcx| {
106107 let variant = adt_def. variant ( variant_index) ;
107108 let adt_did = adt_def. did ( ) ;
108109 let name = if tcx. get_diagnostic_item ( sym:: Option ) == Some ( adt_did)
@@ -114,7 +115,7 @@ fn write_struct_like<'tcx>(
114115 } ;
115116 Some ( ( variant, name) )
116117 } ) ,
117- _ => ty. ty_adt_def ( ) . and_then ( |adt_def| {
118+ EnumInfo :: NotEnum => ty. ty_adt_def ( ) . and_then ( |adt_def| {
118119 if !adt_def. is_enum ( ) {
119120 ty:: tls:: with ( |tcx| {
120121 Some ( ( adt_def. non_enum_variant ( ) , tcx. def_path_str ( adt_def. did ( ) ) ) )
0 commit comments