@@ -133,7 +133,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
133
133
let expected_arg_count = formal_input_tys. len ( ) ;
134
134
135
135
// expected_count, arg_count, error_code, sugg_unit, sugg_tuple_wrap_args
136
- let mut error: Option < ( usize , usize , & str , bool , Option < FnArgsAsTuple < ' _ > > ) > = None ;
136
+ let mut arg_count_error: Option < ( usize , usize , & str , bool , Option < FnArgsAsTuple < ' _ > > ) > =
137
+ None ;
137
138
138
139
// If the arguments should be wrapped in a tuple (ex: closures), unwrap them here
139
140
let ( formal_input_tys, expected_input_tys) = if tuple_arguments == TupleArguments {
@@ -143,7 +144,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
143
144
ty:: Tuple ( arg_types) => {
144
145
// Argument length differs
145
146
if arg_types. len ( ) != provided_args. len ( ) {
146
- error = Some ( ( arg_types. len ( ) , provided_args. len ( ) , "E0057" , false , None ) ) ;
147
+ arg_count_error =
148
+ Some ( ( arg_types. len ( ) , provided_args. len ( ) , "E0057" , false , None ) ) ;
147
149
}
148
150
let expected_input_tys = match expected_input_tys. get ( 0 ) {
149
151
Some ( & ty) => match ty. kind ( ) {
@@ -174,7 +176,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
174
176
if supplied_arg_count >= expected_arg_count {
175
177
( formal_input_tys. to_vec ( ) , expected_input_tys)
176
178
} else {
177
- error = Some ( ( expected_arg_count, supplied_arg_count, "E0060" , false , None ) ) ;
179
+ arg_count_error =
180
+ Some ( ( expected_arg_count, supplied_arg_count, "E0060" , false , None ) ) ;
178
181
( self . err_args ( supplied_arg_count) , vec ! [ ] )
179
182
}
180
183
} else {
@@ -198,7 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
198
201
199
202
let sugg_tuple_wrap_args = self . suggested_tuple_wrap ( expected_input_tys, provided_args) ;
200
203
201
- error = Some ( (
204
+ arg_count_error = Some ( (
202
205
expected_arg_count,
203
206
supplied_arg_count,
204
207
"E0061" ,
@@ -231,6 +234,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
231
234
// This is more complicated than just checking type equality, as arguments could be coerced
232
235
// This version writes those types back so further type checking uses the narrowed types
233
236
let demand_compatible = |idx, final_arg_types : & mut Vec < Option < ( Ty < ' tcx > , Ty < ' tcx > ) > > | {
237
+ // Do not check argument compatibility if the number of args do not match
238
+ if arg_count_error. is_some ( ) {
239
+ return ;
240
+ }
241
+
234
242
let formal_input_ty: Ty < ' tcx > = formal_input_tys[ idx] ;
235
243
let expected_input_ty: Ty < ' tcx > = expected_input_tys[ idx] ;
236
244
let provided_arg = & provided_args[ idx] ;
@@ -328,7 +336,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
328
336
}
329
337
330
338
// If there was an error in parameter count, emit that here
331
- if let Some ( ( expected_count, arg_count, err_code, sugg_unit, sugg_tuple_wrap_args) ) = error
339
+ if let Some ( ( expected_count, arg_count, err_code, sugg_unit, sugg_tuple_wrap_args) ) =
340
+ arg_count_error
332
341
{
333
342
let ( span, start_span, args, ctor_of) = match & call_expr. kind {
334
343
hir:: ExprKind :: Call (
0 commit comments