@@ -9,6 +9,7 @@ use crate::error::{ErrorKind, ShapeError};
9
9
use crate :: { ArrayView , ArrayViewMut , Dimension , RawArrayViewMut } ;
10
10
use std:: fmt;
11
11
use std:: marker:: PhantomData ;
12
+ use std:: num:: NonZeroIsize ;
12
13
use std:: ops:: { Deref , Range , RangeFrom , RangeFull , RangeInclusive , RangeTo , RangeToInclusive } ;
13
14
14
15
/// A slice (range with step size).
@@ -48,6 +49,7 @@ impl Slice {
48
49
/// (This method checks with a debug assertion that `step` is not zero.)
49
50
pub fn new ( start : isize , end : Option < isize > , step : isize ) -> Slice {
50
51
debug_assert_ne ! ( step, 0 , "Slice::new: step must be nonzero" ) ;
52
+ // let step = NonZeroIsize::new(step).unwrap();
51
53
Slice { start, end, step }
52
54
}
53
55
@@ -129,8 +131,7 @@ impl SliceOrIndex {
129
131
/// `step` must be nonzero.
130
132
/// (This method checks with a debug assertion that `step` is not zero.)
131
133
#[ inline]
132
- pub fn step_by ( self , step : isize ) -> Self {
133
- debug_assert_ne ! ( step, 0 , "SliceOrIndex::step_by: step must be nonzero" ) ;
134
+ pub fn step_by ( self , step : NonZeroIsize ) -> Self {
134
135
match self {
135
136
SliceOrIndex :: Slice {
136
137
start,
@@ -139,7 +140,7 @@ impl SliceOrIndex {
139
140
} => SliceOrIndex :: Slice {
140
141
start,
141
142
end,
142
- step : orig_step * step,
143
+ step : orig_step * step. get ( ) ,
143
144
} ,
144
145
SliceOrIndex :: Index ( s) => SliceOrIndex :: Index ( s) ,
145
146
}
@@ -610,7 +611,7 @@ macro_rules! s(
610
611
} ;
611
612
// convert range/index and step into SliceOrIndex
612
613
( @convert $r: expr, $s: expr) => {
613
- <$crate:: SliceOrIndex as :: std:: convert:: From <_>>:: from( $r) . step_by( $s as isize )
614
+ <$crate:: SliceOrIndex as :: std:: convert:: From <_>>:: from( $r) . step_by( std :: num :: NonZeroIsize :: new ( $s ) . unwrap ( ) )
614
615
} ;
615
616
( $( $t: tt) * ) => {
616
617
// The extra `*&` is a workaround for this compiler bug:
0 commit comments