Skip to content

Commit

Permalink
Add tests for empty blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed May 31, 2020
1 parent a9cde3a commit 77dd0ea
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 40 deletions.
2 changes: 0 additions & 2 deletions tests/ui/unit_arg.rs
Expand Up @@ -20,7 +20,6 @@ impl Bar {
}

fn bad() {
foo({});
foo({
1;
});
Expand All @@ -29,7 +28,6 @@ fn bad() {
foo(1);
foo(2);
});
foo3({}, 2, 2);
let b = Bar;
b.bar({
1;
Expand Down
46 changes: 8 additions & 38 deletions tests/ui/unit_arg.stderr
@@ -1,27 +1,12 @@
error: passing a unit value to a function
--> $DIR/unit_arg.rs:23:5
|
LL | foo({});
| ^^^^^^^
|
= note: `-D clippy::unit-arg` implied by `-D warnings`
help: move the expression in front of the call...
|
LL | {};
|
help: ...and use a unit literal instead
|
LL | foo(());
| ^^

error: passing a unit value to a function
--> $DIR/unit_arg.rs:24:5
|
LL | / foo({
LL | | 1;
LL | | });
| |______^
|
= note: `-D clippy::unit-arg` implied by `-D warnings`
help: remove the semicolon from the last statement in the block
|
LL | 1
Expand All @@ -38,7 +23,7 @@ LL | foo(());
| ^^

error: passing a unit value to a function
--> $DIR/unit_arg.rs:27:5
--> $DIR/unit_arg.rs:26:5
|
LL | foo(foo(1));
| ^^^^^^^^^^^
Expand All @@ -53,7 +38,7 @@ LL | foo(());
| ^^

error: passing a unit value to a function
--> $DIR/unit_arg.rs:28:5
--> $DIR/unit_arg.rs:27:5
|
LL | / foo({
LL | | foo(1);
Expand All @@ -80,21 +65,6 @@ LL | foo(());
error: passing a unit value to a function
--> $DIR/unit_arg.rs:32:5
|
LL | foo3({}, 2, 2);
| ^^^^^^^^^^^^^^
|
help: move the expression in front of the call...
|
LL | {};
|
help: ...and use a unit literal instead
|
LL | foo3((), 2, 2);
| ^^

error: passing a unit value to a function
--> $DIR/unit_arg.rs:34:5
|
LL | / b.bar({
LL | | 1;
LL | | });
Expand All @@ -116,7 +86,7 @@ LL | b.bar(());
| ^^

error: passing unit values to a function
--> $DIR/unit_arg.rs:37:5
--> $DIR/unit_arg.rs:35:5
|
LL | taking_multiple_units(foo(0), foo(1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -132,7 +102,7 @@ LL | taking_multiple_units((), ());
| ^^ ^^

error: passing unit values to a function
--> $DIR/unit_arg.rs:38:5
--> $DIR/unit_arg.rs:36:5
|
LL | / taking_multiple_units(foo(0), {
LL | | foo(1);
Expand All @@ -158,7 +128,7 @@ LL | taking_multiple_units((), ());
| ^^ ^^

error: passing unit values to a function
--> $DIR/unit_arg.rs:42:5
--> $DIR/unit_arg.rs:40:5
|
LL | / taking_multiple_units(
LL | | {
Expand Down Expand Up @@ -193,7 +163,7 @@ LL | (),
|

error: passing a unit value to a function
--> $DIR/unit_arg.rs:84:5
--> $DIR/unit_arg.rs:82:5
|
LL | Some(foo(1))
| ^^^^^^^^^^^^
Expand All @@ -207,5 +177,5 @@ help: ...and use a unit literal instead
LL | Some(())
| ^^

error: aborting due to 10 previous errors
error: aborting due to 8 previous errors

26 changes: 26 additions & 0 deletions tests/ui/unit_arg_empty_blocks.rs
@@ -0,0 +1,26 @@
#![warn(clippy::unit_arg)]
#![allow(clippy::no_effect, unused_must_use, unused_variables)]

use std::fmt::Debug;

fn foo<T: Debug>(t: T) {
println!("{:?}", t);
}

fn foo3<T1: Debug, T2: Debug, T3: Debug>(t1: T1, t2: T2, t3: T3) {
println!("{:?}, {:?}, {:?}", t1, t2, t3);
}

fn bad() {
foo({});
foo3({}, 2, 2);
taking_two_units({}, foo(0));
taking_three_units({}, foo(0), foo(1));
}

fn taking_two_units(a: (), b: ()) {}
fn taking_three_units(a: (), b: (), c: ()) {}

fn main() {
bad();
}
51 changes: 51 additions & 0 deletions tests/ui/unit_arg_empty_blocks.stderr
@@ -0,0 +1,51 @@
error: passing a unit value to a function
--> $DIR/unit_arg_empty_blocks.rs:15:5
|
LL | foo({});
| ^^^^--^
| |
| help: use a unit literal instead: `()`
|
= note: `-D clippy::unit-arg` implied by `-D warnings`

error: passing a unit value to a function
--> $DIR/unit_arg_empty_blocks.rs:16:5
|
LL | foo3({}, 2, 2);
| ^^^^^--^^^^^^^
| |
| help: use a unit literal instead: `()`

error: passing unit values to a function
--> $DIR/unit_arg_empty_blocks.rs:17:5
|
LL | taking_two_units({}, foo(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: move the expression in front of the call...
|
LL | foo(0);
|
help: ...and use unit literals instead
|
LL | taking_two_units((), ());
| ^^ ^^

error: passing unit values to a function
--> $DIR/unit_arg_empty_blocks.rs:18:5
|
LL | taking_three_units({}, foo(0), foo(1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: move the expressions in front of the call...
|
LL | foo(0);
LL | foo(1);
|
help: ...and use unit literals instead
|
LL | taking_three_units((), (), ());
| ^^ ^^ ^^

error: aborting due to 4 previous errors

0 comments on commit 77dd0ea

Please sign in to comment.