Skip to content

Commit 77dd0ea

Browse files
committed
Add tests for empty blocks
1 parent a9cde3a commit 77dd0ea

File tree

4 files changed

+85
-40
lines changed

4 files changed

+85
-40
lines changed

tests/ui/unit_arg.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ impl Bar {
2020
}
2121

2222
fn bad() {
23-
foo({});
2423
foo({
2524
1;
2625
});
@@ -29,7 +28,6 @@ fn bad() {
2928
foo(1);
3029
foo(2);
3130
});
32-
foo3({}, 2, 2);
3331
let b = Bar;
3432
b.bar({
3533
1;

tests/ui/unit_arg.stderr

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
error: passing a unit value to a function
22
--> $DIR/unit_arg.rs:23:5
33
|
4-
LL | foo({});
5-
| ^^^^^^^
6-
|
7-
= note: `-D clippy::unit-arg` implied by `-D warnings`
8-
help: move the expression in front of the call...
9-
|
10-
LL | {};
11-
|
12-
help: ...and use a unit literal instead
13-
|
14-
LL | foo(());
15-
| ^^
16-
17-
error: passing a unit value to a function
18-
--> $DIR/unit_arg.rs:24:5
19-
|
204
LL | / foo({
215
LL | | 1;
226
LL | | });
237
| |______^
248
|
9+
= note: `-D clippy::unit-arg` implied by `-D warnings`
2510
help: remove the semicolon from the last statement in the block
2611
|
2712
LL | 1
@@ -38,7 +23,7 @@ LL | foo(());
3823
| ^^
3924

4025
error: passing a unit value to a function
41-
--> $DIR/unit_arg.rs:27:5
26+
--> $DIR/unit_arg.rs:26:5
4227
|
4328
LL | foo(foo(1));
4429
| ^^^^^^^^^^^
@@ -53,7 +38,7 @@ LL | foo(());
5338
| ^^
5439

5540
error: passing a unit value to a function
56-
--> $DIR/unit_arg.rs:28:5
41+
--> $DIR/unit_arg.rs:27:5
5742
|
5843
LL | / foo({
5944
LL | | foo(1);
@@ -80,21 +65,6 @@ LL | foo(());
8065
error: passing a unit value to a function
8166
--> $DIR/unit_arg.rs:32:5
8267
|
83-
LL | foo3({}, 2, 2);
84-
| ^^^^^^^^^^^^^^
85-
|
86-
help: move the expression in front of the call...
87-
|
88-
LL | {};
89-
|
90-
help: ...and use a unit literal instead
91-
|
92-
LL | foo3((), 2, 2);
93-
| ^^
94-
95-
error: passing a unit value to a function
96-
--> $DIR/unit_arg.rs:34:5
97-
|
9868
LL | / b.bar({
9969
LL | | 1;
10070
LL | | });
@@ -116,7 +86,7 @@ LL | b.bar(());
11686
| ^^
11787

11888
error: passing unit values to a function
119-
--> $DIR/unit_arg.rs:37:5
89+
--> $DIR/unit_arg.rs:35:5
12090
|
12191
LL | taking_multiple_units(foo(0), foo(1));
12292
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -132,7 +102,7 @@ LL | taking_multiple_units((), ());
132102
| ^^ ^^
133103

134104
error: passing unit values to a function
135-
--> $DIR/unit_arg.rs:38:5
105+
--> $DIR/unit_arg.rs:36:5
136106
|
137107
LL | / taking_multiple_units(foo(0), {
138108
LL | | foo(1);
@@ -158,7 +128,7 @@ LL | taking_multiple_units((), ());
158128
| ^^ ^^
159129

160130
error: passing unit values to a function
161-
--> $DIR/unit_arg.rs:42:5
131+
--> $DIR/unit_arg.rs:40:5
162132
|
163133
LL | / taking_multiple_units(
164134
LL | | {
@@ -193,7 +163,7 @@ LL | (),
193163
|
194164

195165
error: passing a unit value to a function
196-
--> $DIR/unit_arg.rs:84:5
166+
--> $DIR/unit_arg.rs:82:5
197167
|
198168
LL | Some(foo(1))
199169
| ^^^^^^^^^^^^
@@ -207,5 +177,5 @@ help: ...and use a unit literal instead
207177
LL | Some(())
208178
| ^^
209179

210-
error: aborting due to 10 previous errors
180+
error: aborting due to 8 previous errors
211181

tests/ui/unit_arg_empty_blocks.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![warn(clippy::unit_arg)]
2+
#![allow(clippy::no_effect, unused_must_use, unused_variables)]
3+
4+
use std::fmt::Debug;
5+
6+
fn foo<T: Debug>(t: T) {
7+
println!("{:?}", t);
8+
}
9+
10+
fn foo3<T1: Debug, T2: Debug, T3: Debug>(t1: T1, t2: T2, t3: T3) {
11+
println!("{:?}, {:?}, {:?}", t1, t2, t3);
12+
}
13+
14+
fn bad() {
15+
foo({});
16+
foo3({}, 2, 2);
17+
taking_two_units({}, foo(0));
18+
taking_three_units({}, foo(0), foo(1));
19+
}
20+
21+
fn taking_two_units(a: (), b: ()) {}
22+
fn taking_three_units(a: (), b: (), c: ()) {}
23+
24+
fn main() {
25+
bad();
26+
}

tests/ui/unit_arg_empty_blocks.stderr

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
error: passing a unit value to a function
2+
--> $DIR/unit_arg_empty_blocks.rs:15:5
3+
|
4+
LL | foo({});
5+
| ^^^^--^
6+
| |
7+
| help: use a unit literal instead: `()`
8+
|
9+
= note: `-D clippy::unit-arg` implied by `-D warnings`
10+
11+
error: passing a unit value to a function
12+
--> $DIR/unit_arg_empty_blocks.rs:16:5
13+
|
14+
LL | foo3({}, 2, 2);
15+
| ^^^^^--^^^^^^^
16+
| |
17+
| help: use a unit literal instead: `()`
18+
19+
error: passing unit values to a function
20+
--> $DIR/unit_arg_empty_blocks.rs:17:5
21+
|
22+
LL | taking_two_units({}, foo(0));
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
|
25+
help: move the expression in front of the call...
26+
|
27+
LL | foo(0);
28+
|
29+
help: ...and use unit literals instead
30+
|
31+
LL | taking_two_units((), ());
32+
| ^^ ^^
33+
34+
error: passing unit values to a function
35+
--> $DIR/unit_arg_empty_blocks.rs:18:5
36+
|
37+
LL | taking_three_units({}, foo(0), foo(1));
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
|
40+
help: move the expressions in front of the call...
41+
|
42+
LL | foo(0);
43+
LL | foo(1);
44+
|
45+
help: ...and use unit literals instead
46+
|
47+
LL | taking_three_units((), (), ());
48+
| ^^ ^^ ^^
49+
50+
error: aborting due to 4 previous errors
51+

0 commit comments

Comments
 (0)