@@ -173,8 +173,6 @@ impl<A> Array<A, Ix2> {
173173 /// This is useful when pushing or appending repeatedly to an array to avoid multiple
174174 /// allocations.
175175 ///
176- /// ***Panics*** if the new capacity would exceed `usize::MAX`.
177- ///
178176 /// ***Errors*** with a shape error if the resultant capacity is larger than the addressable
179177 /// bounds; that is, the product of non-zero axis lengths once `axis` has been extended by
180178 /// `additional` exceeds `isize::MAX`.
@@ -197,8 +195,6 @@ impl<A> Array<A, Ix2> {
197195 /// This is useful when pushing or appending repeatedly to an array to avoid multiple
198196 /// allocations.
199197 ///
200- /// ***Panics*** if the new capacity would exceed `usize::MAX`.
201- ///
202198 /// ***Errors*** with a shape error if the resultant capacity is larger than the addressable
203199 /// bounds; that is, the product of non-zero axis lengths once `axis` has been extended by
204200 /// `additional` exceeds `isize::MAX`.
@@ -712,7 +708,7 @@ impl<A, D> Array<A, D>
712708 /// This is useful when pushing or appending repeatedly to an array to avoid multiple
713709 /// allocations.
714710 ///
715- /// ***Panics*** if the axis is out of bounds or if the new capacity would exceed `usize::MAX` .
711+ /// ***Panics*** if the axis is out of bounds.
716712 ///
717713 /// ***Errors*** with a shape error if the resultant capacity is larger than the addressable
718714 /// bounds; that is, the product of non-zero axis lengths once `axis` has been extended by
@@ -733,9 +729,11 @@ impl<A, D> Array<A, D>
733729 let self_dim = self . raw_dim ( ) ;
734730 let remaining_shape = self_dim. remove_axis ( axis) ;
735731
736- // Make sure added capacity doesn't overflow
737- debug_assert ! ( remaining_shape. size( ) . checked_mul( additional) . is_some( ) ) ;
738- let len_to_append = remaining_shape. size ( ) * additional;
732+ // Make sure added capacity doesn't overflow usize::MAX
733+ let len_to_append = remaining_shape
734+ . size ( )
735+ . checked_mul ( additional)
736+ . ok_or ( ShapeError :: from_kind ( ErrorKind :: Overflow ) ) ?;
739737
740738 // Make sure new capacity is still in bounds
741739 let mut res_dim = self_dim;
0 commit comments