mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Surpress type mismatches in calls with mismatched arg counts
This commit is contained in:
parent
25d9e05c03
commit
deddbbfa60
2 changed files with 18 additions and 3 deletions
|
@ -1759,13 +1759,14 @@ impl InferenceContext<'_> {
|
||||||
skip_indices: &[u32],
|
skip_indices: &[u32],
|
||||||
is_varargs: bool,
|
is_varargs: bool,
|
||||||
) {
|
) {
|
||||||
if args.len() != param_tys.len() + skip_indices.len() && !is_varargs {
|
let arg_count_mismatch = args.len() != param_tys.len() + skip_indices.len() && !is_varargs;
|
||||||
|
if arg_count_mismatch {
|
||||||
self.push_diagnostic(InferenceDiagnostic::MismatchedArgCount {
|
self.push_diagnostic(InferenceDiagnostic::MismatchedArgCount {
|
||||||
call_expr: expr,
|
call_expr: expr,
|
||||||
expected: param_tys.len() + skip_indices.len(),
|
expected: param_tys.len() + skip_indices.len(),
|
||||||
found: args.len(),
|
found: args.len(),
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// Quoting https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_typeck/check/mod.rs#L3325 --
|
// Quoting https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_typeck/check/mod.rs#L3325 --
|
||||||
// We do this in a pretty awful way: first we type-check any arguments
|
// We do this in a pretty awful way: first we type-check any arguments
|
||||||
|
@ -1819,7 +1820,7 @@ impl InferenceContext<'_> {
|
||||||
// The function signature may contain some unknown types, so we need to insert
|
// The function signature may contain some unknown types, so we need to insert
|
||||||
// type vars here to avoid type mismatch false positive.
|
// type vars here to avoid type mismatch false positive.
|
||||||
let coercion_target = self.insert_type_vars(coercion_target);
|
let coercion_target = self.insert_type_vars(coercion_target);
|
||||||
if self.coerce(Some(arg), &ty, &coercion_target).is_err() {
|
if self.coerce(Some(arg), &ty, &coercion_target).is_err() && !arg_count_mismatch {
|
||||||
self.result.type_mismatches.insert(
|
self.result.type_mismatches.insert(
|
||||||
arg.into(),
|
arg.into(),
|
||||||
TypeMismatch { expected: coercion_target, actual: ty.clone() },
|
TypeMismatch { expected: coercion_target, actual: ty.clone() },
|
||||||
|
|
|
@ -472,4 +472,18 @@ fn f(
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_type_mismatches_when_arg_count_mismatch() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
fn foo((): (), (): ()) {
|
||||||
|
foo(1, 2, 3);
|
||||||
|
// ^^ error: expected 2 arguments, found 3
|
||||||
|
foo(1);
|
||||||
|
// ^ error: expected 2 arguments, found 1
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue