diff --git a/tests/ui/unit_arg.fixed b/tests/ui/unit_arg.fixed new file mode 100644 index 000000000..d8f3e854c --- /dev/null +++ b/tests/ui/unit_arg.fixed @@ -0,0 +1,53 @@ +// run-rustfix +#![warn(clippy::unit_arg)] +#![allow(clippy::no_effect, unused_must_use)] + +use std::fmt::Debug; + +fn foo(t: T) { + println!("{:?}", t); +} + +fn foo3(t1: T1, t2: T2, t3: T3) { + println!("{:?}, {:?}, {:?}", t1, t2, t3); +} + +struct Bar; + +impl Bar { + fn bar(&self, t: T) { + println!("{:?}", t); + } +} + +fn bad() { + foo(()); + foo(()); + foo(()); + foo(()); + foo3((), 2, 2); + let b = Bar; + b.bar(()); +} + +fn ok() { + foo(()); + foo(1); + foo({ 1 }); + foo3("a", 3, vec![3]); + let b = Bar; + b.bar({ 1 }); + b.bar(()); + question_mark(); +} + +fn question_mark() -> Result<(), ()> { + Ok(Ok(())?)?; + Ok(Ok(()))??; + Ok(()) +} + +fn main() { + bad(); + ok(); +} diff --git a/tests/ui/unit_arg.rs b/tests/ui/unit_arg.rs index 7e421a0d6..1403870ea 100644 --- a/tests/ui/unit_arg.rs +++ b/tests/ui/unit_arg.rs @@ -1,5 +1,6 @@ +// run-rustfix #![warn(clippy::unit_arg)] -#![allow(clippy::no_effect)] +#![allow(clippy::no_effect, unused_must_use)] use std::fmt::Debug; diff --git a/tests/ui/unit_arg.stderr b/tests/ui/unit_arg.stderr index 1da00b6f5..862534b18 100644 --- a/tests/ui/unit_arg.stderr +++ b/tests/ui/unit_arg.stderr @@ -1,5 +1,5 @@ error: passing a unit value to a function - --> $DIR/unit_arg.rs:23:9 + --> $DIR/unit_arg.rs:24:9 | LL | foo({}); | ^^ @@ -11,7 +11,7 @@ LL | foo(()); | ^^ error: passing a unit value to a function - --> $DIR/unit_arg.rs:24:9 + --> $DIR/unit_arg.rs:25:9 | LL | foo({ | _________^ @@ -24,7 +24,7 @@ LL | foo(()); | ^^ error: passing a unit value to a function - --> $DIR/unit_arg.rs:27:9 + --> $DIR/unit_arg.rs:28:9 | LL | foo(foo(1)); | ^^^^^^ @@ -34,7 +34,7 @@ LL | foo(()); | ^^ error: passing a unit value to a function - --> $DIR/unit_arg.rs:28:9 + --> $DIR/unit_arg.rs:29:9 | LL | foo({ | _________^ @@ -48,7 +48,7 @@ LL | foo(()); | ^^ error: passing a unit value to a function - --> $DIR/unit_arg.rs:32:10 + --> $DIR/unit_arg.rs:33:10 | LL | foo3({}, 2, 2); | ^^ @@ -58,7 +58,7 @@ LL | foo3((), 2, 2); | ^^ error: passing a unit value to a function - --> $DIR/unit_arg.rs:34:11 + --> $DIR/unit_arg.rs:35:11 | LL | b.bar({ | ___________^