From 54d9ffc0b9c2e1057f63648d20f9f65e30e7d48f Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Mon, 2 Nov 2020 16:54:53 +0900 Subject: [PATCH] Only separate notes if span is multiline --- .../src/traits/error_reporting/suggestions.rs | 19 ++++++++++++++----- .../issue-65436-raw-ptr-not-send.stderr | 9 +++------ 2 files changed, 17 insertions(+), 11 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 83ce7f1f55e..1e826bac3aa 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1629,11 +1629,20 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { future_or_generator, trait_explanation, an_await_or_yield ), ); - err.span_note(scope_span, &format!("{} is later dropped here", snippet)); - err.span_note( - interior_span, - &format!("this has type `{}` which {}", target_ty, trait_explanation), - ); + if source_map.is_multiline(interior_span) { + err.span_note(scope_span, &format!("{} is later dropped here", snippet)); + err.span_note( + interior_span, + &format!("this has type `{}` which {}", target_ty, trait_explanation), + ); + } else { + let mut span = MultiSpan::from_span(scope_span); + span.push_span_label( + interior_span, + format!("has type `{}` which {}", target_ty, trait_explanation), + ); + err.span_note(span, &format!("{} is later dropped here", snippet)); + } } else { span.push_span_label( yield_span, 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 b733437a51d..5568dab8655 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 @@ -17,12 +17,9 @@ 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; - | ^ -note: this has type `*const u8` which is not `Send` - --> $DIR/issue-65436-raw-ptr-not-send.rs:14:17 - | -LL | bar(Foo(std::ptr::null())).await; - | ^^^^^^^^^^^^^^^^ + | ---------------- ^ + | | + | has type `*const u8` which is not `Send` help: consider moving this into a `let` binding to create a shorter lived borrow --> $DIR/issue-65436-raw-ptr-not-send.rs:14:13 |