about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarc Dominik Migge <marcmigge@gmx.net>2021-01-18 20:18:56 +0100
committerMarc Dominik Migge <marcmigge@gmx.net>2021-01-18 20:18:56 +0100
commiteb476c6c70bccb87378462e4854f8b8fa12c40be (patch)
treeb196e8b1c6922f5fb033e57bff6b34cfbb9b64eb
parent0c347d3d0686d8892512dcc1e13102d15afcc6dd (diff)
downloadrust-eb476c6c70bccb87378462e4854f8b8fa12c40be.tar.gz
rust-eb476c6c70bccb87378462e4854f8b8fa12c40be.zip
Split up tests for unit arg expressions
-rw-r--r--tests/ui/unit_arg.rs16
-rw-r--r--tests/ui/unit_arg.stderr42
-rw-r--r--tests/ui/unit_arg_expressions.rs35
-rw-r--r--tests/ui/unit_arg_expressions.stderr41
4 files changed, 78 insertions, 56 deletions
diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs
index 79dac925f08..cce543006d7 100644
--- a/tests/ui/unit_arg.rs
+++ b/tests/ui/unit_arg.rs
@@ -60,17 +60,6 @@ fn bad() {
     // in this case, the suggestion can be inlined, no need for a surrounding block
     // foo(()); foo(()) instead of { foo(()); foo(()) }
     foo(foo(()));
-    foo(if true {
-        1;
-    });
-    foo(match Some(1) {
-        Some(_) => {
-            1;
-        },
-        None => {
-            0;
-        },
-    });
 }
 
 fn ok() {
@@ -84,11 +73,6 @@ fn ok() {
     question_mark();
     let named_unit_arg = ();
     foo(named_unit_arg);
-    foo(if true { 1 } else { 0 });
-    foo(match Some(1) {
-        Some(_) => 1,
-        None => 0,
-    });
 }
 
 fn question_mark() -> Result<(), ()> {
diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr
index 8679706f8ec..8e3f1811c65 100644
--- a/tests/ui/unit_arg.stderr
+++ b/tests/ui/unit_arg.stderr
@@ -166,45 +166,7 @@ LL |     foo(());
    |
 
 error: passing a unit value to a function
-  --> $DIR/unit_arg.rs:63:5
-   |
-LL | /     foo(if true {
-LL | |         1;
-LL | |     });
-   | |______^
-   |
-help: move the expression in front of the call and replace it with the unit literal `()`
-   |
-LL |     if true {
-LL |         1;
-LL |     };
-LL |     foo(());
-   |
-
-error: passing a unit value to a function
-  --> $DIR/unit_arg.rs:66:5
-   |
-LL | /     foo(match Some(1) {
-LL | |         Some(_) => {
-LL | |             1;
-LL | |         },
-...  |
-LL | |         },
-LL | |     });
-   | |______^
-   |
-help: move the expression in front of the call and replace it with the unit literal `()`
-   |
-LL |     match Some(1) {
-LL |         Some(_) => {
-LL |             1;
-LL |         },
-LL |         None => {
-LL |             0;
- ...
-
-error: passing a unit value to a function
-  --> $DIR/unit_arg.rs:113:5
+  --> $DIR/unit_arg.rs:97:5
    |
 LL |     Some(foo(1))
    |     ^^^^^^^^^^^^
@@ -215,5 +177,5 @@ LL |     foo(1);
 LL |     Some(())
    |
 
-error: aborting due to 12 previous errors
+error: aborting due to 10 previous errors
 
diff --git a/tests/ui/unit_arg_expressions.rs b/tests/ui/unit_arg_expressions.rs
new file mode 100644
index 00000000000..a6807cb2e97
--- /dev/null
+++ b/tests/ui/unit_arg_expressions.rs
@@ -0,0 +1,35 @@
+#![warn(clippy::unit_arg)]
+#![allow(clippy::no_effect)]
+
+use std::fmt::Debug;
+
+fn foo<T: Debug>(t: T) {
+    println!("{:?}", t);
+}
+
+fn bad() {
+    foo(if true {
+        1;
+    });
+    foo(match Some(1) {
+        Some(_) => {
+            1;
+        },
+        None => {
+            0;
+        },
+    });
+}
+
+fn ok() {
+    foo(if true { 1 } else { 0 });
+    foo(match Some(1) {
+        Some(_) => 1,
+        None => 0,
+    });
+}
+
+fn main() {
+    bad();
+    ok();
+}
diff --git a/tests/ui/unit_arg_expressions.stderr b/tests/ui/unit_arg_expressions.stderr
new file mode 100644
index 00000000000..9fb08106b72
--- /dev/null
+++ b/tests/ui/unit_arg_expressions.stderr
@@ -0,0 +1,41 @@
+error: passing a unit value to a function
+  --> $DIR/unit_arg_expressions.rs:11:5
+   |
+LL | /     foo(if true {
+LL | |         1;
+LL | |     });
+   | |______^
+   |
+   = note: `-D clippy::unit-arg` implied by `-D warnings`
+help: move the expression in front of the call and replace it with the unit literal `()`
+   |
+LL |     if true {
+LL |         1;
+LL |     };
+LL |     foo(());
+   |
+
+error: passing a unit value to a function
+  --> $DIR/unit_arg_expressions.rs:14:5
+   |
+LL | /     foo(match Some(1) {
+LL | |         Some(_) => {
+LL | |             1;
+LL | |         },
+...  |
+LL | |         },
+LL | |     });
+   | |______^
+   |
+help: move the expression in front of the call and replace it with the unit literal `()`
+   |
+LL |     match Some(1) {
+LL |         Some(_) => {
+LL |             1;
+LL |         },
+LL |         None => {
+LL |             0;
+ ...
+
+error: aborting due to 2 previous errors
+