Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vn-ki committed Nov 3, 2020
1 parent f44f96d commit 5827fba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
20 changes: 10 additions & 10 deletions compiler/rustc_mir_build/src/build/matches/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
candidate: &mut Candidate<'pat, 'tcx>,
) -> bool {
// repeatedly simplify match pairs until fixed point is reached
debug!("simplify_candidate(candidate={:?})", candidate);
debug!(?candidate, "simplify_candidate");

// exisiting_bindings and new_bindings exists to keep the semantics in order
// reversing the binding order for bindings after `@` change binding order in places
// existing_bindings and new_bindings exists to keep the semantics in order.
// Reversing the binding order for bindings after `@` changes the binding order in places
// it shouldn't be changed, for example `let (Some(a), Some(b)) = (x, y)`
//
// To avoid this, the binding occurs in the following manner:
Expand All @@ -64,16 +64,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// binding in iter 2: [6, 7]
//
// final binding: [1, 2, 3, 6, 7, 4, 5]
let mut exisiting_bindings = mem::take(&mut candidate.bindings);
let mut existing_bindings = mem::take(&mut candidate.bindings);
let mut new_bindings = Vec::new();
loop {
let match_pairs = mem::take(&mut candidate.match_pairs);

if let [MatchPair { pattern: Pat { kind: box PatKind::Or { pats }, .. }, place }] =
*match_pairs
{
exisiting_bindings.extend_from_slice(&new_bindings);
mem::swap(&mut candidate.bindings, &mut exisiting_bindings);
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;
}
Expand All @@ -89,7 +89,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}
}
// 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
// Ex
// struct NonCopyStruct {
Expand All @@ -107,15 +107,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
candidate.bindings.clear();

if !changed {
exisiting_bindings.extend_from_slice(&new_bindings);
mem::swap(&mut candidate.bindings, &mut exisiting_bindings);
existing_bindings.extend_from_slice(&new_bindings);
mem::swap(&mut candidate.bindings, &mut existing_bindings);
// Move or-patterns to the end, because they can result in us
// creating additional candidates, so we want to test them as
// late as possible.
candidate
.match_pairs
.sort_by_key(|pair| matches!(*pair.pattern.kind, PatKind::Or { .. }));
debug!("simplify_candidate: simplifed {:?}", candidate);
debug!(simplified = ?candidate, "simplify_candidate");
return false; // if we were not able to simplify any, done.
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/pattern/bindings-after-at/copy-and-move-mixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ struct C;
struct NC<A, B>(A, B);

fn main() {
// this compiles
let a @ NC(b, c) = NC(C, C);

let a @ NC(b, c @ NC(d, e)) = NC(C, NC(C, C));
//~^ ERROR use of partially moved value
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0382]: use of partially moved value
--> $DIR/copy-and-move-mixed.rs:11:9
--> $DIR/copy-and-move-mixed.rs:14:9
|
LL | let a @ NC(b, c @ NC(d, e)) = NC(C, NC(C, C));
| ^^^^^^^^^^------------^
Expand Down

0 comments on commit 5827fba

Please sign in to comment.