]> git.lizzy.rs Git - rust.git/commitdiff
Skip escape analysis for closure arguments
authorSeo Sanghyeon <sanxiyn@gmail.com>
Mon, 1 Feb 2016 11:35:01 +0000 (20:35 +0900)
committerSeo Sanghyeon <sanxiyn@gmail.com>
Mon, 1 Feb 2016 11:35:01 +0000 (20:35 +0900)
src/escape.rs
tests/compile-fail/escape_analysis.rs

index 32dbbb992267d878ce3110c42a0c4e7fb8c05b4b..edc7b5c6fbbddf284bf0a52546de8ce54d41cf4e 100644 (file)
@@ -1,5 +1,5 @@
 use rustc::lint::*;
-use rustc::front::map::Node::NodeStmt;
+use rustc::front::map::Node::{NodeExpr, NodeStmt};
 use rustc_front::hir::*;
 use rustc_front::intravisit as visit;
 use rustc::middle::ty;
@@ -84,17 +84,19 @@ fn consume(&mut self, _: NodeId, _: Span, cmt: cmt<'tcx>, mode: ConsumeMode) {
     }
     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) {
+        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) {
                 self.set.insert(consume_pat.id);
             }
             return;
         }
         if let Categorization::Rvalue(..) = cmt.cat {
-            if let Some(NodeStmt(st)) = self.cx
-                                                  .tcx
-                                                  .map
-                                                  .find(self.cx.tcx.map.get_parent_node(cmt.id)) {
+            if let Some(NodeStmt(st)) = map.find(map.get_parent_node(cmt.id)) {
                 if let StmtDecl(ref decl, _) = st.node {
                     if let DeclLocal(ref loc) = decl.node {
                         if let Some(ref ex) = loc.init {
index 28154d9414e188b48f7ba8c24a3b88275fc43bbf..f3aa8bff41c2d8c1da734803816e96941bbf6fb2 100644 (file)
@@ -23,6 +23,11 @@ fn warn_arg(x: Box<A>) { //~ ERROR local variable
     x.foo();
 }
 
+fn nowarn_closure_arg() {
+    let x = Some(box A);
+    x.map_or((), |x| take_ref(&x));
+}
+
 fn warn_rename_call() {
     let x = box A;