@@ -288,14 +288,15 @@ impl<'a,'tcx> Builder<'a,'tcx> {
288288 test_outcome : usize ,
289289 candidate : & Candidate < ' pat , ' tcx > )
290290 -> Option < Candidate < ' pat , ' tcx > > {
291- let candidate = candidate. clone ( ) ;
292- let match_pairs = candidate. match_pairs ;
293291 let result = self . match_pairs_under_assumption ( test_lvalue,
294292 test_kind,
295293 test_outcome,
296- match_pairs) ;
294+ & candidate . match_pairs ) ;
297295 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 } ) ,
299300 None => None ,
300301 }
301302 }
@@ -306,21 +307,20 @@ impl<'a,'tcx> Builder<'a,'tcx> {
306307 test_lvalue : & Lvalue < ' tcx > ,
307308 test_kind : & TestKind < ' tcx > ,
308309 test_outcome : usize ,
309- match_pairs : Vec < MatchPair < ' pat , ' tcx > > )
310+ match_pairs : & [ MatchPair < ' pat , ' tcx > ] )
310311 -> Option < Vec < MatchPair < ' pat , ' tcx > > > {
311312 let mut result = vec ! [ ] ;
312313
313314 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 ( ) ) ;
324324 continue ;
325325 }
326326
@@ -445,7 +445,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
445445 /// observed that `option` has the discriminant `Ok`, then the
446446 /// second arm cannot apply.
447447 pub fn consequent_match_pairs_under_assumption < ' pat > ( & mut self ,
448- match_pair : MatchPair < ' pat , ' tcx > ,
448+ match_pair : & MatchPair < ' pat , ' tcx > ,
449449 test_kind : & TestKind < ' tcx > ,
450450 test_outcome : usize )
451451 -> Option < Vec < MatchPair < ' pat , ' tcx > > > {
@@ -511,7 +511,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
511511 PatternKind :: Binding { .. } |
512512 PatternKind :: Leaf { .. } |
513513 PatternKind :: Deref { .. } => {
514- self . error_simplifyable ( & match_pair)
514+ self . error_simplifyable ( match_pair)
515515 }
516516 }
517517 }
0 commit comments