@@ -281,6 +281,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
281281 self . demand_suptype ( provided_arg. span , formal_input_ty, coerced_ty) ;
282282 } ;
283283
284+ let minimum_input_count = formal_input_tys. len ( ) ;
285+
284286 // Check the arguments.
285287 // We do this in a pretty awful way: first we type-check any arguments
286288 // that are not closures, then we type-check the closures. This is so
@@ -303,7 +305,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
303305 } )
304306 }
305307
306- let minimum_input_count = formal_input_tys. len ( ) ;
307308 for ( idx, arg) in provided_args. iter ( ) . enumerate ( ) {
308309 // Warn only for the first loop (the "no closures" one).
309310 // Closure arguments themselves can't be diverging, but
@@ -456,17 +457,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
456457 err. emit ( ) ;
457458 }
458459
459- // We also need to make sure we at least write the ty of the other
460- // arguments which we skipped above.
461- if c_variadic {
462- fn variadic_error < ' tcx > ( sess : & Session , span : Span , ty : Ty < ' tcx > , cast_ty : & str ) {
463- use crate :: structured_errors:: MissingCastForVariadicArg ;
460+ for arg in provided_args. iter ( ) . skip ( minimum_input_count) {
461+ let arg_ty = self . check_expr ( & arg) ;
464462
465- MissingCastForVariadicArg { sess, span, ty, cast_ty } . diagnostic ( ) . emit ( ) ;
466- }
463+ if c_variadic {
464+ // We also need to make sure we at least write the ty of the other
465+ // arguments which we skipped above, either because they were additional
466+ // c_variadic args, or because we had an argument count mismatch.
467+ fn variadic_error < ' tcx > ( sess : & Session , span : Span , ty : Ty < ' tcx > , cast_ty : & str ) {
468+ use crate :: structured_errors:: MissingCastForVariadicArg ;
467469
468- for arg in provided_args . iter ( ) . skip ( expected_arg_count ) {
469- let arg_ty = self . check_expr ( & arg ) ;
470+ MissingCastForVariadicArg { sess , span , ty , cast_ty } . diagnostic ( ) . emit ( ) ;
471+ }
470472
471473 // There are a few types which get autopromoted when passed via varargs
472474 // in C but we just error out instead and require explicit casts.
0 commit comments