Add tests for empty blocks
This commit is contained in:
parent
a9cde3a804
commit
77dd0ea62a
@ -20,7 +20,6 @@ impl Bar {
|
||||
}
|
||||
|
||||
fn bad() {
|
||||
foo({});
|
||||
foo({
|
||||
1;
|
||||
});
|
||||
@ -29,7 +28,6 @@ fn bad() {
|
||||
foo(1);
|
||||
foo(2);
|
||||
});
|
||||
foo3({}, 2, 2);
|
||||
let b = Bar;
|
||||
b.bar({
|
||||
1;
|
||||
|
@ -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
|
||||
@ -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));
|
||||
| ^^^^^^^^^^^
|
||||
@ -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);
|
||||
@ -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 | | });
|
||||
@ -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));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -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);
|
||||
@ -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 | | {
|
||||
@ -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))
|
||||
| ^^^^^^^^^^^^
|
||||
@ -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
tests/ui/unit_arg_empty_blocks.rs
Normal file
26
tests/ui/unit_arg_empty_blocks.rs
Normal file
@ -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
tests/ui/unit_arg_empty_blocks.stderr
Normal file
51
tests/ui/unit_arg_empty_blocks.stderr
Normal file
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user