From 3f17dae37d8829a03312340918a839f0bf8b6088 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 4 Mar 2022 20:28:35 -0800 Subject: [PATCH] check extra args even if the function is not c_variadic --- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 22 ++++++++++--------- src/test/ui/tuple/wrong_argument_ice-4.rs | 6 +++++ src/test/ui/tuple/wrong_argument_ice-4.stderr | 15 +++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/test/ui/tuple/wrong_argument_ice-4.rs create mode 100644 src/test/ui/tuple/wrong_argument_ice-4.stderr diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 3f6247facd1a2..f165093c958db 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -281,6 +281,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.demand_suptype(provided_arg.span, formal_input_ty, coerced_ty); }; + let minimum_input_count = formal_input_tys.len(); + // Check the arguments. // We do this in a pretty awful way: first we type-check any arguments // that are not closures, then we type-check the closures. This is so @@ -303,7 +305,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }) } - let minimum_input_count = formal_input_tys.len(); for (idx, arg) in provided_args.iter().enumerate() { // Warn only for the first loop (the "no closures" one). // Closure arguments themselves can't be diverging, but @@ -456,17 +457,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.emit(); } - // We also need to make sure we at least write the ty of the other - // arguments which we skipped above. - if c_variadic { - fn variadic_error<'tcx>(sess: &Session, span: Span, ty: Ty<'tcx>, cast_ty: &str) { - use crate::structured_errors::MissingCastForVariadicArg; + for arg in provided_args.iter().skip(minimum_input_count) { + let arg_ty = self.check_expr(&arg); - MissingCastForVariadicArg { sess, span, ty, cast_ty }.diagnostic().emit(); - } + if c_variadic { + // We also need to make sure we at least write the ty of the other + // arguments which we skipped above, either because they were additional + // c_variadic args, or because we had an argument count mismatch. + fn variadic_error<'tcx>(sess: &Session, span: Span, ty: Ty<'tcx>, cast_ty: &str) { + use crate::structured_errors::MissingCastForVariadicArg; - for arg in provided_args.iter().skip(expected_arg_count) { - let arg_ty = self.check_expr(&arg); + MissingCastForVariadicArg { sess, span, ty, cast_ty }.diagnostic().emit(); + } // There are a few types which get autopromoted when passed via varargs // in C but we just error out instead and require explicit casts. diff --git a/src/test/ui/tuple/wrong_argument_ice-4.rs b/src/test/ui/tuple/wrong_argument_ice-4.rs new file mode 100644 index 0000000000000..479bd0d819fdb --- /dev/null +++ b/src/test/ui/tuple/wrong_argument_ice-4.rs @@ -0,0 +1,6 @@ +fn main() { + (|| {})(|| { + //~^ ERROR this function takes 0 arguments but 1 argument was supplied + let b = 1; + }); +} diff --git a/src/test/ui/tuple/wrong_argument_ice-4.stderr b/src/test/ui/tuple/wrong_argument_ice-4.stderr new file mode 100644 index 0000000000000..fef5dca856db3 --- /dev/null +++ b/src/test/ui/tuple/wrong_argument_ice-4.stderr @@ -0,0 +1,15 @@ +error[E0057]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/wrong_argument_ice-4.rs:2:5 + | +LL | (|| {})(|| { + | _____^^^^^^^_- + | | | + | | expected 0 arguments +LL | | +LL | | let b = 1; +LL | | }); + | |_____- supplied 1 argument + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0057`.