1
Fork 0

Rollup merge of #123419 - petrochenkov:zeroindex, r=compiler-errors

rustc_index: Add a `ZERO` constant to index types

It is commonly used.
This commit is contained in:
Matthias Krüger 2024-04-03 22:11:02 +02:00 committed by GitHub
commit 25b0e84170
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 80 additions and 90 deletions

View file

@ -22,7 +22,7 @@ rustc_index::newtype_index! {
/// Item definitions in the currently-compiled crate would have the `CrateNum`
/// `LOCAL_CRATE` in their `DefId`.
pub const LOCAL_CRATE: CrateNum = CrateNum::from_u32(0);
pub const LOCAL_CRATE: CrateNum = CrateNum::ZERO;
impl CrateNum {
#[inline]

View file

@ -165,7 +165,7 @@ pub enum Transparency {
impl LocalExpnId {
/// The ID of the theoretical expansion that generates freshly parsed, unexpanded AST.
pub const ROOT: LocalExpnId = LocalExpnId::from_u32(0);
pub const ROOT: LocalExpnId = LocalExpnId::ZERO;
#[inline]
fn from_raw(idx: ExpnIndex) -> LocalExpnId {
@ -242,7 +242,7 @@ impl ExpnId {
/// The ID of the theoretical expansion that generates freshly parsed, unexpanded AST.
/// Invariant: we do not create any ExpnId with local_id == 0 and krate != 0.
pub const fn root() -> ExpnId {
ExpnId { krate: LOCAL_CRATE, local_id: ExpnIndex::from_u32(0) }
ExpnId { krate: LOCAL_CRATE, local_id: ExpnIndex::ZERO }
}
#[inline]

View file

@ -243,7 +243,7 @@ fn t10() {
src_hash,
stable_id,
source_len.to_u32(),
CrateNum::new(0),
CrateNum::ZERO,
FreezeLock::new(lines.read().clone()),
multibyte_chars,
non_narrow_chars,