Skip to content

Commit 8d30033

Browse files
committed
Fix pre-checks in try_boxed_from_iter
1 parent e8d2471 commit 8d30033

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/arr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
/// * The `[T; N: ArrayLength]` and `[T; usize]` explicit forms are limited to `Copy` values. Use
2222
/// [`GenericArray::generate(|| value.clone())`](crate::GenericSequence::generate) for non-`Copy` items.
2323
/// * The `[T; usize]` explicit and `[0, 1, 2, 3]` implicit forms are limited to lengths supported by [`Const<U>`](typenum::Const)
24-
2524
#[macro_export]
2625
macro_rules! arr {
2726
($($x:expr),* $(,)*) => ( $crate::GenericArray::from_array([$($x),*]) );

src/impl_alloc.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ impl<T, N: ArrayLength> GenericArray<T, N> {
9191

9292
// pre-checks
9393
match iter.size_hint() {
94-
(n, _) if n < N::USIZE => return Err(TryFromIterError::TooShort),
95-
(_, Some(n)) if n > N::USIZE => return Err(TryFromIterError::TooLong),
94+
// if the lower bound is greater than N, array will overflow
95+
(n, _) if n > N::USIZE => return Err(TryFromIterError::TooLong),
96+
// if the upper bound is smaller than N, array cannot be filled
97+
(_, Some(n)) if n < N::USIZE => return Err(TryFromIterError::TooShort),
9698
_ => {}
9799
}
98100

0 commit comments

Comments
 (0)