]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_typeck/expr_use_visitor.rs
Auto merge of #68298 - Mark-Simulacrum:binary-depdep-fix, r=petrochenkov
[rust.git] / src / librustc_typeck / expr_use_visitor.rs
index f3f5e54edd1954bb8dae0f8b6530ec909c1bb7f9..1d3ace933cc43673096ac16cb9a0034f32252d77 100644 (file)
@@ -3,20 +3,19 @@
 //! `ExprUseVisitor` determines how expressions are being used.
 
 pub use self::ConsumeMode::*;
-use self::OverloadedCallType::*;
 
 // Export these here so that Clippy can use them.
 pub use mc::{Place, PlaceBase, Projection};
 
-use rustc::hir::def::Res;
-use rustc::hir::def_id::DefId;
-use rustc::hir::ptr::P;
-use rustc::hir::{self, PatKind};
 use rustc::infer::InferCtxt;
 use rustc::ty::{self, adjustment, TyCtxt};
+use rustc_hir as hir;
+use rustc_hir::def::Res;
+use rustc_hir::def_id::DefId;
+use rustc_hir::PatKind;
 
 use crate::mem_categorization as mc;
-use syntax_pos::Span;
+use rustc_span::Span;
 
 ///////////////////////////////////////////////////////////////////////////
 // The Delegate trait
@@ -48,35 +47,6 @@ pub enum MutateMode {
     WriteAndRead, // x += y
 }
 
-#[derive(Copy, Clone)]
-enum OverloadedCallType {
-    FnOverloadedCall,
-    FnMutOverloadedCall,
-    FnOnceOverloadedCall,
-}
-
-impl OverloadedCallType {
-    fn from_trait_id(tcx: TyCtxt<'_>, trait_id: DefId) -> OverloadedCallType {
-        for &(maybe_function_trait, overloaded_call_type) in &[
-            (tcx.lang_items().fn_once_trait(), FnOnceOverloadedCall),
-            (tcx.lang_items().fn_mut_trait(), FnMutOverloadedCall),
-            (tcx.lang_items().fn_trait(), FnOverloadedCall),
-        ] {
-            match maybe_function_trait {
-                Some(function_trait) if function_trait == trait_id => return overloaded_call_type,
-                _ => continue,
-            }
-        }
-
-        bug!("overloaded call didn't map to known function trait")
-    }
-
-    fn from_method_id(tcx: TyCtxt<'_>, method_id: DefId) -> OverloadedCallType {
-        let method = tcx.associated_item(method_id);
-        OverloadedCallType::from_trait_id(tcx, method.container.id())
-    }
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // The ExprUseVisitor type
 //
@@ -150,13 +120,13 @@ fn delegate_consume(&mut self, place: &Place<'tcx>) {
         self.delegate.consume(place, mode);
     }
 
-    fn consume_exprs(&mut self, exprs: &[hir::Expr]) {
+    fn consume_exprs(&mut self, exprs: &[hir::Expr<'_>]) {
         for expr in exprs {
             self.consume_expr(&expr);
         }
     }
 
-    pub fn consume_expr(&mut self, expr: &hir::Expr) {
+    pub fn consume_expr(&mut self, expr: &hir::Expr<'_>) {
         debug!("consume_expr(expr={:?})", expr);
 
         let place = return_if_err!(self.mc.cat_expr(expr));
@@ -164,13 +134,13 @@ pub fn consume_expr(&mut self, expr: &hir::Expr) {
         self.walk_expr(expr);
     }
 
-    fn mutate_expr(&mut self, expr: &hir::Expr) {
+    fn mutate_expr(&mut self, expr: &hir::Expr<'_>) {
         let place = return_if_err!(self.mc.cat_expr(expr));
         self.delegate.mutate(&place);
         self.walk_expr(expr);
     }
 
-    fn borrow_expr(&mut self, expr: &hir::Expr, bk: ty::BorrowKind) {
+    fn borrow_expr(&mut self, expr: &hir::Expr<'_>, bk: ty::BorrowKind) {
         debug!("borrow_expr(expr={:?}, bk={:?})", expr, bk);
 
         let place = return_if_err!(self.mc.cat_expr(expr));
@@ -179,11 +149,11 @@ fn borrow_expr(&mut self, expr: &hir::Expr, bk: ty::BorrowKind) {
         self.walk_expr(expr)
     }
 
-    fn select_from_expr(&mut self, expr: &hir::Expr) {
+    fn select_from_expr(&mut self, expr: &hir::Expr<'_>) {
         self.walk_expr(expr)
     }
 
-    pub fn walk_expr(&mut self, expr: &hir::Expr) {
+    pub fn walk_expr(&mut self, expr: &hir::Expr<'_>) {
         debug!("walk_expr(expr={:?})", expr);
 
         self.walk_adjustment(expr);
@@ -193,7 +163,7 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
 
             hir::ExprKind::Type(ref subexpr, _) => self.walk_expr(subexpr),
 
-            hir::ExprKind::Unary(hir::UnDeref, ref base) => {
+            hir::ExprKind::Unary(hir::UnOp::UnDeref, ref base) => {
                 // *base
                 self.select_from_expr(base);
             }
@@ -211,7 +181,7 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
 
             hir::ExprKind::Call(ref callee, ref args) => {
                 // callee(args)
-                self.walk_callee(expr, callee);
+                self.consume_expr(callee);
                 self.consume_exprs(args);
             }
 
@@ -228,7 +198,7 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
                 self.consume_exprs(exprs);
             }
 
-            hir::ExprKind::Match(ref discr, ref arms, _) => {
+            hir::ExprKind::Match(ref discr, arms, _) => {
                 let discr_place = return_if_err!(self.mc.cat_expr(&discr));
                 self.borrow_expr(&discr, ty::ImmBorrow);
 
@@ -251,7 +221,7 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
             }
 
             hir::ExprKind::InlineAsm(ref ia) => {
-                for (o, output) in ia.inner.outputs.iter().zip(&ia.outputs_exprs) {
+                for (o, output) in ia.inner.outputs.iter().zip(ia.outputs_exprs) {
                     if o.is_indirect {
                         self.consume_expr(output);
                     } else {
@@ -326,35 +296,7 @@ pub fn walk_expr(&mut self, expr: &hir::Expr) {
         }
     }
 
-    fn walk_callee(&mut self, call: &hir::Expr, callee: &hir::Expr) {
-        let callee_ty = return_if_err!(self.mc.expr_ty_adjusted(callee));
-        debug!("walk_callee: callee={:?} callee_ty={:?}", callee, callee_ty);
-        match callee_ty.kind {
-            ty::FnDef(..) | ty::FnPtr(_) => {
-                self.consume_expr(callee);
-            }
-            ty::Error => {}
-            _ => {
-                if let Some(def_id) = self.mc.tables.type_dependent_def_id(call.hir_id) {
-                    match OverloadedCallType::from_method_id(self.tcx(), def_id) {
-                        FnMutOverloadedCall => {
-                            self.borrow_expr(callee, ty::MutBorrow);
-                        }
-                        FnOverloadedCall => {
-                            self.borrow_expr(callee, ty::ImmBorrow);
-                        }
-                        FnOnceOverloadedCall => self.consume_expr(callee),
-                    }
-                } else {
-                    self.tcx()
-                        .sess
-                        .delay_span_bug(call.span, "no type-dependent def for overloaded call");
-                }
-            }
-        }
-    }
-
-    fn walk_stmt(&mut self, stmt: &hir::Stmt) {
+    fn walk_stmt(&mut self, stmt: &hir::Stmt<'_>) {
         match stmt.kind {
             hir::StmtKind::Local(ref local) => {
                 self.walk_local(&local);
@@ -371,7 +313,7 @@ fn walk_stmt(&mut self, stmt: &hir::Stmt) {
         }
     }
 
-    fn walk_local(&mut self, local: &hir::Local) {
+    fn walk_local(&mut self, local: &hir::Local<'_>) {
         if let Some(ref expr) = local.init {
             // Variable declarations with
             // initializers are considered
@@ -385,10 +327,10 @@ fn walk_local(&mut self, local: &hir::Local) {
 
     /// Indicates that the value of `blk` will be consumed, meaning either copied or moved
     /// depending on its type.
-    fn walk_block(&mut self, blk: &hir::Block) {
+    fn walk_block(&mut self, blk: &hir::Block<'_>) {
         debug!("walk_block(blk.hir_id={})", blk.hir_id);
 
-        for stmt in &blk.stmts {
+        for stmt in blk.stmts {
             self.walk_stmt(stmt);
         }
 
@@ -397,7 +339,11 @@ fn walk_block(&mut self, blk: &hir::Block) {
         }
     }
 
-    fn walk_struct_expr(&mut self, fields: &[hir::Field], opt_with: &Option<P<hir::Expr>>) {
+    fn walk_struct_expr(
+        &mut self,
+        fields: &[hir::Field<'_>],
+        opt_with: &Option<&'hir hir::Expr<'_>>,
+    ) {
         // Consume the expressions supplying values for each field.
         for field in fields {
             self.consume_expr(&field.expr);
@@ -450,7 +396,7 @@ fn walk_struct_expr(&mut self, fields: &[hir::Field], opt_with: &Option<P<hir::E
     // Invoke the appropriate delegate calls for anything that gets
     // consumed or borrowed as part of the automatic adjustment
     // process.
-    fn walk_adjustment(&mut self, expr: &hir::Expr) {
+    fn walk_adjustment(&mut self, expr: &hir::Expr<'_>) {
         let adjustments = self.mc.tables.expr_adjustments(expr);
         let mut place = return_if_err!(self.mc.cat_expr_unadjusted(expr));
         for adjustment in adjustments {
@@ -487,7 +433,7 @@ fn walk_adjustment(&mut self, expr: &hir::Expr) {
     /// after all relevant autoderefs have occurred.
     fn walk_autoref(
         &mut self,
-        expr: &hir::Expr,
+        expr: &hir::Expr<'_>,
         base_place: &mc::Place<'tcx>,
         autoref: &adjustment::AutoBorrow<'tcx>,
     ) {
@@ -509,7 +455,7 @@ fn walk_autoref(
         }
     }
 
-    fn walk_arm(&mut self, discr_place: &Place<'tcx>, arm: &hir::Arm) {
+    fn walk_arm(&mut self, discr_place: &Place<'tcx>, arm: &hir::Arm<'_>) {
         self.walk_pat(discr_place, &arm.pat);
 
         if let Some(hir::Guard::If(ref e)) = arm.guard {
@@ -521,12 +467,12 @@ fn walk_arm(&mut self, discr_place: &Place<'tcx>, arm: &hir::Arm) {
 
     /// Walks a pat that occurs in isolation (i.e., top-level of fn argument or
     /// let binding, and *not* a match arm or nested pat.)
-    fn walk_irrefutable_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat) {
+    fn walk_irrefutable_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat<'_>) {
         self.walk_pat(discr_place, pat);
     }
 
     /// The core driver for walking a pattern
-    fn walk_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat) {
+    fn walk_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat<'_>) {
         debug!("walk_pat(discr_place={:?}, pat={:?})", discr_place, pat);
 
         let tcx = self.tcx();
@@ -565,7 +511,7 @@ fn walk_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat) {
         }));
     }
 
-    fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
+    fn walk_captures(&mut self, closure_expr: &hir::Expr<'_>, fn_decl_span: Span) {
         debug!("walk_captures({:?})", closure_expr);
 
         let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id);