Split up tests for unit arg expressions
This commit is contained in:
parent
0c347d3d06
commit
eb476c6c70
@ -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<(), ()> {
|
||||
|
@ -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
|
||||
|
||||
|
35
tests/ui/unit_arg_expressions.rs
Normal file
35
tests/ui/unit_arg_expressions.rs
Normal file
@ -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();
|
||||
}
|
41
tests/ui/unit_arg_expressions.stderr
Normal file
41
tests/ui/unit_arg_expressions.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user