diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index 79dac925f08c..cce543006d77 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 8679706f8ec8..8e3f1811c659 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 000000000000..a6807cb2e973 --- /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: 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 000000000000..9fb08106b723 --- /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 +