]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/implicit_return.fixed
Fix `implicit_return` suggestion for async functions
[rust.git] / tests / ui / implicit_return.fixed
index dd42f06664e155f926e85ea49236286bc79a915e..7698b88a88c8aa80a143ac27ab11e145a880ef51 100644 (file)
@@ -1,7 +1,8 @@
+// edition:2018
 // run-rustfix
 
 #![warn(clippy::implicit_return)]
-#![allow(clippy::needless_return, unused)]
+#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
 
 fn test_end_of_fn() -> bool {
     if true {
@@ -12,16 +13,10 @@ fn test_end_of_fn() -> bool {
     return true
 }
 
-#[allow(clippy::needless_bool)]
 fn test_if_block() -> bool {
-    if true {
-        return true
-    } else {
-        return false
-    }
+    if true { return true } else { return false }
 }
 
-#[allow(clippy::match_bool)]
 #[rustfmt::skip]
 fn test_match(x: bool) -> bool {
     match x {
@@ -30,7 +25,6 @@ fn test_match(x: bool) -> bool {
     }
 }
 
-#[allow(clippy::match_bool, clippy::needless_return)]
 fn test_match_with_unreachable(x: bool) -> bool {
     match x {
         true => return false,
@@ -38,14 +32,12 @@ fn test_match_with_unreachable(x: bool) -> bool {
     }
 }
 
-#[allow(clippy::never_loop)]
 fn test_loop() -> bool {
     loop {
         return true;
     }
 }
 
-#[allow(clippy::never_loop)]
 fn test_loop_with_block() -> bool {
     loop {
         {
@@ -54,7 +46,6 @@ fn test_loop_with_block() -> bool {
     }
 }
 
-#[allow(clippy::never_loop)]
 fn test_loop_with_nests() -> bool {
     loop {
         if true {
@@ -88,15 +79,53 @@ fn test_return_macro() -> String {
     return format!("test {}", "test")
 }
 
-fn main() {
-    let _ = test_end_of_fn();
-    let _ = test_if_block();
-    let _ = test_match(true);
-    let _ = test_match_with_unreachable(true);
-    let _ = test_loop();
-    let _ = test_loop_with_block();
-    let _ = test_loop_with_nests();
-    let _ = test_loop_with_if_let();
-    test_closure();
-    let _ = test_return_macro();
+fn macro_branch_test() -> bool {
+    macro_rules! m {
+        ($t:expr, $f:expr) => {
+            if true { $t } else { $f }
+        };
+    }
+    return m!(true, false)
 }
+
+fn loop_test() -> bool {
+    'outer: loop {
+        if true {
+            return true;
+        }
+
+        let _ = loop {
+            if false {
+                return false;
+            }
+            if true {
+                break true;
+            }
+        };
+    }
+}
+
+fn loop_macro_test() -> bool {
+    macro_rules! m {
+        ($e:expr) => {
+            break $e
+        };
+    }
+    return loop {
+        m!(true);
+    }
+}
+
+fn divergent_test() -> bool {
+    fn diverge() -> ! {
+        panic!()
+    }
+    diverge()
+}
+
+// issue #6940
+async fn foo() -> bool {
+    return true
+}
+
+fn main() {}