Skip to content

Commit 5827fba

Browse files
committed
review comments
1 parent f44f96d commit 5827fba

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

compiler/rustc_mir_build/src/build/matches/simplify.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4444
candidate: &mut Candidate<'pat, 'tcx>,
4545
) -> bool {
4646
// repeatedly simplify match pairs until fixed point is reached
47-
debug!("simplify_candidate(candidate={:?})", candidate);
47+
debug!(?candidate, "simplify_candidate");
4848

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

7272
if let [MatchPair { pattern: Pat { kind: box PatKind::Or { pats }, .. }, place }] =
7373
*match_pairs
7474
{
75-
exisiting_bindings.extend_from_slice(&new_bindings);
76-
mem::swap(&mut candidate.bindings, &mut exisiting_bindings);
75+
existing_bindings.extend_from_slice(&new_bindings);
76+
mem::swap(&mut candidate.bindings, &mut existing_bindings);
7777
candidate.subcandidates = self.create_or_subcandidates(candidate, place, pats);
7878
return true;
7979
}
@@ -89,7 +89,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8989
}
9090
}
9191
}
92-
// issue #69971: the binding order should be right to left if there are more
92+
// Avoid issue #69971: the binding order should be right to left if there are more
9393
// bindings after `@` to please the borrow checker
9494
// Ex
9595
// struct NonCopyStruct {
@@ -107,15 +107,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
107107
candidate.bindings.clear();
108108

109109
if !changed {
110-
exisiting_bindings.extend_from_slice(&new_bindings);
111-
mem::swap(&mut candidate.bindings, &mut exisiting_bindings);
110+
existing_bindings.extend_from_slice(&new_bindings);
111+
mem::swap(&mut candidate.bindings, &mut existing_bindings);
112112
// Move or-patterns to the end, because they can result in us
113113
// creating additional candidates, so we want to test them as
114114
// late as possible.
115115
candidate
116116
.match_pairs
117117
.sort_by_key(|pair| matches!(*pair.pattern.kind, PatKind::Or { .. }));
118-
debug!("simplify_candidate: simplifed {:?}", candidate);
118+
debug!(simplified = ?candidate, "simplify_candidate");
119119
return false; // if we were not able to simplify any, done.
120120
}
121121
}

src/test/ui/pattern/bindings-after-at/copy-and-move-mixed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ struct C;
88
struct NC<A, B>(A, B);
99

1010
fn main() {
11+
// this compiles
12+
let a @ NC(b, c) = NC(C, C);
13+
1114
let a @ NC(b, c @ NC(d, e)) = NC(C, NC(C, C));
1215
//~^ ERROR use of partially moved value
1316
}

src/test/ui/pattern/bindings-after-at/copy-and-move-mixed.stderr

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

0 commit comments

Comments
 (0)