-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add long error explanation for E0728 #65678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} | ||
``` | ||
"##, | ||
|
@@ -2126,6 +2126,74 @@ 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` context | ||
} | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an example inside of an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great. My last nitpick would be to have a link to the async/await documentation, but this is already a great improvement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, at glance, we don't have the links to keywords in error code's explanations. I found the links to RFCs or specific topics. We should have a link to the async/await? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would lean towards over linking over under linking, but I'll defer to @GuillaumeGomez There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to have the links indeed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, the link should be https://doc.rust-lang.org/std/keyword.async.html and https://doc.rust-lang.org/std/keyword.await.html ? |
||
"##, | ||
|
||
E0734: r##" | ||
A stability attribute has been used outside of the standard library. | ||
|
||
|
@@ -2218,6 +2286,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 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.