3 #![feature(rustc_attrs)]
5 // Test to ensure Index projections are handled properly during capture analysis
6 // The array should be moved in entirety, even though only some elements are used.
8 let arr: [String; 5] = [format!("A"), format!("B"), format!("C"), format!("D"), format!("E")];
10 let c = #[rustc_capture_analysis]
11 //~^ ERROR: attributes on expressions are experimental
12 //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
14 //~^ ERROR: First Pass analysis includes:
15 //~| ERROR: Min Capture analysis includes:
16 let [a, b, .., e] = arr;
17 //~^ NOTE: Capturing arr[Index] -> ByValue
18 //~| NOTE: Capturing arr[Index] -> ByValue
19 //~| NOTE: Capturing arr[Index] -> ByValue
20 //~| NOTE: Min Capture arr[] -> ByValue
36 let mut p = Point { x: 10, y: 10, id: String::new() };
38 let c = #[rustc_capture_analysis]
39 //~^ ERROR: attributes on expressions are experimental
40 //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
42 //~^ ERROR: First Pass analysis includes:
43 //~| ERROR: Min Capture analysis includes:
44 let Point { x: ref mut x, y: _, id: moved_id } = p;
45 //~^ NOTE: Capturing p[(0, 0)] -> MutBorrow
46 //~| NOTE: Capturing p[(2, 0)] -> ByValue
47 //~| NOTE: Min Capture p[(0, 0)] -> MutBorrow
48 //~| NOTE: Min Capture p[(2, 0)] -> ByValue
50 println!("{}, {}", x, moved_id);
56 let mut t = (10, String::new(), (String::new(), 42));
58 let c = #[rustc_capture_analysis]
59 //~^ ERROR: attributes on expressions are experimental
60 //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
62 //~^ ERROR: First Pass analysis includes:
63 //~| ERROR: Min Capture analysis includes:
64 let (ref mut x, ref ref_str, (moved_s, _)) = t;
65 //~^ NOTE: Capturing t[(0, 0)] -> MutBorrow
66 //~| NOTE: Capturing t[(1, 0)] -> ImmBorrow
67 //~| NOTE: Capturing t[(2, 0),(0, 0)] -> ByValue
68 //~| NOTE: Min Capture t[(0, 0)] -> MutBorrow
69 //~| NOTE: Min Capture t[(1, 0)] -> ImmBorrow
70 //~| NOTE: Min Capture t[(2, 0),(0, 0)] -> ByValue
72 println!("{}, {} {}", x, ref_str, moved_s);