Skip to content

Commit 28921b4

Browse files
committed
Add more tests
1 parent 6195d6d commit 28921b4

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

src/test/ui/closures/2229_closure_analysis/move_closure.rs

+38
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,49 @@ fn truncate_box_derefs() {
159159
};
160160
}
161161

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+
162198
fn main() {
163199
simple_move_closure();
164200
simple_ref();
165201
struct_contains_ref_to_another_struct_1();
166202
struct_contains_ref_to_another_struct_2();
167203
struct_contains_ref_to_another_struct_3();
168204
truncate_box_derefs();
205+
box_mut_2();
206+
box_mut_1();
169207
}

src/test/ui/closures/2229_closure_analysis/move_closure.stderr

+67-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ LL | let c = #[rustc_capture_analysis]
7070
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
7171
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
7272

73+
error[E0658]: attributes on expressions are experimental
74+
--> $DIR/move_closure.rs:172:13
75+
|
76+
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
78+
|
79+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
80+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
81+
82+
error[E0658]: attributes on expressions are experimental
83+
--> $DIR/move_closure.rs:189:13
84+
|
85+
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
87+
|
88+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
89+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
90+
7391
error: First Pass analysis includes:
7492
--> $DIR/move_closure.rs:15:5
7593
|
@@ -358,6 +376,54 @@ note: Min Capture t[(1, 0)] -> ByValue
358376
LL | println!("{}", t.1.0);
359377
| ^^^^^
360378

361-
error: aborting due to 24 previous errors
379+
error: First Pass analysis includes:
380+
--> $DIR/move_closure.rs:172:39
381+
|
382+
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
383+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
384+
|
385+
note: Capturing box_p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
386+
--> $DIR/move_closure.rs:172:47
387+
|
388+
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
389+
| ^^^^^^^^^^^
390+
391+
error: Min Capture analysis includes:
392+
--> $DIR/move_closure.rs:172:39
393+
|
394+
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
395+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
396+
|
397+
note: Min Capture box_p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
398+
--> $DIR/move_closure.rs:172:47
399+
|
400+
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
401+
| ^^^^^^^^^^^
402+
403+
error: First Pass analysis includes:
404+
--> $DIR/move_closure.rs:189:39
405+
|
406+
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
407+
| ^^^^^^^^^^^^^^^^^^^^^
408+
|
409+
note: Capturing p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
410+
--> $DIR/move_closure.rs:189:47
411+
|
412+
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
413+
| ^^^^^^^
414+
415+
error: Min Capture analysis includes:
416+
--> $DIR/move_closure.rs:189:39
417+
|
418+
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
419+
| ^^^^^^^^^^^^^^^^^^^^^
420+
|
421+
note: Min Capture p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
422+
--> $DIR/move_closure.rs:189:47
423+
|
424+
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
425+
| ^^^^^^^
426+
427+
error: aborting due to 30 previous errors
362428

363429
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)