Skip to content

Commit 8b2409c

Browse files
committed
Rename FnCtxt::associated_item.
1 parent 1be6e2d commit 8b2409c

File tree

3 files changed

+19
-40
lines changed

3 files changed

+19
-40
lines changed

compiler/rustc_typeck/src/check/method/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
369369
// Trait must have a method named `m_name` and it should not have
370370
// type parameters or early-bound regions.
371371
let tcx = self.tcx;
372-
let method_item = match self.associated_item(trait_def_id, m_name, Namespace::ValueNS) {
372+
let method_item = match self.associated_value(trait_def_id, m_name) {
373373
Some(method_item) => method_item,
374374
None => {
375375
tcx.sess.delay_span_bug(
@@ -538,15 +538,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
538538

539539
/// Finds item with name `item_name` defined in impl/trait `def_id`
540540
/// and return it, or `None`, if no such item was defined there.
541-
pub fn associated_item(
542-
&self,
543-
def_id: DefId,
544-
item_name: Ident,
545-
ns: Namespace,
546-
) -> Option<ty::AssocItem> {
541+
pub fn associated_value(&self, def_id: DefId, item_name: Ident) -> Option<ty::AssocItem> {
547542
self.tcx
548543
.associated_items(def_id)
549-
.find_by_name_and_namespace(self.tcx, item_name, ns, def_id)
544+
.find_by_name_and_namespace(self.tcx, item_name, Namespace::ValueNS, def_id)
550545
.copied()
551546
}
552547
}

compiler/rustc_typeck/src/check/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
19151915
.collect()
19161916
} else {
19171917
self.fcx
1918-
.associated_item(def_id, name, Namespace::ValueNS)
1918+
.associated_value(def_id, name)
19191919
.map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
19201920
}
19211921
} else {

compiler/rustc_typeck/src/check/method/suggest.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::check::FnCtxt;
55
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
66
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
77
use rustc_hir as hir;
8-
use rustc_hir::def::Namespace;
98
use rustc_hir::def_id::{DefId, LocalDefId};
109
use rustc_hir::lang_items::LangItem;
1110
use 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

Comments
 (0)