@@ -281,6 +281,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
281
281
self . demand_suptype ( provided_arg. span , formal_input_ty, coerced_ty) ;
282
282
} ;
283
283
284
+ let minimum_input_count = formal_input_tys. len ( ) ;
285
+
284
286
// Check the arguments.
285
287
// We do this in a pretty awful way: first we type-check any arguments
286
288
// that are not closures, then we type-check the closures. This is so
@@ -303,7 +305,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
303
305
} )
304
306
}
305
307
306
- let minimum_input_count = formal_input_tys. len ( ) ;
307
308
for ( idx, arg) in provided_args. iter ( ) . enumerate ( ) {
308
309
// Warn only for the first loop (the "no closures" one).
309
310
// Closure arguments themselves can't be diverging, but
@@ -456,17 +457,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
456
457
err. emit ( ) ;
457
458
}
458
459
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) ;
464
462
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 ;
467
469
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
+ }
470
472
471
473
// There are a few types which get autopromoted when passed via varargs
472
474
// in C but we just error out instead and require explicit casts.
0 commit comments