about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2020-04-01 19:54:11 -0700
committerTyler Mandry <tmandry@gmail.com>2020-04-13 18:58:17 -0700
commitdf0a16b29fcd4e785598b4205a7b9a8cd4c48171 (patch)
treeb39a4f44dabb6fdeae1f39197a00b719b1890397
parent8ce334d53c91c5b9c5b4f809df7f81fbf95c2445 (diff)
downloadrust-df0a16b29fcd4e785598b4205a7b9a8cd4c48171.tar.gz
rust-df0a16b29fcd4e785598b4205a7b9a8cd4c48171.zip
Include type info when available for awaited expr
-rw-r--r--src/librustc_trait_selection/traits/error_reporting/suggestions.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs
index bbe059dda6f..d458104560b 100644
--- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs
+++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs
@@ -1378,10 +1378,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
             )
         };
 
-        let push_target_span = |span: &mut MultiSpan| {
+        let push_target_span_with_fallback = |span: &mut MultiSpan, fallback: &str| {
             if target_ty.is_impl_trait() {
                 // It's not very useful to tell the user the type if it's opaque.
-                span.push_span_label(target_span, "created here".to_string());
+                span.push_span_label(target_span, fallback.to_string());
             } else {
                 span.push_span_label(target_span, format!("has type `{}`", target_ty));
             }
@@ -1390,10 +1390,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
         if let Some(await_span) = from_awaited_ty {
             // The type causing this obligation is one being awaited at await_span.
             let mut span = MultiSpan::from_span(await_span);
-            span.push_span_label(await_span, "await occurs here".to_string());
 
-            if target_span != await_span {
-                push_target_span(&mut span);
+            if target_span == await_span {
+                push_target_span_with_fallback(&mut span, "await occurs here");
+            } else {
+                span.push_span_label(await_span, "await occurs here".to_string());
+                push_target_span_with_fallback(&mut span, "created here");
             }
 
             err.span_note(
@@ -1413,7 +1415,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                 format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet),
             );
 
-            push_target_span(&mut span);
+            push_target_span_with_fallback(&mut span, "created here");
 
             // If available, use the scope span to annotate the drop location.
             if let Some(scope_span) = scope_span {