Skip to content

Commit 7dd1e8c

Browse files
committed
Trait impls are Items, therefore HIR owners.
1 parent f395f2e commit 7dd1e8c

File tree

10 files changed

+16
-22
lines changed

10 files changed

+16
-22
lines changed

Diff for: compiler/rustc_ast_lowering/src/item.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
396396
self_ty: ref ty,
397397
items: ref impl_items,
398398
}) => {
399-
let def_id = self.resolver.local_def_id(id);
400-
401399
// Lower the "impl header" first. This ordering is important
402400
// for in-band lifetimes! Consider `'a` here:
403401
//
@@ -411,10 +409,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
411409
// method, it will not be considered an in-band
412410
// lifetime to be added, but rather a reference to a
413411
// parent lifetime.
414-
let lowered_trait_impl_id = self.lower_node_id(id);
412+
let lowered_trait_def_id = self.lower_node_id(id).expect_owner();
415413
let (generics, (trait_ref, lowered_ty)) = self.add_in_band_defs(
416414
ast_generics,
417-
def_id,
415+
lowered_trait_def_id,
418416
AnonymousLifetimeMode::CreateParameter,
419417
|this, _| {
420418
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
@@ -426,7 +424,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
426424
this.trait_impls
427425
.entry(def_id)
428426
.or_default()
429-
.push(lowered_trait_impl_id);
427+
.push(lowered_trait_def_id);
430428
}
431429
}
432430

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct LoweringContext<'a, 'hir: 'a> {
108108
exported_macros: Vec<hir::MacroDef<'hir>>,
109109
non_exported_macro_attrs: Vec<ast::Attribute>,
110110

111-
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
111+
trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
112112

113113
modules: BTreeMap<LocalDefId, hir::ModuleItems>,
114114

Diff for: compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ pub struct Crate<'hir> {
658658
pub impl_items: BTreeMap<ImplItemId, ImplItem<'hir>>,
659659
pub foreign_items: BTreeMap<ForeignItemId, ForeignItem<'hir>>,
660660
pub bodies: BTreeMap<BodyId, Body<'hir>>,
661-
pub trait_impls: BTreeMap<DefId, Vec<HirId>>,
661+
pub trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
662662

663663
/// A list of the body ids written out in the order in which they
664664
/// appear in the crate. If you're going to process all the bodies

Diff for: compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
361361
.hir()
362362
.trait_impls(trait_did)
363363
.iter()
364-
.filter_map(|impl_node| {
365-
let impl_did = tcx.hir().local_def_id(*impl_node);
364+
.filter_map(|&impl_did| {
366365
match tcx.hir().get_if_local(impl_did.to_def_id()) {
367366
Some(Node::Item(Item {
368367
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),

Diff for: compiler/rustc_middle/src/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl<'hir> Map<'hir> {
449449
}
450450
}
451451

452-
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [HirId] {
452+
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [LocalDefId] {
453453
self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
454454
}
455455

Diff for: compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ rustc_queries! {
956956
/// Passing in any other crate will cause an ICE.
957957
///
958958
/// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
959-
query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
959+
query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
960960
desc { "local trait impls" }
961961
}
962962

Diff for: compiler/rustc_middle/src/ty/trait_def.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use crate::ty::fast_reject;
44
use crate::ty::fold::TypeFoldable;
55
use crate::ty::{Ty, TyCtxt};
66
use rustc_hir as hir;
7-
use rustc_hir::def_id::{CrateNum, DefId};
7+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
88
use rustc_hir::definitions::DefPathHash;
9-
use rustc_hir::HirId;
109

1110
use rustc_data_structures::fx::FxHashMap;
1211
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -201,7 +200,7 @@ impl<'tcx> TyCtxt<'tcx> {
201200
pub(super) fn all_local_trait_impls<'tcx>(
202201
tcx: TyCtxt<'tcx>,
203202
krate: CrateNum,
204-
) -> &'tcx BTreeMap<DefId, Vec<HirId>> {
203+
) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
205204
&tcx.hir_crate(krate).trait_impls
206205
}
207206

@@ -229,8 +228,8 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
229228
}
230229
}
231230

232-
for &hir_id in tcx.hir().trait_impls(trait_id) {
233-
let impl_def_id = tcx.hir().local_def_id(hir_id).to_def_id();
231+
for &impl_def_id in tcx.hir().trait_impls(trait_id) {
232+
let impl_def_id = impl_def_id.to_def_id();
234233

235234
let impl_self_ty = tcx.type_of(impl_def_id);
236235
if impl_self_ty.references_error() {

Diff for: compiler/rustc_typeck/src/coherence/builtin.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ impl<'tcx> Checker<'tcx> {
3838
F: FnMut(TyCtxt<'tcx>, LocalDefId),
3939
{
4040
if Some(self.trait_def_id) == trait_def_id {
41-
for &impl_id in self.tcx.hir().trait_impls(self.trait_def_id) {
42-
let impl_def_id = self.tcx.hir().local_def_id(impl_id);
41+
for &impl_def_id in self.tcx.hir().trait_impls(self.trait_def_id) {
4342
f(self.tcx, impl_def_id);
4443
}
4544
}

Diff for: compiler/rustc_typeck/src/coherence/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
172172
tcx.ensure().specialization_graph_of(def_id);
173173

174174
let impls = tcx.hir().trait_impls(def_id);
175-
for &hir_id in impls {
176-
let impl_def_id = tcx.hir().local_def_id(hir_id);
175+
for &impl_def_id in impls {
177176
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
178177

179178
check_impl(tcx, impl_def_id, trait_ref);

Diff for: src/librustdoc/passes/collect_trait_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ crate fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {
5858
// doesn't work with it anyway, so pull them from the HIR map instead
5959
let mut extra_attrs = Vec::new();
6060
for &trait_did in cx.tcx.all_traits(LOCAL_CRATE).iter() {
61-
for &impl_node in cx.tcx.hir().trait_impls(trait_did) {
62-
let impl_did = cx.tcx.hir().local_def_id(impl_node).to_def_id();
61+
for &impl_did in cx.tcx.hir().trait_impls(trait_did) {
62+
let impl_did = impl_did.to_def_id();
6363
cx.tcx.sess.prof.generic_activity("build_local_trait_impl").run(|| {
6464
let mut parent = cx.tcx.parent(impl_did);
6565
while let Some(did) = parent {

0 commit comments

Comments
 (0)