Skip to content

Commit 4a99d79

Browse files
committed
Auto merge of #17802 - Veykril:arg-mismatch-no-ty-mismatch, r=Veykril
fix: Surpress type mismatches in calls with mismatched arg counts These tend to get very noisy, hiding the actual problem.
2 parents fd3c10d + deddbbf commit 4a99d79

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

crates/hir-ty/src/infer/expr.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,13 +1759,14 @@ impl InferenceContext<'_> {
17591759
skip_indices: &[u32],
17601760
is_varargs: bool,
17611761
) {
1762-
if args.len() != param_tys.len() + skip_indices.len() && !is_varargs {
1762+
let arg_count_mismatch = args.len() != param_tys.len() + skip_indices.len() && !is_varargs;
1763+
if arg_count_mismatch {
17631764
self.push_diagnostic(InferenceDiagnostic::MismatchedArgCount {
17641765
call_expr: expr,
17651766
expected: param_tys.len() + skip_indices.len(),
17661767
found: args.len(),
17671768
});
1768-
}
1769+
};
17691770

17701771
// Quoting https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_typeck/check/mod.rs#L3325 --
17711772
// We do this in a pretty awful way: first we type-check any arguments
@@ -1819,7 +1820,7 @@ impl InferenceContext<'_> {
18191820
// The function signature may contain some unknown types, so we need to insert
18201821
// type vars here to avoid type mismatch false positive.
18211822
let coercion_target = self.insert_type_vars(coercion_target);
1822-
if self.coerce(Some(arg), &ty, &coercion_target).is_err() {
1823+
if self.coerce(Some(arg), &ty, &coercion_target).is_err() && !arg_count_mismatch {
18231824
self.result.type_mismatches.insert(
18241825
arg.into(),
18251826
TypeMismatch { expected: coercion_target, actual: ty.clone() },

crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,18 @@ fn f(
472472
"#,
473473
)
474474
}
475+
476+
#[test]
477+
fn no_type_mismatches_when_arg_count_mismatch() {
478+
check_diagnostics(
479+
r#"
480+
fn foo((): (), (): ()) {
481+
foo(1, 2, 3);
482+
// ^^ error: expected 2 arguments, found 3
483+
foo(1);
484+
// ^ error: expected 2 arguments, found 1
485+
}
486+
"#,
487+
);
488+
}
475489
}

0 commit comments

Comments
 (0)