This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
src/tools/rust-analyzer/crates
ide-diagnostics/src/handlers Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff 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 ( ) } ,
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments