Merge pull request #608 from sanxiyn/escape-closure-arg

Skip escape analysis for closure arguments
This commit is contained in:
llogiq 2016-02-01 13:04:46 +01:00
commit 4da023bfd6
2 changed files with 13 additions and 6 deletions

View file

@ -1,5 +1,5 @@
use rustc::lint::*; use rustc::lint::*;
use rustc::front::map::Node::NodeStmt; use rustc::front::map::Node::{NodeExpr, NodeStmt};
use rustc_front::hir::*; use rustc_front::hir::*;
use rustc_front::intravisit as visit; use rustc_front::intravisit as visit;
use rustc::middle::ty; use rustc::middle::ty;
@ -84,17 +84,19 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
} }
fn matched_pat(&mut self, _: &Pat, _: cmt<'tcx>, _: MatchMode) {} fn matched_pat(&mut self, _: &Pat, _: cmt<'tcx>, _: MatchMode) {}
fn consume_pat(&mut self, consume_pat: &Pat, cmt: cmt<'tcx>, _: ConsumeMode) { fn consume_pat(&mut self, consume_pat: &Pat, cmt: cmt<'tcx>, _: ConsumeMode) {
if self.cx.tcx.map.is_argument(consume_pat.id) { let map = &self.cx.tcx.map;
if map.is_argument(consume_pat.id) {
// Skip closure arguments
if let Some(NodeExpr(..)) = map.find(map.get_parent_node(consume_pat.id)) {
return;
}
if is_box(cmt.ty) { if is_box(cmt.ty) {
self.set.insert(consume_pat.id); self.set.insert(consume_pat.id);
} }
return; return;
} }
if let Categorization::Rvalue(..) = cmt.cat { if let Categorization::Rvalue(..) = cmt.cat {
if let Some(NodeStmt(st)) = self.cx if let Some(NodeStmt(st)) = map.find(map.get_parent_node(cmt.id)) {
.tcx
.map
.find(self.cx.tcx.map.get_parent_node(cmt.id)) {
if let StmtDecl(ref decl, _) = st.node { if let StmtDecl(ref decl, _) = st.node {
if let DeclLocal(ref loc) = decl.node { if let DeclLocal(ref loc) = decl.node {
if let Some(ref ex) = loc.init { if let Some(ref ex) = loc.init {

View file

@ -23,6 +23,11 @@ fn warn_arg(x: Box<A>) { //~ ERROR local variable
x.foo(); x.foo();
} }
fn nowarn_closure_arg() {
let x = Some(box A);
x.map_or((), |x| take_ref(&x));
}
fn warn_rename_call() { fn warn_rename_call() {
let x = box A; let x = box A;