]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/needless_pass_by_value.rs
Auto merge of #4938 - flip1995:rustup, r=flip1995
[rust.git] / clippy_lints / src / needless_pass_by_value.rs
index 64786f48719a9836f0ddf345a76f8c5a1494201a..986cd94cfb3cb794f819004ad84003f1effa099b 100644 (file)
@@ -5,16 +5,17 @@
 };
 use if_chain::if_chain;
 use matches::matches;
+use rustc::declare_lint_pass;
 use rustc::hir::intravisit::FnKind;
 use rustc::hir::*;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc_typeck::expr_use_visitor as euv;
 use rustc::traits;
 use rustc::ty::{self, RegionKind, TypeFoldable};
-use rustc::{declare_lint_pass, declare_tool_lint};
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_errors::Applicability;
+use rustc_session::declare_tool_lint;
 use rustc_target::spec::abi::Abi;
+use rustc_typeck::expr_use_visitor as euv;
 use std::borrow::Cow;
 use syntax::ast::Attribute;
 use syntax::errors::DiagnosticBuilder;
@@ -71,7 +72,7 @@ fn check_fn(
         cx: &LateContext<'a, 'tcx>,
         kind: FnKind<'tcx>,
         decl: &'tcx FnDecl,
-        body: &'tcx Body,
+        body: &'tcx Body<'_>,
         span: Span,
         hir_id: HirId,
     ) {
@@ -134,15 +135,16 @@ fn check_fn(
             ..
         } = {
             let mut ctx = MovedVariablesCtxt::default();
-            euv::ExprUseVisitor::new(&mut ctx, cx.tcx, fn_def_id, cx.param_env, cx.tables)
-                .consume_body(body);
+            cx.tcx.infer_ctxt().enter(|infcx| {
+                euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body);
+            });
             ctx
         };
 
         let fn_sig = cx.tcx.fn_sig(fn_def_id);
         let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig);
 
-        for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(&body.params).enumerate() {
+        for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(body.params).enumerate() {
             // All spans generated from a proc-macro invocation are the same...
             if span == input.span {
                 return;
@@ -325,9 +327,7 @@ struct MovedVariablesCtxt {
 
 impl MovedVariablesCtxt {
     fn move_common(&mut self, cmt: &euv::Place<'_>) {
-        let cmt = unwrap_downcast_or_interior(cmt);
-
-        if let mc::Categorization::Local(vid) = cmt.cat {
+        if let euv::PlaceBase::Local(vid) = cmt.base {
             self.moved_vars.insert(vid);
         }
     }
@@ -344,14 +344,3 @@ fn borrow(&mut self, _: &euv::Place<'tcx>, _: ty::BorrowKind) {}
 
     fn mutate(&mut self, _: &euv::Place<'tcx>) {}
 }
-
-fn unwrap_downcast_or_interior<'a, 'tcx>(mut cmt: &'a euv::Place<'tcx>) -> euv::Place<'tcx> {
-    loop {
-        match cmt.cat {
-            mc::Categorization::Downcast(ref c, _) | mc::Categorization::Interior(ref c, _) => {
-                cmt = c;
-            },
-            _ => return (*cmt).clone(),
-        }
-    }
-}