Skip to content

Commit 9575481

Browse files
committed
Remove trait_of_item query.
1 parent d7ea161 commit 9575481

File tree

10 files changed

+25
-36
lines changed

10 files changed

+25
-36
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
772772
let mut nonconst_call_permission = false;
773773
if let Some(callee_trait) = tcx.trait_of_item(callee)
774774
&& tcx.has_attr(callee_trait, sym::const_trait)
775-
&& Some(callee_trait) == tcx.trait_of_item(caller)
775+
&& Some(callee_trait) == tcx.trait_of_item(caller.to_def_id())
776776
// Can only call methods when it's `<Self as TheTrait>::f`.
777777
&& tcx.types.self_param == substs.type_at(0)
778778
{

compiler/rustc_incremental/src/persist/dirty_clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const BASE_STRUCT: &[&str] =
8080
/// Extra `DepNode`s for functions and methods.
8181
const EXTRA_ASSOCIATED: &[&str] = &[label_strs::associated_item];
8282

83-
const EXTRA_TRAIT: &[&str] = &[label_strs::trait_of_item];
83+
const EXTRA_TRAIT: &[&str] = &[];
8484

8585
// Fully Built Labels
8686

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,19 +1303,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13031303
}
13041304
}
13051305

1306-
fn get_trait_of_item(self, id: DefIndex) -> Option<DefId> {
1307-
let def_key = self.def_key(id);
1308-
match def_key.disambiguated_data.data {
1309-
DefPathData::TypeNs(..) | DefPathData::ValueNs(..) => (),
1310-
// Not an associated item
1311-
_ => return None,
1312-
}
1313-
def_key.parent.and_then(|parent_index| match self.kind(parent_index) {
1314-
EntryKind::Trait | EntryKind::TraitAlias => Some(self.local_def_id(parent_index)),
1315-
_ => None,
1316-
})
1317-
}
1318-
13191306
fn get_native_libraries(self, sess: &'a Session) -> impl Iterator<Item = NativeLib> + 'a {
13201307
self.root.native_libraries.decode((self, sess))
13211308
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
235235
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
236236
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
237237
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
238-
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
239238
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
240239
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
241240

compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,14 +1147,6 @@ rustc_queries! {
11471147
separate_provide_extern
11481148
}
11491149

1150-
/// Given an `associated_item`, find the trait it belongs to.
1151-
/// Return `None` if the `DefId` is not an associated item.
1152-
query trait_of_item(associated_item: DefId) -> Option<DefId> {
1153-
desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
1154-
cache_on_disk_if { associated_item.is_local() }
1155-
separate_provide_extern
1156-
}
1157-
11581150
query is_ctfe_mir_available(key: DefId) -> bool {
11591151
desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
11601152
cache_on_disk_if { key.is_local() }

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,10 +2191,29 @@ impl<'tcx> TyCtxt<'tcx> {
21912191
self.impl_trait_ref(def_id).map(|tr| tr.def_id)
21922192
}
21932193

2194+
/// If the given `DefId` describes an item belonging to a trait,
2195+
/// returns the `DefId` of the trait that the trait item belongs to;
2196+
/// otherwise, returns `None`.
2197+
pub fn trait_of_item(self, def_id: DefId) -> Option<DefId> {
2198+
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
2199+
let parent = self.parent(def_id);
2200+
if let DefKind::Trait | DefKind::TraitAlias = self.def_kind(parent) {
2201+
return Some(parent);
2202+
}
2203+
}
2204+
None
2205+
}
2206+
21942207
/// If the given `DefId` describes a method belonging to an impl, returns the
21952208
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
21962209
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
2197-
self.opt_associated_item(def_id).and_then(|trait_item| trait_item.impl_container(self))
2210+
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
2211+
let parent = self.parent(def_id);
2212+
if let DefKind::Impl = self.def_kind(parent) {
2213+
return Some(parent);
2214+
}
2215+
}
2216+
None
21982217
}
21992218

22002219
/// If the given `DefId` belongs to a trait that was automatically derived, returns `true`.

compiler/rustc_mir_build/src/lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1414

1515
if let DefKind::Fn | DefKind::AssocFn = tcx.def_kind(def_id) {
1616
// If this is trait/impl method, extract the trait's substs.
17-
let trait_substs = match tcx.trait_of_item(def_id) {
17+
let trait_substs = match tcx.trait_of_item(def_id.to_def_id()) {
1818
Some(trait_def_id) => {
1919
let trait_substs_count = tcx.generics_of(trait_def_id).count();
2020
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]

compiler/rustc_passes/src/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
9797

9898
// If the function belongs to a trait, then it must enable the const_trait_impl
9999
// feature to use that trait function (with a const default body).
100-
if tcx.trait_of_item(def_id).is_some() {
100+
if tcx.trait_of_item(def_id.to_def_id()).is_some() {
101101
return true;
102102
}
103103

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
21292129
}
21302130
] = path.segments
21312131
&& data.trait_ref.def_id == *trait_id
2132-
&& self.tcx.trait_of_item(item_id) == Some(*trait_id)
2132+
&& self.tcx.trait_of_item(*item_id) == Some(*trait_id)
21332133
&& !self.is_tainted_by_errors()
21342134
{
21352135
let (verb, noun) = match self.tcx.associated_item(item_id).kind {

compiler/rustc_ty_utils/src/assoc.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
99
associated_item_def_ids,
1010
associated_items,
1111
impl_item_implementor_ids,
12-
trait_of_item,
1312
..*providers
1413
};
1514
}
@@ -40,13 +39,6 @@ fn impl_item_implementor_ids(tcx: TyCtxt<'_>, impl_id: DefId) -> FxHashMap<DefId
4039
.collect()
4140
}
4241

43-
/// If the given `DefId` describes an item belonging to a trait,
44-
/// returns the `DefId` of the trait that the trait item belongs to;
45-
/// otherwise, returns `None`.
46-
fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
47-
tcx.opt_associated_item(def_id).and_then(|associated_item| associated_item.trait_container(tcx))
48-
}
49-
5042
fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
5143
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
5244
let parent_def_id = tcx.hir().get_parent_item(id);

0 commit comments

Comments
 (0)