Skip to content

Commit cd35e25

Browse files
committed
Add additional match test case
1 parent 20de556 commit cd35e25

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,38 @@ pub fn edge_case_char(event: char) {
4141
};
4242
}
4343

44+
enum SingleVariant {
45+
A
46+
}
47+
48+
struct TestStruct {
49+
x: i32,
50+
y: i32,
51+
z: i32,
52+
}
53+
54+
fn edge_case_if() {
55+
let sv = SingleVariant::A;
56+
let condition = true;
57+
// sv should not be captured as it is a SingleVariant
58+
let _a = || {
59+
match sv {
60+
SingleVariant::A if condition => (),
61+
_ => ()
62+
}
63+
};
64+
let mut mut_sv = sv;
65+
_a();
66+
67+
// ts should be captured
68+
let ts = TestStruct { x: 1, y: 1, z: 1 };
69+
let _b = || { match ts {
70+
TestStruct{ x: 1, .. } => (),
71+
_ => ()
72+
}};
73+
let mut mut_ts = ts;
74+
//~^ ERROR: cannot move out of `ts` because it is borrowed
75+
_b();
76+
}
77+
4478
fn main() {}
Lines changed: 17 additions & 0 deletions
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)