mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
use const unwrap
Stable since 1.83 (our MSRV)
This commit is contained in:
parent
3bd7486362
commit
6d4e71085d
@ -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.
|
||||
|
@ -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`].
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user