Skip to content

Commit f0b5114

Browse files
committed
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 <[email protected]>
1 parent 438455d commit f0b5114

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/librustc/traits/error_reporting.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -2306,18 +2306,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
23062306
let source_map = self.tcx.sess.source_map();
23072307

23082308
let is_async_fn = self.tcx.parent(first_generator)
2309-
.and_then(|parent_did| self.tcx.hir().get_if_local(parent_did))
2310-
.and_then(|parent_node| match parent_node {
2311-
Node::Item(item) => Some(&item.kind),
2312-
_ => None,
2313-
})
2314-
.and_then(|parent_item_kind| match parent_item_kind {
2315-
hir::ItemKind::Fn(_, hir::FnHeader { asyncness, .. }, _, _) => Some(asyncness),
2316-
_ => None,
2309+
.map(|parent_did| self.tcx.asyncness(parent_did))
2310+
.map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
2311+
.unwrap_or(false);
2312+
let is_async_move = self.tcx.hir().as_local_hir_id(first_generator)
2313+
.and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
2314+
.map(|body_id| self.tcx.hir().body(body_id))
2315+
.and_then(|body| body.generator_kind())
2316+
.map(|generator_kind| match generator_kind {
2317+
hir::GeneratorKind::Async(..) => true,
2318+
_ => false,
23172319
})
2318-
.map(|parent_asyncness| *parent_asyncness == hir::IsAsync::Async)
23192320
.unwrap_or(false);
2320-
let await_or_yield = if is_async_fn { "await" } else { "yield" };
2321+
let await_or_yield = if is_async_fn || is_async_move { "await" } else { "yield" };
23212322

23222323
// Special case the primary error message when send or sync is the trait that was
23232324
// not implemented.

src/test/ui/async-await/issue-64130-4-async-move.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ LL | pub fn foo() -> impl Future + Send {
55
| ^^^^^^^^^^^^^^^^^^ future returned by `foo` is not `Send`
66
|
77
= help: the trait `std::marker::Sync` is not implemented for `(dyn std::any::Any + std::marker::Send + 'static)`
8-
note: future is not `Send` as this value is used across an yield
8+
note: future is not `Send` as this value is used across an await
99
--> $DIR/issue-64130-4-async-move.rs:21:26
1010
|
1111
LL | match client.status() {
1212
| ------ has type `&Client`
1313
LL | 200 => {
1414
LL | let _x = get().await;
15-
| ^^^^^^^^^^^ yield occurs here, with `client` maybe used later
15+
| ^^^^^^^^^^^ await occurs here, with `client` maybe used later
1616
...
1717
LL | }
1818
| - `client` is later dropped here

0 commit comments

Comments
 (0)