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 e5daebda24b..b15e0c327d3 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1735,16 +1735,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // | | // LL | | foo(tx.clone()); // LL | | }).await; - // | | - ^^^^^^- value is later dropped here - // | | | | - // | |__________| await occurs here, with value maybe used later + // | | - ^^^^^^ await occurs here, with value maybe used later + // | |__________| // | has type `closure` which is not `Send` + // note: value is later dropped here + // LL | | }).await; + // | | ^ // - // If available, use the scope span to annotate the drop location. - if let Some(scope_span) = scope_span { - let scope_span = source_map.end_point(scope_span); - span.push_span_label(scope_span, format!("{} is later dropped here", snippet)); - } span.push_span_label( yield_span, format!("{} occurs here, with {} maybe used later", await_or_yield, snippet), @@ -1753,6 +1750,18 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { interior_span, format!("has type `{}` which {}", target_ty, trait_explanation), ); + // If available, use the scope span to annotate the drop location. + let mut scope_note = None; + if let Some(scope_span) = scope_span { + let scope_span = source_map.end_point(scope_span); + + let msg = format!("{} is later dropped here", snippet); + if source_map.is_multiline(yield_span.between(scope_span)) { + span.push_span_label(scope_span, msg); + } else { + scope_note = Some((scope_span, msg)); + } + } err.span_note( span, &format!( @@ -1760,6 +1769,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { future_or_generator, trait_explanation, an_await_or_yield ), ); + if let Some((span, msg)) = scope_note { + err.span_note(span, &msg); + } } }; match interior_or_upvar_span { 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 4929aa29d0f..db309938119 100644 --- a/src/test/ui/async-await/issue-70935-complex-spans.stderr +++ b/src/test/ui/async-await/issue-70935-complex-spans.stderr @@ -12,10 +12,14 @@ LL | baz(|| async{ | _____________- LL | | foo(tx.clone()); LL | | }).await; - | | - ^^^^^^- the value is later dropped here - | | | | - | |_________| await occurs here, with the value maybe used later + | | - ^^^^^^ await occurs here, with the value maybe used later + | |_________| | has type `[closure@$DIR/issue-70935-complex-spans.rs:13:13: 15:10]` which is not `Send` +note: the value is later dropped here + --> $DIR/issue-70935-complex-spans.rs:15:17 + | +LL | }).await; + | ^ error: aborting due to previous error diff --git a/src/test/ui/async-await/issues/issue-65436-raw-ptr-not-send.stderr b/src/test/ui/async-await/issues/issue-65436-raw-ptr-not-send.stderr index cac174061a2..b4d20064803 100644 --- a/src/test/ui/async-await/issues/issue-65436-raw-ptr-not-send.stderr +++ b/src/test/ui/async-await/issues/issue-65436-raw-ptr-not-send.stderr @@ -9,10 +9,14 @@ note: future is not `Send` as this value is used across an await --> $DIR/issue-65436-raw-ptr-not-send.rs:14:35 | LL | bar(Foo(std::ptr::null())).await; - | ---------------- ^^^^^^- `std::ptr::null()` is later dropped here - | | | - | | await occurs here, with `std::ptr::null()` maybe used later + | ---------------- ^^^^^^ await occurs here, with `std::ptr::null()` maybe used later + | | | has type `*const u8` which is not `Send` +note: `std::ptr::null()` is later dropped here + --> $DIR/issue-65436-raw-ptr-not-send.rs:14:41 + | +LL | bar(Foo(std::ptr::null())).await; + | ^ help: consider moving this into a `let` binding to create a shorter lived borrow --> $DIR/issue-65436-raw-ptr-not-send.rs:14:13 | diff --git a/src/test/ui/async-await/unnecessary-await.rs b/src/test/ui/async-await/unnecessary-await.rs index b994dc82e4d..24673777b80 100644 --- a/src/test/ui/async-await/unnecessary-await.rs +++ b/src/test/ui/async-await/unnecessary-await.rs @@ -1,8 +1,8 @@ // edition:2018 async fn foo () { } -fn bar () -> impl std::future::Future { async {} } -fn boo () {} +fn bar() -> impl std::future::Future { async {} } +fn boo() {} async fn baz() -> std::io::Result<()> { foo().await; diff --git a/src/test/ui/async-await/unnecessary-await.stderr b/src/test/ui/async-await/unnecessary-await.stderr index fc22ebc5972..23dea2d3a0c 100644 --- a/src/test/ui/async-await/unnecessary-await.stderr +++ b/src/test/ui/async-await/unnecessary-await.stderr @@ -16,7 +16,7 @@ LL + boo(); | help: alternatively, consider making `fn boo` asynchronous | -LL | async fn boo () {} +LL | async fn boo() {} | +++++ error: aborting due to previous error