about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/escape.rs44
1 files changed, 4 insertions, 40 deletions
diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs
index 090d7a2eb93..909d82a7be5 100644
--- a/clippy_lints/src/escape.rs
+++ b/clippy_lints/src/escape.rs
@@ -1,12 +1,11 @@
 use crate::utils::span_lint;
 use rustc::hir::intravisit as visit;
-use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
 use rustc::hir::*;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use rustc::middle::expr_use_visitor::*;
 use rustc::middle::mem_categorization::{cmt_, Categorization};
 use rustc::ty::layout::LayoutOf;
-use rustc::ty::{self, Ty, UpvarCapture};
+use rustc::ty::{self, Ty};
 use rustc::util::nodemap::NodeSet;
 use rustc::{declare_tool_lint, lint_array};
 use syntax::ast::NodeId;
@@ -89,17 +88,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
         let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
         ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body);
 
-        let mut capture_visitor = CaptureVisitor {
-            cx,
-            moved: NodeSet::default(),
-        };
-        capture_visitor.visit_body(body);
-
-        for node in v.set.difference(&capture_visitor.moved) {
+        for node in v.set {
             span_lint(
                 cx,
                 BOXED_LOCAL,
-                cx.tcx.hir().span(*node),
+                cx.tcx.hir().span(node),
                 "local variable doesn't need to be boxed here",
             );
         }
@@ -109,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
 impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
     fn consume(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
         if let Categorization::Local(lid) = cmt.cat {
-            if let Move(DirectRefMove) = mode {
+            if let Move(DirectRefMove) | Move(CaptureMove) = mode {
                 // moved out or in. clearly can't be localized
                 self.set.remove(&lid);
             }
@@ -199,32 +192,3 @@ impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {
         }
     }
 }
-
-struct CaptureVisitor<'a, 'tcx: 'a> {
-    cx: &'a LateContext<'a, 'tcx>,
-    moved: NodeSet,
-}
-
-impl<'a, 'tcx> Visitor<'tcx> for CaptureVisitor<'a, 'tcx> {
-    fn visit_expr(&mut self, expr: &'tcx Expr) {
-        if let ExprKind::Closure(..) = expr.node {
-            if let ty::Closure(def_id, _) = &self.cx.tables.expr_ty(expr).sty {
-                if let Some(upvar_list) = &self.cx.tables.upvar_list.get(&def_id) {
-                    for upvar_id in upvar_list.iter() {
-                        if let UpvarCapture::ByValue = self.cx.tables.upvar_capture(*upvar_id) {
-                            let hir_id = upvar_id.var_path.hir_id;
-                            let id = &self.cx.tcx.hir().hir_to_node_id(hir_id);
-                            self.moved.insert(*id);
-                        }
-                    }
-                }
-            }
-        } else {
-            walk_expr(self, expr);
-        }
-    }
-
-    fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::None
-    }
-}