]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[rust.git] / tests / ui / closures / 2229_closure_analysis / preserve_field_drop_order.rs
1 // edition:2021
2
3 // Tests that in cases where we individually capture all the fields of a type,
4 // we still drop them in the order they would have been dropped in the 2018 edition.
5
6 // NOTE: It is *critical* that the order of the min capture NOTES in the stderr output
7 //       does *not* change!
8
9 #![feature(rustc_attrs)]
10
11 #[derive(Debug)]
12 struct HasDrop;
13 impl Drop for HasDrop {
14     fn drop(&mut self) {
15         println!("dropped");
16     }
17 }
18
19 fn test_one() {
20     let a = (HasDrop, HasDrop);
21     let b = (HasDrop, HasDrop);
22
23     let c = #[rustc_capture_analysis]
24     //~^ ERROR: attributes on expressions are experimental
25     //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
26     || {
27         //~^ ERROR: Min Capture analysis includes:
28         //~| ERROR
29         println!("{:?}", a.0);
30         //~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow
31         //~| NOTE
32         println!("{:?}", a.1);
33         //~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow
34         //~| NOTE
35
36         println!("{:?}", b.0);
37         //~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow
38         //~| NOTE
39         println!("{:?}", b.1);
40         //~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow
41         //~| NOTE
42     };
43 }
44
45 fn test_two() {
46     let a = (HasDrop, HasDrop);
47     let b = (HasDrop, HasDrop);
48
49     let c = #[rustc_capture_analysis]
50     //~^ ERROR: attributes on expressions are experimental
51     //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
52     || {
53         //~^ ERROR: Min Capture analysis includes:
54         //~| ERROR
55         println!("{:?}", a.1);
56         //~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow
57         //~| NOTE
58         println!("{:?}", a.0);
59         //~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow
60         //~| NOTE
61
62         println!("{:?}", b.1);
63         //~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow
64         //~| NOTE
65         println!("{:?}", b.0);
66         //~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow
67         //~| NOTE
68     };
69 }
70
71 fn test_three() {
72     let a = (HasDrop, HasDrop);
73     let b = (HasDrop, HasDrop);
74
75     let c = #[rustc_capture_analysis]
76     //~^ ERROR: attributes on expressions are experimental
77     //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
78     || {
79         //~^ ERROR: Min Capture analysis includes:
80         //~| ERROR
81         println!("{:?}", b.1);
82         //~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow
83         //~| NOTE
84         println!("{:?}", a.1);
85         //~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow
86         //~| NOTE
87         println!("{:?}", a.0);
88         //~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow
89         //~| NOTE
90
91         println!("{:?}", b.0);
92         //~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow
93         //~| NOTE
94     };
95 }
96
97 fn main() {
98     test_one();
99     test_two();
100     test_three();
101 }