1 [`await`] has been used outside [`async`] function or block.
3 Erroneous code examples:
5 ```edition2018,compile_fail,E0728
7 # use std::future::Future;
8 # use std::task::{Context, Poll};
10 # struct WakeOnceThenComplete(bool);
12 # fn wake_and_yield_once() -> WakeOnceThenComplete {
13 # WakeOnceThenComplete(false)
16 # impl Future for WakeOnceThenComplete {
18 # fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
22 # cx.waker().wake_by_ref();
30 wake_and_yield_once().await // `await` is used outside `async` context
34 [`await`] is used to suspend the current computation until the given
35 future is ready to produce a value. So it is legal only within
36 an [`async`] context, like an `async fn` or an `async` block.
40 # use std::future::Future;
41 # use std::task::{Context, Poll};
43 # struct WakeOnceThenComplete(bool);
45 # fn wake_and_yield_once() -> WakeOnceThenComplete {
46 # WakeOnceThenComplete(false)
49 # impl Future for WakeOnceThenComplete {
51 # fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
55 # cx.waker().wake_by_ref();
63 wake_and_yield_once().await // `await` is used within `async` function
66 fn bar(x: u8) -> impl Future<Output = u8> {
68 wake_and_yield_once().await; // `await` is used within `async` block
74 [`async`]: https://doc.rust-lang.org/std/keyword.async.html
75 [`await`]: https://doc.rust-lang.org/std/keyword.await.html