Move is_argument check into mutate

This commit is contained in:
flip1995 2019-10-06 14:49:26 +02:00
parent 3aa531c194
commit 3d39379f9c
No known key found for this signature in database
GPG Key ID: 693086869D506637
2 changed files with 31 additions and 13 deletions

View File

@ -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> {

View File

@ -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<A>) {
| ^
|
= 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<PeekableSeekable<&()>>) -> () {}
| ^^^^^^^^^^^
error: aborting due to 2 previous errors