File tree Expand file tree Collapse file tree 4 files changed +78
-56
lines changed Expand file tree Collapse file tree 4 files changed +78
-56
lines changed Original file line number Diff line number Diff line change @@ -60,17 +60,6 @@ fn bad() {
60
60
// in this case, the suggestion can be inlined, no need for a surrounding block
61
61
// foo(()); foo(()) instead of { foo(()); foo(()) }
62
62
foo ( foo ( ( ) ) ) ;
63
- foo ( if true {
64
- 1 ;
65
- } ) ;
66
- foo ( match Some ( 1 ) {
67
- Some ( _) => {
68
- 1 ;
69
- } ,
70
- None => {
71
- 0 ;
72
- } ,
73
- } ) ;
74
63
}
75
64
76
65
fn ok ( ) {
@@ -84,11 +73,6 @@ fn ok() {
84
73
question_mark ( ) ;
85
74
let named_unit_arg = ( ) ;
86
75
foo ( named_unit_arg) ;
87
- foo ( if true { 1 } else { 0 } ) ;
88
- foo ( match Some ( 1 ) {
89
- Some ( _) => 1 ,
90
- None => 0 ,
91
- } ) ;
92
76
}
93
77
94
78
fn question_mark ( ) -> Result < ( ) , ( ) > {
Original file line number Diff line number Diff line change @@ -166,45 +166,7 @@ LL | foo(());
166
166
|
167
167
168
168
error: passing a unit value to a function
169
- --> $DIR/unit_arg.rs:63:5
170
- |
171
- LL | / foo(if true {
172
- LL | | 1;
173
- LL | | });
174
- | |______^
175
- |
176
- help: move the expression in front of the call and replace it with the unit literal `()`
177
- |
178
- LL | if true {
179
- LL | 1;
180
- LL | };
181
- LL | foo(());
182
- |
183
-
184
- error: passing a unit value to a function
185
- --> $DIR/unit_arg.rs:66:5
186
- |
187
- LL | / foo(match Some(1) {
188
- LL | | Some(_) => {
189
- LL | | 1;
190
- LL | | },
191
- ... |
192
- LL | | },
193
- LL | | });
194
- | |______^
195
- |
196
- help: move the expression in front of the call and replace it with the unit literal `()`
197
- |
198
- LL | match Some(1) {
199
- LL | Some(_) => {
200
- LL | 1;
201
- LL | },
202
- LL | None => {
203
- LL | 0;
204
- ...
205
-
206
- error: passing a unit value to a function
207
- --> $DIR/unit_arg.rs:113:5
169
+ --> $DIR/unit_arg.rs:97:5
208
170
|
209
171
LL | Some(foo(1))
210
172
| ^^^^^^^^^^^^
@@ -215,5 +177,5 @@ LL | foo(1);
215
177
LL | Some(())
216
178
|
217
179
218
- error: aborting due to 12 previous errors
180
+ error: aborting due to 10 previous errors
219
181
Original file line number Diff line number Diff line change
1
+ #![ warn( clippy:: unit_arg) ]
2
+ #![ allow( clippy:: no_effect) ]
3
+
4
+ use std:: fmt:: Debug ;
5
+
6
+ fn foo < T : Debug > ( t : T ) {
7
+ println ! ( "{:?}" , t) ;
8
+ }
9
+
10
+ fn bad ( ) {
11
+ foo ( if true {
12
+ 1 ;
13
+ } ) ;
14
+ foo ( match Some ( 1 ) {
15
+ Some ( _) => {
16
+ 1 ;
17
+ } ,
18
+ None => {
19
+ 0 ;
20
+ } ,
21
+ } ) ;
22
+ }
23
+
24
+ fn ok ( ) {
25
+ foo ( if true { 1 } else { 0 } ) ;
26
+ foo ( match Some ( 1 ) {
27
+ Some ( _) => 1 ,
28
+ None => 0 ,
29
+ } ) ;
30
+ }
31
+
32
+ fn main ( ) {
33
+ bad ( ) ;
34
+ ok ( ) ;
35
+ }
Original file line number Diff line number Diff line change
1
+ error: passing a unit value to a function
2
+ --> $DIR/unit_arg_expressions.rs:11:5
3
+ |
4
+ LL | / foo(if true {
5
+ LL | | 1;
6
+ LL | | });
7
+ | |______^
8
+ |
9
+ = note: `-D clippy::unit-arg` implied by `-D warnings`
10
+ help: move the expression in front of the call and replace it with the unit literal `()`
11
+ |
12
+ LL | if true {
13
+ LL | 1;
14
+ LL | };
15
+ LL | foo(());
16
+ |
17
+
18
+ error: passing a unit value to a function
19
+ --> $DIR/unit_arg_expressions.rs:14:5
20
+ |
21
+ LL | / foo(match Some(1) {
22
+ LL | | Some(_) => {
23
+ LL | | 1;
24
+ LL | | },
25
+ ... |
26
+ LL | | },
27
+ LL | | });
28
+ | |______^
29
+ |
30
+ help: move the expression in front of the call and replace it with the unit literal `()`
31
+ |
32
+ LL | match Some(1) {
33
+ LL | Some(_) => {
34
+ LL | 1;
35
+ LL | },
36
+ LL | None => {
37
+ LL | 0;
38
+ ...
39
+
40
+ error: aborting due to 2 previous errors
41
+
You can’t perform that action at this time.
0 commit comments