about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2019-09-20 16:07:13 +0900
committerManish Goregaokar <manishsmail@gmail.com>2019-09-21 10:01:06 +0900
commitee9e1af4ed55cee61ec278e83c229fda0eff22ec (patch)
treed0ad54ba71b2dac03373c9bb59d166149935fbf1
parenta2ab0698ccf7e53a80e8eb044bad7db9b1544539 (diff)
downloadrust-ee9e1af4ed55cee61ec278e83c229fda0eff22ec.tar.gz
rust-ee9e1af4ed55cee61ec278e83c229fda0eff22ec.zip
implicit_return: make it use a rustfix test
-rw-r--r--tests/ui/implicit_return.fixed102
-rw-r--r--tests/ui/implicit_return.rs3
-rw-r--r--tests/ui/implicit_return.stderr22
3 files changed, 116 insertions, 11 deletions
diff --git a/tests/ui/implicit_return.fixed b/tests/ui/implicit_return.fixed
new file mode 100644
index 00000000000..dd42f06664e
--- /dev/null
+++ b/tests/ui/implicit_return.fixed
@@ -0,0 +1,102 @@
+// run-rustfix
+
+#![warn(clippy::implicit_return)]
+#![allow(clippy::needless_return, unused)]
+
+fn test_end_of_fn() -> bool {
+    if true {
+        // no error!
+        return true;
+    }
+
+    return true
+}
+
+#[allow(clippy::needless_bool)]
+fn test_if_block() -> bool {
+    if true {
+        return true
+    } else {
+        return false
+    }
+}
+
+#[allow(clippy::match_bool)]
+#[rustfmt::skip]
+fn test_match(x: bool) -> bool {
+    match x {
+        true => return false,
+        false => { return true },
+    }
+}
+
+#[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 {
+        return true;
+    }
+}
+
+#[allow(clippy::never_loop)]
+fn test_loop_with_block() -> bool {
+    loop {
+        {
+            return true;
+        }
+    }
+}
+
+#[allow(clippy::never_loop)]
+fn test_loop_with_nests() -> bool {
+    loop {
+        if true {
+            return 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 _ = || { return true };
+    let _ = || return true;
+}
+
+fn test_panic() -> bool {
+    panic!()
+}
+
+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();
+}
diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs
index 47e0679c430..5abbf6a5583 100644
--- a/tests/ui/implicit_return.rs
+++ b/tests/ui/implicit_return.rs
@@ -1,4 +1,7 @@
+// run-rustfix
+
 #![warn(clippy::implicit_return)]
+#![allow(clippy::needless_return, unused)]
 
 fn test_end_of_fn() -> bool {
     if true {
diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr
index 41b0873317e..21822344437 100644
--- a/tests/ui/implicit_return.stderr
+++ b/tests/ui/implicit_return.stderr
@@ -1,5 +1,5 @@
 error: missing return statement
-  --> $DIR/implicit_return.rs:9:5
+  --> $DIR/implicit_return.rs:12:5
    |
 LL |     true
    |     ^^^^ help: add `return` as shown: `return true`
@@ -7,61 +7,61 @@ LL |     true
    = note: `-D clippy::implicit-return` implied by `-D warnings`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:15:9
+  --> $DIR/implicit_return.rs:18:9
    |
 LL |         true
    |         ^^^^ help: add `return` as shown: `return true`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:17:9
+  --> $DIR/implicit_return.rs:20:9
    |
 LL |         false
    |         ^^^^^ help: add `return` as shown: `return false`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:25:17
+  --> $DIR/implicit_return.rs:28:17
    |
 LL |         true => false,
    |                 ^^^^^ help: add `return` as shown: `return false`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:26:20
+  --> $DIR/implicit_return.rs:29:20
    |
 LL |         false => { true },
    |                    ^^^^ help: add `return` as shown: `return true`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:41:9
+  --> $DIR/implicit_return.rs:44:9
    |
 LL |         break true;
    |         ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:49:13
+  --> $DIR/implicit_return.rs:52:13
    |
 LL |             break true;
    |             ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:58:13
+  --> $DIR/implicit_return.rs:61:13
    |
 LL |             break true;
    |             ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:76:18
+  --> $DIR/implicit_return.rs:79:18
    |
 LL |     let _ = || { true };
    |                  ^^^^ help: add `return` as shown: `return true`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:77:16
+  --> $DIR/implicit_return.rs:80:16
    |
 LL |     let _ = || true;
    |                ^^^^ help: add `return` as shown: `return true`
 
 error: missing return statement
-  --> $DIR/implicit_return.rs:85:5
+  --> $DIR/implicit_return.rs:88:5
    |
 LL |     format!("test {}", "test")
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")`