@@ -328,8 +328,9 @@ where
328328
329329/// Implementation of ArrayView2::from(&S) where S is a slice to a 2D array
330330///
331- /// **Panics** if the product of non-zero axis lengths overflows `isize` (This can only occur if A
332- /// is zero-sized because slices cannot contain more than `isize::MAX` number of bytes).
331+ /// **Panics** if the product of non-zero axis lengths overflows `isize`. (This
332+ /// can only occur if A is zero-sized or if `N` is zero, because slices cannot
333+ /// contain more than `isize::MAX` number of bytes.)
333334impl < ' a , A , const N : usize > From < & ' a [ [ A ; N ] ] > for ArrayView < ' a , A , Ix2 > {
334335 /// Create a two-dimensional read-only array view of the data in `slice`
335336 fn from ( xs : & ' a [ [ A ; N ] ] ) -> Self {
@@ -339,6 +340,11 @@ impl<'a, A, const N: usize> From<&'a [[A; N]]> for ArrayView<'a, A, Ix2> {
339340 if size_of :: < A > ( ) == 0 {
340341 dimension:: size_of_shape_checked ( & dim)
341342 . expect ( "Product of non-zero axis lengths must not overflow isize." ) ;
343+ } else if N == 0 {
344+ assert ! (
345+ xs. len( ) <= isize :: MAX as usize ,
346+ "Product of non-zero axis lengths must not overflow isize." ,
347+ ) ;
342348 }
343349
344350 // `cols * rows` is guaranteed to fit in `isize` because we checked that it fits in
@@ -384,8 +390,9 @@ where
384390
385391/// Implementation of ArrayViewMut2::from(&S) where S is a slice to a 2D array
386392///
387- /// **Panics** if the product of non-zero axis lengths overflows `isize` (This can only occur if A
388- /// is zero-sized because slices cannot contain more than `isize::MAX` number of bytes).
393+ /// **Panics** if the product of non-zero axis lengths overflows `isize`. (This
394+ /// can only occur if `A` is zero-sized or if `N` is zero, because slices
395+ /// cannot contain more than `isize::MAX` number of bytes.)
389396impl < ' a , A , const N : usize > From < & ' a mut [ [ A ; N ] ] > for ArrayViewMut < ' a , A , Ix2 > {
390397 /// Create a two-dimensional read-write array view of the data in `slice`
391398 fn from ( xs : & ' a mut [ [ A ; N ] ] ) -> Self {
@@ -395,6 +402,11 @@ impl<'a, A, const N: usize> From<&'a mut [[A; N]]> for ArrayViewMut<'a, A, Ix2>
395402 if size_of :: < A > ( ) == 0 {
396403 dimension:: size_of_shape_checked ( & dim)
397404 . expect ( "Product of non-zero axis lengths must not overflow isize." ) ;
405+ } else if N == 0 {
406+ assert ! (
407+ xs. len( ) <= isize :: MAX as usize ,
408+ "Product of non-zero axis lengths must not overflow isize." ,
409+ ) ;
398410 }
399411
400412 // `cols * rows` is guaranteed to fit in `isize` because we checked that it fits in
0 commit comments