@@ -288,14 +288,15 @@ impl<'a,'tcx> Builder<'a,'tcx> {
288
288
test_outcome : usize ,
289
289
candidate : & Candidate < ' pat , ' tcx > )
290
290
-> Option < Candidate < ' pat , ' tcx > > {
291
- let candidate = candidate. clone ( ) ;
292
- let match_pairs = candidate. match_pairs ;
293
291
let result = self . match_pairs_under_assumption ( test_lvalue,
294
292
test_kind,
295
293
test_outcome,
296
- match_pairs) ;
294
+ & candidate . match_pairs ) ;
297
295
match result {
298
- Some ( match_pairs) => Some ( Candidate { match_pairs : match_pairs, ..candidate } ) ,
296
+ Some ( match_pairs) => Some ( Candidate { match_pairs : match_pairs,
297
+ bindings : candidate. bindings . clone ( ) ,
298
+ guard : candidate. guard . clone ( ) ,
299
+ arm_index : candidate. arm_index } ) ,
299
300
None => None ,
300
301
}
301
302
}
@@ -306,21 +307,20 @@ impl<'a,'tcx> Builder<'a,'tcx> {
306
307
test_lvalue : & Lvalue < ' tcx > ,
307
308
test_kind : & TestKind < ' tcx > ,
308
309
test_outcome : usize ,
309
- match_pairs : Vec < MatchPair < ' pat , ' tcx > > )
310
+ match_pairs : & [ MatchPair < ' pat , ' tcx > ] )
310
311
-> Option < Vec < MatchPair < ' pat , ' tcx > > > {
311
312
let mut result = vec ! [ ] ;
312
313
313
314
for match_pair in match_pairs {
314
- // if the match pair is testing a different lvalue, it
315
- // is unaffected by this test.
316
- if match_pair. lvalue != * test_lvalue {
317
- result. push ( match_pair) ;
318
- continue ;
319
- }
320
-
321
- // if this test doesn't tell us anything about this match-pair, then hang onto it.
322
- if !self . test_informs_match_pair ( & match_pair, test_kind, test_outcome) {
323
- result. push ( match_pair) ;
315
+ // If the match pair is either:
316
+ // (1) testing a different lvalue; or,
317
+ // (2) the test doesn't tell us anything about this match-pair,
318
+ // then we have to retain it as for after the test is complete.
319
+ if
320
+ match_pair. lvalue != * test_lvalue || // (1)
321
+ !self . test_informs_match_pair ( match_pair, test_kind, test_outcome) // (2)
322
+ {
323
+ result. push ( match_pair. clone ( ) ) ;
324
324
continue ;
325
325
}
326
326
@@ -445,7 +445,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
445
445
/// observed that `option` has the discriminant `Ok`, then the
446
446
/// second arm cannot apply.
447
447
pub fn consequent_match_pairs_under_assumption < ' pat > ( & mut self ,
448
- match_pair : MatchPair < ' pat , ' tcx > ,
448
+ match_pair : & MatchPair < ' pat , ' tcx > ,
449
449
test_kind : & TestKind < ' tcx > ,
450
450
test_outcome : usize )
451
451
-> Option < Vec < MatchPair < ' pat , ' tcx > > > {
@@ -511,7 +511,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
511
511
PatternKind :: Binding { .. } |
512
512
PatternKind :: Leaf { .. } |
513
513
PatternKind :: Deref { .. } => {
514
- self . error_simplifyable ( & match_pair)
514
+ self . error_simplifyable ( match_pair)
515
515
}
516
516
}
517
517
}
0 commit comments