]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/check/writeback.rs
rustc: remove unnecessary ItemSubsts wrapper.
[rust.git] / src / librustc_typeck / check / writeback.rs
index b43e2423757d1faef9df751445363881339760d5..dcdfed6cbd888e98196a1aea8aaa4bce175baad8 100644 (file)
@@ -16,7 +16,7 @@
 use rustc::hir;
 use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
 use rustc::infer::{InferCtxt};
-use rustc::ty::{self, Ty, TyCtxt, MethodCall, MethodCallee};
+use rustc::ty::{self, Ty, TyCtxt, MethodCallee};
 use rustc::ty::adjustment;
 use rustc::ty::fold::{TypeFolder,TypeFoldable};
 use rustc::util::nodemap::DefIdSet;
@@ -106,7 +106,7 @@ fn fix_scalar_builtin_expr(&mut self, e: &hir::Expr) {
                 let inner_ty = self.fcx.resolve_type_vars_if_possible(&inner_ty);
 
                 if inner_ty.is_scalar() {
-                    self.fcx.tables.borrow_mut().method_map.remove(&MethodCall::expr(e.id));
+                    self.fcx.tables.borrow_mut().method_map.remove(&e.id);
                 }
             }
             hir::ExprBinary(ref op, ref lhs, ref rhs) |
@@ -118,7 +118,7 @@ fn fix_scalar_builtin_expr(&mut self, e: &hir::Expr) {
                 let rhs_ty = self.fcx.resolve_type_vars_if_possible(&rhs_ty);
 
                 if lhs_ty.is_scalar() && rhs_ty.is_scalar() {
-                    self.fcx.tables.borrow_mut().method_map.remove(&MethodCall::expr(e.id));
+                    self.fcx.tables.borrow_mut().method_map.remove(&e.id);
 
                     // weird but true: the by-ref binops put an
                     // adjustment on the lhs but not the rhs; the
@@ -164,7 +164,7 @@ fn visit_expr(&mut self, e: &'gcx hir::Expr) {
         self.fix_scalar_builtin_expr(e);
 
         self.visit_node_id(e.span, e.id);
-        self.visit_method_map_entry(e.span, MethodCall::expr(e.id));
+        self.visit_method_map_entry(e.span, e.id);
 
         if let hir::ExprClosure(_, _, body, _) = e.node {
             let body = self.fcx.tcx.hir.body(body);
@@ -295,14 +295,12 @@ fn visit_node_id(&mut self, span: Span, node_id: ast::NodeId) {
         debug!("Node {} has type {:?}", node_id, n_ty);
 
         // Resolve any substitutions
-        self.fcx.opt_node_ty_substs(node_id, |item_substs| {
-            let item_substs = self.resolve(item_substs, &span);
-            if !item_substs.is_noop() {
-                debug!("write_substs_to_tcx({}, {:?})", node_id, item_substs);
-                assert!(!item_substs.substs.needs_infer());
-                self.tables.item_substs.insert(node_id, item_substs);
-            }
-        });
+        if let Some(&substs) = self.fcx.tables.borrow().node_substs.get(&node_id) {
+            let substs = self.resolve(&substs, &span);
+            debug!("write_substs_to_tcx({}, {:?})", node_id, substs);
+            assert!(!substs.needs_infer());
+            self.tables.node_substs.insert(node_id, substs);
+        }
     }
 
     fn visit_adjustments(&mut self, span: Span, node_id: ast::NodeId) {
@@ -335,13 +333,16 @@ fn visit_adjustments(&mut self, span: Span, node_id: ast::NodeId) {
                     }
 
                     adjustment::Adjust::DerefRef { autoderefs, autoref, unsize } => {
-                        for autoderef in 0..autoderefs {
-                            let method_call = MethodCall::autoderef(node_id, autoderef as u32);
-                            self.visit_method_map_entry(span, method_call);
-                        }
-
                         adjustment::Adjust::DerefRef {
-                            autoderefs: autoderefs,
+                            autoderefs: autoderefs.iter().map(|overloaded| {
+                                overloaded.map(|method| {
+                                    MethodCallee {
+                                        def_id: method.def_id,
+                                        substs: self.resolve(&method.substs, &span),
+                                        sig: self.resolve(&method.sig, &span),
+                                    }
+                                })
+                            }).collect(),
                             autoref: self.resolve(&autoref, &span),
                             unsize: unsize,
                         }
@@ -359,27 +360,22 @@ fn visit_adjustments(&mut self, span: Span, node_id: ast::NodeId) {
 
     fn visit_method_map_entry(&mut self,
                               method_span: Span,
-                              method_call: MethodCall) {
+                              node_id: ast::NodeId) {
         // Resolve any method map entry
-        let new_method = match self.fcx.tables.borrow_mut().method_map.remove(&method_call) {
+        let new_method = match self.fcx.tables.borrow_mut().method_map.remove(&node_id) {
             Some(method) => {
-                debug!("writeback::resolve_method_map_entry(call={:?}, entry={:?})",
-                       method_call,
-                       method);
-                let new_method = MethodCallee {
+                Some(MethodCallee {
                     def_id: method.def_id,
-                    ty: self.resolve(&method.ty, &method_span),
                     substs: self.resolve(&method.substs, &method_span),
-                };
-
-                Some(new_method)
+                    sig: self.resolve(&method.sig, &method_span),
+                })
             }
             None => None
         };
 
         //NB(jroesch): We need to match twice to avoid a double borrow which would cause an ICE
         if let Some(method) = new_method {
-            self.tables.method_map.insert(method_call, method);
+            self.tables.method_map.insert(node_id, method);
         }
     }