From fb81c429ebd45f9ba2b1810f548cf59a45feb222 Mon Sep 17 00:00:00 2001 From: csmoe Date: Tue, 5 May 2020 23:24:34 +0800 Subject: [PATCH] make yield span optional --- src/librustc_middle/ty/context.rs | 2 +- .../traits/error_reporting/suggestions.rs | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index e43eb01ad96f..cc89e59096d8 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -305,7 +305,7 @@ pub struct GeneratorInteriorTypeCause<'tcx> { /// Span of the scope of the captured binding. pub scope_span: Option, /// Span of `.await` or `yield` expression. - pub yield_span: Span, + pub yield_span: Option, /// Expr which the type evaluated from. pub expr: Option, } diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index 5ec2d68ab2a7..cd1c75dc5f29 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -127,7 +127,7 @@ pub trait InferCtxtExt<'tcx> { err: &mut DiagnosticBuilder<'_>, target_span: Span, scope_span: &Option, - await_span: Span, + yield_span: Option, expr: Option, snippet: String, inner_generator_body: Option<&hir::Body<'_>>, @@ -1353,7 +1353,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'_>, target_span: Span, scope_span: &Option, - yield_span: Span, + yield_span: Option, expr: Option, snippet: String, inner_generator_body: Option<&hir::Body<'_>>, @@ -1446,11 +1446,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { "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), - ); + + 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), + ); span.push_span_label( target_span,