diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 19f497ffd41..bb6e0e5c51c 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -113,18 +113,6 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } let map = &self.cx.tcx.hir(); - if is_argument(map, cmt.hir_id) { - // Skip closure arguments - let parent_id = map.get_parent_node(cmt.hir_id); - if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) { - return; - } - - if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) { - self.set.insert(cmt.hir_id); - } - return; - } if let Categorization::Local(lid) = cmt.cat { if let Some(Node::Binding(_)) = map.find(cmt.hir_id) { if self.set.contains(&lid) { @@ -143,7 +131,21 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn mutate(&mut self, _: &cmt_<'tcx>) {} + fn mutate(&mut self, cmt: &cmt_<'tcx>) { + let map = &self.cx.tcx.hir(); + if is_argument(map, cmt.hir_id) { + // Skip closure arguments + let parent_id = map.get_parent_node(cmt.hir_id); + if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) { + return; + } + + if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) { + self.set.insert(cmt.hir_id); + } + return; + } + } } impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> { diff --git a/tests/ui/escape_analysis.stderr b/tests/ui/escape_analysis.stderr index e69de29bb2d..19342fe1be7 100644 --- a/tests/ui/escape_analysis.stderr +++ b/tests/ui/escape_analysis.stderr @@ -0,0 +1,16 @@ +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:39:13 + | +LL | fn warn_arg(x: Box) { + | ^ + | + = note: `-D clippy::boxed-local` implied by `-D warnings` + +error: local variable doesn't need to be boxed here + --> $DIR/escape_analysis.rs:130:12 + | +LL | pub fn new(_needs_name: Box>) -> () {} + | ^^^^^^^^^^^ + +error: aborting due to 2 previous errors +