]> git.lizzy.rs Git - rust.git/commitdiff
fixed #606
authorllogiq <bogusandre@gmail.com>
Mon, 1 Feb 2016 19:37:07 +0000 (20:37 +0100)
committerllogiq <bogusandre@gmail.com>
Mon, 1 Feb 2016 19:37:07 +0000 (20:37 +0100)
src/escape.rs
tests/compile-fail/escape_analysis.rs

index edc7b5c6fbbddf284bf0a52546de8ce54d41cf4e..68dd2307e3fe890613fb3e1bc815678150b5ebf8 100644 (file)
@@ -31,9 +31,9 @@
 /// ```
 declare_lint!(pub BOXED_LOCAL, Warn, "using Box<T> where unnecessary");
 
-fn is_box(ty: ty::Ty) -> bool {
+fn is_non_trait_box(ty: ty::Ty) -> bool {
     match ty.sty {
-        ty::TyBox(..) => true,
+        ty::TyBox(ref inner) => !inner.is_trait(),
         _ => false
     }
 }
@@ -90,7 +90,7 @@ fn consume_pat(&mut self, consume_pat: &Pat, cmt: cmt<'tcx>, _: ConsumeMode) {
             if let Some(NodeExpr(..)) = map.find(map.get_parent_node(consume_pat.id)) {
                 return;
             }
-            if is_box(cmt.ty) {
+            if is_non_trait_box(cmt.ty) {
                 self.set.insert(consume_pat.id);
             }
             return;
@@ -101,7 +101,7 @@ fn consume_pat(&mut self, consume_pat: &Pat, cmt: cmt<'tcx>, _: ConsumeMode) {
                     if let DeclLocal(ref loc) = decl.node {
                         if let Some(ref ex) = loc.init {
                             if let ExprBox(..) = ex.node {
-                                if is_box(cmt.ty) {
+                                if is_non_trait_box(cmt.ty) {
                                     // let x = box (...)
                                     self.set.insert(consume_pat.id);
                                 }
index f3aa8bff41c2d8c1da734803816e96941bbf6fb2..c0893bcd767b111c09310d72e4b3d935777a3105 100644 (file)
@@ -11,9 +11,24 @@ impl A {
     fn foo(&self){}
 }
 
+trait Z {
+    fn bar(&self);
+}
+
+impl Z for A {
+    fn bar(&self) {
+        //nothing
+    }
+}
+
 fn main() {
 }
 
+fn ok_box_trait(boxed_trait: &Box<Z>) {
+    let boxed_local = boxed_trait;
+    // done
+}
+
 fn warn_call() {
     let x = box A; //~ ERROR local variable
     x.foo();