diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index f7f4c52c2a1d..96db025158fb 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -369,7 +369,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Trait must have a method named `m_name` and it should not have // type parameters or early-bound regions. let tcx = self.tcx; - let method_item = match self.associated_item(trait_def_id, m_name, Namespace::ValueNS) { + let method_item = match self.associated_value(trait_def_id, m_name) { Some(method_item) => method_item, None => { tcx.sess.delay_span_bug( @@ -538,15 +538,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Finds item with name `item_name` defined in impl/trait `def_id` /// and return it, or `None`, if no such item was defined there. - pub fn associated_item( - &self, - def_id: DefId, - item_name: Ident, - ns: Namespace, - ) -> Option { + pub fn associated_value(&self, def_id: DefId, item_name: Ident) -> Option { self.tcx .associated_items(def_id) - .find_by_name_and_namespace(self.tcx, item_name, ns, def_id) + .find_by_name_and_namespace(self.tcx, item_name, Namespace::ValueNS, def_id) .copied() } } diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 5615a08369df..b704ff8c7cb2 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1915,7 +1915,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { .collect() } else { self.fcx - .associated_item(def_id, name, Namespace::ValueNS) + .associated_value(def_id, name) .map_or_else(SmallVec::new, |x| SmallVec::from_buf([x])) } } else { diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 7f9c75c7fee6..dfe020ba82ac 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -5,7 +5,6 @@ use crate::check::FnCtxt; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; -use rustc_hir::def::Namespace; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, Node, QPath}; @@ -99,16 +98,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { CandidateSource::ImplSource(impl_did) => { // Provide the best span we can. Use the item, if local to crate, else // the impl, if local to crate (item may be defaulted), else nothing. - let item = match self - .associated_item(impl_did, item_name, Namespace::ValueNS) - .or_else(|| { - let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?; - self.associated_item( - impl_trait_ref.def_id, - item_name, - Namespace::ValueNS, - ) - }) { + let item = match self.associated_value(impl_did, item_name).or_else(|| { + let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?; + self.associated_value(impl_trait_ref.def_id, item_name) + }) { Some(item) => item, None => continue, }; @@ -187,11 +180,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } CandidateSource::TraitSource(trait_did) => { - let item = - match self.associated_item(trait_did, item_name, Namespace::ValueNS) { - Some(item) => item, - None => continue, - }; + let item = match self.associated_value(trait_did, item_name) { + Some(item) => item, + None => continue, + }; let item_span = self .tcx .sess @@ -271,16 +263,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Suggest clamping down the type if the method that is being attempted to // be used exists at all, and the type is an ambiguous numeric type // ({integer}/{float}). - let mut candidates = all_traits(self.tcx).into_iter().filter_map(|info| { - self.associated_item(info.def_id, item_name, Namespace::ValueNS) - }); + let mut candidates = all_traits(self.tcx) + .into_iter() + .filter_map(|info| self.associated_value(info.def_id, item_name)); // There are methods that are defined on the primitive types and won't be // found when exploring `all_traits`, but we also need them to be acurate on // our suggestions (#47759). let fund_assoc = |opt_def_id: Option| { - opt_def_id - .and_then(|id| self.associated_item(id, item_name, Namespace::ValueNS)) - .is_some() + opt_def_id.and_then(|id| self.associated_value(id, item_name)).is_some() }; let lang_items = tcx.lang_items(); let found_candidate = candidates.next().is_some() @@ -398,11 +388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .inherent_impls(adt_deref.did) .iter() .filter_map(|def_id| { - self.associated_item( - *def_id, - item_name, - Namespace::ValueNS, - ) + self.associated_value(*def_id, item_name) }) .count() >= 1 @@ -515,9 +501,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .iter() .copied() .filter(|def_id| { - if let Some(assoc) = - self.associated_item(*def_id, item_name, Namespace::ValueNS) - { + if let Some(assoc) = self.associated_value(*def_id, item_name) { // Check for both mode is the same so we avoid suggesting // incorrect associated item. match (mode, assoc.fn_has_self_parameter, source) { @@ -1588,7 +1572,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }) && (type_is_local || info.def_id.is_local()) && self - .associated_item(info.def_id, item_name, Namespace::ValueNS) + .associated_value(info.def_id, item_name) .filter(|item| { if let ty::AssocKind::Fn = item.kind { let id = item