Skip to content

Commit 1335b4c

Browse files
committed
Add additional match test case
1 parent 4d8d72f commit 1335b4c

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// edition:2021
2+
3+
enum SingleVariant {
4+
A
5+
}
6+
7+
struct TestStruct {
8+
x: i32,
9+
y: i32,
10+
z: i32,
11+
}
12+
13+
fn main() {
14+
let sv = SingleVariant::A;
15+
let condition = true;
16+
// sv should not be captured as it is a SingleVariant
17+
let _a = || {
18+
match sv {
19+
SingleVariant::A if condition => (),
20+
_ => ()
21+
}
22+
};
23+
let mut mut_sv = sv;
24+
_a();
25+
26+
// ts should be captured
27+
let ts = TestStruct { x: 1, y: 1, z: 1 };
28+
let _b = || { match ts {
29+
TestStruct{ x: 1, .. } => (),
30+
_ => ()
31+
}};
32+
let mut mut_ts = ts;
33+
//~^ ERROR: cannot move out of `ts` because it is borrowed
34+
_b();
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0505]: cannot move out of `ts` because it is borrowed
2+
--> $DIR/match-edge-cases.rs:32:22
3+
|
4+
LL | let _b = || { match ts {
5+
| -- -- borrow occurs due to use in closure
6+
| |
7+
| borrow of `ts` occurs here
8+
...
9+
LL | let mut mut_ts = ts;
10+
| ^^ move out of `ts` occurs here
11+
LL |
12+
LL | _b();
13+
| -- borrow later used here
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0505`.

0 commit comments

Comments
 (0)