@@ -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 } ;
@@ -1876,6 +1875,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18761875 self . tcx . erase_late_bound_regions ( value)
18771876 }
18781877
1878+ /// Determine if the given associated item type is relevant in the current context.
1879+ fn is_relevant_kind_for_mode ( & self , kind : ty:: AssocKind ) -> bool {
1880+ match ( self . mode , kind) {
1881+ ( Mode :: MethodCall , ty:: AssocKind :: Fn ) => true ,
1882+ ( Mode :: Path , ty:: AssocKind :: Const | ty:: AssocKind :: Fn ) => true ,
1883+ _ => false ,
1884+ }
1885+ }
1886+
18791887 /// Finds the method with the appropriate name (or return type, as the case may be). If
18801888 /// `allow_similar_names` is set, find methods with close-matching names.
18811889 // The length of the returned iterator is nearly always 0 or 1 and this
@@ -1888,7 +1896,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18881896 . associated_items ( def_id)
18891897 . in_definition_order ( )
18901898 . filter ( |x| {
1891- if x. kind . namespace ( ) != Namespace :: ValueNS {
1899+ if ! self . is_relevant_kind_for_mode ( x. kind ) {
18921900 return false ;
18931901 }
18941902 match lev_distance_with_substrings ( name. as_str ( ) , x. name . as_str ( ) , max_dist)
@@ -1902,10 +1910,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
19021910 } else {
19031911 self . fcx
19041912 . associated_value ( def_id, name)
1913+ . filter ( |x| self . is_relevant_kind_for_mode ( x. kind ) )
19051914 . map_or_else ( SmallVec :: new, |x| SmallVec :: from_buf ( [ x] ) )
19061915 }
19071916 } else {
1908- self . tcx . associated_items ( def_id) . in_definition_order ( ) . copied ( ) . collect ( )
1917+ self . tcx
1918+ . associated_items ( def_id)
1919+ . in_definition_order ( )
1920+ . filter ( |x| self . is_relevant_kind_for_mode ( x. kind ) )
1921+ . copied ( )
1922+ . collect ( )
19091923 }
19101924 }
19111925}
0 commit comments