Skip to content

Commit ec7d272

Browse files
committed
Localize many method calls
1 parent b20dbd9 commit ec7d272

17 files changed

Lines changed: 32 additions & 25 deletions

File tree

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
107107
);
108108

109109
return ty::GenericPredicates {
110-
parent: Some(tcx.parent(def_id.to_def_id())),
110+
parent: Some(tcx.local_parent(def_id).to_def_id()),
111111
predicates: tcx.arena.alloc_from_iter(predicates),
112112
};
113113
}

compiler/rustc_incremental/src/assert_dep_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ struct IfThisChanged<'tcx> {
107107

108108
impl<'tcx> IfThisChanged<'tcx> {
109109
fn process_attrs(&mut self, def_id: LocalDefId) {
110-
let def_path_hash = self.tcx.def_path_hash(def_id.to_def_id());
110+
let def_path_hash = self.tcx.local_def_path_hash(def_id);
111111
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
112112
let attrs = self.tcx.hir_attrs(hir_id);
113113
for attr in attrs {

compiler/rustc_incremental/src/persist/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<'tcx> CleanVisitor<'tcx> {
350350

351351
fn check_item(&mut self, item_id: LocalDefId) {
352352
let item_span = self.tcx.def_span(item_id.to_def_id());
353-
let def_path_hash = self.tcx.def_path_hash(item_id.to_def_id());
353+
let def_path_hash = self.tcx.local_def_path_hash(item_id);
354354

355355
let Some(clean_attrs) = find_attr!(self.tcx, item_id, RustcClean(attr) => attr) else {
356356
return;

compiler/rustc_lint/src/default_could_be_derived.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
6363
}
6464
let hir::ImplItemKind::Fn(_sig, body_id) = impl_item.kind else { return };
6565
let impl_id = cx.tcx.local_parent(impl_item.owner_id.def_id);
66-
if cx.tcx.is_automatically_derived(impl_id.to_def_id()) {
66+
if cx.tcx.is_automatically_derived_local(impl_id) {
6767
// We don't care about what `#[derive(Default)]` produces in this lint.
6868
return;
6969
}

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
727727
is_stub: false,
728728
},
729729
extra_filename: tcx.sess.opts.cg.extra_filename.clone(),
730-
stable_crate_id: tcx.def_path_hash(LOCAL_CRATE.as_def_id()).stable_crate_id(),
730+
stable_crate_id: tcx.stable_crate_id(LOCAL_CRATE),
731731
required_panic_strategy: tcx.required_panic_strategy(LOCAL_CRATE),
732732
panic_in_drop_strategy: tcx.sess.opts.unstable_opts.panic_in_drop,
733733
edition: tcx.sess.edition(),

compiler/rustc_middle/src/dep_graph/dep_node_key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'tcx> DepNodeKey<'tcx> for LocalDefId {
109109

110110
#[inline(always)]
111111
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
112-
self.to_def_id().to_fingerprint(tcx)
112+
tcx.local_def_path_hash(*self).0
113113
}
114114

115115
#[inline(always)]
@@ -207,7 +207,7 @@ impl<'tcx> DepNodeKey<'tcx> for HirId {
207207
#[inline(always)]
208208
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
209209
let HirId { owner, local_id } = *self;
210-
let def_path_hash = tcx.def_path_hash(owner.to_def_id());
210+
let def_path_hash = tcx.local_def_path_hash(owner.def_id);
211211
Fingerprint::new(
212212
// `owner` is local, so is completely defined by the local hash
213213
def_path_hash.local_hash(),

compiler/rustc_middle/src/ty/context.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,12 @@ impl<'tcx> TyCtxt<'tcx> {
12071207
}
12081208
}
12091209

1210+
#[inline]
1211+
pub fn local_def_path_hash(self, def_id: LocalDefId) -> rustc_hir::definitions::DefPathHash {
1212+
// Accessing the DefPathHash is ok, it is incr. comp. stable.
1213+
self.definitions_untracked().def_path_hash(def_id)
1214+
}
1215+
12101216
#[inline]
12111217
pub fn crate_types(self) -> &'tcx [CrateType] {
12121218
&self.crate_types

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ impl<'tcx> TyCtxt<'tcx> {
14111411

14121412
// Generate a deterministically-derived seed from the item's path hash
14131413
// to allow for cross-crate compilation to actually work
1414-
let mut field_shuffle_seed = self.def_path_hash(did.to_def_id()).0.to_smaller_hash();
1414+
let mut field_shuffle_seed = self.local_def_path_hash(did).0.to_smaller_hash();
14151415

14161416
// If the user defined a custom seed for layout randomization, xor the item's
14171417
// path hash with the user defined seed, this will allowing determinism while
@@ -1988,6 +1988,11 @@ impl<'tcx> TyCtxt<'tcx> {
19881988
find_attr!(self, def_id, AutomaticallyDerived(..))
19891989
}
19901990

1991+
/// Check if the given `DefId` is `#\[automatically_derived\]`.
1992+
pub fn is_automatically_derived_local(self, def_id: LocalDefId) -> bool {
1993+
find_attr!(self, def_id, AutomaticallyDerived(..))
1994+
}
1995+
19911996
/// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err`
19921997
/// with the name of the crate containing the impl.
19931998
pub fn span_of_impl(self, impl_def_id: DefId) -> Result<Span, Symbol> {

compiler/rustc_mir_transform/src/coverage/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
6161
//
6262
// This affects not just the associated items of an impl block, but also
6363
// any closures and other nested functions within those associated items.
64-
if tcx.is_automatically_derived(def_id.to_def_id()) {
64+
if tcx.is_automatically_derived_local(def_id) {
6565
return false;
6666
}
6767

compiler/rustc_passes/src/dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
380380
/// for discussion).
381381
fn should_ignore_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) -> bool {
382382
if let hir::ImplItemImplKind::Trait { .. } = impl_item.impl_kind
383-
&& let impl_of = self.tcx.parent(impl_item.owner_id.to_def_id())
384-
&& self.tcx.is_automatically_derived(impl_of)
383+
&& let impl_of = self.tcx.local_parent(impl_item.owner_id.def_id)
384+
&& self.tcx.is_automatically_derived_local(impl_of)
385385
&& let trait_ref = self.tcx.impl_trait_ref(impl_of).instantiate_identity()
386386
&& find_attr!(self.tcx, trait_ref.def_id, RustcTrivialFieldReads)
387387
{

0 commit comments

Comments
 (0)