rustc_index: Add a ZERO
constant to index types
It is commonly used.
This commit is contained in:
parent
ceab6128fa
commit
b40ea03f8a
42 changed files with 80 additions and 90 deletions
|
@ -846,9 +846,8 @@ pub struct OwnerNodes<'tcx> {
|
|||
|
||||
impl<'tcx> OwnerNodes<'tcx> {
|
||||
pub fn node(&self) -> OwnerNode<'tcx> {
|
||||
use rustc_index::Idx;
|
||||
// Indexing must ensure it is an OwnerNode.
|
||||
self.nodes[ItemLocalId::new(0)].node.as_owner().unwrap()
|
||||
self.nodes[ItemLocalId::ZERO].node.as_owner().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -856,7 +855,7 @@ impl fmt::Debug for OwnerNodes<'_> {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("OwnerNodes")
|
||||
// Do not print all the pointers to all the nodes, as it would be unreadable.
|
||||
.field("node", &self.nodes[ItemLocalId::from_u32(0)])
|
||||
.field("node", &self.nodes[ItemLocalId::ZERO])
|
||||
.field(
|
||||
"parents",
|
||||
&self
|
||||
|
|
|
@ -17,7 +17,7 @@ impl Debug for OwnerId {
|
|||
|
||||
impl From<OwnerId> for HirId {
|
||||
fn from(owner: OwnerId) -> HirId {
|
||||
HirId { owner, local_id: ItemLocalId::from_u32(0) }
|
||||
HirId { owner, local_id: ItemLocalId::ZERO }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ impl HirId {
|
|||
|
||||
#[inline]
|
||||
pub fn make_owner(owner: LocalDefId) -> Self {
|
||||
Self { owner: OwnerId { def_id: owner }, local_id: ItemLocalId::from_u32(0) }
|
||||
Self { owner: OwnerId { def_id: owner }, local_id: ItemLocalId::ZERO }
|
||||
}
|
||||
|
||||
pub fn index(self) -> (usize, usize) {
|
||||
|
@ -172,6 +172,6 @@ unsafe impl StableOrd for ItemLocalId {
|
|||
|
||||
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.
|
||||
pub const CRATE_HIR_ID: HirId =
|
||||
HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::from_u32(0) };
|
||||
HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::ZERO };
|
||||
|
||||
pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue