diff --git a/integer/src/primitive.rs b/integer/src/primitive.rs index cea9655..f7abbd6 100644 --- a/integer/src/primitive.rs +++ b/integer/src/primitive.rs @@ -59,13 +59,10 @@ pub const fn shrink_dword(dw: DoubleWord) -> Option { /// Note that then length is only checked in the debug mode. #[inline] pub fn lowest_dword(words: &[Word]) -> DoubleWord { - debug_assert!(words.len() >= 2); - - // SAFETY: length checked by the assertion above - unsafe { - let lo = *words.get_unchecked(0); - let hi = *words.get_unchecked(1); + if let [lo, hi, ..] = *words { double_word(lo, hi) + } else { + panic!("expected at least two words"); } } @@ -74,14 +71,10 @@ pub fn lowest_dword(words: &[Word]) -> DoubleWord { /// Note that then length is only checked in the debug mode. #[inline] pub fn highest_dword(words: &[Word]) -> DoubleWord { - let len = words.len(); - debug_assert!(len >= 2); - - // SAFETY: length checked by the assertion above - unsafe { - let lo = *words.get_unchecked(len - 2); - let hi = *words.get_unchecked(len - 1); + if let [.., lo, hi] = *words { double_word(lo, hi) + } else { + panic!("expected at least two words"); } }