@@ -16,7 +16,7 @@ fn simple_move_closure() {
16
16
//~^ ERROR: First Pass analysis includes:
17
17
//~| ERROR: Min Capture analysis includes:
18
18
t. 0 . 0 = "new S" . into ( ) ;
19
- //~^ NOTE: Capturing t[(0, 0),(0, 0)] -> ByValue
19
+ //~^ NOTE: Capturing t[(0, 0),(0, 0)] -> MutBorrow
20
20
//~| NOTE: Min Capture t[(0, 0),(0, 0)] -> ByValue
21
21
} ;
22
22
c ( ) ;
@@ -78,7 +78,7 @@ fn struct_contains_ref_to_another_struct_2() {
78
78
//~^ ERROR: First Pass analysis includes:
79
79
//~| ERROR: Min Capture analysis includes:
80
80
let _t = t. 0 . 0 ;
81
- //~^ NOTE: Capturing t[(0, 0),Deref] -> ImmBorrow
81
+ //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0) ] -> ImmBorrow
82
82
//~| NOTE: Min Capture t[(0, 0),Deref] -> ImmBorrow
83
83
} ;
84
84
@@ -100,8 +100,7 @@ fn struct_contains_ref_to_another_struct_3() {
100
100
//~^ ERROR: First Pass analysis includes:
101
101
//~| ERROR: Min Capture analysis includes:
102
102
let _t = t. 0 . 0 ;
103
- //~^ NOTE: Capturing t[(0, 0),Deref] -> ImmBorrow
104
- //~| NOTE: Capturing t[(0, 0)] -> ByValue
103
+ //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ByValue
105
104
//~| NOTE: Min Capture t[(0, 0)] -> ByValue
106
105
} ;
107
106
@@ -122,8 +121,7 @@ fn truncate_box_derefs() {
122
121
//~^ ERROR: First Pass analysis includes:
123
122
//~| ERROR: Min Capture analysis includes:
124
123
let _t = b. 0 ;
125
- //~^ NOTE: Capturing b[Deref,(0, 0)] -> ByValue
126
- //~| NOTE: Capturing b[] -> ByValue
124
+ //~^ NOTE: Capturing b[Deref,(0, 0)] -> ImmBorrow
127
125
//~| NOTE: Min Capture b[] -> ByValue
128
126
} ;
129
127
@@ -139,7 +137,7 @@ fn truncate_box_derefs() {
139
137
//~^ ERROR: First Pass analysis includes:
140
138
//~| ERROR: Min Capture analysis includes:
141
139
println ! ( "{}" , b. 0 ) ;
142
- //~^ NOTE: Capturing b[Deref,(0, 0)] -> ByValue
140
+ //~^ NOTE: Capturing b[Deref,(0, 0)] -> ImmBorrow
143
141
//~| NOTE: Min Capture b[] -> ByValue
144
142
} ;
145
143
@@ -156,16 +154,54 @@ fn truncate_box_derefs() {
156
154
//~^ ERROR: First Pass analysis includes:
157
155
//~| ERROR: Min Capture analysis includes:
158
156
println ! ( "{}" , t. 1.0 ) ;
159
- //~^ NOTE: Capturing t[(1, 0),Deref,(0, 0)] -> ByValue
157
+ //~^ NOTE: Capturing t[(1, 0),Deref,(0, 0)] -> ImmBorrow
160
158
//~| NOTE: Min Capture t[(1, 0)] -> ByValue
161
159
} ;
162
160
}
163
161
162
+ struct Foo { x : i32 }
163
+
164
+ // Ensure that even in move closures, if the data is not owned by the root variable
165
+ // then we don't truncate the derefs or a ByValue capture, rather do a reborrow
166
+ fn box_mut_1 ( ) {
167
+ let mut foo = Foo { x : 0 } ;
168
+
169
+ let p_foo = & mut foo;
170
+ let box_p_foo = Box :: new ( p_foo) ;
171
+
172
+ let c = #[ rustc_capture_analysis] move || box_p_foo. x += 10 ;
173
+ //~^ ERROR: attributes on expressions are experimental
174
+ //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
175
+ //~| First Pass analysis includes:
176
+ //~| NOTE: Capturing box_p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
177
+ //~| Min Capture analysis includes:
178
+ //~| NOTE: Min Capture box_p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
179
+ }
180
+
181
+ // Ensure that even in move closures, if the data is not owned by the root variable
182
+ // then we don't truncate the derefs or a ByValue capture, rather do a reborrow
183
+ fn box_mut_2 ( ) {
184
+ let foo = Foo { x : 0 } ;
185
+
186
+ let mut box_foo = Box :: new ( foo) ;
187
+ let p_foo = & mut box_foo;
188
+
189
+ let c = #[ rustc_capture_analysis] move || p_foo. x += 10 ;
190
+ //~^ ERROR: attributes on expressions are experimental
191
+ //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
192
+ //~| First Pass analysis includes:
193
+ //~| NOTE: Capturing p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
194
+ //~| Min Capture analysis includes:
195
+ //~| NOTE: Min Capture p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
196
+ }
197
+
164
198
fn main ( ) {
165
199
simple_move_closure ( ) ;
166
200
simple_ref ( ) ;
167
201
struct_contains_ref_to_another_struct_1 ( ) ;
168
202
struct_contains_ref_to_another_struct_2 ( ) ;
169
203
struct_contains_ref_to_another_struct_3 ( ) ;
170
204
truncate_box_derefs ( ) ;
205
+ box_mut_2 ( ) ;
206
+ box_mut_1 ( ) ;
171
207
}
0 commit comments