@@ -133,7 +133,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
133133 let expected_arg_count = formal_input_tys. len ( ) ;
134134
135135 // 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 ;
137138
138139 // If the arguments should be wrapped in a tuple (ex: closures), unwrap them here
139140 let ( formal_input_tys, expected_input_tys) = if tuple_arguments == TupleArguments {
@@ -143,7 +144,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
143144 ty:: Tuple ( arg_types) => {
144145 // Argument length differs
145146 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 ) ) ;
147149 }
148150 let expected_input_tys = match expected_input_tys. get ( 0 ) {
149151 Some ( & ty) => match ty. kind ( ) {
@@ -174,7 +176,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
174176 if supplied_arg_count >= expected_arg_count {
175177 ( formal_input_tys. to_vec ( ) , expected_input_tys)
176178 } 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 ) ) ;
178181 ( self . err_args ( supplied_arg_count) , vec ! [ ] )
179182 }
180183 } else {
@@ -198,7 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
198201
199202 let sugg_tuple_wrap_args = self . suggested_tuple_wrap ( expected_input_tys, provided_args) ;
200203
201- error = Some ( (
204+ arg_count_error = Some ( (
202205 expected_arg_count,
203206 supplied_arg_count,
204207 "E0061" ,
@@ -231,6 +234,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
231234 // This is more complicated than just checking type equality, as arguments could be coerced
232235 // This version writes those types back so further type checking uses the narrowed types
233236 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+
234242 let formal_input_ty: Ty < ' tcx > = formal_input_tys[ idx] ;
235243 let expected_input_ty: Ty < ' tcx > = expected_input_tys[ idx] ;
236244 let provided_arg = & provided_args[ idx] ;
@@ -328,7 +336,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
328336 }
329337
330338 // 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
332341 {
333342 let ( span, start_span, args, ctor_of) = match & call_expr. kind {
334343 hir:: ExprKind :: Call (
0 commit comments