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.
pub const fn detached() -> Self {
match NonZeroU64::new(Self::DETACHED) {
Some(v) => Self(v),
None => unreachable!(),
}
Self(NonZeroU64::new(Self::DETACHED).unwrap())
}
/// 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.
const fn pack(id: FileId, low: u64) -> Self {
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.
None => unreachable!(),
}
// The file ID is non-zero.
Self(NonZeroU64::new(bits).unwrap())
}
/// Whether the span is detached.

View File

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

View File

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