@@ -116,24 +116,23 @@ impl<'tcx> MatchPairTree<'tcx> {
116
116
}
117
117
118
118
let place = place_builder. try_to_place ( cx) ;
119
- let default_irrefutable = || TestCase :: Irrefutable { } ;
120
119
let mut subpairs = Vec :: new ( ) ;
121
120
let test_case = match pattern. kind {
122
- PatKind :: Wild | PatKind :: Error ( _) => default_irrefutable ( ) ,
121
+ PatKind :: Wild | PatKind :: Error ( _) => None ,
123
122
124
- PatKind :: Or { ref pats } => TestCase :: Or {
123
+ PatKind :: Or { ref pats } => Some ( TestCase :: Or {
125
124
pats : pats. iter ( ) . map ( |pat| FlatPat :: new ( place_builder. clone ( ) , pat, cx) ) . collect ( ) ,
126
- } ,
125
+ } ) ,
127
126
128
127
PatKind :: Range ( ref range) => {
129
128
if range. is_full_range ( cx. tcx ) == Some ( true ) {
130
- default_irrefutable ( )
129
+ None
131
130
} else {
132
- TestCase :: Range ( Arc :: clone ( range) )
131
+ Some ( TestCase :: Range ( Arc :: clone ( range) ) )
133
132
}
134
133
}
135
134
136
- PatKind :: Constant { value } => TestCase :: Constant { value } ,
135
+ PatKind :: Constant { value } => Some ( TestCase :: Constant { value } ) ,
137
136
138
137
PatKind :: AscribeUserType {
139
138
ascription : Ascription { ref annotation, variance } ,
@@ -154,7 +153,7 @@ impl<'tcx> MatchPairTree<'tcx> {
154
153
extra_data. ascriptions . push ( super :: Ascription { source, annotation, variance } ) ;
155
154
}
156
155
157
- default_irrefutable ( )
156
+ None
158
157
}
159
158
160
159
PatKind :: Binding { mode, var, ref subpattern, .. } => {
@@ -199,12 +198,12 @@ impl<'tcx> MatchPairTree<'tcx> {
199
198
} ) ;
200
199
}
201
200
202
- default_irrefutable ( )
201
+ None
203
202
}
204
203
205
204
PatKind :: ExpandedConstant { subpattern : ref pattern, def_id : _, is_inline : false } => {
206
205
MatchPairTree :: for_pattern ( place_builder, pattern, cx, & mut subpairs, extra_data) ;
207
- default_irrefutable ( )
206
+ None
208
207
}
209
208
PatKind :: ExpandedConstant { subpattern : ref pattern, def_id, is_inline : true } => {
210
209
MatchPairTree :: for_pattern ( place_builder, pattern, cx, & mut subpairs, extra_data) ;
@@ -233,7 +232,7 @@ impl<'tcx> MatchPairTree<'tcx> {
233
232
extra_data. ascriptions . push ( super :: Ascription { annotation, source, variance } ) ;
234
233
}
235
234
236
- default_irrefutable ( )
235
+ None
237
236
}
238
237
239
238
PatKind :: Array { ref prefix, ref slice, ref suffix } => {
@@ -245,7 +244,7 @@ impl<'tcx> MatchPairTree<'tcx> {
245
244
slice,
246
245
suffix,
247
246
) ;
248
- default_irrefutable ( )
247
+ None
249
248
}
250
249
PatKind :: Slice { ref prefix, ref slice, ref suffix } => {
251
250
cx. prefix_slice_suffix (
@@ -258,12 +257,12 @@ impl<'tcx> MatchPairTree<'tcx> {
258
257
) ;
259
258
260
259
if prefix. is_empty ( ) && slice. is_some ( ) && suffix. is_empty ( ) {
261
- default_irrefutable ( )
260
+ None
262
261
} else {
263
- TestCase :: Slice {
262
+ Some ( TestCase :: Slice {
264
263
len : prefix. len ( ) + suffix. len ( ) ,
265
264
variable_length : slice. is_some ( ) ,
266
- }
265
+ } )
267
266
}
268
267
}
269
268
@@ -279,16 +278,12 @@ impl<'tcx> MatchPairTree<'tcx> {
279
278
. apply_ignore_module ( cx. tcx , cx. infcx . typing_env ( cx. param_env ) )
280
279
} ) && ( adt_def. did ( ) . is_local ( )
281
280
|| !adt_def. is_variant_list_non_exhaustive ( ) ) ;
282
- if irrefutable {
283
- default_irrefutable ( )
284
- } else {
285
- TestCase :: Variant { adt_def, variant_index }
286
- }
281
+ if irrefutable { None } else { Some ( TestCase :: Variant { adt_def, variant_index } ) }
287
282
}
288
283
289
284
PatKind :: Leaf { ref subpatterns } => {
290
285
cx. field_match_pairs ( & mut subpairs, extra_data, place_builder, subpatterns) ;
291
- default_irrefutable ( )
286
+ None
292
287
}
293
288
294
289
PatKind :: Deref { ref subpattern } => {
@@ -299,7 +294,7 @@ impl<'tcx> MatchPairTree<'tcx> {
299
294
& mut subpairs,
300
295
extra_data,
301
296
) ;
302
- default_irrefutable ( )
297
+ None
303
298
}
304
299
305
300
PatKind :: DerefPattern { ref subpattern, mutability } => {
@@ -316,18 +311,25 @@ impl<'tcx> MatchPairTree<'tcx> {
316
311
& mut subpairs,
317
312
extra_data,
318
313
) ;
319
- TestCase :: Deref { temp, mutability }
314
+ Some ( TestCase :: Deref { temp, mutability } )
320
315
}
321
316
322
- PatKind :: Never => TestCase :: Never ,
317
+ PatKind :: Never => Some ( TestCase :: Never ) ,
323
318
} ;
324
319
325
- match_pairs. push ( MatchPairTree {
326
- place,
327
- test_case,
328
- subpairs,
329
- pattern_ty : pattern. ty ,
330
- pattern_span : pattern. span ,
331
- } ) ;
320
+ if let Some ( test_case) = test_case {
321
+ // This pattern is refutable, so push a new match-pair node.
322
+ match_pairs. push ( MatchPairTree {
323
+ place,
324
+ test_case,
325
+ subpairs,
326
+ pattern_ty : pattern. ty ,
327
+ pattern_span : pattern. span ,
328
+ } )
329
+ } else {
330
+ // This pattern is irrefutable, so it doesn't need its own match-pair node.
331
+ // Just push its refutable subpatterns instead, if any.
332
+ match_pairs. extend ( subpairs) ;
333
+ }
332
334
}
333
335
}
0 commit comments