Move Or
test out of the loop
This commit is contained in:
parent
3ea464f36a
commit
96ff1a4538
1 changed files with 26 additions and 22 deletions
|
@ -62,19 +62,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
let mut existing_bindings = mem::take(&mut candidate.bindings);
|
let mut existing_bindings = mem::take(&mut candidate.bindings);
|
||||||
let mut new_bindings = Vec::new();
|
let mut new_bindings = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
let match_pairs = mem::take(&mut candidate.match_pairs);
|
|
||||||
|
|
||||||
if let [MatchPair { pattern: Pat { kind: PatKind::Or { pats }, .. }, place }] =
|
|
||||||
&*match_pairs
|
|
||||||
{
|
|
||||||
existing_bindings.extend_from_slice(&new_bindings);
|
|
||||||
mem::swap(&mut candidate.bindings, &mut existing_bindings);
|
|
||||||
candidate.subcandidates = self.create_or_subcandidates(candidate, place, pats);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
for match_pair in match_pairs {
|
for match_pair in mem::take(&mut candidate.match_pairs) {
|
||||||
match self.simplify_match_pair(match_pair, candidate) {
|
match self.simplify_match_pair(match_pair, candidate) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
changed = true;
|
changed = true;
|
||||||
|
@ -84,6 +73,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid issue #69971: the binding order should be right to left if there are more
|
// Avoid issue #69971: the binding order should be right to left if there are more
|
||||||
// bindings after `@` to please the borrow checker
|
// bindings after `@` to please the borrow checker
|
||||||
// Ex
|
// Ex
|
||||||
|
@ -102,18 +92,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
candidate.bindings.clear();
|
candidate.bindings.clear();
|
||||||
|
|
||||||
if !changed {
|
if !changed {
|
||||||
|
// If we were not able to simplify anymore, done.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
existing_bindings.extend_from_slice(&new_bindings);
|
existing_bindings.extend_from_slice(&new_bindings);
|
||||||
mem::swap(&mut candidate.bindings, &mut existing_bindings);
|
mem::swap(&mut candidate.bindings, &mut existing_bindings);
|
||||||
|
|
||||||
|
let did_expand_or =
|
||||||
|
if let [MatchPair { pattern: Pat { kind: PatKind::Or { pats }, .. }, place }] =
|
||||||
|
&*candidate.match_pairs
|
||||||
|
{
|
||||||
|
candidate.subcandidates = self.create_or_subcandidates(candidate, place, pats);
|
||||||
|
candidate.match_pairs.clear();
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
// Move or-patterns to the end, because they can result in us
|
// Move or-patterns to the end, because they can result in us
|
||||||
// creating additional candidates, so we want to test them as
|
// creating additional candidates, so we want to test them as
|
||||||
// late as possible.
|
// late as possible.
|
||||||
candidate
|
candidate.match_pairs.sort_by_key(|pair| matches!(pair.pattern.kind, PatKind::Or { .. }));
|
||||||
.match_pairs
|
|
||||||
.sort_by_key(|pair| matches!(pair.pattern.kind, PatKind::Or { .. }));
|
|
||||||
debug!(simplified = ?candidate, "simplify_candidate");
|
debug!(simplified = ?candidate, "simplify_candidate");
|
||||||
return false; // if we were not able to simplify any, done.
|
|
||||||
}
|
did_expand_or
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given `candidate` that has a single or-pattern for its match-pairs,
|
/// Given `candidate` that has a single or-pattern for its match-pairs,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue