Skip to content

Commit 3d39379

Browse files
committed
Move is_argument check into mutate
1 parent 3aa531c commit 3d39379

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

clippy_lints/src/escape.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,6 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
113113
}
114114
}
115115
let map = &self.cx.tcx.hir();
116-
if is_argument(map, cmt.hir_id) {
117-
// Skip closure arguments
118-
let parent_id = map.get_parent_node(cmt.hir_id);
119-
if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) {
120-
return;
121-
}
122-
123-
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
124-
self.set.insert(cmt.hir_id);
125-
}
126-
return;
127-
}
128116
if let Categorization::Local(lid) = cmt.cat {
129117
if let Some(Node::Binding(_)) = map.find(cmt.hir_id) {
130118
if self.set.contains(&lid) {
@@ -143,7 +131,21 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
143131
}
144132
}
145133

146-
fn mutate(&mut self, _: &cmt_<'tcx>) {}
134+
fn mutate(&mut self, cmt: &cmt_<'tcx>) {
135+
let map = &self.cx.tcx.hir();
136+
if is_argument(map, cmt.hir_id) {
137+
// Skip closure arguments
138+
let parent_id = map.get_parent_node(cmt.hir_id);
139+
if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) {
140+
return;
141+
}
142+
143+
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
144+
self.set.insert(cmt.hir_id);
145+
}
146+
return;
147+
}
148+
}
147149
}
148150

149151
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {

tests/ui/escape_analysis.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: local variable doesn't need to be boxed here
2+
--> $DIR/escape_analysis.rs:39:13
3+
|
4+
LL | fn warn_arg(x: Box<A>) {
5+
| ^
6+
|
7+
= note: `-D clippy::boxed-local` implied by `-D warnings`
8+
9+
error: local variable doesn't need to be boxed here
10+
--> $DIR/escape_analysis.rs:130:12
11+
|
12+
LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
13+
| ^^^^^^^^^^^
14+
15+
error: aborting due to 2 previous errors
16+

0 commit comments

Comments
 (0)