Skip to content

Commit 9c7ff1a

Browse files
authored
Rollup merge of #94636 - compiler-errors:issue-94599, r=davidtwco
Check extra function arg exprs even if the fn is not C-variadic We should still call check_expr on the args that exceed the formal input ty count, so that we have expr types to emit during writeback. Not sure where this regressed, but it wasn't due to the same root cause as #94334 I think. I thought this might've regressed in #92360, but I think that is in stable, ad the test I provided (which minimizes #94599) passes on stable in playground. Maybe it regressed in #93118. Anywho, fixes #94599.
2 parents 3d1eaf4 + 3f17dae commit 9c7ff1a

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
(|| {})(|| {
3+
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
4+
let b = 1;
5+
});
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0057]: this function takes 0 arguments but 1 argument was supplied
2+
--> $DIR/wrong_argument_ice-4.rs:2:5
3+
|
4+
LL | (|| {})(|| {
5+
| _____^^^^^^^_-
6+
| | |
7+
| | expected 0 arguments
8+
LL | |
9+
LL | | let b = 1;
10+
LL | | });
11+
| |_____- supplied 1 argument
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0057`.

0 commit comments

Comments
 (0)