@@ -43,60 +43,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
43
43
// let y = x;
44
44
// }
45
45
//
46
- // We can't just reverse the binding order, because we must preserve pattern-order
47
- // otherwise, e.g. in `let (Some(a), Some(b)) = (x, y)`. Our rule then is: deepest-first,
48
- // and bindings at the same depth stay in source order.
49
- //
50
- // To do this, every time around the loop we prepend the newly found bindings to the
51
- // bindings we already had.
52
- //
53
- // example:
54
- // candidate.bindings = [1, 2, 3]
55
- // bindings in iter 1: [4, 5]
56
- // bindings in iter 2: [6, 7]
57
- //
58
- // final bindings: [6, 7, 4, 5, 1, 2, 3]
59
- let mut accumulated_bindings = mem:: take ( candidate_bindings) ;
60
- let mut simplified_match_pairs = Vec :: new ( ) ;
61
- // Repeatedly simplify match pairs until we're left with only unsimplifiable ones.
62
- loop {
63
- for mut match_pair in mem:: take ( match_pairs) {
64
- if let TestCase :: Irrefutable { binding, ascription } = match_pair. test_case {
65
- if let Some ( binding) = binding {
66
- candidate_bindings. push ( binding) ;
67
- }
68
- if let Some ( ascription) = ascription {
69
- candidate_ascriptions. push ( ascription) ;
70
- }
71
- // Simplifiable pattern; we replace it with its subpairs and simplify further.
72
- match_pairs. append ( & mut match_pair. subpairs ) ;
73
- } else {
74
- // Unsimplifiable pattern; we recursively simplify its subpairs and don't
75
- // process it further.
76
- self . simplify_match_pairs (
77
- & mut match_pair. subpairs ,
78
- candidate_bindings,
79
- candidate_ascriptions,
80
- ) ;
81
- simplified_match_pairs. push ( match_pair) ;
46
+ // We therefore lower bindings from left-to-right, except we lower the `x` in `x @ pat`
47
+ // after any bindings in `pat`. This doesn't work for or-patterns: the current structure of
48
+ // match lowering forces us to lower bindings inside or-patterns last.
49
+ for mut match_pair in mem:: take ( match_pairs) {
50
+ self . simplify_match_pairs (
51
+ & mut match_pair. subpairs ,
52
+ candidate_bindings,
53
+ candidate_ascriptions,
54
+ ) ;
55
+ if let TestCase :: Irrefutable { binding, ascription } = match_pair. test_case {
56
+ if let Some ( binding) = binding {
57
+ candidate_bindings. push ( binding) ;
82
58
}
83
- }
84
-
85
- // This does: accumulated_bindings = candidate.bindings.take() ++ accumulated_bindings
86
- candidate_bindings. extend_from_slice ( & accumulated_bindings) ;
87
- mem:: swap ( candidate_bindings, & mut accumulated_bindings) ;
88
- candidate_bindings. clear ( ) ;
89
-
90
- if match_pairs. is_empty ( ) {
91
- break ;
59
+ if let Some ( ascription) = ascription {
60
+ candidate_ascriptions. push ( ascription) ;
61
+ }
62
+ // Simplifiable pattern; we replace it with its already simplified subpairs.
63
+ match_pairs. append ( & mut match_pair. subpairs ) ;
64
+ } else {
65
+ // Unsimplifiable pattern; we keep it.
66
+ match_pairs. push ( match_pair) ;
92
67
}
93
68
}
94
69
95
- // Store computed bindings back in `candidate_bindings`.
96
- mem:: swap ( candidate_bindings, & mut accumulated_bindings) ;
97
- // Store simplified match pairs back in `match_pairs`.
98
- mem:: swap ( match_pairs, & mut simplified_match_pairs) ;
99
-
100
70
// Move or-patterns to the end, because they can result in us
101
71
// creating additional candidates, so we want to test them as
102
72
// late as possible.
0 commit comments