Remove trait_of_item query.
This commit is contained in:
parent
d7ea161b7e
commit
957548183d
10 changed files with 25 additions and 36 deletions
|
@ -772,7 +772,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
let mut nonconst_call_permission = false;
|
let mut nonconst_call_permission = false;
|
||||||
if let Some(callee_trait) = tcx.trait_of_item(callee)
|
if let Some(callee_trait) = tcx.trait_of_item(callee)
|
||||||
&& tcx.has_attr(callee_trait, sym::const_trait)
|
&& 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`.
|
// Can only call methods when it's `<Self as TheTrait>::f`.
|
||||||
&& tcx.types.self_param == substs.type_at(0)
|
&& tcx.types.self_param == substs.type_at(0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,7 +80,7 @@ const BASE_STRUCT: &[&str] =
|
||||||
/// Extra `DepNode`s for functions and methods.
|
/// Extra `DepNode`s for functions and methods.
|
||||||
const EXTRA_ASSOCIATED: &[&str] = &[label_strs::associated_item];
|
const EXTRA_ASSOCIATED: &[&str] = &[label_strs::associated_item];
|
||||||
|
|
||||||
const EXTRA_TRAIT: &[&str] = &[label_strs::trait_of_item];
|
const EXTRA_TRAIT: &[&str] = &[];
|
||||||
|
|
||||||
// Fully Built Labels
|
// Fully Built Labels
|
||||||
|
|
||||||
|
|
|
@ -1303,19 +1303,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
fn get_native_libraries(self, sess: &'a Session) -> impl Iterator<Item = NativeLib> + 'a {
|
||||||
self.root.native_libraries.decode((self, sess))
|
self.root.native_libraries.decode((self, sess))
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,7 +235,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||||
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
|
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
|
||||||
is_foreign_item => { cdata.is_foreign_item(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)) }
|
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_mir_available => { cdata.is_item_mir_available(def_id.index) }
|
||||||
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
|
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
|
||||||
|
|
||||||
|
|
|
@ -1147,14 +1147,6 @@ rustc_queries! {
|
||||||
separate_provide_extern
|
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 {
|
query is_ctfe_mir_available(key: DefId) -> bool {
|
||||||
desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
|
||||||
cache_on_disk_if { key.is_local() }
|
cache_on_disk_if { key.is_local() }
|
||||||
|
|
|
@ -2191,10 +2191,29 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.impl_trait_ref(def_id).map(|tr| tr.def_id)
|
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
|
/// 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`.
|
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
|
||||||
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
|
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 the given `DefId` belongs to a trait that was automatically derived, returns `true`.
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub(crate) fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
|
||||||
|
|
||||||
if let DefKind::Fn | DefKind::AssocFn = tcx.def_kind(def_id) {
|
if let DefKind::Fn | DefKind::AssocFn = tcx.def_kind(def_id) {
|
||||||
// If this is trait/impl method, extract the trait's substs.
|
// 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) => {
|
Some(trait_def_id) => {
|
||||||
let trait_substs_count = tcx.generics_of(trait_def_id).count();
|
let trait_substs_count = tcx.generics_of(trait_def_id).count();
|
||||||
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
|
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
|
||||||
|
|
|
@ -97,7 +97,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
|
||||||
|
|
||||||
// If the function belongs to a trait, then it must enable the const_trait_impl
|
// 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).
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2129,7 +2129,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
] = path.segments
|
] = path.segments
|
||||||
&& data.trait_ref.def_id == *trait_id
|
&& 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()
|
&& !self.is_tainted_by_errors()
|
||||||
{
|
{
|
||||||
let (verb, noun) = match self.tcx.associated_item(item_id).kind {
|
let (verb, noun) = match self.tcx.associated_item(item_id).kind {
|
||||||
|
|
|
@ -9,7 +9,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
||||||
associated_item_def_ids,
|
associated_item_def_ids,
|
||||||
associated_items,
|
associated_items,
|
||||||
impl_item_implementor_ids,
|
impl_item_implementor_ids,
|
||||||
trait_of_item,
|
|
||||||
..*providers
|
..*providers
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -40,13 +39,6 @@ fn impl_item_implementor_ids(tcx: TyCtxt<'_>, impl_id: DefId) -> FxHashMap<DefId
|
||||||
.collect()
|
.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 {
|
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 id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||||
let parent_def_id = tcx.hir().get_parent_item(id);
|
let parent_def_id = tcx.hir().get_parent_item(id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue