about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2019-10-31 14:36:41 +0000
committerDavid Wood <david@davidtw.co>2019-12-08 16:29:11 +0000
commitf0b51145c5006f79da8304e1fb09d6f0eb95ae1a (patch)
treeecb257020cd6755fb7112ea4ae440b69881d0e92
parent438455d18bb45e20cf11f06622e95ecf9c4209c4 (diff)
downloadrust-f0b51145c5006f79da8304e1fb09d6f0eb95ae1a.tar.gz
rust-f0b51145c5006f79da8304e1fb09d6f0eb95ae1a.zip
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 <david@davidtw.co>
-rw-r--r--src/librustc/traits/error_reporting.rs21
-rw-r--r--src/test/ui/async-await/issue-64130-4-async-move.stderr4
2 files changed, 13 insertions, 12 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_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.
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