Skip to content

Commit dd91804

Browse files
committed
Update and add more tests
1 parent 3893656 commit dd91804

5 files changed

+118
-65
lines changed

src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.rs

+33-30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// Tests that in cases where we individually capture all the fields of a type,
44
// we still drop them in the order they would have been dropped in the 2018 edition.
55

6+
// NOTE: It is *critical* that the order of the min capture NOTES in the stderr output
7+
// does *not* change!
8+
69
#![feature(rustc_attrs)]
710

811
#[derive(Debug)]
@@ -21,21 +24,21 @@ fn test_one() {
2124
//~^ ERROR: attributes on expressions are experimental
2225
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
2326
|| {
24-
//~^ ERROR: First Pass analysis includes:
25-
//~| ERROR: Min Capture analysis includes:
27+
//~^ ERROR: Min Capture analysis includes:
28+
//~| ERROR
2629
println!("{:?}", a.0);
27-
//~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow
28-
//~| NOTE: Min Capture a[(0, 0)] -> ImmBorrow
30+
//~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow
31+
//~| NOTE
2932
println!("{:?}", a.1);
30-
//~^ NOTE: Capturing a[(1, 0)] -> ImmBorrow
31-
//~| NOTE: Min Capture a[(1, 0)] -> ImmBorrow
33+
//~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow
34+
//~| NOTE
3235

3336
println!("{:?}", b.0);
34-
//~^ NOTE: Capturing b[(0, 0)] -> ImmBorrow
35-
//~| NOTE: Min Capture b[(0, 0)] -> ImmBorrow
37+
//~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow
38+
//~| NOTE
3639
println!("{:?}", b.1);
37-
//~^ NOTE: Capturing b[(1, 0)] -> ImmBorrow
38-
//~| NOTE: Min Capture b[(1, 0)] -> ImmBorrow
40+
//~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow
41+
//~| NOTE
3942
};
4043
}
4144

@@ -47,21 +50,21 @@ fn test_two() {
4750
//~^ ERROR: attributes on expressions are experimental
4851
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
4952
|| {
50-
//~^ ERROR: First Pass analysis includes:
51-
//~| ERROR: Min Capture analysis includes:
53+
//~^ ERROR: Min Capture analysis includes:
54+
//~| ERROR
5255
println!("{:?}", a.1);
53-
//~^ NOTE: Capturing a[(1, 0)] -> ImmBorrow
54-
//~| NOTE: Min Capture a[(1, 0)] -> ImmBorrow
56+
//~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow
57+
//~| NOTE
5558
println!("{:?}", a.0);
56-
//~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow
57-
//~| NOTE: Min Capture a[(0, 0)] -> ImmBorrow
59+
//~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow
60+
//~| NOTE
5861

5962
println!("{:?}", b.1);
60-
//~^ NOTE: Capturing b[(1, 0)] -> ImmBorrow
61-
//~| NOTE: Min Capture b[(1, 0)] -> ImmBorrow
63+
//~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow
64+
//~| NOTE
6265
println!("{:?}", b.0);
63-
//~^ NOTE: Capturing b[(0, 0)] -> ImmBorrow
64-
//~| NOTE: Min Capture b[(0, 0)] -> ImmBorrow
66+
//~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow
67+
//~| NOTE
6568
};
6669
}
6770

@@ -73,21 +76,21 @@ fn test_three() {
7376
//~^ ERROR: attributes on expressions are experimental
7477
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
7578
|| {
76-
//~^ ERROR: First Pass analysis includes:
77-
//~| ERROR: Min Capture analysis includes:
79+
//~^ ERROR: Min Capture analysis includes:
80+
//~| ERROR
7881
println!("{:?}", b.1);
79-
//~^ NOTE: Capturing b[(1, 0)] -> ImmBorrow
80-
//~| NOTE: Min Capture b[(1, 0)] -> ImmBorrow
82+
//~^ NOTE: Min Capture b[(1, 0)] -> ImmBorrow
83+
//~| NOTE
8184
println!("{:?}", a.1);
82-
//~^ NOTE: Capturing a[(1, 0)] -> ImmBorrow
83-
//~| NOTE: Min Capture a[(1, 0)] -> ImmBorrow
85+
//~^ NOTE: Min Capture a[(1, 0)] -> ImmBorrow
86+
//~| NOTE
8487
println!("{:?}", a.0);
85-
//~^ NOTE: Capturing a[(0, 0)] -> ImmBorrow
86-
//~| NOTE: Min Capture a[(0, 0)] -> ImmBorrow
88+
//~^ NOTE: Min Capture a[(0, 0)] -> ImmBorrow
89+
//~| NOTE
8790

8891
println!("{:?}", b.0);
89-
//~^ NOTE: Capturing b[(0, 0)] -> ImmBorrow
90-
//~| NOTE: Min Capture b[(0, 0)] -> ImmBorrow
92+
//~^ NOTE: Min Capture b[(0, 0)] -> ImmBorrow
93+
//~| NOTE
9194
};
9295
}
9396

src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order.stderr

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: attributes on expressions are experimental
2-
--> $DIR/preserve_field_drop_order.rs:20:13
2+
--> $DIR/preserve_field_drop_order.rs:23:13
33
|
44
LL | let c = #[rustc_capture_analysis]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | let c = #[rustc_capture_analysis]
88
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
99

1010
error[E0658]: attributes on expressions are experimental
11-
--> $DIR/preserve_field_drop_order.rs:46:13
11+
--> $DIR/preserve_field_drop_order.rs:49:13
1212
|
1313
LL | let c = #[rustc_capture_analysis]
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -17,7 +17,7 @@ LL | let c = #[rustc_capture_analysis]
1717
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
1818

1919
error[E0658]: attributes on expressions are experimental
20-
--> $DIR/preserve_field_drop_order.rs:72:13
20+
--> $DIR/preserve_field_drop_order.rs:75:13
2121
|
2222
LL | let c = #[rustc_capture_analysis]
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | let c = #[rustc_capture_analysis]
2626
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
2727

2828
error: First Pass analysis includes:
29-
--> $DIR/preserve_field_drop_order.rs:23:5
29+
--> $DIR/preserve_field_drop_order.rs:26:5
3030
|
3131
LL | / || {
3232
LL | |
@@ -38,28 +38,28 @@ LL | | };
3838
| |_____^
3939
|
4040
note: Capturing a[(0, 0)] -> ImmBorrow
41-
--> $DIR/preserve_field_drop_order.rs:26:26
41+
--> $DIR/preserve_field_drop_order.rs:29:26
4242
|
4343
LL | println!("{:?}", a.0);
4444
| ^^^
4545
note: Capturing a[(1, 0)] -> ImmBorrow
46-
--> $DIR/preserve_field_drop_order.rs:29:26
46+
--> $DIR/preserve_field_drop_order.rs:32:26
4747
|
4848
LL | println!("{:?}", a.1);
4949
| ^^^
5050
note: Capturing b[(0, 0)] -> ImmBorrow
51-
--> $DIR/preserve_field_drop_order.rs:33:26
51+
--> $DIR/preserve_field_drop_order.rs:36:26
5252
|
5353
LL | println!("{:?}", b.0);
5454
| ^^^
5555
note: Capturing b[(1, 0)] -> ImmBorrow
56-
--> $DIR/preserve_field_drop_order.rs:36:26
56+
--> $DIR/preserve_field_drop_order.rs:39:26
5757
|
5858
LL | println!("{:?}", b.1);
5959
| ^^^
6060

6161
error: Min Capture analysis includes:
62-
--> $DIR/preserve_field_drop_order.rs:23:5
62+
--> $DIR/preserve_field_drop_order.rs:26:5
6363
|
6464
LL | / || {
6565
LL | |
@@ -71,28 +71,28 @@ LL | | };
7171
| |_____^
7272
|
7373
note: Min Capture a[(0, 0)] -> ImmBorrow
74-
--> $DIR/preserve_field_drop_order.rs:26:26
74+
--> $DIR/preserve_field_drop_order.rs:29:26
7575
|
7676
LL | println!("{:?}", a.0);
7777
| ^^^
7878
note: Min Capture a[(1, 0)] -> ImmBorrow
79-
--> $DIR/preserve_field_drop_order.rs:29:26
79+
--> $DIR/preserve_field_drop_order.rs:32:26
8080
|
8181
LL | println!("{:?}", a.1);
8282
| ^^^
8383
note: Min Capture b[(0, 0)] -> ImmBorrow
84-
--> $DIR/preserve_field_drop_order.rs:33:26
84+
--> $DIR/preserve_field_drop_order.rs:36:26
8585
|
8686
LL | println!("{:?}", b.0);
8787
| ^^^
8888
note: Min Capture b[(1, 0)] -> ImmBorrow
89-
--> $DIR/preserve_field_drop_order.rs:36:26
89+
--> $DIR/preserve_field_drop_order.rs:39:26
9090
|
9191
LL | println!("{:?}", b.1);
9292
| ^^^
9393

9494
error: First Pass analysis includes:
95-
--> $DIR/preserve_field_drop_order.rs:49:5
95+
--> $DIR/preserve_field_drop_order.rs:52:5
9696
|
9797
LL | / || {
9898
LL | |
@@ -104,28 +104,28 @@ LL | | };
104104
| |_____^
105105
|
106106
note: Capturing a[(1, 0)] -> ImmBorrow
107-
--> $DIR/preserve_field_drop_order.rs:52:26
107+
--> $DIR/preserve_field_drop_order.rs:55:26
108108
|
109109
LL | println!("{:?}", a.1);
110110
| ^^^
111111
note: Capturing a[(0, 0)] -> ImmBorrow
112-
--> $DIR/preserve_field_drop_order.rs:55:26
112+
--> $DIR/preserve_field_drop_order.rs:58:26
113113
|
114114
LL | println!("{:?}", a.0);
115115
| ^^^
116116
note: Capturing b[(1, 0)] -> ImmBorrow
117-
--> $DIR/preserve_field_drop_order.rs:59:26
117+
--> $DIR/preserve_field_drop_order.rs:62:26
118118
|
119119
LL | println!("{:?}", b.1);
120120
| ^^^
121121
note: Capturing b[(0, 0)] -> ImmBorrow
122-
--> $DIR/preserve_field_drop_order.rs:62:26
122+
--> $DIR/preserve_field_drop_order.rs:65:26
123123
|
124124
LL | println!("{:?}", b.0);
125125
| ^^^
126126

127127
error: Min Capture analysis includes:
128-
--> $DIR/preserve_field_drop_order.rs:49:5
128+
--> $DIR/preserve_field_drop_order.rs:52:5
129129
|
130130
LL | / || {
131131
LL | |
@@ -137,28 +137,28 @@ LL | | };
137137
| |_____^
138138
|
139139
note: Min Capture a[(0, 0)] -> ImmBorrow
140-
--> $DIR/preserve_field_drop_order.rs:55:26
140+
--> $DIR/preserve_field_drop_order.rs:58:26
141141
|
142142
LL | println!("{:?}", a.0);
143143
| ^^^
144144
note: Min Capture a[(1, 0)] -> ImmBorrow
145-
--> $DIR/preserve_field_drop_order.rs:52:26
145+
--> $DIR/preserve_field_drop_order.rs:55:26
146146
|
147147
LL | println!("{:?}", a.1);
148148
| ^^^
149149
note: Min Capture b[(0, 0)] -> ImmBorrow
150-
--> $DIR/preserve_field_drop_order.rs:62:26
150+
--> $DIR/preserve_field_drop_order.rs:65:26
151151
|
152152
LL | println!("{:?}", b.0);
153153
| ^^^
154154
note: Min Capture b[(1, 0)] -> ImmBorrow
155-
--> $DIR/preserve_field_drop_order.rs:59:26
155+
--> $DIR/preserve_field_drop_order.rs:62:26
156156
|
157157
LL | println!("{:?}", b.1);
158158
| ^^^
159159

160160
error: First Pass analysis includes:
161-
--> $DIR/preserve_field_drop_order.rs:75:5
161+
--> $DIR/preserve_field_drop_order.rs:78:5
162162
|
163163
LL | / || {
164164
LL | |
@@ -170,28 +170,28 @@ LL | | };
170170
| |_____^
171171
|
172172
note: Capturing b[(1, 0)] -> ImmBorrow
173-
--> $DIR/preserve_field_drop_order.rs:78:26
173+
--> $DIR/preserve_field_drop_order.rs:81:26
174174
|
175175
LL | println!("{:?}", b.1);
176176
| ^^^
177177
note: Capturing a[(1, 0)] -> ImmBorrow
178-
--> $DIR/preserve_field_drop_order.rs:81:26
178+
--> $DIR/preserve_field_drop_order.rs:84:26
179179
|
180180
LL | println!("{:?}", a.1);
181181
| ^^^
182182
note: Capturing a[(0, 0)] -> ImmBorrow
183-
--> $DIR/preserve_field_drop_order.rs:84:26
183+
--> $DIR/preserve_field_drop_order.rs:87:26
184184
|
185185
LL | println!("{:?}", a.0);
186186
| ^^^
187187
note: Capturing b[(0, 0)] -> ImmBorrow
188-
--> $DIR/preserve_field_drop_order.rs:88:26
188+
--> $DIR/preserve_field_drop_order.rs:91:26
189189
|
190190
LL | println!("{:?}", b.0);
191191
| ^^^
192192

193193
error: Min Capture analysis includes:
194-
--> $DIR/preserve_field_drop_order.rs:75:5
194+
--> $DIR/preserve_field_drop_order.rs:78:5
195195
|
196196
LL | / || {
197197
LL | |
@@ -203,22 +203,22 @@ LL | | };
203203
| |_____^
204204
|
205205
note: Min Capture b[(0, 0)] -> ImmBorrow
206-
--> $DIR/preserve_field_drop_order.rs:88:26
206+
--> $DIR/preserve_field_drop_order.rs:91:26
207207
|
208208
LL | println!("{:?}", b.0);
209209
| ^^^
210210
note: Min Capture b[(1, 0)] -> ImmBorrow
211-
--> $DIR/preserve_field_drop_order.rs:78:26
211+
--> $DIR/preserve_field_drop_order.rs:81:26
212212
|
213213
LL | println!("{:?}", b.1);
214214
| ^^^
215215
note: Min Capture a[(0, 0)] -> ImmBorrow
216-
--> $DIR/preserve_field_drop_order.rs:84:26
216+
--> $DIR/preserve_field_drop_order.rs:87:26
217217
|
218218
LL | println!("{:?}", a.0);
219219
| ^^^
220220
note: Min Capture a[(1, 0)] -> ImmBorrow
221-
--> $DIR/preserve_field_drop_order.rs:81:26
221+
--> $DIR/preserve_field_drop_order.rs:84:26
222222
|
223223
LL | println!("{:?}", a.1);
224224
| ^^^

src/test/ui/closures/2229_closure_analysis/preserve_field_drop_order2.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// [twenty_twentyone]compile-flags: --edition 2021
66

77
#[derive(Debug)]
8-
struct Dropable(String);
8+
struct Dropable(&'static str);
99

1010
impl Drop for Dropable {
1111
fn drop(&mut self) {
@@ -19,10 +19,40 @@ struct A {
1919
y: Dropable,
2020
}
2121

22+
#[derive(Debug)]
23+
struct B {
24+
c: A,
25+
d: A,
26+
}
27+
28+
#[derive(Debug)]
29+
struct R<'a> {
30+
c: &'a A,
31+
d: &'a A,
32+
}
33+
2234
fn main() {
23-
let a = A { x: Dropable(format!("x")), y: Dropable(format!("y")) };
35+
let a = A { x: Dropable("x"), y: Dropable("y") };
2436

2537
let c = move || println!("{:?} {:?}", a.y, a.x);
2638

2739
c();
40+
41+
let b = B {
42+
c: A { x: Dropable("b.c.x"), y: Dropable("b.c.y") },
43+
d: A { x: Dropable("b.d.x"), y: Dropable("b.d.y") },
44+
};
45+
46+
let d = move || println!("{:?} {:?} {:?} {:?}", b.d.y, b.d.x, b.c.y, b.c.x);
47+
48+
d();
49+
50+
let r = R {
51+
c: &A { x: Dropable("r.c.x"), y: Dropable("r.c.y") },
52+
d: &A { x: Dropable("r.d.x"), y: Dropable("r.d.y") },
53+
};
54+
55+
let e = move || println!("{:?} {:?} {:?} {:?}", r.d.y, r.d.x, r.c.y, r.c.x);
56+
57+
e();
2858
}

0 commit comments

Comments
 (0)