Skip to content

Commit

Permalink
Don't lint unit args if expression kind is path
Browse files Browse the repository at this point in the history
  • Loading branch information
mdm committed Feb 24, 2021
1 parent eb476c6 commit 9fe9d94
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 96 deletions.
14 changes: 4 additions & 10 deletions clippy_lints/src/types.rs
Expand Up @@ -955,16 +955,10 @@ impl<'tcx> LateLintPass<'tcx> for UnitArg {
.iter()
.filter(|arg| {
if is_unit(cx.typeck_results().expr_ty(arg)) && !is_unit_literal(arg) {
match &arg.kind {
ExprKind::Block(..)
| ExprKind::Call(..)
| ExprKind::If(..)
| ExprKind::MethodCall(..) => true,
ExprKind::Match(..) => {
!matches!(&arg.kind, ExprKind::Match(.., MatchSource::TryDesugar))
},
_ => false,
}
!matches!(
&arg.kind,
ExprKind::Match(.., MatchSource::TryDesugar) | ExprKind::Path(..)
)
} else {
false
}
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/unit_arg.rs
Expand Up @@ -27,6 +27,10 @@ impl Bar {
}
}

fn baz<T: Debug>(t: T) {
foo(t);
}

fn bad() {
foo({
1;
Expand Down Expand Up @@ -73,6 +77,7 @@ fn ok() {
question_mark();
let named_unit_arg = ();
foo(named_unit_arg);
baz(());
}

fn question_mark() -> Result<(), ()> {
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/unit_arg.stderr
@@ -1,5 +1,5 @@
error: passing a unit value to a function
--> $DIR/unit_arg.rs:31:5
--> $DIR/unit_arg.rs:35:5
|
LL | / foo({
LL | | 1;
Expand All @@ -20,7 +20,7 @@ LL | foo(());
|

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

error: passing a unit value to a function
--> $DIR/unit_arg.rs:35:5
--> $DIR/unit_arg.rs:39:5
|
LL | / foo({
LL | | foo(1);
Expand All @@ -54,7 +54,7 @@ LL | foo(());
|

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

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

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

error: passing unit values to a function
--> $DIR/unit_arg.rs:48:5
--> $DIR/unit_arg.rs:52:5
|
LL | / taking_multiple_units(
LL | | {
Expand Down Expand Up @@ -140,7 +140,7 @@ LL | foo(2);
...

error: passing a unit value to a function
--> $DIR/unit_arg.rs:59:13
--> $DIR/unit_arg.rs:63:13
|
LL | None.or(Some(foo(2)));
| ^^^^^^^^^^^^
Expand All @@ -154,7 +154,7 @@ LL | });
|

error: passing a unit value to a function
--> $DIR/unit_arg.rs:62:5
--> $DIR/unit_arg.rs:66:5
|
LL | foo(foo(()));
| ^^^^^^^^^^^^
Expand All @@ -166,7 +166,7 @@ LL | foo(());
|

error: passing a unit value to a function
--> $DIR/unit_arg.rs:97:5
--> $DIR/unit_arg.rs:102:5
|
LL | Some(foo(1))
| ^^^^^^^^^^^^
Expand Down
35 changes: 0 additions & 35 deletions tests/ui/unit_arg_expressions.rs

This file was deleted.

41 changes: 0 additions & 41 deletions tests/ui/unit_arg_expressions.stderr

This file was deleted.

0 comments on commit 9fe9d94

Please sign in to comment.