]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/implicit_return.rs
Fix `implicit_return` suggestion for async functions
[rust.git] / tests / ui / implicit_return.rs
index 0fe4a283abfbc99ecd2e1abf4bbeb9760da5d786..45bbc2ec670e05463d1a0f8d6f8d5fc557561cfe 100644 (file)
@@ -1,23 +1,22 @@
+// edition:2018
+// run-rustfix
+
 #![warn(clippy::implicit_return)]
+#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
 
 fn test_end_of_fn() -> bool {
     if true {
         // no error!
         return true;
     }
+
     true
 }
 
-#[allow(clippy::needless_bool)]
 fn test_if_block() -> bool {
-    if true {
-        true
-    } else {
-        false
-    }
+    if true { true } else { false }
 }
 
-#[allow(clippy::match_bool)]
 #[rustfmt::skip]
 fn test_match(x: bool) -> bool {
     match x {
@@ -26,14 +25,19 @@ fn test_match(x: bool) -> bool {
     }
 }
 
-#[allow(clippy::never_loop)]
+fn test_match_with_unreachable(x: bool) -> bool {
+    match x {
+        true => return false,
+        false => unreachable!(),
+    }
+}
+
 fn test_loop() -> bool {
     loop {
         break true;
     }
 }
 
-#[allow(clippy::never_loop)]
 fn test_loop_with_block() -> bool {
     loop {
         {
@@ -42,7 +46,6 @@ fn test_loop_with_block() -> bool {
     }
 }
 
-#[allow(clippy::never_loop)]
 fn test_loop_with_nests() -> bool {
     loop {
         if true {
@@ -53,18 +56,76 @@ fn test_loop_with_nests() -> bool {
     }
 }
 
+#[allow(clippy::redundant_pattern_matching)]
+fn test_loop_with_if_let() -> bool {
+    loop {
+        if let Some(x) = Some(true) {
+            return x;
+        }
+    }
+}
+
 fn test_closure() {
     #[rustfmt::skip]
     let _ = || { true };
     let _ = || true;
 }
 
-fn main() {
-    let _ = test_end_of_fn();
-    let _ = test_if_block();
-    let _ = test_match(true);
-    let _ = test_loop();
-    let _ = test_loop_with_block();
-    let _ = test_loop_with_nests();
-    test_closure();
+fn test_panic() -> bool {
+    panic!()
+}
+
+fn test_return_macro() -> String {
+    format!("test {}", "test")
 }
+
+fn macro_branch_test() -> bool {
+    macro_rules! m {
+        ($t:expr, $f:expr) => {
+            if true { $t } else { $f }
+        };
+    }
+    m!(true, false)
+}
+
+fn loop_test() -> bool {
+    'outer: loop {
+        if true {
+            break true;
+        }
+
+        let _ = loop {
+            if false {
+                break 'outer false;
+            }
+            if true {
+                break true;
+            }
+        };
+    }
+}
+
+fn loop_macro_test() -> bool {
+    macro_rules! m {
+        ($e:expr) => {
+            break $e
+        };
+    }
+    loop {
+        m!(true);
+    }
+}
+
+fn divergent_test() -> bool {
+    fn diverge() -> ! {
+        panic!()
+    }
+    diverge()
+}
+
+// issue #6940
+async fn foo() -> bool {
+    true
+}
+
+fn main() {}