mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
review comments
This commit is contained in:
parent
f44f96d61c
commit
5827fbadf6
@ -44,10 +44,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
candidate: &mut Candidate<'pat, 'tcx>,
|
candidate: &mut Candidate<'pat, 'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// repeatedly simplify match pairs until fixed point is reached
|
// 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
|
// existing_bindings and new_bindings exists to keep the semantics in order.
|
||||||
// reversing the binding order for bindings after `@` change binding order in places
|
// 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)`
|
// it shouldn't be changed, for example `let (Some(a), Some(b)) = (x, y)`
|
||||||
//
|
//
|
||||||
// To avoid this, the binding occurs in the following manner:
|
// To avoid this, the binding occurs in the following manner:
|
||||||
@ -64,7 +64,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
// binding in iter 2: [6, 7]
|
// binding in iter 2: [6, 7]
|
||||||
//
|
//
|
||||||
// final binding: [1, 2, 3, 6, 7, 4, 5]
|
// 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();
|
let mut new_bindings = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
let match_pairs = mem::take(&mut candidate.match_pairs);
|
let match_pairs = mem::take(&mut candidate.match_pairs);
|
||||||
@ -72,8 +72,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
if let [MatchPair { pattern: Pat { kind: box PatKind::Or { pats }, .. }, place }] =
|
if let [MatchPair { pattern: Pat { kind: box PatKind::Or { pats }, .. }, place }] =
|
||||||
*match_pairs
|
*match_pairs
|
||||||
{
|
{
|
||||||
exisiting_bindings.extend_from_slice(&new_bindings);
|
existing_bindings.extend_from_slice(&new_bindings);
|
||||||
mem::swap(&mut candidate.bindings, &mut exisiting_bindings);
|
mem::swap(&mut candidate.bindings, &mut existing_bindings);
|
||||||
candidate.subcandidates = self.create_or_subcandidates(candidate, place, pats);
|
candidate.subcandidates = self.create_or_subcandidates(candidate, place, pats);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -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
|
// bindings after `@` to please the borrow checker
|
||||||
// Ex
|
// Ex
|
||||||
// struct NonCopyStruct {
|
// struct NonCopyStruct {
|
||||||
@ -107,15 +107,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
candidate.bindings.clear();
|
candidate.bindings.clear();
|
||||||
|
|
||||||
if !changed {
|
if !changed {
|
||||||
exisiting_bindings.extend_from_slice(&new_bindings);
|
existing_bindings.extend_from_slice(&new_bindings);
|
||||||
mem::swap(&mut candidate.bindings, &mut exisiting_bindings);
|
mem::swap(&mut candidate.bindings, &mut existing_bindings);
|
||||||
// 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
|
.match_pairs
|
||||||
.sort_by_key(|pair| matches!(*pair.pattern.kind, PatKind::Or { .. }));
|
.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.
|
return false; // if we were not able to simplify any, done.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@ struct C;
|
|||||||
struct NC<A, B>(A, B);
|
struct NC<A, B>(A, B);
|
||||||
|
|
||||||
fn main() {
|
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));
|
let a @ NC(b, c @ NC(d, e)) = NC(C, NC(C, C));
|
||||||
//~^ ERROR use of partially moved value
|
//~^ ERROR use of partially moved value
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error[E0382]: use of partially moved value
|
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));
|
LL | let a @ NC(b, c @ NC(d, e)) = NC(C, NC(C, C));
|
||||||
| ^^^^^^^^^^------------^
|
| ^^^^^^^^^^------------^
|
||||||
|
Loading…
Reference in New Issue
Block a user