Skip to content

Commit 5332cdb

Browse files
author
Michael Wright
committed
Remove unneeded visitor class
Use ExprUseVisitor correctly instead.
1 parent 9d6ecc7 commit 5332cdb

File tree

1 file changed

+4
-40
lines changed

1 file changed

+4
-40
lines changed

clippy_lints/src/escape.rs

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::utils::span_lint;
22
use rustc::hir::intravisit as visit;
3-
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
43
use rustc::hir::*;
54
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
65
use rustc::middle::expr_use_visitor::*;
76
use rustc::middle::mem_categorization::{cmt_, Categorization};
87
use rustc::ty::layout::LayoutOf;
9-
use rustc::ty::{self, Ty, UpvarCapture};
8+
use rustc::ty::{self, Ty};
109
use rustc::util::nodemap::NodeSet;
1110
use rustc::{declare_tool_lint, lint_array};
1211
use syntax::ast::NodeId;
@@ -89,17 +88,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
8988
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
9089
ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body);
9190

92-
let mut capture_visitor = CaptureVisitor {
93-
cx,
94-
moved: NodeSet::default(),
95-
};
96-
capture_visitor.visit_body(body);
97-
98-
for node in v.set.difference(&capture_visitor.moved) {
91+
for node in v.set {
9992
span_lint(
10093
cx,
10194
BOXED_LOCAL,
102-
cx.tcx.hir().span(*node),
95+
cx.tcx.hir().span(node),
10396
"local variable doesn't need to be boxed here",
10497
);
10598
}
@@ -109,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
109102
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
110103
fn consume(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
111104
if let Categorization::Local(lid) = cmt.cat {
112-
if let Move(DirectRefMove) = mode {
105+
if let Move(DirectRefMove) | Move(CaptureMove) = mode {
113106
// moved out or in. clearly can't be localized
114107
self.set.remove(&lid);
115108
}
@@ -199,32 +192,3 @@ impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {
199192
}
200193
}
201194
}
202-
203-
struct CaptureVisitor<'a, 'tcx: 'a> {
204-
cx: &'a LateContext<'a, 'tcx>,
205-
moved: NodeSet,
206-
}
207-
208-
impl<'a, 'tcx> Visitor<'tcx> for CaptureVisitor<'a, 'tcx> {
209-
fn visit_expr(&mut self, expr: &'tcx Expr) {
210-
if let ExprKind::Closure(..) = expr.node {
211-
if let ty::Closure(def_id, _) = &self.cx.tables.expr_ty(expr).sty {
212-
if let Some(upvar_list) = &self.cx.tables.upvar_list.get(&def_id) {
213-
for upvar_id in upvar_list.iter() {
214-
if let UpvarCapture::ByValue = self.cx.tables.upvar_capture(*upvar_id) {
215-
let hir_id = upvar_id.var_path.hir_id;
216-
let id = &self.cx.tcx.hir().hir_to_node_id(hir_id);
217-
self.moved.insert(*id);
218-
}
219-
}
220-
}
221-
}
222-
} else {
223-
walk_expr(self, expr);
224-
}
225-
}
226-
227-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
228-
NestedVisitorMap::None
229-
}
230-
}

0 commit comments

Comments
 (0)