@@ -33,13 +33,8 @@ pub(crate) struct Pat<'tcx> {
33
33
pub ( crate ) enum PatKind < ' tcx > {
34
34
Wild ,
35
35
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 > ,
43
38
subpatterns : Vec < FieldPat < ' tcx > > ,
44
39
} ,
45
40
@@ -67,8 +62,8 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
67
62
match self . kind {
68
63
PatKind :: Wild => write ! ( f, "_" ) ,
69
64
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)
72
67
}
73
68
PatKind :: Deref { ref subpattern } => write_ref_like ( f, self . ty , subpattern) ,
74
69
PatKind :: Constant { value } => write ! ( f, "{value}" ) ,
@@ -95,14 +90,20 @@ fn start_or_comma() -> impl FnMut() -> &'static str {
95
90
}
96
91
}
97
92
93
+ #[ derive( Clone , Debug ) ]
94
+ pub ( crate ) enum EnumInfo < ' tcx > {
95
+ Enum { adt_def : AdtDef < ' tcx > , variant_index : VariantIdx } ,
96
+ NotEnum ,
97
+ }
98
+
98
99
fn write_struct_like < ' tcx > (
99
100
f : & mut impl fmt:: Write ,
100
101
ty : Ty < ' tcx > ,
101
- kind : & PatKind < ' tcx > ,
102
+ enum_info : & EnumInfo < ' tcx > ,
102
103
subpatterns : & [ FieldPat < ' tcx > ] ,
103
104
) -> 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| {
106
107
let variant = adt_def. variant ( variant_index) ;
107
108
let adt_did = adt_def. did ( ) ;
108
109
let name = if tcx. get_diagnostic_item ( sym:: Option ) == Some ( adt_did)
@@ -114,7 +115,7 @@ fn write_struct_like<'tcx>(
114
115
} ;
115
116
Some ( ( variant, name) )
116
117
} ) ,
117
- _ => ty. ty_adt_def ( ) . and_then ( |adt_def| {
118
+ EnumInfo :: NotEnum => ty. ty_adt_def ( ) . and_then ( |adt_def| {
118
119
if !adt_def. is_enum ( ) {
119
120
ty:: tls:: with ( |tcx| {
120
121
Some ( ( adt_def. non_enum_variant ( ) , tcx. def_path_str ( adt_def. did ( ) ) ) )
0 commit comments