use const unwrap

Stable since 1.83 (our MSRV)
This commit is contained in:
PgBiel 2025-05-09 16:10:36 -03:00
parent 3bd7486362
commit 6d4e71085d
3 changed files with 7 additions and 21 deletions

View File

@ -71,10 +71,7 @@ impl Span {
/// Create a span that does not point into any file. /// Create a span that does not point into any file.
pub const fn detached() -> Self { pub const fn detached() -> Self {
match NonZeroU64::new(Self::DETACHED) { Self(NonZeroU64::new(Self::DETACHED).unwrap())
Some(v) => Self(v),
None => unreachable!(),
}
} }
/// Create a new span from a file id and a number. /// Create a new span from a file id and a number.
@ -111,11 +108,9 @@ impl Span {
/// Pack a file ID and the low bits into a span. /// Pack a file ID and the low bits into a span.
const fn pack(id: FileId, low: u64) -> Self { const fn pack(id: FileId, low: u64) -> Self {
let bits = ((id.into_raw().get() as u64) << Self::FILE_ID_SHIFT) | low; let bits = ((id.into_raw().get() as u64) << Self::FILE_ID_SHIFT) | low;
match NonZeroU64::new(bits) {
Some(v) => Self(v), // The file ID is non-zero.
// The file ID is non-zero. Self(NonZeroU64::new(bits).unwrap())
None => unreachable!(),
}
} }
/// Whether the span is detached. /// Whether the span is detached.

View File

@ -66,17 +66,11 @@ pub trait NonZeroExt {
} }
impl NonZeroExt for NonZeroUsize { impl NonZeroExt for NonZeroUsize {
const ONE: Self = match Self::new(1) { const ONE: Self = Self::new(1).unwrap();
Some(v) => v,
None => unreachable!(),
};
} }
impl NonZeroExt for NonZeroU32 { impl NonZeroExt for NonZeroU32 {
const ONE: Self = match Self::new(1) { const ONE: Self = Self::new(1).unwrap();
Some(v) => v,
None => unreachable!(),
};
} }
/// Extra methods for [`Arc`]. /// Extra methods for [`Arc`].

View File

@ -95,10 +95,7 @@ impl PicoStr {
} }
}; };
match NonZeroU64::new(value) { Ok(Self(NonZeroU64::new(value).unwrap()))
Some(value) => Ok(Self(value)),
None => unreachable!(),
}
} }
/// Resolve to a decoded string. /// Resolve to a decoded string.