File tree 2 files changed +18
-3
lines changed
ide-diagnostics/src/handlers
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -1759,13 +1759,14 @@ impl InferenceContext<'_> {
1759
1759
skip_indices : & [ u32 ] ,
1760
1760
is_varargs : bool ,
1761
1761
) {
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 {
1763
1764
self . push_diagnostic ( InferenceDiagnostic :: MismatchedArgCount {
1764
1765
call_expr : expr,
1765
1766
expected : param_tys. len ( ) + skip_indices. len ( ) ,
1766
1767
found : args. len ( ) ,
1767
1768
} ) ;
1768
- }
1769
+ } ;
1769
1770
1770
1771
// Quoting https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_typeck/check/mod.rs#L3325 --
1771
1772
// We do this in a pretty awful way: first we type-check any arguments
@@ -1819,7 +1820,7 @@ impl InferenceContext<'_> {
1819
1820
// The function signature may contain some unknown types, so we need to insert
1820
1821
// type vars here to avoid type mismatch false positive.
1821
1822
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 {
1823
1824
self . result . type_mismatches . insert (
1824
1825
arg. into ( ) ,
1825
1826
TypeMismatch { expected : coercion_target, actual : ty. clone ( ) } ,
Original file line number Diff line number Diff line change @@ -472,4 +472,18 @@ fn f(
472
472
"# ,
473
473
)
474
474
}
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
+ }
475
489
}
You can’t perform that action at this time.
0 commit comments