-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust tests wrt. 'async_closure' feature gate.
- Loading branch information
Showing
20 changed files
with
206 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// compile-pass | ||
// edition:2018 | ||
|
||
#![feature(async_await, async_closure)] | ||
|
||
macro_rules! match_expr { | ||
($x:expr) => {} | ||
} | ||
|
||
fn main() { | ||
match_expr!(async || {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// run-pass | ||
|
||
// edition:2018 | ||
// aux-build:arc_wake.rs | ||
|
||
#![feature(async_await, async_closure)] | ||
|
||
extern crate arc_wake; | ||
|
||
use std::pin::Pin; | ||
use std::future::Future; | ||
use std::sync::{ | ||
Arc, | ||
atomic::{self, AtomicUsize}, | ||
}; | ||
use std::task::{Context, Poll}; | ||
use arc_wake::ArcWake; | ||
|
||
struct Counter { | ||
wakes: AtomicUsize, | ||
} | ||
|
||
impl ArcWake for Counter { | ||
fn wake(self: Arc<Self>) { | ||
Self::wake_by_ref(&self) | ||
} | ||
fn wake_by_ref(arc_self: &Arc<Self>) { | ||
arc_self.wakes.fetch_add(1, atomic::Ordering::SeqCst); | ||
} | ||
} | ||
|
||
struct WakeOnceThenComplete(bool); | ||
|
||
fn wake_and_yield_once() -> WakeOnceThenComplete { WakeOnceThenComplete(false) } | ||
|
||
impl Future for WakeOnceThenComplete { | ||
type Output = (); | ||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { | ||
if self.0 { | ||
Poll::Ready(()) | ||
} else { | ||
cx.waker().wake_by_ref(); | ||
self.0 = true; | ||
Poll::Pending | ||
} | ||
} | ||
} | ||
|
||
fn async_closure(x: u8) -> impl Future<Output = u8> { | ||
(async move |x: u8| -> u8 { | ||
wake_and_yield_once().await; | ||
x | ||
})(x) | ||
} | ||
|
||
fn test_future_yields_once_then_returns<F, Fut>(f: F) | ||
where | ||
F: FnOnce(u8) -> Fut, | ||
Fut: Future<Output = u8>, | ||
{ | ||
let mut fut = Box::pin(f(9)); | ||
let counter = Arc::new(Counter { wakes: AtomicUsize::new(0) }); | ||
let waker = ArcWake::into_waker(counter.clone()); | ||
let mut cx = Context::from_waker(&waker); | ||
assert_eq!(0, counter.wakes.load(atomic::Ordering::SeqCst)); | ||
assert_eq!(Poll::Pending, fut.as_mut().poll(&mut cx)); | ||
assert_eq!(1, counter.wakes.load(atomic::Ordering::SeqCst)); | ||
assert_eq!(Poll::Ready(9), fut.as_mut().poll(&mut cx)); | ||
} | ||
|
||
fn main() { | ||
macro_rules! test { | ||
($($fn_name:expr,)*) => { $( | ||
test_future_yields_once_then_returns($fn_name); | ||
)* } | ||
} | ||
|
||
test! { | ||
async_closure, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
// compile-pass | ||
// edition:2018 | ||
|
||
#![feature(async_await, await_macro)] | ||
#![feature(async_await)] | ||
|
||
macro_rules! match_expr { | ||
($x:expr) => {} | ||
} | ||
|
||
fn main() { | ||
match_expr!(async {}); | ||
match_expr!(async || {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// edition:2018 | ||
// gate-test-async_closure | ||
|
||
fn f() { | ||
let _ = async || {}; //~ ERROR async closures are unstable | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0658]: async closures are unstable | ||
--> $DIR/feature-async-closure.rs:5:13 | ||
| | ||
LL | let _ = async || {}; | ||
| ^^^^^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/62290 | ||
= help: add #![feature(async_closure)] to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// edition:2018 | ||
|
||
#![feature(async_await, async_closure)] | ||
|
||
async fn print_dur() {} | ||
|
||
fn main() { | ||
(async || 2333)().await; | ||
//~^ ERROR `await` is only allowed inside `async` functions and blocks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error[E0728]: `await` is only allowed inside `async` functions and blocks | ||
--> $DIR/issue-62009-2.rs:8:5 | ||
| | ||
LL | fn main() { | ||
| ---- this is not `async` | ||
LL | (async || 2333)().await; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/ui/async-await/suggest-missing-await-closure.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// edition:2018 | ||
// run-rustfix | ||
|
||
#![feature(async_await, async_closure)] | ||
|
||
fn take_u32(_x: u32) {} | ||
|
||
async fn make_u32() -> u32 { | ||
22 | ||
} | ||
|
||
#[allow(unused)] | ||
async fn suggest_await_in_async_closure() { | ||
async || { | ||
let x = make_u32(); | ||
take_u32(x.await) | ||
//~^ ERROR mismatched types [E0308] | ||
//~| HELP consider using `.await` here | ||
//~| SUGGESTION x.await | ||
}; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// edition:2018 | ||
// run-rustfix | ||
|
||
#![feature(async_await, async_closure)] | ||
|
||
fn take_u32(_x: u32) {} | ||
|
||
async fn make_u32() -> u32 { | ||
22 | ||
} | ||
|
||
#[allow(unused)] | ||
async fn suggest_await_in_async_closure() { | ||
async || { | ||
let x = make_u32(); | ||
take_u32(x) | ||
//~^ ERROR mismatched types [E0308] | ||
//~| HELP consider using `.await` here | ||
//~| SUGGESTION x.await | ||
}; | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
src/test/ui/async-await/suggest-missing-await-closure.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/suggest-missing-await-closure.rs:16:18 | ||
| | ||
LL | take_u32(x) | ||
| ^ | ||
| | | ||
| expected u32, found opaque type | ||
| help: consider using `.await` here: `x.await` | ||
| | ||
= note: expected type `u32` | ||
found type `impl std::future::Future` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters