diff options
| author | llogiq <bogusandre@gmail.com> | 2016-01-16 00:03:58 +0100 |
|---|---|---|
| committer | llogiq <bogusandre@gmail.com> | 2016-01-16 00:03:58 +0100 |
| commit | 840d87022e33ddd0a3e6ac40b26a4a4fc4fcb32c (patch) | |
| tree | e06dc7208b12e3b3ca291e804893209760a50e97 /src | |
| parent | da8a788b778ef0fcfdb3ff36ed3b9ce487e276dc (diff) | |
| parent | 07830c44af2bc95332b36b51434bd73300c33fc1 (diff) | |
| download | rust-840d87022e33ddd0a3e6ac40b26a4a4fc4fcb32c.tar.gz rust-840d87022e33ddd0a3e6ac40b26a4a4fc4fcb32c.zip | |
Merge pull request #523 from sanxiyn/escape-arg
Extend escape analysis to arguments
Diffstat (limited to 'src')
| -rw-r--r-- | src/escape.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/escape.rs b/src/escape.rs index 079fdcf09a0..8ef64aee84c 100644 --- a/src/escape.rs +++ b/src/escape.rs @@ -31,6 +31,13 @@ pub struct EscapePass; /// ``` declare_lint!(pub BOXED_LOCAL, Warn, "using Box<T> where unnecessary"); +fn is_box(ty: ty::Ty) -> bool { + match ty.sty { + ty::TyBox(..) => true, + _ => false + } +} + struct EscapeDelegate<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, set: NodeSet, @@ -77,6 +84,12 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } fn matched_pat(&mut self, _: &Pat, _: cmt<'tcx>, _: MatchMode) {} fn consume_pat(&mut self, consume_pat: &Pat, cmt: cmt<'tcx>, _: ConsumeMode) { + if self.cx.tcx.map.is_argument(consume_pat.id) { + if is_box(cmt.ty) { + self.set.insert(consume_pat.id); + } + return; + } if let Categorization::Rvalue(..) = cmt.cat { if let Some(Node::NodeStmt(st)) = self.cx .tcx @@ -86,7 +99,7 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { if let DeclLocal(ref loc) = decl.node { if let Some(ref ex) = loc.init { if let ExprBox(..) = ex.node { - if let ty::TyBox(..) = cmt.ty.sty { + if is_box(cmt.ty) { // let x = box (...) self.set.insert(consume_pat.id); } |
