Skip to content

Commit 786a80e

Browse files
committed
Only store a LocalDefId in hir::ImplItem.
1 parent a871a0f commit 786a80e

File tree

56 files changed

+163
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+163
-165
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
9898
}
9999
AssocCtxt::Impl => {
100100
let hir_item = lctx.lower_impl_item(item);
101-
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
101+
let id = hir_item.impl_item_id();
102102
lctx.impl_items.insert(id, hir_item);
103103
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
104104
}
@@ -931,7 +931,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
931931
let has_value = true;
932932
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
933933
hir::ImplItem {
934-
hir_id: self.lower_node_id(i.id),
934+
def_id: self.lower_node_id(i.id).expect_owner(),
935935
ident: i.ident,
936936
attrs: self.lower_attrs(&i.attrs),
937937
generics,
@@ -947,7 +947,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
947947
let has_value = true;
948948
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
949949
hir::ImplItemRef {
950-
id: hir::ImplItemId { hir_id: self.lower_node_id(i.id) },
950+
id: hir::ImplItemId { def_id: self.lower_node_id(i.id).expect_owner() },
951951
ident: i.ident,
952952
span: i.span,
953953
vis: self.lower_visibility(&i.vis, Some(i.id)),

compiler/rustc_hir/src/hir.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,14 +1969,21 @@ pub enum TraitItemKind<'hir> {
19691969
// so it can fetched later.
19701970
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
19711971
pub struct ImplItemId {
1972-
pub hir_id: HirId,
1972+
pub def_id: LocalDefId,
1973+
}
1974+
1975+
impl ImplItemId {
1976+
pub fn hir_id(&self) -> HirId {
1977+
// Items are always HIR owners.
1978+
HirId::make_owner(self.def_id)
1979+
}
19731980
}
19741981

19751982
/// Represents anything within an `impl` block.
19761983
#[derive(Debug)]
19771984
pub struct ImplItem<'hir> {
19781985
pub ident: Ident,
1979-
pub hir_id: HirId,
1986+
pub def_id: LocalDefId,
19801987
pub vis: Visibility<'hir>,
19811988
pub defaultness: Defaultness,
19821989
pub attrs: &'hir [Attribute],
@@ -1985,6 +1992,17 @@ pub struct ImplItem<'hir> {
19851992
pub span: Span,
19861993
}
19871994

1995+
impl ImplItem<'_> {
1996+
pub fn hir_id(&self) -> HirId {
1997+
// Items are always HIR owners.
1998+
HirId::make_owner(self.def_id)
1999+
}
2000+
2001+
pub fn impl_item_id(&self) -> ImplItemId {
2002+
ImplItemId { def_id: self.def_id }
2003+
}
2004+
}
2005+
19882006
/// Represents various kinds of content within an `impl`.
19892007
#[derive(Debug, HashStable_Generic)]
19902008
pub enum ImplItemKind<'hir> {
@@ -2903,11 +2921,10 @@ impl<'hir> Node<'hir> {
29032921

29042922
pub fn hir_id(&self) -> Option<HirId> {
29052923
match self {
2906-
Node::Item(Item { def_id, .. }) | Node::TraitItem(TraitItem { def_id, .. }) => {
2907-
Some(HirId::make_owner(*def_id))
2908-
}
2924+
Node::Item(Item { def_id, .. })
2925+
| Node::TraitItem(TraitItem { def_id, .. })
2926+
| Node::ImplItem(ImplItem { def_id, .. }) => Some(HirId::make_owner(*def_id)),
29092927
Node::ForeignItem(ForeignItem { hir_id, .. })
2910-
| Node::ImplItem(ImplItem { hir_id, .. })
29112928
| Node::Field(StructField { hir_id, .. })
29122929
| Node::AnonConst(AnonConst { hir_id, .. })
29132930
| Node::Expr(Expr { hir_id, .. })

compiler/rustc_hir/src/intravisit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
10041004
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
10051005
// N.B., deliberately force a compilation error if/when new fields are added.
10061006
let ImplItem {
1007-
hir_id: _,
1007+
def_id: _,
10081008
ident,
10091009
ref vis,
10101010
ref defaultness,
@@ -1021,7 +1021,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
10211021
visitor.visit_generics(generics);
10221022
match *kind {
10231023
ImplItemKind::Const(ref ty, body) => {
1024-
visitor.visit_id(impl_item.hir_id);
1024+
visitor.visit_id(impl_item.hir_id());
10251025
visitor.visit_ty(ty);
10261026
visitor.visit_nested_body(body);
10271027
}
@@ -1031,11 +1031,11 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
10311031
&sig.decl,
10321032
body_id,
10331033
impl_item.span,
1034-
impl_item.hir_id,
1034+
impl_item.hir_id(),
10351035
);
10361036
}
10371037
ImplItemKind::TyAlias(ref ty) => {
1038-
visitor.visit_id(impl_item.hir_id);
1038+
visitor.visit_id(impl_item.hir_id());
10391039
visitor.visit_ty(ty);
10401040
}
10411041
}

compiler/rustc_hir/src/stable_hash_impls.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
5353
}
5454

5555
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
56-
type KeyType = (DefPathHash, ItemLocalId);
56+
type KeyType = DefPathHash;
5757

5858
#[inline]
59-
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
60-
self.hir_id.to_stable_hash_key(hcx)
59+
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
60+
hcx.local_def_path_hash(self.def_id)
6161
}
6262
}
6363

@@ -103,7 +103,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ForeignItemId {
103103

104104
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId {
105105
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
106-
hcx.hash_reference_to_item(self.hir_id, hasher)
106+
hcx.hash_reference_to_item(self.hir_id(), hasher)
107107
}
108108
}
109109

@@ -154,7 +154,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
154154
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
155155
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
156156
let ImplItem {
157-
hir_id: _,
157+
def_id: _,
158158
ident,
159159
ref vis,
160160
defaultness,

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ impl<'a> State<'a> {
973973
}
974974

975975
pub fn print_impl_item(&mut self, ii: &hir::ImplItem<'_>) {
976-
self.ann.pre(self, AnnNode::SubItem(ii.hir_id));
976+
self.ann.pre(self, AnnNode::SubItem(ii.hir_id()));
977977
self.hardbreak_if_not_bol();
978978
self.maybe_print_comment(ii.span.lo());
979979
self.print_outer_attributes(&ii.attrs);
@@ -995,7 +995,7 @@ impl<'a> State<'a> {
995995
self.print_associated_type(ii.ident, &ii.generics, None, Some(ty));
996996
}
997997
}
998-
self.ann.post(self, AnnNode::SubItem(ii.hir_id))
998+
self.ann.post(self, AnnNode::SubItem(ii.hir_id()))
999999
}
10001000

10011001
pub fn print_local(&mut self, init: Option<&hir::Expr<'_>>, decl: impl Fn(&mut Self)) {

compiler/rustc_incremental/src/assert_dep_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl Visitor<'tcx> for IfThisChanged<'tcx> {
177177
}
178178

179179
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
180-
self.process_attrs(impl_item.hir_id, &impl_item.attrs);
180+
self.process_attrs(impl_item.hir_id(), &impl_item.attrs);
181181
intravisit::walk_impl_item(self, impl_item);
182182
}
183183

compiler/rustc_incremental/src/persist/dirty_clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
458458
}
459459

460460
fn visit_impl_item(&mut self, item: &hir::ImplItem<'_>) {
461-
self.check_item(item.hir_id, item.span);
461+
self.check_item(item.hir_id(), item.span);
462462
}
463463

464464
fn visit_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
77
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
88
use rustc_hir::def_id::DefId;
99
use rustc_hir::intravisit::{walk_ty, ErasedMap, NestedVisitorMap, Visitor};
10-
use rustc_hir::{
11-
self as hir, GenericBound, ImplItem, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind,
12-
};
10+
use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
1311
use rustc_middle::ty::{self, AssocItemContainer, RegionKind, Ty, TypeFoldable, TypeVisitor};
1412
use rustc_span::symbol::Ident;
1513
use rustc_span::{MultiSpan, Span};
@@ -342,12 +340,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
342340
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
343341
let tcx = self.tcx();
344342
match tcx.hir().get_if_local(def_id) {
345-
Some(Node::ImplItem(ImplItem { ident, hir_id, .. })) => {
346-
match tcx.hir().find(tcx.hir().get_parent_item(*hir_id)) {
343+
Some(Node::ImplItem(impl_item)) => {
344+
match tcx.hir().find(tcx.hir().get_parent_item(impl_item.hir_id())) {
347345
Some(Node::Item(Item {
348346
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
349347
..
350-
})) => Some((*ident, self_ty)),
348+
})) => Some((impl_item.ident, self_ty)),
351349
_ => None,
352350
}
353351
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
600600
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
601601
if let hir::VisibilityKind::Inherited = item.vis.node {
602602
for impl_item_ref in items {
603-
self.private_traits.insert(impl_item_ref.id.hir_id);
603+
self.private_traits.insert(impl_item_ref.id.hir_id());
604604
}
605605
}
606606
}
@@ -644,15 +644,14 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
644644

645645
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
646646
// If the method is an impl for a trait, don't doc.
647-
if method_context(cx, impl_item.hir_id) == MethodLateContext::TraitImpl {
647+
if method_context(cx, impl_item.hir_id()) == MethodLateContext::TraitImpl {
648648
return;
649649
}
650650

651-
let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id);
652-
let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id());
651+
let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
653652
self.check_missing_docs_attrs(
654653
cx,
655-
Some(impl_item.hir_id),
654+
Some(impl_item.hir_id()),
656655
&impl_item.attrs,
657656
impl_item.span,
658657
article,
@@ -1378,7 +1377,7 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
13781377
}
13791378

13801379
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
1381-
self.perform_lint(cx, "item", impl_item.hir_id, &impl_item.vis, impl_item.span, false);
1380+
self.perform_lint(cx, "item", impl_item.hir_id(), &impl_item.vis, impl_item.span, false);
13821381
}
13831382
}
13841383

compiler/rustc_lint/src/late.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
314314
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
315315
let generics = self.context.generics.take();
316316
self.context.generics = Some(&impl_item.generics);
317-
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |cx| {
318-
cx.with_param_env(impl_item.hir_id, |cx| {
317+
self.with_lint_attrs(impl_item.hir_id(), &impl_item.attrs, |cx| {
318+
cx.with_param_env(impl_item.hir_id(), |cx| {
319319
lint_callback!(cx, check_impl_item, impl_item);
320320
hir_visit::walk_impl_item(cx, impl_item);
321321
lint_callback!(cx, check_impl_item_post, impl_item);

0 commit comments

Comments
 (0)