@@ -10,7 +10,6 @@ use crate::usefulness::PlaceCtxt;
10
10
use crate :: { Captures , TypeCx } ;
11
11
12
12
use self :: Constructor :: * ;
13
- use self :: PatOrWild :: * ;
14
13
15
14
/// Values and patterns can be represented as a constructor applied to some fields. This represents
16
15
/// a pattern in this form.
@@ -75,7 +74,7 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
75
74
other_ctor : & Constructor < Cx > ,
76
75
ctor_arity : usize ,
77
76
) -> SmallVec < [ PatOrWild < ' p , Cx > ; 2 ] > {
78
- let wildcard_sub_tys = || ( 0 ..ctor_arity) . map ( |_| Wild ) . collect ( ) ;
77
+ let wildcard_sub_tys = || ( 0 ..ctor_arity) . map ( |_| PatOrWild :: Wild ) . collect ( ) ;
79
78
match ( & self . ctor , other_ctor) {
80
79
// Return a wildcard for each field of `other_ctor`.
81
80
( Wildcard , _) => wildcard_sub_tys ( ) ,
@@ -91,14 +90,15 @@ impl<'p, Cx: TypeCx> DeconstructedPat<'p, Cx> {
91
90
// Fill in the fields from both ends.
92
91
let new_arity = fields. len ( ) ;
93
92
for i in 0 ..prefix {
94
- fields[ i] = Pat ( & self . fields [ i] ) ;
93
+ fields[ i] = PatOrWild :: Pat ( & self . fields [ i] ) ;
95
94
}
96
95
for i in 0 ..suffix {
97
- fields[ new_arity - 1 - i] = Pat ( & self . fields [ self . fields . len ( ) - 1 - i] ) ;
96
+ fields[ new_arity - 1 - i] =
97
+ PatOrWild :: Pat ( & self . fields [ self . fields . len ( ) - 1 - i] ) ;
98
98
}
99
99
fields
100
100
}
101
- _ => self . fields . iter ( ) . map ( Pat ) . collect ( ) ,
101
+ _ => self . fields . iter ( ) . map ( PatOrWild :: Pat ) . collect ( ) ,
102
102
}
103
103
}
104
104
@@ -162,29 +162,29 @@ pub(crate) enum PatOrWild<'p, Cx: TypeCx> {
162
162
impl < ' p , Cx : TypeCx > PatOrWild < ' p , Cx > {
163
163
pub ( crate ) fn as_pat ( & self ) -> Option < & ' p DeconstructedPat < ' p , Cx > > {
164
164
match self {
165
- Wild => None ,
166
- Pat ( pat) => Some ( pat) ,
165
+ PatOrWild :: Wild => None ,
166
+ PatOrWild :: Pat ( pat) => Some ( pat) ,
167
167
}
168
168
}
169
169
pub ( crate ) fn ctor ( self ) -> & ' p Constructor < Cx > {
170
170
match self {
171
- Wild => & Wildcard ,
172
- Pat ( pat) => pat. ctor ( ) ,
171
+ PatOrWild :: Wild => & Wildcard ,
172
+ PatOrWild :: Pat ( pat) => pat. ctor ( ) ,
173
173
}
174
174
}
175
175
176
176
pub ( crate ) fn is_or_pat ( & self ) -> bool {
177
177
match self {
178
- Wild => false ,
179
- Pat ( pat) => pat. is_or_pat ( ) ,
178
+ PatOrWild :: Wild => false ,
179
+ PatOrWild :: Pat ( pat) => pat. is_or_pat ( ) ,
180
180
}
181
181
}
182
182
183
183
/// Expand this (possibly-nested) or-pattern into its alternatives.
184
184
pub ( crate ) fn flatten_or_pat ( self ) -> SmallVec < [ Self ; 1 ] > {
185
185
match self {
186
- Pat ( pat) if pat. is_or_pat ( ) => {
187
- pat. iter_fields ( ) . flat_map ( |p| Pat ( p) . flatten_or_pat ( ) ) . collect ( )
186
+ PatOrWild :: Pat ( pat) if pat. is_or_pat ( ) => {
187
+ pat. iter_fields ( ) . flat_map ( |p| PatOrWild :: Pat ( p) . flatten_or_pat ( ) ) . collect ( )
188
188
}
189
189
_ => smallvec ! [ self ] ,
190
190
}
@@ -198,13 +198,13 @@ impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
198
198
ctor_arity : usize ,
199
199
) -> SmallVec < [ PatOrWild < ' p , Cx > ; 2 ] > {
200
200
match self {
201
- Wild => ( 0 ..ctor_arity) . map ( |_| Wild ) . collect ( ) ,
202
- Pat ( pat) => pat. specialize ( other_ctor, ctor_arity) ,
201
+ PatOrWild :: Wild => ( 0 ..ctor_arity) . map ( |_| PatOrWild :: Wild ) . collect ( ) ,
202
+ PatOrWild :: Pat ( pat) => pat. specialize ( other_ctor, ctor_arity) ,
203
203
}
204
204
}
205
205
206
206
pub ( crate ) fn set_useful ( & self ) {
207
- if let Pat ( pat) = self {
207
+ if let PatOrWild :: Pat ( pat) = self {
208
208
pat. set_useful ( )
209
209
}
210
210
}
@@ -213,8 +213,8 @@ impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
213
213
impl < ' p , Cx : TypeCx > fmt:: Debug for PatOrWild < ' p , Cx > {
214
214
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
215
215
match self {
216
- Wild => write ! ( f, "_" ) ,
217
- Pat ( pat) => pat. fmt ( f) ,
216
+ PatOrWild :: Wild => write ! ( f, "_" ) ,
217
+ PatOrWild :: Pat ( pat) => pat. fmt ( f) ,
218
218
}
219
219
}
220
220
}
0 commit comments