Directly use AttributeMap inside OwnerInfo.
This commit is contained in:
parent
1c7f85f17c
commit
41e80b85cf
8 changed files with 42 additions and 28 deletions
|
@ -672,6 +672,23 @@ pub struct ParentedNode<'tcx> {
|
|||
pub node: Node<'tcx>,
|
||||
}
|
||||
|
||||
/// Attributes owner by a HIR owner.
|
||||
#[derive(Debug)]
|
||||
pub struct AttributeMap<'tcx> {
|
||||
pub map: BTreeMap<ItemLocalId, &'tcx [Attribute]>,
|
||||
pub hash: Fingerprint,
|
||||
}
|
||||
|
||||
impl<'tcx> AttributeMap<'tcx> {
|
||||
pub const EMPTY: &'static AttributeMap<'static> =
|
||||
&AttributeMap { map: BTreeMap::new(), hash: Fingerprint::ZERO };
|
||||
|
||||
#[inline]
|
||||
pub fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] {
|
||||
self.map.get(&id).copied().unwrap_or(&[])
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OwnerNodes<'tcx> {
|
||||
/// Pre-computed hash of the full HIR.
|
||||
|
@ -691,8 +708,8 @@ pub struct OwnerInfo<'hir> {
|
|||
pub nodes: OwnerNodes<'hir>,
|
||||
/// Map from each nested owner to its parent's local id.
|
||||
pub parenting: FxHashMap<LocalDefId, ItemLocalId>,
|
||||
|
||||
pub attrs: BTreeMap<ItemLocalId, &'hir [Attribute]>,
|
||||
/// Collected attributes of the HIR nodes.
|
||||
pub attrs: AttributeMap<'hir>,
|
||||
/// Map indicating what traits are in scope for places where this
|
||||
/// is relevant; generated by resolve.
|
||||
pub trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
//!
|
||||
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
|
||||
|
||||
#![feature(const_btree_new)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![feature(once_cell)]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
|
||||
|
||||
use crate::hir::{
|
||||
BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, Mod, OwnerNodes,
|
||||
TraitItem, TraitItemId, Ty, VisibilityKind,
|
||||
AttributeMap, BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId,
|
||||
Mod, OwnerNodes, TraitItem, TraitItemId, Ty, VisibilityKind,
|
||||
};
|
||||
use crate::hir_id::{HirId, ItemLocalId};
|
||||
use rustc_span::def_id::DefPathHash;
|
||||
|
@ -218,3 +218,12 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
|
|||
hash.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap<'tcx> {
|
||||
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
||||
// We ignore the `map` since it refers to information included in `hash` which is hashed in
|
||||
// the collector and used for the crate hash.
|
||||
let AttributeMap { hash, map: _ } = *self;
|
||||
hash.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue