@@ -325,8 +325,9 @@ where
325
325
326
326
/// Implementation of ArrayView2::from(&S) where S is a slice to a 2D array
327
327
///
328
- /// **Panics** if the product of non-zero axis lengths overflows `isize` (This can only occur if A
329
- /// is zero-sized because slices cannot contain more than `isize::MAX` number of bytes).
328
+ /// **Panics** if the product of non-zero axis lengths overflows `isize`. (This
329
+ /// can only occur if A is zero-sized or if `N` is zero, because slices cannot
330
+ /// contain more than `isize::MAX` number of bytes.)
330
331
impl < ' a , A , const N : usize > From < & ' a [ [ A ; N ] ] > for ArrayView < ' a , A , Ix2 > {
331
332
/// Create a two-dimensional read-only array view of the data in `slice`
332
333
fn from ( xs : & ' a [ [ A ; N ] ] ) -> Self {
@@ -336,6 +337,11 @@ impl<'a, A, const N: usize> From<&'a [[A; N]]> for ArrayView<'a, A, Ix2> {
336
337
if size_of :: < A > ( ) == 0 {
337
338
dimension:: size_of_shape_checked ( & dim)
338
339
. expect ( "Product of non-zero axis lengths must not overflow isize." ) ;
340
+ } else if N == 0 {
341
+ assert ! (
342
+ xs. len( ) <= isize :: MAX as usize ,
343
+ "Product of non-zero axis lengths must not overflow isize." ,
344
+ ) ;
339
345
}
340
346
341
347
// `cols * rows` is guaranteed to fit in `isize` because we checked that it fits in
@@ -381,8 +387,9 @@ where
381
387
382
388
/// Implementation of ArrayViewMut2::from(&S) where S is a slice to a 2D array
383
389
///
384
- /// **Panics** if the product of non-zero axis lengths overflows `isize` (This can only occur if A
385
- /// is zero-sized because slices cannot contain more than `isize::MAX` number of bytes).
390
+ /// **Panics** if the product of non-zero axis lengths overflows `isize`. (This
391
+ /// can only occur if `A` is zero-sized or if `N` is zero, because slices
392
+ /// cannot contain more than `isize::MAX` number of bytes.)
386
393
impl < ' a , A , const N : usize > From < & ' a mut [ [ A ; N ] ] > for ArrayViewMut < ' a , A , Ix2 > {
387
394
/// Create a two-dimensional read-write array view of the data in `slice`
388
395
fn from ( xs : & ' a mut [ [ A ; N ] ] ) -> Self {
@@ -392,6 +399,11 @@ impl<'a, A, const N: usize> From<&'a mut [[A; N]]> for ArrayViewMut<'a, A, Ix2>
392
399
if size_of :: < A > ( ) == 0 {
393
400
dimension:: size_of_shape_checked ( & dim)
394
401
. expect ( "Product of non-zero axis lengths must not overflow isize." ) ;
402
+ } else if N == 0 {
403
+ assert ! (
404
+ xs. len( ) <= isize :: MAX as usize ,
405
+ "Product of non-zero axis lengths must not overflow isize." ,
406
+ ) ;
395
407
}
396
408
397
409
// `cols * rows` is guaranteed to fit in `isize` because we checked that it fits in
0 commit comments