Skip to content

Commit 0893456

Browse files
committed
Auto merge of #3513 - rust-lang:rustup-2024-04-25, r=RalfJung
Automatic Rustup
2 parents c2c7072 + 15b04db commit 0893456

File tree

8 files changed

+155
-88
lines changed

8 files changed

+155
-88
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c1feb3eceef7d5f0126c309a87062cf413fe0a25
1+
cb3752d20e0f5d24348062211102a08d46fbecff

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![feature(let_chains)]
1313
#![feature(lint_reasons)]
1414
#![feature(trait_upcasting)]
15-
#![feature(absolute_path)]
1615
// Configure clippy and other lints
1716
#![allow(
1817
clippy::collapsible_else_if,

tests/fail/coroutine-pinned-moved.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
2-
#![feature(coroutines, coroutine_trait)]
2+
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
33

44
use std::{
55
ops::{Coroutine, CoroutineState},
66
pin::Pin,
77
};
88

99
fn firstn() -> impl Coroutine<Yield = u64, Return = ()> {
10+
#[coroutine]
1011
static move || {
1112
let mut num = 0;
1213
let num = &mut num;

tests/pass/coroutine.rs

+146-79
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@revisions: stack tree
22
//@[tree]compile-flags: -Zmiri-tree-borrows
3-
#![feature(coroutines, coroutine_trait, never_type)]
3+
#![feature(coroutines, coroutine_trait, never_type, stmt_expr_attributes)]
44

55
use std::fmt::Debug;
66
use std::mem::ManuallyDrop;
@@ -43,94 +43,144 @@ fn basic() {
4343
panic!()
4444
}
4545

46-
finish(1, false, || yield 1);
46+
finish(
47+
1,
48+
false,
49+
#[coroutine]
50+
|| yield 1,
51+
);
4752

48-
finish(3, false, || {
49-
let mut x = 0;
50-
yield 1;
51-
x += 1;
52-
yield 1;
53-
x += 1;
54-
yield 1;
55-
assert_eq!(x, 2);
56-
});
53+
finish(
54+
3,
55+
false,
56+
#[coroutine]
57+
|| {
58+
let mut x = 0;
59+
yield 1;
60+
x += 1;
61+
yield 1;
62+
x += 1;
63+
yield 1;
64+
assert_eq!(x, 2);
65+
},
66+
);
5767

58-
finish(7 * 8 / 2, false, || {
59-
for i in 0..8 {
60-
yield i;
61-
}
62-
});
68+
finish(
69+
7 * 8 / 2,
70+
false,
71+
#[coroutine]
72+
|| {
73+
for i in 0..8 {
74+
yield i;
75+
}
76+
},
77+
);
6378

64-
finish(1, false, || {
65-
if true {
66-
yield 1;
67-
} else {
68-
}
69-
});
79+
finish(
80+
1,
81+
false,
82+
#[coroutine]
83+
|| {
84+
if true {
85+
yield 1;
86+
} else {
87+
}
88+
},
89+
);
7090

71-
finish(1, false, || {
72-
if false {
73-
} else {
74-
yield 1;
75-
}
76-
});
91+
finish(
92+
1,
93+
false,
94+
#[coroutine]
95+
|| {
96+
if false {
97+
} else {
98+
yield 1;
99+
}
100+
},
101+
);
77102

78-
finish(2, false, || {
79-
if {
80-
yield 1;
81-
false
82-
} {
103+
finish(
104+
2,
105+
false,
106+
#[coroutine]
107+
|| {
108+
if {
109+
yield 1;
110+
false
111+
} {
112+
yield 1;
113+
panic!()
114+
}
83115
yield 1;
84-
panic!()
85-
}
86-
yield 1;
87-
});
116+
},
117+
);
88118

89119
// also test self-referential coroutines
90120
assert_eq!(
91-
finish(5, true, static || {
92-
let mut x = 5;
93-
let y = &mut x;
94-
*y = 5;
95-
yield *y;
96-
*y = 10;
97-
x
98-
}),
121+
finish(
122+
5,
123+
true,
124+
#[coroutine]
125+
static || {
126+
let mut x = 5;
127+
let y = &mut x;
128+
*y = 5;
129+
yield *y;
130+
*y = 10;
131+
x
132+
}
133+
),
99134
10
100135
);
101136
assert_eq!(
102-
finish(5, true, || {
103-
let mut x = Box::new(5);
104-
let y = &mut *x;
105-
*y = 5;
106-
yield *y;
107-
*y = 10;
108-
*x
109-
}),
137+
finish(
138+
5,
139+
true,
140+
#[coroutine]
141+
|| {
142+
let mut x = Box::new(5);
143+
let y = &mut *x;
144+
*y = 5;
145+
yield *y;
146+
*y = 10;
147+
*x
148+
}
149+
),
110150
10
111151
);
112152

113153
let b = true;
114-
finish(1, false, || {
115-
yield 1;
116-
if b {
117-
return;
118-
}
119-
#[allow(unused)]
120-
let x = never();
121-
#[allow(unreachable_code)]
122-
yield 2;
123-
drop(x);
124-
});
125-
126-
finish(3, false, || {
127-
yield 1;
128-
#[allow(unreachable_code)]
129-
let _x: (String, !) = (String::new(), {
154+
finish(
155+
1,
156+
false,
157+
#[coroutine]
158+
|| {
159+
yield 1;
160+
if b {
161+
return;
162+
}
163+
#[allow(unused)]
164+
let x = never();
165+
#[allow(unreachable_code)]
130166
yield 2;
131-
return;
132-
});
133-
});
167+
drop(x);
168+
},
169+
);
170+
171+
finish(
172+
3,
173+
false,
174+
#[coroutine]
175+
|| {
176+
yield 1;
177+
#[allow(unreachable_code)]
178+
let _x: (String, !) = (String::new(), {
179+
yield 2;
180+
return;
181+
});
182+
},
183+
);
134184
}
135185

136186
fn smoke_resume_arg() {
@@ -172,7 +222,8 @@ fn smoke_resume_arg() {
172222
}
173223

174224
drain(
175-
&mut |mut b| {
225+
&mut #[coroutine]
226+
|mut b| {
176227
while b != 0 {
177228
b = yield (b + 1);
178229
}
@@ -181,21 +232,35 @@ fn smoke_resume_arg() {
181232
vec![(1, Yielded(2)), (-45, Yielded(-44)), (500, Yielded(501)), (0, Complete(-1))],
182233
);
183234

184-
expect_drops(2, || drain(&mut |a| yield a, vec![(DropMe, Yielded(DropMe))]));
235+
expect_drops(2, || {
236+
drain(
237+
&mut #[coroutine]
238+
|a| yield a,
239+
vec![(DropMe, Yielded(DropMe))],
240+
)
241+
});
185242

186243
expect_drops(6, || {
187244
drain(
188-
&mut |a| yield yield a,
245+
&mut #[coroutine]
246+
|a| yield yield a,
189247
vec![(DropMe, Yielded(DropMe)), (DropMe, Yielded(DropMe)), (DropMe, Complete(DropMe))],
190248
)
191249
});
192250

193251
#[allow(unreachable_code)]
194-
expect_drops(2, || drain(&mut |a| yield return a, vec![(DropMe, Complete(DropMe))]));
252+
expect_drops(2, || {
253+
drain(
254+
&mut #[coroutine]
255+
|a| yield return a,
256+
vec![(DropMe, Complete(DropMe))],
257+
)
258+
});
195259

196260
expect_drops(2, || {
197261
drain(
198-
&mut |a: DropMe| {
262+
&mut #[coroutine]
263+
|a: DropMe| {
199264
if false { yield () } else { a }
200265
},
201266
vec![(DropMe, Complete(DropMe))],
@@ -205,7 +270,8 @@ fn smoke_resume_arg() {
205270
expect_drops(4, || {
206271
drain(
207272
#[allow(unused_assignments, unused_variables)]
208-
&mut |mut a: DropMe| {
273+
&mut #[coroutine]
274+
|mut a: DropMe| {
209275
a = yield;
210276
a = yield;
211277
a = yield;
@@ -228,7 +294,8 @@ fn uninit_fields() {
228294
}
229295

230296
fn run<T>(x: bool, y: bool) {
231-
let mut c = || {
297+
let mut c = #[coroutine]
298+
|| {
232299
if x {
233300
let _a: T;
234301
if y {

tests/pass/portable-simd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@compile-flags: -Zmiri-strict-provenance
2-
#![feature(portable_simd, adt_const_params, inline_const, core_intrinsics)]
2+
#![feature(portable_simd, adt_const_params, core_intrinsics)]
33
#![allow(incomplete_features, internal_features)]
44
use std::intrinsics::simd as intrinsics;
55
use std::ptr;

tests/pass/shims/path.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@compile-flags: -Zmiri-disable-isolation
2-
#![feature(absolute_path)]
32
use std::path::{absolute, Path};
43

54
#[track_caller]

tests/pass/stacked-borrows/coroutine-self-referential.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// See https://github.com/rust-lang/unsafe-code-guidelines/issues/148:
22
// this fails when Stacked Borrows is strictly applied even to `!Unpin` types.
3-
#![feature(coroutines, coroutine_trait)]
3+
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
44

55
use std::{
66
ops::{Coroutine, CoroutineState},
77
pin::Pin,
88
};
99

1010
fn firstn() -> impl Coroutine<Yield = u64, Return = ()> {
11+
#[coroutine]
1112
static move || {
1213
let mut num = 0;
1314
let num = &mut num;

tests/pass/track-caller-attribute.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn test_coroutine() {
232232
}
233233

234234
#[rustfmt::skip]
235-
let coroutine = #[track_caller] |arg: String| {
235+
let coroutine = #[track_caller] #[coroutine] |arg: String| {
236236
yield ("first", arg.clone(), Location::caller());
237237
yield ("second", arg.clone(), Location::caller());
238238
};
@@ -255,15 +255,15 @@ fn test_coroutine() {
255255
assert_eq!(mono_loc.column(), 42);
256256

257257
#[rustfmt::skip]
258-
let non_tracked_coroutine = || { yield Location::caller(); };
258+
let non_tracked_coroutine = #[coroutine] || { yield Location::caller(); };
259259
let non_tracked_line = line!() - 1; // This is the line of the coroutine, not its caller
260260
let non_tracked_loc = match Box::pin(non_tracked_coroutine).as_mut().resume(()) {
261261
CoroutineState::Yielded(val) => val,
262262
_ => unreachable!(),
263263
};
264264
assert_eq!(non_tracked_loc.file(), file!());
265265
assert_eq!(non_tracked_loc.line(), non_tracked_line);
266-
assert_eq!(non_tracked_loc.column(), 44);
266+
assert_eq!(non_tracked_loc.column(), 57);
267267
}
268268

269269
fn main() {

0 commit comments

Comments
 (0)