diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-01-30 20:46:50 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-02-15 19:32:28 +0100 |
| commit | a871a0f11196ed028edeedc4843338f702880672 (patch) | |
| tree | c8420d83e77f3b66d3b47b6ddfc1aac50626f63b /compiler/rustc_hir | |
| parent | cebbba081e4609099df3921de8a1422b7ea52599 (diff) | |
| download | rust-a871a0f11196ed028edeedc4843338f702880672.tar.gz rust-a871a0f11196ed028edeedc4843338f702880672.zip | |
Only store a LocalDefId in hir::TraitItem.
Diffstat (limited to 'compiler/rustc_hir')
| -rw-r--r-- | compiler/rustc_hir/src/hir.rs | 29 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/intravisit.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/stable_hash_impls.rs | 10 |
3 files changed, 33 insertions, 14 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 2abb8fb2731..d47e0a4629a 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1907,7 +1907,14 @@ pub struct FnSig<'hir> { // so it can fetched later. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)] pub struct TraitItemId { - pub hir_id: HirId, + pub def_id: LocalDefId, +} + +impl TraitItemId { + pub fn hir_id(&self) -> HirId { + // Items are always HIR owners. + HirId::make_owner(self.def_id) + } } /// Represents an item declaration within a trait declaration, @@ -1917,13 +1924,24 @@ pub struct TraitItemId { #[derive(Debug)] pub struct TraitItem<'hir> { pub ident: Ident, - pub hir_id: HirId, + pub def_id: LocalDefId, pub attrs: &'hir [Attribute], pub generics: Generics<'hir>, pub kind: TraitItemKind<'hir>, pub span: Span, } +impl TraitItem<'_> { + pub fn hir_id(&self) -> HirId { + // Items are always HIR owners. + HirId::make_owner(self.def_id) + } + + pub fn trait_item_id(&self) -> TraitItemId { + TraitItemId { def_id: self.def_id } + } +} + /// Represents a trait method's body (or just argument names). #[derive(Encodable, Debug, HashStable_Generic)] pub enum TraitFn<'hir> { @@ -2885,9 +2903,10 @@ impl<'hir> Node<'hir> { pub fn hir_id(&self) -> Option<HirId> { match self { - Node::Item(Item { def_id, .. }) => Some(HirId::make_owner(*def_id)), + Node::Item(Item { def_id, .. }) | Node::TraitItem(TraitItem { def_id, .. }) => { + Some(HirId::make_owner(*def_id)) + } Node::ForeignItem(ForeignItem { hir_id, .. }) - | Node::TraitItem(TraitItem { hir_id, .. }) | Node::ImplItem(ImplItem { hir_id, .. }) | Node::Field(StructField { hir_id, .. }) | Node::AnonConst(AnonConst { hir_id, .. }) @@ -2922,7 +2941,7 @@ mod size_asserts { rustc_data_structures::static_assert_size!(super::Ty<'static>, 72); rustc_data_structures::static_assert_size!(super::Item<'static>, 200); - rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 152); + rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 144); rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 168); rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 160); } diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index e492cef7733..a145d4dc476 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -964,12 +964,12 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai visitor.visit_generics(&trait_item.generics); match trait_item.kind { TraitItemKind::Const(ref ty, default) => { - visitor.visit_id(trait_item.hir_id); + visitor.visit_id(trait_item.hir_id()); visitor.visit_ty(ty); walk_list!(visitor, visit_nested_body, default); } TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => { - visitor.visit_id(trait_item.hir_id); + visitor.visit_id(trait_item.hir_id()); visitor.visit_fn_decl(&sig.decl); for ¶m_name in param_names { visitor.visit_ident(param_name); @@ -981,11 +981,11 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai &sig.decl, body_id, trait_item.span, - trait_item.hir_id, + trait_item.hir_id(), ); } TraitItemKind::Type(bounds, ref default) => { - visitor.visit_id(trait_item.hir_id); + visitor.visit_id(trait_item.hir_id()); walk_list!(visitor, visit_param_bound, bounds); walk_list!(visitor, visit_ty, default); } diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index b0d332e0028..e7e676fe147 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -44,11 +44,11 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId { } impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId { - type KeyType = (DefPathHash, ItemLocalId); + type KeyType = DefPathHash; #[inline] - fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) { - self.hir_id.to_stable_hash_key(hcx) + fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash { + hcx.local_def_path_hash(self.def_id) } } @@ -109,7 +109,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItemId { impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItemId { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { - hcx.hash_reference_to_item(self.hir_id, hasher) + hcx.hash_reference_to_item(self.hir_id(), hasher) } } @@ -139,7 +139,7 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for VisibilityKind<'_> impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { - let TraitItem { hir_id: _, ident, ref attrs, ref generics, ref kind, span } = *self; + let TraitItem { def_id: _, ident, ref attrs, ref generics, ref kind, span } = *self; hcx.hash_hir_item_like(|hcx| { ident.name.hash_stable(hcx, hasher); |
