@@ -9,7 +9,6 @@ use rustc_data_structures::fx::FxHashSet;
99use rustc_errors:: Applicability ;
1010use rustc_hir as hir;
1111use rustc_hir:: def:: DefKind ;
12- use rustc_hir:: def:: Namespace ;
1312use rustc_infer:: infer:: canonical:: OriginalQueryValues ;
1413use rustc_infer:: infer:: canonical:: { Canonical , QueryResponse } ;
1514use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
@@ -1881,14 +1880,19 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18811880 // The length of the returned iterator is nearly always 0 or 1 and this
18821881 // method is fairly hot.
18831882 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+ } ;
18841888 if let Some ( name) = self . method_name {
18851889 if self . allow_similar_names {
18861890 let max_dist = max ( name. as_str ( ) . len ( ) , 3 ) / 3 ;
18871891 self . tcx
18881892 . associated_items ( def_id)
18891893 . in_definition_order ( )
18901894 . filter ( |x| {
1891- if x. kind . namespace ( ) != Namespace :: ValueNS {
1895+ if ! relevant_kind_for_mode ( x. kind ) {
18921896 return false ;
18931897 }
18941898 match lev_distance_with_substrings ( name. as_str ( ) , x. name . as_str ( ) , max_dist)
@@ -1902,10 +1906,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
19021906 } else {
19031907 self . fcx
19041908 . associated_value ( def_id, name)
1909+ . filter ( |x| relevant_kind_for_mode ( x. kind ) )
19051910 . map_or_else ( SmallVec :: new, |x| SmallVec :: from_buf ( [ x] ) )
19061911 }
19071912 } 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 ( )
19091919 }
19101920 }
19111921}
0 commit comments