]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/implicit_return.rs
Auto merge of #4478 - tsurai:master, r=flip1995
[rust.git] / tests / ui / implicit_return.rs
index 6188835e555a07812e3faaaa856cdb7592fd3696..47e0679c430d78dd49f4d851f5c3ad1cfae1cbd1 100644 (file)
@@ -1,12 +1,3 @@
-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 #![warn(clippy::implicit_return)]
 
 fn test_end_of_fn() -> bool {
@@ -14,6 +5,7 @@ fn test_end_of_fn() -> bool {
         // no error!
         return true;
     }
+
     true
 }
 
@@ -35,6 +27,14 @@ 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,
+        false => unreachable!(),
+    }
+}
+
 #[allow(clippy::never_loop)]
 fn test_loop() -> bool {
     loop {
@@ -42,16 +42,58 @@ fn test_loop() -> bool {
     }
 }
 
+#[allow(clippy::never_loop)]
+fn test_loop_with_block() -> bool {
+    loop {
+        {
+            break true;
+        }
+    }
+}
+
+#[allow(clippy::never_loop)]
+fn test_loop_with_nests() -> bool {
+    loop {
+        if true {
+            break true;
+        } else {
+            let _ = true;
+        }
+    }
+}
+
+#[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 test_panic() -> bool {
+    panic!()
+}
+
+fn test_return_macro() -> String {
+    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();
 }