let mut nonconst_call_permission = false;
if let Some(callee_trait) = tcx.trait_of_item(callee)
&& tcx.has_attr(callee_trait, sym::const_trait)
- && Some(callee_trait) == tcx.trait_of_item(caller)
+ && Some(callee_trait) == tcx.trait_of_item(caller.to_def_id())
// Can only call methods when it's `<Self as TheTrait>::f`.
&& tcx.types.self_param == substs.type_at(0)
{
/// Extra `DepNode`s for functions and methods.
const EXTRA_ASSOCIATED: &[&str] = &[label_strs::associated_item];
-const EXTRA_TRAIT: &[&str] = &[label_strs::trait_of_item];
+const EXTRA_TRAIT: &[&str] = &[];
// Fully Built Labels
}
}
- fn get_trait_of_item(self, id: DefIndex) -> Option<DefId> {
- let def_key = self.def_key(id);
- match def_key.disambiguated_data.data {
- DefPathData::TypeNs(..) | DefPathData::ValueNs(..) => (),
- // Not an associated item
- _ => return None,
- }
- def_key.parent.and_then(|parent_index| match self.kind(parent_index) {
- EntryKind::Trait | EntryKind::TraitAlias => Some(self.local_def_id(parent_index)),
- _ => None,
- })
- }
-
fn get_native_libraries(self, sess: &'a Session) -> impl Iterator<Item = NativeLib> + 'a {
self.root.native_libraries.decode((self, sess))
}
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
- trait_of_item => { cdata.get_trait_of_item(def_id.index) }
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
separate_provide_extern
}
- /// Given an `associated_item`, find the trait it belongs to.
- /// Return `None` if the `DefId` is not an associated item.
- query trait_of_item(associated_item: DefId) -> Option<DefId> {
- desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
- cache_on_disk_if { associated_item.is_local() }
- separate_provide_extern
- }
-
query is_ctfe_mir_available(key: DefId) -> bool {
desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
self.impl_trait_ref(def_id).map(|tr| tr.def_id)
}
+ /// If the given `DefId` describes an item belonging to a trait,
+ /// returns the `DefId` of the trait that the trait item belongs to;
+ /// otherwise, returns `None`.
+ pub fn trait_of_item(self, def_id: DefId) -> Option<DefId> {
+ if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
+ let parent = self.parent(def_id);
+ if let DefKind::Trait | DefKind::TraitAlias = self.def_kind(parent) {
+ return Some(parent);
+ }
+ }
+ None
+ }
+
/// If the given `DefId` describes a method belonging to an impl, returns the
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
- self.opt_associated_item(def_id).and_then(|trait_item| trait_item.impl_container(self))
+ if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
+ let parent = self.parent(def_id);
+ if let DefKind::Impl = self.def_kind(parent) {
+ return Some(parent);
+ }
+ }
+ None
}
/// If the given `DefId` belongs to a trait that was automatically derived, returns `true`.
if let DefKind::Fn | DefKind::AssocFn = tcx.def_kind(def_id) {
// If this is trait/impl method, extract the trait's substs.
- let trait_substs = match tcx.trait_of_item(def_id) {
+ let trait_substs = match tcx.trait_of_item(def_id.to_def_id()) {
Some(trait_def_id) => {
let trait_substs_count = tcx.generics_of(trait_def_id).count();
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
// If the function belongs to a trait, then it must enable the const_trait_impl
// feature to use that trait function (with a const default body).
- if tcx.trait_of_item(def_id).is_some() {
+ if tcx.trait_of_item(def_id.to_def_id()).is_some() {
return true;
}
}
] = path.segments
&& data.trait_ref.def_id == *trait_id
- && self.tcx.trait_of_item(item_id) == Some(*trait_id)
+ && self.tcx.trait_of_item(*item_id) == Some(*trait_id)
&& !self.is_tainted_by_errors()
{
let (verb, noun) = match self.tcx.associated_item(item_id).kind {
associated_item_def_ids,
associated_items,
impl_item_implementor_ids,
- trait_of_item,
..*providers
};
}
.collect()
}
-/// If the given `DefId` describes an item belonging to a trait,
-/// returns the `DefId` of the trait that the trait item belongs to;
-/// otherwise, returns `None`.
-fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
- tcx.opt_associated_item(def_id).and_then(|associated_item| associated_item.trait_container(tcx))
-}
-
fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let parent_def_id = tcx.hir().get_parent_item(id);