From f0b51145c5006f79da8304e1fb09d6f0eb95ae1a Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 31 Oct 2019 14:36:41 +0000 Subject: [PATCH] async/await: correct diag note for `async move` This commit corrects the diagnostic note for `async move {}` so that `await` is mentioned, rather than `yield`. Signed-off-by: David Wood --- src/librustc/traits/error_reporting.rs | 23 ++++++++++--------- .../issue-64130-4-async-move.stderr | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 53dbd186e66..84ffb74045e 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -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_asyncness| *parent_asyncness == hir::IsAsync::Async) + .map(|parent_did| self.tcx.asyncness(parent_did)) + .map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async) .unwrap_or(false); - let await_or_yield = if is_async_fn { "await" } else { "yield" }; + 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, + }) + .unwrap_or(false); + 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. diff --git a/src/test/ui/async-await/issue-64130-4-async-move.stderr b/src/test/ui/async-await/issue-64130-4-async-move.stderr index 3def984972f..ddbb469b99c 100644 --- a/src/test/ui/async-await/issue-64130-4-async-move.stderr +++ b/src/test/ui/async-await/issue-64130-4-async-move.stderr @@ -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