File tree Expand file tree Collapse file tree 3 files changed +71
-6
lines changed Expand file tree Collapse file tree 3 files changed +71
-6
lines changed Original file line number Diff line number Diff line change @@ -955,7 +955,16 @@ impl<'tcx> LateLintPass<'tcx> for UnitArg {
955
955
. iter ( )
956
956
. filter ( |arg| {
957
957
if is_unit ( cx. typeck_results ( ) . expr_ty ( arg) ) && !is_unit_literal ( arg) {
958
- !matches ! ( & arg. kind, ExprKind :: Match ( .., MatchSource :: TryDesugar ) )
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
+ }
959
968
} else {
960
969
false
961
970
}
Original file line number Diff line number Diff line change @@ -59,7 +59,18 @@ fn bad() {
59
59
None . or ( Some ( foo ( 2 ) ) ) ;
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
- foo ( foo ( ( ) ) )
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
+ } ) ;
63
74
}
64
75
65
76
fn ok ( ) {
@@ -71,6 +82,13 @@ fn ok() {
71
82
b. bar ( { 1 } ) ;
72
83
b. bar ( ( ) ) ;
73
84
question_mark ( ) ;
85
+ let named_unit_arg = ( ) ;
86
+ foo ( named_unit_arg) ;
87
+ foo ( if true { 1 } else { 0 } ) ;
88
+ foo ( match Some ( 1 ) {
89
+ Some ( _) => 1 ,
90
+ None => 0 ,
91
+ } ) ;
74
92
}
75
93
76
94
fn question_mark ( ) -> Result < ( ) , ( ) > {
Original file line number Diff line number Diff line change @@ -156,17 +156,55 @@ LL | });
156
156
error: passing a unit value to a function
157
157
--> $DIR/unit_arg.rs:62:5
158
158
|
159
- LL | foo(foo(()))
159
+ LL | foo(foo(()));
160
160
| ^^^^^^^^^^^^
161
161
|
162
162
help: move the expression in front of the call and replace it with the unit literal `()`
163
163
|
164
164
LL | foo(());
165
- LL | foo(())
165
+ LL | foo(());
166
+ |
167
+
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
166
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
+ ...
167
205
168
206
error: passing a unit value to a function
169
- --> $DIR/unit_arg.rs:95 :5
207
+ --> $DIR/unit_arg.rs:113 :5
170
208
|
171
209
LL | Some(foo(1))
172
210
| ^^^^^^^^^^^^
@@ -177,5 +215,5 @@ LL | foo(1);
177
215
LL | Some(())
178
216
|
179
217
180
- error: aborting due to 10 previous errors
218
+ error: aborting due to 12 previous errors
181
219
You can’t perform that action at this time.
0 commit comments