Skip to content

Commit

Permalink
Rollup merge of rust-lang#94636 - compiler-errors:issue-94599, r=davi…
Browse files Browse the repository at this point in the history
…dtwco

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 rust-lang#94334 I think. I thought this might've regressed in rust-lang#92360, but I think that is in stable, ad the test I provided (which minimizes rust-lang#94599) passes on stable in playground. Maybe it regressed in rust-lang#93118.

Anywho, fixes rust-lang#94599.
  • Loading branch information
matthiaskrgr authored Mar 7, 2022
2 parents 3d1eaf4 + 3f17dae commit 9c7ff1a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
22 changes: 12 additions & 10 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/tuple/wrong_argument_ice-4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
(|| {})(|| {
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
let b = 1;
});
}
15 changes: 15 additions & 0 deletions src/test/ui/tuple/wrong_argument_ice-4.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 9c7ff1a

Please sign in to comment.