@@ -5,7 +5,6 @@ use crate::check::FnCtxt;
55use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
66use rustc_errors:: { pluralize, struct_span_err, Applicability , DiagnosticBuilder } ;
77use rustc_hir as hir;
8- use rustc_hir:: def:: Namespace ;
98use rustc_hir:: def_id:: { DefId , LocalDefId } ;
109use rustc_hir:: lang_items:: LangItem ;
1110use rustc_hir:: { ExprKind , Node , QPath } ;
@@ -99,16 +98,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9998 CandidateSource :: ImplSource ( impl_did) => {
10099 // Provide the best span we can. Use the item, if local to crate, else
101100 // the impl, if local to crate (item may be defaulted), else nothing.
102- let item = match self
103- . associated_item ( impl_did, item_name, Namespace :: ValueNS )
104- . or_else ( || {
105- let impl_trait_ref = self . tcx . impl_trait_ref ( impl_did) ?;
106- self . associated_item (
107- impl_trait_ref. def_id ,
108- item_name,
109- Namespace :: ValueNS ,
110- )
111- } ) {
101+ let item = match self . associated_value ( impl_did, item_name) . or_else ( || {
102+ let impl_trait_ref = self . tcx . impl_trait_ref ( impl_did) ?;
103+ self . associated_value ( impl_trait_ref. def_id , item_name)
104+ } ) {
112105 Some ( item) => item,
113106 None => continue ,
114107 } ;
@@ -187,11 +180,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
187180 }
188181 }
189182 CandidateSource :: TraitSource ( trait_did) => {
190- let item =
191- match self . associated_item ( trait_did, item_name, Namespace :: ValueNS ) {
192- Some ( item) => item,
193- None => continue ,
194- } ;
183+ let item = match self . associated_value ( trait_did, item_name) {
184+ Some ( item) => item,
185+ None => continue ,
186+ } ;
195187 let item_span = self
196188 . tcx
197189 . sess
@@ -271,16 +263,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
271263 // Suggest clamping down the type if the method that is being attempted to
272264 // be used exists at all, and the type is an ambiguous numeric type
273265 // ({integer}/{float}).
274- let mut candidates = all_traits ( self . tcx ) . into_iter ( ) . filter_map ( |info| {
275- self . associated_item ( info . def_id , item_name , Namespace :: ValueNS )
276- } ) ;
266+ let mut candidates = all_traits ( self . tcx )
267+ . into_iter ( )
268+ . filter_map ( |info| self . associated_value ( info . def_id , item_name ) ) ;
277269 // There are methods that are defined on the primitive types and won't be
278270 // found when exploring `all_traits`, but we also need them to be acurate on
279271 // our suggestions (#47759).
280272 let fund_assoc = |opt_def_id : Option < DefId > | {
281- opt_def_id
282- . and_then ( |id| self . associated_item ( id, item_name, Namespace :: ValueNS ) )
283- . is_some ( )
273+ opt_def_id. and_then ( |id| self . associated_value ( id, item_name) ) . is_some ( )
284274 } ;
285275 let lang_items = tcx. lang_items ( ) ;
286276 let found_candidate = candidates. next ( ) . is_some ( )
@@ -398,11 +388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
398388 . inherent_impls ( adt_deref. did )
399389 . iter ( )
400390 . filter_map ( |def_id| {
401- self . associated_item (
402- * def_id,
403- item_name,
404- Namespace :: ValueNS ,
405- )
391+ self . associated_value ( * def_id, item_name)
406392 } )
407393 . count ( )
408394 >= 1
@@ -515,9 +501,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
515501 . iter ( )
516502 . copied ( )
517503 . filter ( |def_id| {
518- if let Some ( assoc) =
519- self . associated_item ( * def_id, item_name, Namespace :: ValueNS )
520- {
504+ if let Some ( assoc) = self . associated_value ( * def_id, item_name) {
521505 // Check for both mode is the same so we avoid suggesting
522506 // incorrect associated item.
523507 match ( mode, assoc. fn_has_self_parameter , source) {
@@ -1588,7 +1572,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15881572 }
15891573 } ) && ( type_is_local || info. def_id . is_local ( ) )
15901574 && self
1591- . associated_item ( info. def_id , item_name, Namespace :: ValueNS )
1575+ . associated_value ( info. def_id , item_name)
15921576 . filter ( |item| {
15931577 if let ty:: AssocKind :: Fn = item. kind {
15941578 let id = item
0 commit comments