Directly use AttributeMap inside OwnerInfo.

This commit is contained in:
Camille GILLOT
2021-09-12 11:41:35 +02:00
parent 1c7f85f17c
commit 41e80b85cf
8 changed files with 42 additions and 28 deletions

View File

@@ -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]>>,