pub impl_items: BTreeMap<ImplItemId, ImplItem<'hir>>,
pub foreign_items: BTreeMap<ForeignItemId, ForeignItem<'hir>>,
pub bodies: BTreeMap<BodyId, Body<'hir>>,
- pub trait_impls: BTreeMap<DefId, Vec<HirId>>,
+ pub trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
/// A list of the body ids written out in the order in which they
/// appear in the crate. If you're going to process all the bodies
/// A list of modules written out in the order in which they
/// appear in the crate. This includes the main crate module.
- pub modules: BTreeMap<HirId, ModuleItems>,
+ pub modules: BTreeMap<LocalDefId, ModuleItems>,
/// A list of proc macro HirIds, written out in the order in which
/// they are declared in the static array generated by proc_macro_harness.
pub proc_macros: Vec<HirId>,
/// A macro definition, in this crate or imported from another.
///
/// Not parsed directly, but created on macro import or `macro_rules!` expansion.
-#[derive(Debug, HashStable_Generic)]
+#[derive(Debug)]
pub struct MacroDef<'hir> {
pub ident: Ident,
pub vis: Visibility<'hir>,
pub attrs: &'hir [Attribute],
- pub hir_id: HirId,
+ pub def_id: LocalDefId,
pub span: Span,
pub ast: ast::MacroDef,
}
+impl MacroDef<'_> {
+ pub fn hir_id(&self) -> HirId {
+ HirId::make_owner(self.def_id)
+ }
+}
+
/// A block of statements `{ .. }`, which may have a label (in this case the
/// `targeted_by_break` field will be `true`) and may be `unsafe` by means of
/// the `rules` being anything but `DefaultBlock`.
// 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,
#[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> {
// so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
pub struct ImplItemId {
- pub hir_id: HirId,
+ pub def_id: LocalDefId,
+}
+
+impl ImplItemId {
+ pub fn hir_id(&self) -> HirId {
+ // Items are always HIR owners.
+ HirId::make_owner(self.def_id)
+ }
}
/// Represents anything within an `impl` block.
#[derive(Debug)]
pub struct ImplItem<'hir> {
pub ident: Ident,
- pub hir_id: HirId,
+ pub def_id: LocalDefId,
pub vis: Visibility<'hir>,
pub defaultness: Defaultness,
pub attrs: &'hir [Attribute],
pub span: Span,
}
+impl ImplItem<'_> {
+ pub fn hir_id(&self) -> HirId {
+ // Items are always HIR owners.
+ HirId::make_owner(self.def_id)
+ }
+
+ pub fn impl_item_id(&self) -> ImplItemId {
+ ImplItemId { def_id: self.def_id }
+ }
+}
+
/// Represents various kinds of content within an `impl`.
#[derive(Debug, HashStable_Generic)]
pub enum ImplItemKind<'hir> {
// so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug, Hash)]
pub struct ItemId {
- pub id: HirId,
+ pub def_id: LocalDefId,
}
impl ItemId {
pub fn hir_id(&self) -> HirId {
- self.id
+ // Items are always HIR owners.
+ HirId::make_owner(self.def_id)
}
}
#[derive(Debug)]
pub struct Item<'hir> {
pub ident: Ident,
- pub hir_id: HirId,
+ pub def_id: LocalDefId,
pub attrs: &'hir [Attribute],
pub kind: ItemKind<'hir>,
pub vis: Visibility<'hir>,
}
impl Item<'_> {
+ pub fn hir_id(&self) -> HirId {
+ // Items are always HIR owners.
+ HirId::make_owner(self.def_id)
+ }
+
pub fn item_id(&self) -> ItemId {
- ItemId { id: self.hir_id }
+ ItemId { def_id: self.def_id }
}
}
// so it can fetched later.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
pub struct ForeignItemId {
- pub hir_id: HirId,
+ pub def_id: LocalDefId,
+}
+
+impl ForeignItemId {
+ pub fn hir_id(&self) -> HirId {
+ // Items are always HIR owners.
+ HirId::make_owner(self.def_id)
+ }
}
/// A reference from a foreign block to one of its items. This
pub vis: Visibility<'hir>,
}
-#[derive(Debug, HashStable_Generic)]
+#[derive(Debug)]
pub struct ForeignItem<'hir> {
- #[stable_hasher(project(name))]
pub ident: Ident,
pub attrs: &'hir [Attribute],
pub kind: ForeignItemKind<'hir>,
- pub hir_id: HirId,
+ pub def_id: LocalDefId,
pub span: Span,
pub vis: Visibility<'hir>,
}
+impl ForeignItem<'_> {
+ pub fn hir_id(&self) -> HirId {
+ // Items are always HIR owners.
+ HirId::make_owner(self.def_id)
+ }
+
+ pub fn foreign_item_id(&self) -> ForeignItemId {
+ ForeignItemId { def_id: self.def_id }
+ }
+}
+
/// An item within an `extern` block.
#[derive(Debug, HashStable_Generic)]
pub enum ForeignItemKind<'hir> {
pub fn hir_id(&self) -> Option<HirId> {
match self {
- Node::Item(Item { hir_id, .. })
- | Node::ForeignItem(ForeignItem { hir_id, .. })
- | Node::TraitItem(TraitItem { hir_id, .. })
- | Node::ImplItem(ImplItem { hir_id, .. })
- | Node::Field(StructField { hir_id, .. })
+ Node::Item(Item { def_id, .. })
+ | Node::TraitItem(TraitItem { def_id, .. })
+ | Node::ImplItem(ImplItem { def_id, .. })
+ | Node::ForeignItem(ForeignItem { def_id, .. })
+ | Node::MacroDef(MacroDef { def_id, .. }) => Some(HirId::make_owner(*def_id)),
+ Node::Field(StructField { hir_id, .. })
| Node::AnonConst(AnonConst { hir_id, .. })
| Node::Expr(Expr { hir_id, .. })
| Node::Stmt(Stmt { hir_id, .. })
| Node::Arm(Arm { hir_id, .. })
| Node::Block(Block { hir_id, .. })
| Node::Local(Local { hir_id, .. })
- | Node::MacroDef(MacroDef { hir_id, .. })
| Node::Lifetime(Lifetime { hir_id, .. })
| Node::Param(Param { hir_id, .. })
| Node::GenericParam(GenericParam { hir_id, .. }) => Some(*hir_id),
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
- rustc_data_structures::static_assert_size!(super::Item<'static>, 208);
- rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 152);
+ rustc_data_structures::static_assert_size!(super::Item<'static>, 200);
+ 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);
+ rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 152);
}