@@ -131,11 +131,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
131
131
ascriptions : & mut Vec < Ascription < ' tcx > > ,
132
132
match_pairs : & mut Vec < MatchPair < ' pat , ' tcx > > ,
133
133
) -> Result < ( ) , MatchPair < ' pat , ' tcx > > {
134
- assert ! ( match_pair. subpairs. is_empty( ) , "mustn't simplify a match pair twice" ) ;
135
134
match match_pair. pattern . kind {
135
+ PatKind :: Leaf { .. }
136
+ | PatKind :: Deref { .. }
137
+ | PatKind :: Array { .. }
138
+ | PatKind :: Never
139
+ | PatKind :: Wild
140
+ | PatKind :: Error ( _) => { }
141
+
136
142
PatKind :: AscribeUserType {
137
- ref subpattern,
138
143
ascription : thir:: Ascription { ref annotation, variance } ,
144
+ ..
139
145
} => {
140
146
// Apply the type ascription to the value at `match_pair.place`
141
147
if let Some ( source) = match_pair. place . try_to_place ( self ) {
@@ -145,15 +151,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
145
151
variance,
146
152
} ) ;
147
153
}
148
-
149
- match_pairs. push ( MatchPair :: new ( match_pair. place , subpattern, self ) ) ;
150
-
151
- Ok ( ( ) )
152
- }
153
-
154
- PatKind :: Wild | PatKind :: Error ( _) => {
155
- // nothing left to do
156
- Ok ( ( ) )
157
154
}
158
155
159
156
PatKind :: Binding {
@@ -162,7 +159,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
162
159
mode,
163
160
var,
164
161
ty : _,
165
- ref subpattern,
162
+ subpattern : _ ,
166
163
is_primary : _,
167
164
} => {
168
165
if let Some ( source) = match_pair. place . try_to_place ( self ) {
@@ -173,24 +170,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
173
170
binding_mode : mode,
174
171
} ) ;
175
172
}
176
-
177
- if let Some ( subpattern) = subpattern. as_ref ( ) {
178
- // this is the `x @ P` case; have to keep matching against `P` now
179
- match_pairs. push ( MatchPair :: new ( match_pair. place , subpattern, self ) ) ;
180
- }
181
-
182
- Ok ( ( ) )
183
- }
184
-
185
- PatKind :: Never => {
186
- // A never pattern acts like a load from the place.
187
- // FIXME(never_patterns): load from the place
188
- Ok ( ( ) )
189
- }
190
-
191
- PatKind :: Constant { .. } => {
192
- // FIXME normalize patterns when possible
193
- Err ( match_pair)
194
173
}
195
174
196
175
PatKind :: InlineConstant { subpattern : ref pattern, def } => {
@@ -225,38 +204,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
225
204
variance : ty:: Contravariant ,
226
205
} ) ;
227
206
}
228
- match_pairs . push ( MatchPair :: new ( match_pair . place , pattern , self ) ) ;
207
+ }
229
208
230
- Ok ( ( ) )
209
+ PatKind :: Constant { .. } => {
210
+ // FIXME normalize patterns when possible
211
+ return Err ( match_pair) ;
231
212
}
232
213
233
214
PatKind :: Range ( ref range) => {
234
- if let Some ( true ) = range. is_full_range ( self . tcx ) {
235
- // Irrefutable pattern match.
236
- return Ok ( ( ) ) ;
215
+ if range. is_full_range ( self . tcx ) != Some ( true ) {
216
+ return Err ( match_pair) ;
237
217
}
238
- Err ( match_pair)
239
218
}
240
219
241
220
PatKind :: Slice { ref prefix, ref slice, ref suffix } => {
242
- if prefix. is_empty ( ) && slice. is_some ( ) && suffix. is_empty ( ) {
243
- // irrefutable
244
- self . prefix_slice_suffix ( match_pairs, & match_pair. place , prefix, slice, suffix) ;
245
- Ok ( ( ) )
246
- } else {
247
- self . prefix_slice_suffix (
248
- & mut match_pair. subpairs ,
249
- & match_pair. place ,
250
- prefix,
251
- slice,
252
- suffix,
253
- ) ;
221
+ if !( prefix. is_empty ( ) && slice. is_some ( ) && suffix. is_empty ( ) ) {
254
222
self . simplify_match_pairs ( & mut match_pair. subpairs , bindings, ascriptions) ;
255
- Err ( match_pair)
223
+ return Err ( match_pair) ;
256
224
}
257
225
}
258
226
259
- PatKind :: Variant { adt_def, args, variant_index, ref subpatterns } => {
227
+ PatKind :: Variant { adt_def, args, variant_index, subpatterns : _ } => {
260
228
let irrefutable = adt_def. variants ( ) . iter_enumerated ( ) . all ( |( i, v) | {
261
229
i == variant_index || {
262
230
( self . tcx . features ( ) . exhaustive_patterns
@@ -268,36 +236,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
268
236
}
269
237
} ) && ( adt_def. did ( ) . is_local ( )
270
238
|| !adt_def. is_variant_list_non_exhaustive ( ) ) ;
271
- if irrefutable {
272
- let place_builder = match_pair. place . downcast ( adt_def, variant_index) ;
273
- match_pairs. extend ( self . field_match_pairs ( place_builder, subpatterns) ) ;
274
- Ok ( ( ) )
275
- } else {
276
- let downcast_place = match_pair. place . clone ( ) . downcast ( adt_def, variant_index) ; // `(x as Variant)`
277
- match_pair. subpairs = self . field_match_pairs ( downcast_place, subpatterns) ;
239
+ if !irrefutable {
278
240
self . simplify_match_pairs ( & mut match_pair. subpairs , bindings, ascriptions) ;
279
- Err ( match_pair)
241
+ return Err ( match_pair) ;
280
242
}
281
243
}
282
244
283
- PatKind :: Array { ref prefix, ref slice, ref suffix } => {
284
- self . prefix_slice_suffix ( match_pairs, & match_pair. place , prefix, slice, suffix) ;
285
- Ok ( ( ) )
286
- }
287
-
288
- PatKind :: Leaf { ref subpatterns } => {
289
- // tuple struct, match subpats (if any)
290
- match_pairs. extend ( self . field_match_pairs ( match_pair. place , subpatterns) ) ;
291
- Ok ( ( ) )
292
- }
293
-
294
- PatKind :: Deref { ref subpattern } => {
295
- let place_builder = match_pair. place . deref ( ) ;
296
- match_pairs. push ( MatchPair :: new ( place_builder, subpattern, self ) ) ;
297
- Ok ( ( ) )
298
- }
299
-
300
- PatKind :: Or { .. } => Err ( match_pair) ,
245
+ PatKind :: Or { .. } => return Err ( match_pair) ,
301
246
}
247
+
248
+ // Simplifiable pattern; we replace it with its subpairs.
249
+ match_pairs. append ( & mut match_pair. subpairs ) ;
250
+ Ok ( ( ) )
302
251
}
303
252
}
0 commit comments