pub struct ModuleItems {
// Use BTreeSets here so items are in the same order as in the
// list of all items in Crate
- pub items: BTreeSet<HirId>,
+ pub items: BTreeSet<ItemId>,
pub trait_items: BTreeSet<TraitItemId>,
pub impl_items: BTreeSet<ImplItemId>,
pub foreign_items: BTreeSet<ForeignItemId>,
// does, because it can affect the order in which errors are
// detected, which in turn can make UI tests yield
// slightly different results.
- pub items: BTreeMap<HirId, Item<'hir>>,
+ pub items: BTreeMap<ItemId, Item<'hir>>,
pub trait_items: BTreeMap<TraitItemId, TraitItem<'hir>>,
pub impl_items: BTreeMap<ImplItemId, ImplItem<'hir>>,
}
impl Crate<'hir> {
- pub fn item(&self, id: HirId) -> &Item<'hir> {
+ pub fn item(&self, id: ItemId) -> &Item<'hir> {
&self.items[&id]
}
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
pub enum UnOp {
/// The `*` operator (deferencing).
- UnDeref,
+ Deref,
/// The `!` operator (logical negation).
- UnNot,
+ Not,
/// The `-` operator (negation).
- UnNeg,
+ Neg,
}
impl UnOp {
pub fn as_str(self) -> &'static str {
match self {
- Self::UnDeref => "*",
- Self::UnNot => "!",
- Self::UnNeg => "-",
+ Self::Deref => "*",
+ Self::Not => "!",
+ Self::Neg => "-",
}
}
/// Returns `true` if the unary operator takes its argument by value.
pub fn is_by_value(self) -> bool {
- matches!(self, Self::UnNeg | Self::UnNot)
+ matches!(self, Self::Neg | Self::Not)
}
}
pub span: Span,
}
-// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
-#[cfg(target_arch = "x86_64")]
-rustc_data_structures::static_assert_size!(Expr<'static>, 72);
-
impl Expr<'_> {
pub fn precedence(&self) -> ExprPrecedence {
match self.kind {
// https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md#type-ascription-and-temporaries
ExprKind::Type(ref e, _) => e.is_place_expr(allow_projections_from),
- ExprKind::Unary(UnOp::UnDeref, _) => true,
+ ExprKind::Unary(UnOp::Deref, _) => true,
ExprKind::Field(ref base, _) | ExprKind::Index(ref base, _) => {
allow_projections_from(base) || base.is_place_expr(allow_projections_from)
// The bodies for items are stored "out of line", in a separate
// hashmap in the `Crate`. Here we just record the hir-id of the item
// so it can fetched later.
-#[derive(Copy, Clone, Encodable, Debug)]
+#[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 {
+ // Items are always HIR owners.
+ HirId::make_owner(self.def_id)
+ }
}
/// An item
#[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>,
pub span: Span,
}
+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 { def_id: self.def_id }
+ }
+}
+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Encodable, Decodable, HashStable_Generic)]
pub enum Unsafety {
pub fn hir_id(&self) -> Option<HirId> {
match self {
- Node::Item(Item { hir_id, .. })
- | Node::ForeignItem(ForeignItem { hir_id, .. })
+ Node::Item(Item { 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, .. })
}
}
}
+
+// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
+#[cfg(target_arch = "x86_64")]
+mod size_asserts {
+ rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
+ rustc_data_structures::static_assert_size!(super::Expr<'static>, 72);
+ rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
+ 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>, 200);
+ rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 152);
+ rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 168);
+ rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 160);
+}