2021-06-27 01:22:46 -05:00
|
|
|
// edition:2021
|
2020-10-12 19:16:02 -05:00
|
|
|
|
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
|
|
|
|
struct Point {
|
|
|
|
x: i32,
|
|
|
|
y: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
// This testcase ensures that nested closures are handles properly
|
|
|
|
// - The nested closure is analyzed first.
|
|
|
|
// - The capture kind of the nested closure is accounted for by the enclosing closure
|
|
|
|
// - Any captured path by the nested closure that starts off a local variable in the enclosing
|
|
|
|
// closure is not listed as a capture of the enclosing closure.
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut p = Point { x: 5, y: 20 };
|
|
|
|
|
|
|
|
let mut c1 = #[rustc_capture_analysis]
|
|
|
|
//~^ ERROR: attributes on expressions are experimental
|
2020-11-13 00:51:19 -06:00
|
|
|
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
|
2024-01-10 00:39:02 -06:00
|
|
|
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
2020-10-12 19:16:02 -05:00
|
|
|
|| {
|
2020-11-13 00:51:19 -06:00
|
|
|
//~^ ERROR: First Pass analysis includes:
|
|
|
|
//~| ERROR: Min Capture analysis includes:
|
2020-10-12 19:16:02 -05:00
|
|
|
println!("{}", p.x);
|
2020-11-13 00:51:19 -06:00
|
|
|
//~^ NOTE: Capturing p[(0, 0)] -> ImmBorrow
|
|
|
|
//~| NOTE: Min Capture p[(0, 0)] -> ImmBorrow
|
2020-10-12 19:16:02 -05:00
|
|
|
let incr = 10;
|
|
|
|
let mut c2 = #[rustc_capture_analysis]
|
|
|
|
//~^ ERROR: attributes on expressions are experimental
|
2020-11-13 00:51:19 -06:00
|
|
|
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
|
2024-01-10 00:39:02 -06:00
|
|
|
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
2020-10-12 19:16:02 -05:00
|
|
|
|| p.y += incr;
|
2020-11-13 00:51:19 -06:00
|
|
|
//~^ ERROR: First Pass analysis includes:
|
|
|
|
//~| ERROR: Min Capture analysis includes:
|
|
|
|
//~| NOTE: Capturing p[(1, 0)] -> MutBorrow
|
|
|
|
//~| NOTE: Capturing incr[] -> ImmBorrow
|
|
|
|
//~| NOTE: Min Capture p[(1, 0)] -> MutBorrow
|
|
|
|
//~| NOTE: Min Capture incr[] -> ImmBorrow
|
|
|
|
//~| NOTE: Capturing p[(1, 0)] -> MutBorrow
|
|
|
|
//~| NOTE: Min Capture p[(1, 0)] -> MutBorrow
|
2020-10-12 19:16:02 -05:00
|
|
|
c2();
|
|
|
|
println!("{}", p.y);
|
2021-10-13 16:14:37 -05:00
|
|
|
//~^ NOTE: Capturing p[(1, 0)] -> ImmBorrow
|
2020-10-12 19:16:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
c1();
|
|
|
|
|
|
|
|
let px = &p.x;
|
|
|
|
|
|
|
|
println!("{}", px);
|
|
|
|
|
|
|
|
c1();
|
|
|
|
}
|