3 // Test borrow checker when we precise capture when using boxes
5 struct MetaData { x: String, name: String }
6 struct Data { m: MetaData }
7 struct BoxedData(Box<Data>);
8 struct EvenMoreBoxedData(Box<BoxedData>);
10 // Check diagnostics when the same path is mutated both inside and outside the closure
12 let m = MetaData { x: format!("x"), name: format!("name") };
14 let b = BoxedData(Box::new(d));
15 let mut e = EvenMoreBoxedData(Box::new(b));
18 e.0.0.m.x = format!("not-x");
21 e.0.0.m.x = format!("not-x");
22 //~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed
26 // Check diagnostics when a path is mutated inside a closure while attempting to read it outside
29 let m = MetaData { x: format!("x"), name: format!("name") };
31 let b = BoxedData(Box::new(d));
32 let mut e = EvenMoreBoxedData(Box::new(b));
35 e.0.0.m.x = format!("not-x");
38 println!("{}", e.0.0.m.x);
39 //~^ ERROR: cannot borrow `e.0.0.m.x` as immutable because it is also borrowed as mutable
43 // Check diagnostics when a path is read inside a closure while attempting to mutate it outside
46 let m = MetaData { x: format!("x"), name: format!("name") };
48 let b = BoxedData(Box::new(d));
49 let mut e = EvenMoreBoxedData(Box::new(b));
52 println!("{}", e.0.0.m.x);
55 e.0.0.m.x = format!("not-x");
56 //~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed