]>
Commit | Line | Data |
---|---|---|
fc512014 XL |
1 | #![feature(capture_disjoint_fields)] |
2 | //~^ WARNING: the feature `capture_disjoint_fields` is incomplete | |
3 | //~| NOTE: `#[warn(incomplete_features)]` on by default | |
4 | //~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> | |
5 | #![feature(rustc_attrs)] | |
6 | ||
7 | // Test to ensure Index projections are handled properly during capture analysis | |
8 | // The array should be moved in entirety, even though only some elements are used. | |
9 | fn arrays() { | |
10 | let arr: [String; 5] = [format!("A"), format!("B"), format!("C"), format!("D"), format!("E")]; | |
11 | ||
12 | let c = #[rustc_capture_analysis] | |
13 | //~^ ERROR: attributes on expressions are experimental | |
14 | //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> | |
15 | || { | |
16 | //~^ ERROR: First Pass analysis includes: | |
17 | //~| ERROR: Min Capture analysis includes: | |
18 | let [a, b, .., e] = arr; | |
19 | //~^ NOTE: Capturing arr[Index] -> ByValue | |
20 | //~| NOTE: Min Capture arr[] -> ByValue | |
21 | assert_eq!(a, "A"); | |
22 | assert_eq!(b, "B"); | |
23 | assert_eq!(e, "E"); | |
24 | }; | |
25 | ||
26 | c(); | |
27 | } | |
28 | ||
29 | struct Point { | |
30 | x: i32, | |
31 | y: i32, | |
32 | id: String, | |
33 | } | |
34 | ||
35 | fn structs() { | |
36 | let mut p = Point { x: 10, y: 10, id: String::new() }; | |
37 | ||
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> | |
41 | || { | |
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 | |
49 | ||
50 | println!("{}, {}", x, moved_id); | |
51 | }; | |
52 | c(); | |
53 | } | |
54 | ||
55 | fn tuples() { | |
56 | let mut t = (10, String::new(), (String::new(), 42)); | |
57 | ||
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> | |
61 | || { | |
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 | |
71 | ||
72 | println!("{}, {} {}", x, ref_str, moved_s); | |
73 | }; | |
74 | c(); | |
75 | } | |
76 | ||
77 | fn main() {} |