@@ -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 } ;
@@ -1876,6 +1875,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1876
1875
self . tcx . erase_late_bound_regions ( value)
1877
1876
}
1878
1877
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
+
1879
1887
/// Finds the method with the appropriate name (or return type, as the case may be). If
1880
1888
/// `allow_similar_names` is set, find methods with close-matching names.
1881
1889
// The length of the returned iterator is nearly always 0 or 1 and this
@@ -1888,7 +1896,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1888
1896
. associated_items ( def_id)
1889
1897
. in_definition_order ( )
1890
1898
. filter ( |x| {
1891
- if x. kind . namespace ( ) != Namespace :: ValueNS {
1899
+ if ! self . is_relevant_kind_for_mode ( x. kind ) {
1892
1900
return false ;
1893
1901
}
1894
1902
match lev_distance_with_substrings ( name. as_str ( ) , x. name . as_str ( ) , max_dist)
@@ -1902,10 +1910,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1902
1910
} else {
1903
1911
self . fcx
1904
1912
. associated_value ( def_id, name)
1913
+ . filter ( |x| self . is_relevant_kind_for_mode ( x. kind ) )
1905
1914
. map_or_else ( SmallVec :: new, |x| SmallVec :: from_buf ( [ x] ) )
1906
1915
}
1907
1916
} 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 ( )
1909
1923
}
1910
1924
}
1911
1925
}
0 commit comments