From add21c44a1617c902fdec358fdd6be6d67e9158f Mon Sep 17 00:00:00 2001 From: csmoe Date: Thu, 17 Oct 2019 00:57:18 +0800 Subject: [PATCH 1/2] add debuginfo in generator_interior --- src/librustc/hir/mod.rs | 10 ++++++++++ src/librustc_typeck/check/generator_interior.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 7350f89018be2..a20568f56f1c6 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1833,6 +1833,16 @@ impl fmt::Display for YieldSource { } } +impl core::convert::From for YieldSource { + fn from(gen_kind: GeneratorKind) -> Self { + match gen_kind { + // Guess based on the kind of the current generator. + GeneratorKind::Gen => Self::Yield, + GeneratorKind::Async(_) => Self::Await, + } + } +} + #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum CaptureClause { CaptureByValue, diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index 619768e018c77..368b09cc091fc 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -31,7 +31,6 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { debug!("generator_interior: attempting to record type {:?} {:?} {:?} {:?}", ty, scope, expr, source_span); - let live_across_yield = scope.map(|s| { self.region_scope_tree.yield_in_scope(s).and_then(|yield_data| { // If we are recording an expression that is the last yield @@ -53,15 +52,11 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { }).unwrap_or_else(|| Some(YieldData { span: DUMMY_SP, expr_and_pat_count: 0, - source: match self.kind { // Guess based on the kind of the current generator. - hir::GeneratorKind::Gen => hir::YieldSource::Yield, - hir::GeneratorKind::Async(_) => hir::YieldSource::Await, - }, + source: self.kind.into(), })); if let Some(yield_data) = live_across_yield { let ty = self.fcx.resolve_vars_if_possible(&ty); - debug!("type in expr = {:?}, scope = {:?}, type = {:?}, count = {}, yield_span = {:?}", expr, scope, ty, self.expr_count, yield_data.span); @@ -93,6 +88,11 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { } else { debug!("no type in expr = {:?}, count = {:?}, span = {:?}", expr, self.expr_count, expr.map(|e| e.span)); + let ty = self.fcx.resolve_vars_if_possible(&ty); + if let Some((unresolved_type, unresolved_type_span)) = self.fcx.unresolved_type_vars(&ty) { + debug!("remained unresolved_type = {:?}, unresolved_type_span: {:?}", + unresolved_type, unresolved_type_span); + } } } } From c337cb266b200034e03570eddfffa9db70e4c9be Mon Sep 17 00:00:00 2001 From: csmoe Date: Tue, 22 Oct 2019 02:44:12 +0800 Subject: [PATCH 2/2] record previous unresolve span for generator error reporting --- src/librustc/hir/mod.rs | 6 +++--- src/librustc_typeck/check/generator_interior.rs | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index a20568f56f1c6..5297146575f75 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1833,9 +1833,9 @@ impl fmt::Display for YieldSource { } } -impl core::convert::From for YieldSource { - fn from(gen_kind: GeneratorKind) -> Self { - match gen_kind { +impl From for YieldSource { + fn from(kind: GeneratorKind) -> Self { + match kind { // Guess based on the kind of the current generator. GeneratorKind::Gen => Self::Yield, GeneratorKind::Async(_) => Self::Await, diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index 368b09cc091fc..8e388316d1855 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -18,6 +18,7 @@ struct InteriorVisitor<'a, 'tcx> { region_scope_tree: &'tcx region::ScopeTree, expr_count: usize, kind: hir::GeneratorKind, + prev_unresolved_span: Option, } impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { @@ -68,9 +69,12 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { yield_data.source); // If unresolved type isn't a ty_var then unresolved_type_span is None + let span = self.prev_unresolved_span.unwrap_or_else( + || unresolved_type_span.unwrap_or(source_span) + ); self.fcx.need_type_info_err_in_generator( self.kind, - unresolved_type_span.unwrap_or(source_span), + span, unresolved_type, ) .span_note(yield_data.span, &*note) @@ -89,9 +93,11 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { debug!("no type in expr = {:?}, count = {:?}, span = {:?}", expr, self.expr_count, expr.map(|e| e.span)); let ty = self.fcx.resolve_vars_if_possible(&ty); - if let Some((unresolved_type, unresolved_type_span)) = self.fcx.unresolved_type_vars(&ty) { + if let Some((unresolved_type, unresolved_type_span)) + = self.fcx.unresolved_type_vars(&ty) { debug!("remained unresolved_type = {:?}, unresolved_type_span: {:?}", unresolved_type, unresolved_type_span); + self.prev_unresolved_span = unresolved_type_span; } } } @@ -111,6 +117,7 @@ pub fn resolve_interior<'a, 'tcx>( region_scope_tree: fcx.tcx.region_scope_tree(def_id), expr_count: 0, kind, + prev_unresolved_span: None, }; intravisit::walk_body(&mut visitor, body);