about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-20 22:05:33 +0100
committerGitHub <noreply@github.com>2019-12-20 22:05:33 +0100
commitd7dc3502f9ad8f8ab0cc7f22388b92b2216f57fe (patch)
tree970db129863bb632270db2d3a3590f0ec2c8db0e
parent86282d0b0f7a4a7083579ade68a9cd69410531c5 (diff)
parentff4f6a125891b3474fac1cfd2e86784d4ec073a9 (diff)
downloadrust-d7dc3502f9ad8f8ab0cc7f22388b92b2216f57fe.tar.gz
rust-d7dc3502f9ad8f8ab0cc7f22388b92b2216f57fe.zip
Rollup merge of #67392 - csmoe:async-typeinfo, r=estebank
Fix unresolved type span inside async object

Closes #65180
r? @estebank
It's hard to create a minimal repro for that issue, [decided](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async-foundations/topic/meeting.202019.2E12.2E17/near/183675659) to give up finding mcve.
cc [previous take](https://github.com/rust-lang/rust/pull/65668)
-rw-r--r--src/librustc/hir/mod.rs10
-rw-r--r--src/librustc_typeck/check/generator_interior.rs21
2 files changed, 24 insertions, 7 deletions
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs
index 6b354b01518..2cffcc5bfad 100644
--- a/src/librustc/hir/mod.rs
+++ b/src/librustc/hir/mod.rs
@@ -1857,6 +1857,16 @@ impl fmt::Display for YieldSource {
     }
 }
 
+impl From<GeneratorKind> 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,
+        }
+    }
+}
+
 // N.B., if you change this, you'll probably want to change the corresponding
 // type structure in middle/ty.rs as well.
 #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs
index fcf6b22f74f..607efca88dd 100644
--- a/src/librustc_typeck/check/generator_interior.rs
+++ b/src/librustc_typeck/check/generator_interior.rs
@@ -19,6 +19,7 @@ struct InteriorVisitor<'a, 'tcx> {
     region_scope_tree: &'tcx region::ScopeTree,
     expr_count: usize,
     kind: hir::GeneratorKind,
+    prev_unresolved_span: Option<Span>,
 }
 
 impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
@@ -32,7 +33,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
@@ -54,15 +54,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);
 
@@ -74,9 +70,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)
@@ -94,6 +93,13 @@ 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);
+                self.prev_unresolved_span = unresolved_type_span;
+            }
         }
     }
 }
@@ -112,6 +118,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);