Skip to content

Commit df73e41

Browse files
authored
Eliminate unreachable!() in check_slice_length() (#200)
1 parent e9c3d23 commit df73e41

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

src/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,17 +1211,13 @@ where
12111211
}
12121212

12131213
/// Generate a [`TryFromSliceError`] if the slice doesn't match the given length.
1214-
#[cfg_attr(debug_assertions, allow(clippy::panic_in_result_fn))]
12151214
fn check_slice_length<T, U: ArraySize>(slice: &[T]) -> Result<(), TryFromSliceError> {
12161215
debug_assert_eq!(Array::<(), U>::default().len(), U::USIZE);
12171216

1218-
if slice.len() != U::USIZE {
1219-
// Hack: `TryFromSliceError` lacks a public constructor
1220-
<&[T; 1]>::try_from([].as_slice())?;
1221-
1222-
#[cfg(debug_assertions)]
1223-
unreachable!();
1217+
if slice.len() == U::USIZE {
1218+
Ok(())
1219+
} else {
1220+
// Hack: `TryFromSliceError` lacks a public constructor, so this fakes one
1221+
<&[T; 1]>::try_from([].as_slice()).map(|_| ())
12241222
}
1225-
1226-
Ok(())
12271223
}

0 commit comments

Comments
 (0)