]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/escape_analysis.rs
Auto merge of #68717 - petrochenkov:stabexpat, r=varkor
[rust.git] / tests / ui / escape_analysis.rs
index b99534d05e17077249e6a57f035947b875729a8a..c0a52d832c00a2793fa49252ab0bbb88c511e4c0 100644 (file)
@@ -1,14 +1,18 @@
-#![feature(plugin, box_syntax)]
-
-#![allow(warnings, clippy)]
-
-#![warn(boxed_local)]
+#![feature(box_syntax)]
+#![allow(
+    clippy::borrowed_box,
+    clippy::needless_pass_by_value,
+    clippy::unused_unit,
+    clippy::redundant_clone,
+    clippy::match_single_binding
+)]
+#![warn(clippy::boxed_local)]
 
 #[derive(Clone)]
 struct A;
 
 impl A {
-    fn foo(&self){}
+    fn foo(&self) {}
 }
 
 trait Z {
@@ -21,10 +25,9 @@ fn bar(&self) {
     }
 }
 
-fn main() {
-}
+fn main() {}
 
-fn ok_box_trait(boxed_trait: &Box<Z>) {
+fn ok_box_trait(boxed_trait: &Box<dyn Z>) {
     let boxed_local = boxed_trait;
     // done
 }
@@ -60,8 +63,7 @@ fn warn_pass() {
 }
 
 fn nowarn_return() -> Box<A> {
-    let fx = box A;
-    fx // moved out, "escapes"
+    box A // moved out, "escapes"
 }
 
 fn nowarn_move() {
@@ -78,11 +80,9 @@ fn nowarn_pass() {
     take_box(&bx); // fn needs &Box
 }
 
-
 fn take_box(x: &Box<A>) {}
 fn take_ref(x: &A) {}
 
-
 fn nowarn_ref_take() {
     // false positive, should actually warn
     let x = box A;
@@ -93,14 +93,15 @@ fn nowarn_ref_take() {
 fn nowarn_match() {
     let x = box A; // moved into a match
     match x {
-        y => drop(y)
+        y => drop(y),
     }
 }
 
 fn warn_match() {
     let x = box A;
-    match &x { // not moved
-        ref y => ()
+    match &x {
+        // not moved
+        ref y => (),
     }
 }
 
@@ -108,12 +109,12 @@ fn nowarn_large_array() {
     // should not warn, is large array
     // and should not be on stack
     let x = box [1; 10000];
-    match &x { // not moved
-        ref y => ()
+    match &x {
+        // not moved
+        ref y => (),
     }
 }
 
-
 /// ICE regression test
 pub trait Foo {
     type Item;
@@ -127,5 +128,49 @@ pub struct PeekableSeekable<I: Foo> {
     _peeked: I::Item,
 }
 
-pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {
+pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
+
+/// Regression for #916, #1123
+///
+/// This shouldn't warn for `boxed_local`as the implementation of a trait
+/// can't change much about the trait definition.
+trait BoxedAction {
+    fn do_sth(self: Box<Self>);
+}
+
+impl BoxedAction for u64 {
+    fn do_sth(self: Box<Self>) {
+        println!("{}", *self)
+    }
+}
+
+/// Regression for #1478
+///
+/// This shouldn't warn for `boxed_local`as self itself is a box type.
+trait MyTrait {
+    fn do_sth(self);
+}
+
+impl<T> MyTrait for Box<T> {
+    fn do_sth(self) {}
+}
+
+// Issue #3739 - capture in closures
+mod issue_3739 {
+    use super::A;
+
+    fn consume<T>(_: T) {}
+    fn borrow<T>(_: &T) {}
+
+    fn closure_consume(x: Box<A>) {
+        let _ = move || {
+            consume(x);
+        };
+    }
+
+    fn closure_borrow(x: Box<A>) {
+        let _ = || {
+            borrow(&x);
+        };
+    }
 }