]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check/generator_interior.rs
update async-await send/sync test
[rust.git] / src / librustc_typeck / check / generator_interior.rs
index 3069f1b1d77d40444ed6fa4bff80e2459ed7b819..7185de76fcbb6184324fe01f3325c72a391b0fb2 100644 (file)
@@ -4,18 +4,21 @@
 //! types computed here.
 
 use super::FnCtxt;
-use crate::util::nodemap::FxHashMap;
-use rustc::hir::def::{CtorKind, DefKind, Res};
-use rustc::hir::def_id::DefId;
-use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
-use rustc::hir::{self, Expr, ExprKind, Pat, PatKind};
+use rustc::hir::map::Map;
 use rustc::middle::region::{self, YieldData};
 use rustc::ty::{self, Ty};
-use syntax_pos::Span;
+use rustc_data_structures::fx::FxHashMap;
+use rustc_hir as hir;
+use rustc_hir::def::{CtorKind, DefKind, Res};
+use rustc_hir::def_id::DefId;
+use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
+use rustc_hir::{Expr, ExprKind, Pat, PatKind};
+use rustc_span::Span;
 
 struct InteriorVisitor<'a, 'tcx> {
     fcx: &'a FnCtxt<'a, 'tcx>,
     types: FxHashMap<ty::GeneratorInteriorTypeCause<'tcx>, usize>,
+    exprs: Vec<Option<hir::HirId>>,
     region_scope_tree: &'tcx region::ScopeTree,
     expr_count: usize,
     kind: hir::GeneratorKind,
@@ -30,7 +33,7 @@ fn record(
         expr: Option<&'tcx Expr<'tcx>>,
         source_span: Span,
     ) {
-        use syntax_pos::DUMMY_SP;
+        use rustc_span::DUMMY_SP;
 
         debug!(
             "generator_interior: attempting to record type {:?} {:?} {:?} {:?}",
@@ -97,6 +100,7 @@ fn record(
                         scope_span,
                     })
                     .or_insert(entries);
+                self.exprs.push(expr.map(|e| e.hir_id));
             }
         } else {
             debug!(
@@ -134,6 +138,7 @@ pub fn resolve_interior<'a, 'tcx>(
         expr_count: 0,
         kind,
         prev_unresolved_span: None,
+        exprs: vec![],
     };
     intravisit::walk_body(&mut visitor, body);
 
@@ -168,7 +173,8 @@ pub fn resolve_interior<'a, 'tcx>(
     });
 
     // Store the generator types and spans into the tables for this generator.
-    let interior_types = types.iter().map(|t| t.0.clone()).collect::<Vec<_>>();
+    let interior_types =
+        types.iter().zip(visitor.exprs).map(|(t, e)| (t.0.clone(), e)).collect::<Vec<_>>();
     visitor.fcx.inh.tables.borrow_mut().generator_interior_types = interior_types;
 
     // Extract type components
@@ -192,7 +198,9 @@ pub fn resolve_interior<'a, 'tcx>(
 // librustc/middle/region.rs since `expr_count` is compared against the results
 // there.
 impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
-    fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
+    type Map = Map<'tcx>;
+
+    fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> {
         NestedVisitorMap::None
     }