]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_trait_selection/traits/error_reporting/suggestions.rs
record upvar into GeneratorInteriorTypeCause
[rust.git] / src / librustc_trait_selection / traits / error_reporting / suggestions.rs
index 5ec2d68ab2a7d52048b9ff211796181a9a694918..9525910e39c6fcba3967cebcea6b13157bd3521f 100644 (file)
@@ -127,7 +127,7 @@ fn note_obligation_cause_for_async_await(
         err: &mut DiagnosticBuilder<'_>,
         target_span: Span,
         scope_span: &Option<Span>,
-        await_span: Span,
+        yield_span: Option<Span>,
         expr: Option<hir::HirId>,
         snippet: String,
         inner_generator_body: Option<&hir::Body<'_>>,
@@ -1353,7 +1353,7 @@ fn note_obligation_cause_for_async_await(
         err: &mut DiagnosticBuilder<'_>,
         target_span: Span,
         scope_span: &Option<Span>,
-        yield_span: Span,
+        yield_span: Option<Span>,
         expr: Option<hir::HirId>,
         snippet: String,
         inner_generator_body: Option<&hir::Body<'_>>,
@@ -1446,32 +1446,35 @@ fn note_obligation_cause_for_async_await(
                 "note_obligation_cause_for_async_await generator_interior_types: {:#?}",
                 tables.generator_interior_types
             );
-            let mut span = MultiSpan::from_span(yield_span);
-            span.push_span_label(
-                yield_span,
-                format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet),
-            );
 
-            span.push_span_label(
-                target_span,
-                format!("has type `{}` which {}", target_ty, trait_explanation),
-            );
+            if let Some(yield_span) = yield_span {
+                let mut span = MultiSpan::from_span(yield_span);
+                span.push_span_label(
+                    yield_span,
+                    format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet),
+                );
 
-            // If available, use the scope span to annotate the drop location.
-            if let Some(scope_span) = scope_span {
                 span.push_span_label(
-                    source_map.end_point(*scope_span),
-                    format!("`{}` is later dropped here", snippet),
+                    target_span,
+                    format!("has type `{}` which {}", target_ty, trait_explanation),
                 );
-            }
 
-            err.span_note(
-                span,
-                &format!(
-                    "{} {} as this value is used across {}",
-                    future_or_generator, trait_explanation, an_await_or_yield
-                ),
-            );
+                // If available, use the scope span to annotate the drop location.
+                if let Some(scope_span) = scope_span {
+                    span.push_span_label(
+                        source_map.end_point(*scope_span),
+                        format!("`{}` is later dropped here", snippet),
+                    );
+                }
+
+                err.span_note(
+                    span,
+                    &format!(
+                        "{} {} as this value is used across {}",
+                        future_or_generator, trait_explanation, an_await_or_yield
+                    ),
+                );
+            }
         }
 
         if let Some(expr_id) = expr {