File tree 2 files changed +51
-0
lines changed
src/test/ui/closures/2229_closure_analysis
2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -41,4 +41,38 @@ pub fn edge_case_char(event: char) {
41
41
} ;
42
42
}
43
43
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
+
44
78
fn main ( ) { }
Original file line number Diff line number Diff line change
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`.
You can’t perform that action at this time.
0 commit comments