Skip to content

Commit

Permalink
Rollup merge of rust-lang#65678 - JohnTitor:add-e0728-explanation, r=…
Browse files Browse the repository at this point in the history
…GuilliaumeGomez

Add long error explanation for E0728

Part of rust-lang#61137

r? @GuillaumeGomez
  • Loading branch information
JohnTitor authored Oct 23, 2019
2 parents 88e3ae2 + a1f6589 commit b799465
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 5 deletions.
83 changes: 80 additions & 3 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,8 +2045,8 @@ so that a generator can then be constructed:
async fn bar<T>() -> () {}
async fn foo() {
bar::<String>().await;
// ^^^^^^^^ specify type explicitly
bar::<String>().await;
// ^^^^^^^^ specify type explicitly
}
```
"##,
Expand Down Expand Up @@ -2126,6 +2126,84 @@ static X: u32 = 42;
```
"##,

E0728: r##"
[`await`] has been used outside [`async`] function or block.
Erroneous code examples:
```edition2018,compile_fail,E0728
# use std::pin::Pin;
# use std::future::Future;
# use std::task::{Context, Poll};
#
# 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 foo() {
wake_and_yield_once().await // `await` is used outside `async` context
}
```
[`await`] is used to suspend the current computation until the given
future is ready to produce a value. So it is legal only within
an [`async`] context, like an `async fn` or an `async` block.
```edition2018
# use std::pin::Pin;
# use std::future::Future;
# use std::task::{Context, Poll};
#
# 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
# }
# }
# }
#
async fn foo() {
wake_and_yield_once().await // `await` is used within `async` function
}
fn bar(x: u8) -> impl Future<Output = u8> {
async move {
wake_and_yield_once().await; // `await` is used within `async` block
x
}
}
```
[`async`]: https://doc.rust-lang.org/std/keyword.async.html
[`await`]: https://doc.rust-lang.org/std/keyword.await.html
"##,

E0734: r##"
A stability attribute has been used outside of the standard library.
Expand Down Expand Up @@ -2218,6 +2296,5 @@ See [RFC 2091] for details on this and other limitations.
// E0702, // replaced with a generic attribute input check
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
E0727, // `async` generators are not yet supported
E0728, // `await` must be in an `async` function or block
E0739, // invalid track_caller application/syntax
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,5 @@ LL | let _ = await bar()?;

error: aborting due to 35 previous errors

For more information about this error, try `rustc --explain E0277`.
Some errors have detailed explanations: E0277, E0728.
For more information about an error, try `rustc --explain E0277`.
1 change: 1 addition & 0 deletions src/test/ui/async-await/issues/issue-51719.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | let _gen = || foo().await;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0728`.
1 change: 1 addition & 0 deletions src/test/ui/async-await/issues/issue-51751.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ LL | let finished = result.await;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0728`.
3 changes: 2 additions & 1 deletion src/test/ui/async-await/issues/issue-62009-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ LL | F: Future

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
Some errors have detailed explanations: E0277, E0728.
For more information about an error, try `rustc --explain E0277`.
1 change: 1 addition & 0 deletions src/test/ui/async-await/issues/issue-62009-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | (async || 2333)().await;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0728`.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ LL | let y = do_the_thing().await;

error: aborting due to previous error

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

0 comments on commit b799465

Please sign in to comment.