Skip to content

Commit 9fe9d94

Browse files
committed
Don't lint unit args if expression kind is path
1 parent eb476c6 commit 9fe9d94

File tree

5 files changed

+19
-96
lines changed

5 files changed

+19
-96
lines changed

clippy_lints/src/types.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -955,16 +955,10 @@ impl<'tcx> LateLintPass<'tcx> for UnitArg {
955955
.iter()
956956
.filter(|arg| {
957957
if is_unit(cx.typeck_results().expr_ty(arg)) && !is_unit_literal(arg) {
958-
match &arg.kind {
959-
ExprKind::Block(..)
960-
| ExprKind::Call(..)
961-
| ExprKind::If(..)
962-
| ExprKind::MethodCall(..) => true,
963-
ExprKind::Match(..) => {
964-
!matches!(&arg.kind, ExprKind::Match(.., MatchSource::TryDesugar))
965-
},
966-
_ => false,
967-
}
958+
!matches!(
959+
&arg.kind,
960+
ExprKind::Match(.., MatchSource::TryDesugar) | ExprKind::Path(..)
961+
)
968962
} else {
969963
false
970964
}

tests/ui/unit_arg.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ impl Bar {
2727
}
2828
}
2929

30+
fn baz<T: Debug>(t: T) {
31+
foo(t);
32+
}
33+
3034
fn bad() {
3135
foo({
3236
1;
@@ -73,6 +77,7 @@ fn ok() {
7377
question_mark();
7478
let named_unit_arg = ();
7579
foo(named_unit_arg);
80+
baz(());
7681
}
7782

7883
fn question_mark() -> Result<(), ()> {

tests/ui/unit_arg.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: passing a unit value to a function
2-
--> $DIR/unit_arg.rs:31:5
2+
--> $DIR/unit_arg.rs:35:5
33
|
44
LL | / foo({
55
LL | | 1;
@@ -20,7 +20,7 @@ LL | foo(());
2020
|
2121

2222
error: passing a unit value to a function
23-
--> $DIR/unit_arg.rs:34:5
23+
--> $DIR/unit_arg.rs:38:5
2424
|
2525
LL | foo(foo(1));
2626
| ^^^^^^^^^^^
@@ -32,7 +32,7 @@ LL | foo(());
3232
|
3333

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

5656
error: passing a unit value to a function
57-
--> $DIR/unit_arg.rs:40:5
57+
--> $DIR/unit_arg.rs:44:5
5858
|
5959
LL | / b.bar({
6060
LL | | 1;
@@ -74,7 +74,7 @@ LL | b.bar(());
7474
|
7575

7676
error: passing unit values to a function
77-
--> $DIR/unit_arg.rs:43:5
77+
--> $DIR/unit_arg.rs:47:5
7878
|
7979
LL | taking_multiple_units(foo(0), foo(1));
8080
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -87,7 +87,7 @@ LL | taking_multiple_units((), ());
8787
|
8888

8989
error: passing unit values to a function
90-
--> $DIR/unit_arg.rs:44:5
90+
--> $DIR/unit_arg.rs:48:5
9191
|
9292
LL | / taking_multiple_units(foo(0), {
9393
LL | | foo(1);
@@ -110,7 +110,7 @@ LL | taking_multiple_units((), ());
110110
|
111111

112112
error: passing unit values to a function
113-
--> $DIR/unit_arg.rs:48:5
113+
--> $DIR/unit_arg.rs:52:5
114114
|
115115
LL | / taking_multiple_units(
116116
LL | | {
@@ -140,7 +140,7 @@ LL | foo(2);
140140
...
141141

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

156156
error: passing a unit value to a function
157-
--> $DIR/unit_arg.rs:62:5
157+
--> $DIR/unit_arg.rs:66:5
158158
|
159159
LL | foo(foo(()));
160160
| ^^^^^^^^^^^^
@@ -166,7 +166,7 @@ LL | foo(());
166166
|
167167

168168
error: passing a unit value to a function
169-
--> $DIR/unit_arg.rs:97:5
169+
--> $DIR/unit_arg.rs:102:5
170170
|
171171
LL | Some(foo(1))
172172
| ^^^^^^^^^^^^

tests/ui/unit_arg_expressions.rs

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/ui/unit_arg_expressions.stderr

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)