Skip to content

Commit

Permalink
async/await: correct diag note for async move
Browse files Browse the repository at this point in the history
This commit corrects the diagnostic note for `async move {}` so that
`await` is mentioned, rather than `yield`.

Signed-off-by: David Wood <[email protected]>
  • Loading branch information
davidtwco committed Dec 8, 2019
1 parent 438455d commit f0b5114
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2306,18 +2306,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let source_map = self.tcx.sess.source_map();

let is_async_fn = self.tcx.parent(first_generator)
.and_then(|parent_did| self.tcx.hir().get_if_local(parent_did))
.and_then(|parent_node| match parent_node {
Node::Item(item) => Some(&item.kind),
_ => None,
})
.and_then(|parent_item_kind| match parent_item_kind {
hir::ItemKind::Fn(_, hir::FnHeader { asyncness, .. }, _, _) => Some(asyncness),
_ => None,
.map(|parent_did| self.tcx.asyncness(parent_did))
.map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
.unwrap_or(false);
let is_async_move = self.tcx.hir().as_local_hir_id(first_generator)
.and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
.map(|body_id| self.tcx.hir().body(body_id))
.and_then(|body| body.generator_kind())
.map(|generator_kind| match generator_kind {
hir::GeneratorKind::Async(..) => true,
_ => false,
})
.map(|parent_asyncness| *parent_asyncness == hir::IsAsync::Async)
.unwrap_or(false);
let await_or_yield = if is_async_fn { "await" } else { "yield" };
let await_or_yield = if is_async_fn || is_async_move { "await" } else { "yield" };

// Special case the primary error message when send or sync is the trait that was
// not implemented.
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/async-await/issue-64130-4-async-move.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ LL | pub fn foo() -> impl Future + Send {
| ^^^^^^^^^^^^^^^^^^ future returned by `foo` is not `Send`
|
= help: the trait `std::marker::Sync` is not implemented for `(dyn std::any::Any + std::marker::Send + 'static)`
note: future is not `Send` as this value is used across an yield
note: future is not `Send` as this value is used across an await
--> $DIR/issue-64130-4-async-move.rs:21:26
|
LL | match client.status() {
| ------ has type `&Client`
LL | 200 => {
LL | let _x = get().await;
| ^^^^^^^^^^^ yield occurs here, with `client` maybe used later
| ^^^^^^^^^^^ await occurs here, with `client` maybe used later
...
LL | }
| - `client` is later dropped here
Expand Down

0 comments on commit f0b5114

Please sign in to comment.