@@ -116,24 +116,23 @@ impl<'tcx> MatchPairTree<'tcx> {
116116 }
117117
118118 let place = place_builder. try_to_place ( cx) ;
119- let default_irrefutable = || TestCase :: Irrefutable { } ;
120119 let mut subpairs = Vec :: new ( ) ;
121120 let test_case = match pattern. kind {
122- PatKind :: Wild | PatKind :: Error ( _) => default_irrefutable ( ) ,
121+ PatKind :: Wild | PatKind :: Error ( _) => None ,
123122
124- PatKind :: Or { ref pats } => TestCase :: Or {
123+ PatKind :: Or { ref pats } => Some ( TestCase :: Or {
125124 pats : pats. iter ( ) . map ( |pat| FlatPat :: new ( place_builder. clone ( ) , pat, cx) ) . collect ( ) ,
126- } ,
125+ } ) ,
127126
128127 PatKind :: Range ( ref range) => {
129128 if range. is_full_range ( cx. tcx ) == Some ( true ) {
130- default_irrefutable ( )
129+ None
131130 } else {
132- TestCase :: Range ( Arc :: clone ( range) )
131+ Some ( TestCase :: Range ( Arc :: clone ( range) ) )
133132 }
134133 }
135134
136- PatKind :: Constant { value } => TestCase :: Constant { value } ,
135+ PatKind :: Constant { value } => Some ( TestCase :: Constant { value } ) ,
137136
138137 PatKind :: AscribeUserType {
139138 ascription : Ascription { ref annotation, variance } ,
@@ -154,7 +153,7 @@ impl<'tcx> MatchPairTree<'tcx> {
154153 extra_data. ascriptions . push ( super :: Ascription { source, annotation, variance } ) ;
155154 }
156155
157- default_irrefutable ( )
156+ None
158157 }
159158
160159 PatKind :: Binding { mode, var, ref subpattern, .. } => {
@@ -199,12 +198,12 @@ impl<'tcx> MatchPairTree<'tcx> {
199198 } ) ;
200199 }
201200
202- default_irrefutable ( )
201+ None
203202 }
204203
205204 PatKind :: ExpandedConstant { subpattern : ref pattern, def_id : _, is_inline : false } => {
206205 MatchPairTree :: for_pattern ( place_builder, pattern, cx, & mut subpairs, extra_data) ;
207- default_irrefutable ( )
206+ None
208207 }
209208 PatKind :: ExpandedConstant { subpattern : ref pattern, def_id, is_inline : true } => {
210209 MatchPairTree :: for_pattern ( place_builder, pattern, cx, & mut subpairs, extra_data) ;
@@ -233,7 +232,7 @@ impl<'tcx> MatchPairTree<'tcx> {
233232 extra_data. ascriptions . push ( super :: Ascription { annotation, source, variance } ) ;
234233 }
235234
236- default_irrefutable ( )
235+ None
237236 }
238237
239238 PatKind :: Array { ref prefix, ref slice, ref suffix } => {
@@ -245,7 +244,7 @@ impl<'tcx> MatchPairTree<'tcx> {
245244 slice,
246245 suffix,
247246 ) ;
248- default_irrefutable ( )
247+ None
249248 }
250249 PatKind :: Slice { ref prefix, ref slice, ref suffix } => {
251250 cx. prefix_slice_suffix (
@@ -258,12 +257,12 @@ impl<'tcx> MatchPairTree<'tcx> {
258257 ) ;
259258
260259 if prefix. is_empty ( ) && slice. is_some ( ) && suffix. is_empty ( ) {
261- default_irrefutable ( )
260+ None
262261 } else {
263- TestCase :: Slice {
262+ Some ( TestCase :: Slice {
264263 len : prefix. len ( ) + suffix. len ( ) ,
265264 variable_length : slice. is_some ( ) ,
266- }
265+ } )
267266 }
268267 }
269268
@@ -279,16 +278,12 @@ impl<'tcx> MatchPairTree<'tcx> {
279278 . apply_ignore_module ( cx. tcx , cx. infcx . typing_env ( cx. param_env ) )
280279 } ) && ( adt_def. did ( ) . is_local ( )
281280 || !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 } ) }
287282 }
288283
289284 PatKind :: Leaf { ref subpatterns } => {
290285 cx. field_match_pairs ( & mut subpairs, extra_data, place_builder, subpatterns) ;
291- default_irrefutable ( )
286+ None
292287 }
293288
294289 PatKind :: Deref { ref subpattern } => {
@@ -299,7 +294,7 @@ impl<'tcx> MatchPairTree<'tcx> {
299294 & mut subpairs,
300295 extra_data,
301296 ) ;
302- default_irrefutable ( )
297+ None
303298 }
304299
305300 PatKind :: DerefPattern { ref subpattern, mutability } => {
@@ -316,18 +311,25 @@ impl<'tcx> MatchPairTree<'tcx> {
316311 & mut subpairs,
317312 extra_data,
318313 ) ;
319- TestCase :: Deref { temp, mutability }
314+ Some ( TestCase :: Deref { temp, mutability } )
320315 }
321316
322- PatKind :: Never => TestCase :: Never ,
317+ PatKind :: Never => Some ( TestCase :: Never ) ,
323318 } ;
324319
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+ }
332334 }
333335}
0 commit comments