@@ -9,7 +9,6 @@ use rustc_data_structures::fx::FxHashSet;
9
9
use rustc_errors:: Applicability ;
10
10
use rustc_hir as hir;
11
11
use rustc_hir:: def:: DefKind ;
12
- use rustc_hir:: def:: Namespace ;
13
12
use rustc_infer:: infer:: canonical:: OriginalQueryValues ;
14
13
use rustc_infer:: infer:: canonical:: { Canonical , QueryResponse } ;
15
14
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
@@ -1881,14 +1880,19 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1881
1880
// The length of the returned iterator is nearly always 0 or 1 and this
1882
1881
// method is fairly hot.
1883
1882
fn impl_or_trait_item ( & self , def_id : DefId ) -> SmallVec < [ ty:: AssocItem ; 1 ] > {
1883
+ let relevant_kind_for_mode = |kind| match ( self . mode , kind) {
1884
+ ( Mode :: MethodCall , ty:: AssocKind :: Fn ) => true ,
1885
+ ( Mode :: Path , ty:: AssocKind :: Const | ty:: AssocKind :: Fn ) => true ,
1886
+ _ => false ,
1887
+ } ;
1884
1888
if let Some ( name) = self . method_name {
1885
1889
if self . allow_similar_names {
1886
1890
let max_dist = max ( name. as_str ( ) . len ( ) , 3 ) / 3 ;
1887
1891
self . tcx
1888
1892
. associated_items ( def_id)
1889
1893
. in_definition_order ( )
1890
1894
. filter ( |x| {
1891
- if x. kind . namespace ( ) != Namespace :: ValueNS {
1895
+ if ! relevant_kind_for_mode ( x. kind ) {
1892
1896
return false ;
1893
1897
}
1894
1898
match lev_distance_with_substrings ( name. as_str ( ) , x. name . as_str ( ) , max_dist)
@@ -1902,10 +1906,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1902
1906
} else {
1903
1907
self . fcx
1904
1908
. associated_value ( def_id, name)
1909
+ . filter ( |x| relevant_kind_for_mode ( x. kind ) )
1905
1910
. map_or_else ( SmallVec :: new, |x| SmallVec :: from_buf ( [ x] ) )
1906
1911
}
1907
1912
} else {
1908
- self . tcx . associated_items ( def_id) . in_definition_order ( ) . copied ( ) . collect ( )
1913
+ self . tcx
1914
+ . associated_items ( def_id)
1915
+ . in_definition_order ( )
1916
+ . filter ( |x| relevant_kind_for_mode ( x. kind ) )
1917
+ . copied ( )
1918
+ . collect ( )
1909
1919
}
1910
1920
}
1911
1921
}
0 commit comments