rust/src/test/ui/closures/2229_closure_analysis/capture-disjoint-field-struct.rs

29 lines
658 B
Rust
Raw Normal View History

// FIXME(arora-aman) add run-pass once 2229 is implemented
#![feature(capture_disjoint_fields)]
//~^ WARNING the feature `capture_disjoint_fields` is incomplete
#![feature(rustc_attrs)]
struct Point {
x: i32,
y: i32,
}
fn main() {
let mut p = Point { x: 10, y: 10 };
let c = #[rustc_capture_analysis]
//~^ ERROR: attributes on expressions are experimental
|| {
println!("{}", p.x);
//~^ ERROR: Capturing p[(0, 0)] -> ImmBorrow
2020-11-10 08:05:50 +00:00
//~| ERROR: Min Capture p[(0, 0)] -> ImmBorrow
};
// `c` should only capture `p.x`, therefore mutating `p.y` is allowed.
let py = &mut p.y;
c();
*py = 20;
}