@@ -1922,21 +1922,32 @@ impl InferenceContext<'_> {
1922
1922
VisibleFromModule :: Filter ( self . resolver . module ( ) ) ,
1923
1923
method_name,
1924
1924
) ;
1925
- let ( receiver_ty , method_ty , substs ) = match resolved {
1925
+ match resolved {
1926
1926
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 ( ) ) ;
1932
1927
if !visible {
1933
1928
self . push_diagnostic ( InferenceDiagnostic :: PrivateAssocItem {
1934
1929
id : tgt_expr. into ( ) ,
1935
1930
item : func. into ( ) ,
1936
1931
} )
1937
1932
}
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
+ )
1939
1948
}
1949
+ // Failed to resolve, report diagnostic and try to resolve as call to field access or
1950
+ // assoc function
1940
1951
None => {
1941
1952
let field_with_same_name_exists = match self . lookup_field ( & receiver_ty, method_name)
1942
1953
{
@@ -1956,12 +1967,11 @@ impl InferenceContext<'_> {
1956
1967
VisibleFromModule :: Filter ( self . resolver . module ( ) ) ,
1957
1968
Some ( method_name) ,
1958
1969
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)
1964
1973
}
1974
+ _ => None ,
1965
1975
} ,
1966
1976
) ;
1967
1977
@@ -1973,31 +1983,41 @@ impl InferenceContext<'_> {
1973
1983
assoc_func_with_same_name,
1974
1984
} ) ;
1975
1985
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
+ ) ,
1993
2014
None => {
1994
2015
self . check_call_arguments ( tgt_expr, args, & [ ] , & [ ] , & [ ] , true ) ;
1995
2016
self . err_ty ( )
1996
2017
}
1997
- } ;
2018
+ }
1998
2019
}
1999
- } ;
2000
- self . check_method_call ( tgt_expr, args, method_ty, substs, receiver_ty, expected)
2020
+ }
2001
2021
}
2002
2022
2003
2023
fn check_method_call (
@@ -2067,9 +2087,10 @@ impl InferenceContext<'_> {
2067
2087
expected_inputs : & [ Ty ] ,
2068
2088
param_tys : & [ Ty ] ,
2069
2089
skip_indices : & [ u32 ] ,
2070
- is_varargs : bool ,
2090
+ ignore_arg_param_mismatch : bool ,
2071
2091
) {
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 ( ) ;
2073
2094
if arg_count_mismatch {
2074
2095
self . push_diagnostic ( InferenceDiagnostic :: MismatchedArgCount {
2075
2096
call_expr : expr,
@@ -2098,7 +2119,7 @@ impl InferenceContext<'_> {
2098
2119
continue ;
2099
2120
}
2100
2121
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 ) {
2102
2123
skip_indices. next ( ) ;
2103
2124
}
2104
2125
if skip_indices. peek ( ) . copied ( ) == Some ( idx as u32 ) {
0 commit comments