Add more tests

This commit is contained in:
Aman Arora 2021-07-09 04:34:11 -04:00
parent 6195d6dcac
commit 28921b4213
2 changed files with 105 additions and 1 deletions

View file

@ -159,6 +159,42 @@ fn truncate_box_derefs() {
};
}
struct Foo { x: i32 }
// Ensure that even in move closures, if the data is not owned by the root variable
// then we don't truncate the derefs or a ByValue capture, rather do a reborrow
fn box_mut_1() {
let mut foo = Foo { x: 0 } ;
let p_foo = &mut foo;
let box_p_foo = Box::new(p_foo);
let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
//~^ ERROR: attributes on expressions are experimental
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
//~| First Pass analysis includes:
//~| NOTE: Capturing box_p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
//~| Min Capture analysis includes:
//~| NOTE: Min Capture box_p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
}
// Ensure that even in move closures, if the data is not owned by the root variable
// then we don't truncate the derefs or a ByValue capture, rather do a reborrow
fn box_mut_2() {
let foo = Foo { x: 0 } ;
let mut box_foo = Box::new(foo);
let p_foo = &mut box_foo;
let c = #[rustc_capture_analysis] move || p_foo.x += 10;
//~^ ERROR: attributes on expressions are experimental
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
//~| First Pass analysis includes:
//~| NOTE: Capturing p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
//~| Min Capture analysis includes:
//~| NOTE: Min Capture p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
}
fn main() {
simple_move_closure();
simple_ref();
@ -166,4 +202,6 @@ fn main() {
struct_contains_ref_to_another_struct_2();
struct_contains_ref_to_another_struct_3();
truncate_box_derefs();
box_mut_2();
box_mut_1();
}

View file

@ -70,6 +70,24 @@ LL | let c = #[rustc_capture_analysis]
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
error[E0658]: attributes on expressions are experimental
--> $DIR/move_closure.rs:172:13
|
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
error[E0658]: attributes on expressions are experimental
--> $DIR/move_closure.rs:189:13
|
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
error: First Pass analysis includes:
--> $DIR/move_closure.rs:15:5
|
@ -358,6 +376,54 @@ note: Min Capture t[(1, 0)] -> ByValue
LL | println!("{}", t.1.0);
| ^^^^^
error: aborting due to 24 previous errors
error: First Pass analysis includes:
--> $DIR/move_closure.rs:172:39
|
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: Capturing box_p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
--> $DIR/move_closure.rs:172:47
|
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
| ^^^^^^^^^^^
error: Min Capture analysis includes:
--> $DIR/move_closure.rs:172:39
|
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: Min Capture box_p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
--> $DIR/move_closure.rs:172:47
|
LL | let c = #[rustc_capture_analysis] move || box_p_foo.x += 10;
| ^^^^^^^^^^^
error: First Pass analysis includes:
--> $DIR/move_closure.rs:189:39
|
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
| ^^^^^^^^^^^^^^^^^^^^^
|
note: Capturing p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
--> $DIR/move_closure.rs:189:47
|
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
| ^^^^^^^
error: Min Capture analysis includes:
--> $DIR/move_closure.rs:189:39
|
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
| ^^^^^^^^^^^^^^^^^^^^^
|
note: Min Capture p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow
--> $DIR/move_closure.rs:189:47
|
LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10;
| ^^^^^^^
error: aborting due to 30 previous errors
For more information about this error, try `rustc --explain E0658`.