Skip to content

Commit 43315bc

Browse files
committed
Adjust tests wrt. 'async_closure' feature gate.
1 parent bb7fbb9 commit 43315bc

20 files changed

+206
-76
lines changed

Diff for: src/test/ui/async-await/async-await.rs

-8
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ fn async_nonmove_block(x: u8) -> impl Future<Output = u8> {
7070
}
7171
}
7272

73-
fn async_closure(x: u8) -> impl Future<Output = u8> {
74-
(async move |x: u8| -> u8 {
75-
wake_and_yield_once().await;
76-
x
77-
})(x)
78-
}
79-
8073
async fn async_fn(x: u8) -> u8 {
8174
wake_and_yield_once().await;
8275
x
@@ -180,7 +173,6 @@ fn main() {
180173
test! {
181174
async_block,
182175
async_nonmove_block,
183-
async_closure,
184176
async_fn,
185177
generic_async_fn,
186178
async_fn_with_internal_borrow,
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-pass
2+
// edition:2018
3+
4+
#![feature(async_await, async_closure)]
5+
6+
macro_rules! match_expr {
7+
($x:expr) => {}
8+
}
9+
10+
fn main() {
11+
match_expr!(async || {});
12+
}

Diff for: src/test/ui/async-await/async-closure.rs

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// run-pass
2+
3+
// edition:2018
4+
// aux-build:arc_wake.rs
5+
6+
#![feature(async_await, async_closure)]
7+
8+
extern crate arc_wake;
9+
10+
use std::pin::Pin;
11+
use std::future::Future;
12+
use std::sync::{
13+
Arc,
14+
atomic::{self, AtomicUsize},
15+
};
16+
use std::task::{Context, Poll};
17+
use arc_wake::ArcWake;
18+
19+
struct Counter {
20+
wakes: AtomicUsize,
21+
}
22+
23+
impl ArcWake for Counter {
24+
fn wake(self: Arc<Self>) {
25+
Self::wake_by_ref(&self)
26+
}
27+
fn wake_by_ref(arc_self: &Arc<Self>) {
28+
arc_self.wakes.fetch_add(1, atomic::Ordering::SeqCst);
29+
}
30+
}
31+
32+
struct WakeOnceThenComplete(bool);
33+
34+
fn wake_and_yield_once() -> WakeOnceThenComplete { WakeOnceThenComplete(false) }
35+
36+
impl Future for WakeOnceThenComplete {
37+
type Output = ();
38+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
39+
if self.0 {
40+
Poll::Ready(())
41+
} else {
42+
cx.waker().wake_by_ref();
43+
self.0 = true;
44+
Poll::Pending
45+
}
46+
}
47+
}
48+
49+
fn async_closure(x: u8) -> impl Future<Output = u8> {
50+
(async move |x: u8| -> u8 {
51+
wake_and_yield_once().await;
52+
x
53+
})(x)
54+
}
55+
56+
fn test_future_yields_once_then_returns<F, Fut>(f: F)
57+
where
58+
F: FnOnce(u8) -> Fut,
59+
Fut: Future<Output = u8>,
60+
{
61+
let mut fut = Box::pin(f(9));
62+
let counter = Arc::new(Counter { wakes: AtomicUsize::new(0) });
63+
let waker = ArcWake::into_waker(counter.clone());
64+
let mut cx = Context::from_waker(&waker);
65+
assert_eq!(0, counter.wakes.load(atomic::Ordering::SeqCst));
66+
assert_eq!(Poll::Pending, fut.as_mut().poll(&mut cx));
67+
assert_eq!(1, counter.wakes.load(atomic::Ordering::SeqCst));
68+
assert_eq!(Poll::Ready(9), fut.as_mut().poll(&mut cx));
69+
}
70+
71+
fn main() {
72+
macro_rules! test {
73+
($($fn_name:expr,)*) => { $(
74+
test_future_yields_once_then_returns($fn_name);
75+
)* }
76+
}
77+
78+
test! {
79+
async_closure,
80+
}
81+
}

Diff for: src/test/ui/async-await/async-matches-expr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// compile-pass
22
// edition:2018
33

4-
#![feature(async_await, await_macro)]
4+
#![feature(async_await)]
55

66
macro_rules! match_expr {
77
($x:expr) => {}
88
}
99

1010
fn main() {
1111
match_expr!(async {});
12-
match_expr!(async || {});
1312
}

Diff for: src/test/ui/async-await/await-macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// edition:2018
44
// aux-build:arc_wake.rs
55

6-
#![feature(async_await, await_macro)]
6+
#![feature(async_await, async_closure, await_macro)]
77

88
extern crate arc_wake;
99

Diff for: src/test/ui/async-await/feature-async-closure.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// edition:2018
2+
// gate-test-async_closure
3+
4+
fn f() {
5+
let _ = async || {}; //~ ERROR async closures are unstable
6+
}
7+
8+
fn main() {}

Diff for: src/test/ui/async-await/feature-async-closure.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: async closures are unstable
2+
--> $DIR/feature-async-closure.rs:5:13
3+
|
4+
LL | let _ = async || {};
5+
| ^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/62290
8+
= help: add #![feature(async_closure)] to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

Diff for: src/test/ui/async-await/issues/issue-62009.rs renamed to src/test/ui/async-await/issues/issue-62009-1.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ fn main() {
1111
//~^ ERROR `await` is only allowed inside `async` functions and blocks
1212
let task1 = print_dur().await;
1313
}.await;
14-
(async || 2333)().await;
15-
//~^ ERROR `await` is only allowed inside `async` functions and blocks
1614
(|_| 2333).await;
1715
//~^ ERROR `await` is only allowed inside `async` functions and blocks
1816
//~^^ ERROR
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0728]: `await` is only allowed inside `async` functions and blocks
2-
--> $DIR/issue-62009.rs:8:5
2+
--> $DIR/issue-62009-1.rs:8:5
33
|
44
LL | fn main() {
55
| ---- this is not `async`
66
LL | async { let (); }.await;
77
| ^^^^^^^^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
88

99
error[E0728]: `await` is only allowed inside `async` functions and blocks
10-
--> $DIR/issue-62009.rs:10:5
10+
--> $DIR/issue-62009-1.rs:10:5
1111
|
1212
LL | fn main() {
1313
| ---- this is not `async`
@@ -19,31 +19,22 @@ LL | | }.await;
1919
| |___________^ only allowed inside `async` functions and blocks
2020

2121
error[E0728]: `await` is only allowed inside `async` functions and blocks
22-
--> $DIR/issue-62009.rs:14:5
23-
|
24-
LL | fn main() {
25-
| ---- this is not `async`
26-
...
27-
LL | (async || 2333)().await;
28-
| ^^^^^^^^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
29-
30-
error[E0728]: `await` is only allowed inside `async` functions and blocks
31-
--> $DIR/issue-62009.rs:16:5
22+
--> $DIR/issue-62009-1.rs:14:5
3223
|
3324
LL | fn main() {
3425
| ---- this is not `async`
3526
...
3627
LL | (|_| 2333).await;
3728
| ^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
3829

39-
error[E0277]: the trait bound `[closure@$DIR/issue-62009.rs:16:5: 16:15]: std::future::Future` is not satisfied
40-
--> $DIR/issue-62009.rs:16:5
30+
error[E0277]: the trait bound `[closure@$DIR/issue-62009-1.rs:14:5: 14:15]: std::future::Future` is not satisfied
31+
--> $DIR/issue-62009-1.rs:14:5
4132
|
4233
LL | (|_| 2333).await;
43-
| ^^^^^^^^^^^^^^^^ the trait `std::future::Future` is not implemented for `[closure@$DIR/issue-62009.rs:16:5: 16:15]`
34+
| ^^^^^^^^^^^^^^^^ the trait `std::future::Future` is not implemented for `[closure@$DIR/issue-62009-1.rs:14:5: 14:15]`
4435
|
4536
= note: required by `std::future::poll_with_tls_context`
4637

47-
error: aborting due to 5 previous errors
38+
error: aborting due to 4 previous errors
4839

4940
For more information about this error, try `rustc --explain E0277`.

Diff for: src/test/ui/async-await/issues/issue-62009-2.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// edition:2018
2+
3+
#![feature(async_await, async_closure)]
4+
5+
async fn print_dur() {}
6+
7+
fn main() {
8+
(async || 2333)().await;
9+
//~^ ERROR `await` is only allowed inside `async` functions and blocks
10+
}

Diff for: src/test/ui/async-await/issues/issue-62009-2.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error[E0728]: `await` is only allowed inside `async` functions and blocks
2+
--> $DIR/issue-62009-2.rs:8:5
3+
|
4+
LL | fn main() {
5+
| ---- this is not `async`
6+
LL | (async || 2333)().await;
7+
| ^^^^^^^^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
8+
9+
error: aborting due to previous error
10+

Diff for: src/test/ui/async-await/no-args-non-move-async-closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// edition:2018
22

3-
#![feature(async_await, await_macro)]
3+
#![feature(async_await, async_closure, await_macro)]
44

55
fn main() {
66
let _ = async |x: u8| {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// edition:2018
2+
// run-rustfix
3+
4+
#![feature(async_await, async_closure)]
5+
6+
fn take_u32(_x: u32) {}
7+
8+
async fn make_u32() -> u32 {
9+
22
10+
}
11+
12+
#[allow(unused)]
13+
async fn suggest_await_in_async_closure() {
14+
async || {
15+
let x = make_u32();
16+
take_u32(x.await)
17+
//~^ ERROR mismatched types [E0308]
18+
//~| HELP consider using `.await` here
19+
//~| SUGGESTION x.await
20+
};
21+
}
22+
23+
fn main() {}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// edition:2018
2+
// run-rustfix
3+
4+
#![feature(async_await, async_closure)]
5+
6+
fn take_u32(_x: u32) {}
7+
8+
async fn make_u32() -> u32 {
9+
22
10+
}
11+
12+
#[allow(unused)]
13+
async fn suggest_await_in_async_closure() {
14+
async || {
15+
let x = make_u32();
16+
take_u32(x)
17+
//~^ ERROR mismatched types [E0308]
18+
//~| HELP consider using `.await` here
19+
//~| SUGGESTION x.await
20+
};
21+
}
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/suggest-missing-await-closure.rs:16:18
3+
|
4+
LL | take_u32(x)
5+
| ^
6+
| |
7+
| expected u32, found opaque type
8+
| help: consider using `.await` here: `x.await`
9+
|
10+
= note: expected type `u32`
11+
found type `impl std::future::Future`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0308`.

Diff for: src/test/ui/async-await/suggest-missing-await.fixed

-11
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,4 @@ async fn suggest_await_in_async_fn() {
1818
//~| SUGGESTION x.await
1919
}
2020

21-
#[allow(unused)]
22-
async fn suggest_await_in_async_closure() {
23-
async || {
24-
let x = make_u32();
25-
take_u32(x.await)
26-
//~^ ERROR mismatched types [E0308]
27-
//~| HELP consider using `.await` here
28-
//~| SUGGESTION x.await
29-
};
30-
}
31-
3221
fn main() {}

Diff for: src/test/ui/async-await/suggest-missing-await.rs

-11
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,4 @@ async fn suggest_await_in_async_fn() {
1818
//~| SUGGESTION x.await
1919
}
2020

21-
#[allow(unused)]
22-
async fn suggest_await_in_async_closure() {
23-
async || {
24-
let x = make_u32();
25-
take_u32(x)
26-
//~^ ERROR mismatched types [E0308]
27-
//~| HELP consider using `.await` here
28-
//~| SUGGESTION x.await
29-
};
30-
}
31-
3221
fn main() {}

Diff for: src/test/ui/async-await/suggest-missing-await.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ LL | take_u32(x)
1010
= note: expected type `u32`
1111
found type `impl std::future::Future`
1212

13-
error[E0308]: mismatched types
14-
--> $DIR/suggest-missing-await.rs:25:18
15-
|
16-
LL | take_u32(x)
17-
| ^
18-
| |
19-
| expected u32, found opaque type
20-
| help: consider using `.await` here: `x.await`
21-
|
22-
= note: expected type `u32`
23-
found type `impl std::future::Future`
24-
25-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
2614

2715
For more information about this error, try `rustc --explain E0308`.

Diff for: src/test/ui/feature-gates/feature-gate-async-await.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ async fn foo() {} //~ ERROR async fn is unstable
1515

1616
fn main() {
1717
let _ = async {}; //~ ERROR async blocks are unstable
18-
let _ = async || {}; //~ ERROR async closures are unstable
1918
}

Diff for: src/test/ui/feature-gates/feature-gate-async-await.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ LL | let _ = async {};
4040
= note: for more information, see https://github.com/rust-lang/rust/issues/50547
4141
= help: add #![feature(async_await)] to the crate attributes to enable
4242

43-
error[E0658]: async closures are unstable
44-
--> $DIR/feature-gate-async-await.rs:18:13
45-
|
46-
LL | let _ = async || {};
47-
| ^^^^^^^^^^^
48-
|
49-
= note: for more information, see https://github.com/rust-lang/rust/issues/50547
50-
= help: add #![feature(async_await)] to the crate attributes to enable
51-
52-
error: aborting due to 6 previous errors
43+
error: aborting due to 5 previous errors
5344

5445
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)