From 5518d1931d4035a207438d625464dce9c3171d54 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 27 Jan 2022 16:22:22 +0000 Subject: [PATCH] Guess head span of async blocks --- .../src/traits/error_reporting/suggestions.rs | 1 + .../ui/async-await/issue-64130-4-async-move.stderr | 10 ++-------- src/test/ui/async-await/issue-70818.stderr | 2 +- .../ui/async-await/issue-70935-complex-spans.stderr | 9 ++------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 6634f3e364d3..9eed03bb2238 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1680,6 +1680,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { )); let original_span = err.span.primary_span().unwrap(); + let original_span = self.tcx.sess.source_map().guess_head_span(original_span); let mut span = MultiSpan::from_span(original_span); let message = outer_generator 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 2d4327f4ea8a..3a84907e0c04 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 @@ -1,14 +1,8 @@ error: future cannot be sent between threads safely --> $DIR/issue-64130-4-async-move.rs:17:5 | -LL | / async move { -LL | | -LL | | match client.status() { -LL | | 200 => { -... | -LL | | } -LL | | } - | |_____^ future created by async block is not `Send` +LL | async move { + | ^^^^^^^^^^ future created by async block is not `Send` | = help: the trait `Sync` is not implemented for `(dyn Any + Send + 'static)` note: future is not `Send` as this value is used across an await diff --git a/src/test/ui/async-await/issue-70818.stderr b/src/test/ui/async-await/issue-70818.stderr index 3fc08c18bc0e..cb50c70f9984 100644 --- a/src/test/ui/async-await/issue-70818.stderr +++ b/src/test/ui/async-await/issue-70818.stderr @@ -2,7 +2,7 @@ error: future cannot be sent between threads safely --> $DIR/issue-70818.rs:5:5 | LL | async { (ty, ty1) } - | ^^^^^^^^^^^^^^^^^^^ future created by async block is not `Send` + | ^^^^^ future created by async block is not `Send` | note: captured value is not `Send` --> $DIR/issue-70818.rs:5:18 diff --git a/src/test/ui/async-await/issue-70935-complex-spans.stderr b/src/test/ui/async-await/issue-70935-complex-spans.stderr index c7b6893afd6f..ad61f21741bb 100644 --- a/src/test/ui/async-await/issue-70935-complex-spans.stderr +++ b/src/test/ui/async-await/issue-70935-complex-spans.stderr @@ -1,13 +1,8 @@ error: future cannot be sent between threads safely --> $DIR/issue-70935-complex-spans.rs:11:5 | -LL | / async move { -LL | | -LL | | baz(|| async{ -LL | | foo(tx.clone()); -LL | | }).await; -LL | | } - | |_____^ future created by async block is not `Send` +LL | async move { + | ^^^^^^^^^^ future created by async block is not `Send` | = help: the trait `Sync` is not implemented for `Sender` note: future is not `Send` as this value is used across an await