@@ -1922,21 +1922,32 @@ impl InferenceContext<'_> {
19221922 VisibleFromModule :: Filter ( self . resolver . module ( ) ) ,
19231923 method_name,
19241924 ) ;
1925- let ( receiver_ty , method_ty , substs ) = match resolved {
1925+ match resolved {
19261926 Some ( ( adjust, func, visible) ) => {
1927- let ( ty, adjustments) = adjust. apply ( & mut self . table , receiver_ty) ;
1928- let generics = generics ( self . db . upcast ( ) , func. into ( ) ) ;
1929- let substs = self . substs_for_method_call ( generics, generic_args) ;
1930- self . write_expr_adj ( receiver, adjustments) ;
1931- self . write_method_resolution ( tgt_expr, func, substs. clone ( ) ) ;
19321927 if !visible {
19331928 self . push_diagnostic ( InferenceDiagnostic :: PrivateAssocItem {
19341929 id : tgt_expr. into ( ) ,
19351930 item : func. into ( ) ,
19361931 } )
19371932 }
1938- ( ty, self . db . value_ty ( func. into ( ) ) . unwrap ( ) , substs)
1933+
1934+ let ( ty, adjustments) = adjust. apply ( & mut self . table , receiver_ty) ;
1935+ self . write_expr_adj ( receiver, adjustments) ;
1936+
1937+ let generics = generics ( self . db . upcast ( ) , func. into ( ) ) ;
1938+ let substs = self . substs_for_method_call ( generics, generic_args) ;
1939+ self . write_method_resolution ( tgt_expr, func, substs. clone ( ) ) ;
1940+ self . check_method_call (
1941+ tgt_expr,
1942+ args,
1943+ self . db . value_ty ( func. into ( ) ) . expect ( "we have a function def" ) ,
1944+ substs,
1945+ ty,
1946+ expected,
1947+ )
19391948 }
1949+ // Failed to resolve, report diagnostic and try to resolve as call to field access or
1950+ // assoc function
19401951 None => {
19411952 let field_with_same_name_exists = match self . lookup_field ( & receiver_ty, method_name)
19421953 {
@@ -1956,12 +1967,11 @@ impl InferenceContext<'_> {
19561967 VisibleFromModule :: Filter ( self . resolver . module ( ) ) ,
19571968 Some ( method_name) ,
19581969 method_resolution:: LookupMode :: Path ,
1959- |_ty, item, visible| {
1960- if visible {
1961- Some ( item)
1962- } else {
1963- None
1970+ |_ty, item, visible| match item {
1971+ hir_def:: AssocItemId :: FunctionId ( function_id) if visible => {
1972+ Some ( function_id)
19641973 }
1974+ _ => None ,
19651975 } ,
19661976 ) ;
19671977
@@ -1973,31 +1983,41 @@ impl InferenceContext<'_> {
19731983 assoc_func_with_same_name,
19741984 } ) ;
19751985
1976- return match field_with_same_name_exists {
1977- Some ( field_ty) => match field_ty. callable_sig ( self . db ) {
1978- Some ( sig) => self . check_call (
1979- tgt_expr,
1980- args,
1981- field_ty,
1982- sig. params ( ) ,
1983- sig. ret ( ) . clone ( ) ,
1984- & [ ] ,
1985- true ,
1986- expected,
1987- ) ,
1988- None => {
1989- self . check_call_arguments ( tgt_expr, args, & [ ] , & [ ] , & [ ] , true ) ;
1990- field_ty
1991- }
1992- } ,
1986+ let recovered = match assoc_func_with_same_name {
1987+ Some ( f) => {
1988+ let generics = generics ( self . db . upcast ( ) , f. into ( ) ) ;
1989+ let substs = self . substs_for_method_call ( generics, generic_args) ;
1990+ let f = self
1991+ . db
1992+ . value_ty ( f. into ( ) )
1993+ . expect ( "we have a function def" )
1994+ . substitute ( Interner , & substs) ;
1995+ let sig = f. callable_sig ( self . db ) . expect ( "we have a function def" ) ;
1996+ Some ( ( f, sig, true ) )
1997+ }
1998+ None => field_with_same_name_exists. and_then ( |field_ty| {
1999+ let callable_sig = field_ty. callable_sig ( self . db ) ?;
2000+ Some ( ( field_ty, callable_sig, false ) )
2001+ } ) ,
2002+ } ;
2003+ match recovered {
2004+ Some ( ( callee_ty, sig, strip_first) ) => self . check_call (
2005+ tgt_expr,
2006+ args,
2007+ callee_ty,
2008+ sig. params ( ) . get ( strip_first as usize ..) . unwrap_or ( & [ ] ) ,
2009+ sig. ret ( ) . clone ( ) ,
2010+ & [ ] ,
2011+ true ,
2012+ expected,
2013+ ) ,
19932014 None => {
19942015 self . check_call_arguments ( tgt_expr, args, & [ ] , & [ ] , & [ ] , true ) ;
19952016 self . err_ty ( )
19962017 }
1997- } ;
2018+ }
19982019 }
1999- } ;
2000- self . check_method_call ( tgt_expr, args, method_ty, substs, receiver_ty, expected)
2020+ }
20012021 }
20022022
20032023 fn check_method_call (
@@ -2067,9 +2087,10 @@ impl InferenceContext<'_> {
20672087 expected_inputs : & [ Ty ] ,
20682088 param_tys : & [ Ty ] ,
20692089 skip_indices : & [ u32 ] ,
2070- is_varargs : bool ,
2090+ ignore_arg_param_mismatch : bool ,
20712091 ) {
2072- let arg_count_mismatch = args. len ( ) != param_tys. len ( ) + skip_indices. len ( ) && !is_varargs;
2092+ let arg_count_mismatch =
2093+ !ignore_arg_param_mismatch && args. len ( ) != param_tys. len ( ) + skip_indices. len ( ) ;
20732094 if arg_count_mismatch {
20742095 self . push_diagnostic ( InferenceDiagnostic :: MismatchedArgCount {
20752096 call_expr : expr,
@@ -2098,7 +2119,7 @@ impl InferenceContext<'_> {
20982119 continue ;
20992120 }
21002121
2101- while skip_indices. peek ( ) . is_some_and ( |i| * i < idx as u32 ) {
2122+ while skip_indices. peek ( ) . is_some_and ( |& i| i < idx as u32 ) {
21022123 skip_indices. next ( ) ;
21032124 }
21042125 if skip_indices. peek ( ) . copied ( ) == Some ( idx as u32 ) {
0 commit comments