Skip to content

Commit b976ad0

Browse files
committed
hir atribute map to HirOwner
1 parent 84687a6 commit b976ad0

File tree

5 files changed

+11
-19
lines changed

5 files changed

+11
-19
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,6 @@ pub enum TraitItemKind<'hir> {
20552055
// The bodies for items are stored "out of line", in a separate
20562056
// hashmap in the `Crate`. Here we just record the hir-id of the item
20572057
// so it can fetched later.
2058-
/// TODO review
20592058
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
20602059
pub struct ImplItemId {
20612060
pub def_id: HirOwner,
@@ -2654,7 +2653,6 @@ impl VariantData<'hir> {
26542653
// The bodies for items are stored "out of line", in a separate
26552654
// hashmap in the `Crate`. Here we just record the hir-id of the item
26562655
// so it can fetched later.
2657-
/// TODO review
26582656
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug, Hash)]
26592657
pub struct ItemId {
26602658
pub def_id: HirOwner,
@@ -2860,7 +2858,6 @@ pub enum AssocItemKind {
28602858
// The bodies for items are stored "out of line", in a separate
28612859
// hashmap in the `Crate`. Here we just record the hir-id of the item
28622860
// so it can fetched later.
2863-
// TODO review
28642861
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
28652862
pub struct ForeignItemId {
28662863
pub def_id: HirOwner,

compiler/rustc_hir/src/hir_id.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use rustc_index::vec::IndexVec;
33
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
44
use std::fmt;
55

6-
/// TODO
76
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
87
pub struct HirOwner {
98
pub def_id: LocalDefId,

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ impl<'hir> Map<'hir> {
814814
/// Given a node ID, gets a list of attributes associated with the AST
815815
/// corresponding to the node-ID.
816816
pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] {
817-
self.tcx.hir_attrs(id.owner.def_id).get(id.local_id)
817+
self.tcx.hir_attrs(id.owner).get(id.local_id)
818818
}
819819

820820
/// Gets the span of the definition of the specified HIR node.
@@ -953,7 +953,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
953953
let def_path_hash = tcx.definitions.def_path_hash(def_id.def_id);
954954
let mut hasher = StableHasher::new();
955955
hod.with_bodies.as_ref()?.hash_stable(&mut hcx, &mut hasher);
956-
AttributeMap { map: &tcx.untracked_crate.attrs, prefix: def_id.def_id }
956+
AttributeMap { map: &tcx.untracked_crate.attrs, prefix: def_id }
957957
.hash_stable(&mut hcx, &mut hasher);
958958
Some((def_path_hash, hasher.finish()))
959959
})

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for OwnerNodes<'tcx> {
6969
#[derive(Copy, Clone)]
7070
pub struct AttributeMap<'tcx> {
7171
map: &'tcx BTreeMap<HirId, &'tcx [Attribute]>,
72-
prefix: LocalDefId,
72+
prefix: HirOwner,
7373
}
7474

7575
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for AttributeMap<'tcx> {
@@ -95,21 +95,17 @@ impl<'tcx> std::fmt::Debug for AttributeMap<'tcx> {
9595

9696
impl<'tcx> AttributeMap<'tcx> {
9797
fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] {
98-
self.map
99-
.get(&HirId { owner: HirOwner { def_id: self.prefix }, local_id: id })
100-
.copied()
101-
.unwrap_or(&[])
98+
self.map.get(&HirId { owner: self.prefix, local_id: id }).copied().unwrap_or(&[])
10299
}
103100

104101
fn range(&self) -> std::collections::btree_map::Range<'_, rustc_hir::HirId, &[Attribute]> {
105102
let local_zero = ItemLocalId::from_u32(0);
106-
let range = HirId { owner: HirOwner { def_id: self.prefix }, local_id: local_zero }
107-
..HirId {
108-
owner: HirOwner {
109-
def_id: LocalDefId { local_def_index: self.prefix.local_def_index + 1 },
110-
},
111-
local_id: local_zero,
112-
};
103+
let range = HirId { owner: self.prefix, local_id: local_zero }..HirId {
104+
owner: HirOwner {
105+
def_id: LocalDefId { local_def_index: self.prefix.def_id.local_def_index + 1 },
106+
},
107+
local_id: local_zero,
108+
};
113109
self.map.range(range)
114110
}
115111
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ rustc_queries! {
7474
///
7575
/// This can be conveniently accessed by methods on `tcx.hir()`.
7676
/// Avoid calling this query directly.
77-
query hir_attrs(key: LocalDefId) -> rustc_middle::hir::AttributeMap<'tcx> {
77+
query hir_attrs(key: HirOwner) -> rustc_middle::hir::AttributeMap<'tcx> {
7878
eval_always
7979
desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
8080
}

0 commit comments

Comments
 (0)