File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -604,6 +604,17 @@ macro_rules! s(
604604 }
605605 }
606606 } ;
607+ // empty call, i.e. `s![]`
608+ ( @parse :: std:: marker:: PhantomData :: <$crate:: Ix0 >, [ ] ) => {
609+ {
610+ #[ allow( unsafe_code) ]
611+ unsafe {
612+ $crate:: SliceInfo :: new_unchecked( [ ] , :: std:: marker:: PhantomData :: <$crate:: Ix0 >)
613+ }
614+ }
615+ } ;
616+ // Catch-all clause for syntax errors
617+ ( @parse $( $t: tt) * ) => { compile_error!( "Invalid syntax in s![] call." ) } ;
607618 // convert range/index into SliceOrIndex
608619 ( @convert $r: expr) => {
609620 <$crate:: SliceOrIndex as :: std:: convert:: From <_>>:: from( $r)
@@ -612,8 +623,6 @@ macro_rules! s(
612623 ( @convert $r: expr, $s: expr) => {
613624 <$crate:: SliceOrIndex as :: std:: convert:: From <_>>:: from( $r) . step_by( $s as isize )
614625 } ;
615- // Catch-all clause for syntax errors
616- ( @parse $( $t: tt) * ) => { compile_error!( "Invalid syntax in s![], expected at least one index or range" ) } ;
617626 ( $( $t: tt) * ) => {
618627 // The extra `*&` is a workaround for this compiler bug:
619628 // https://github.com/rust-lang/rust/issues/23014
Original file line number Diff line number Diff line change @@ -92,6 +92,13 @@ fn test_slice() {
9292 assert ! ( vi. iter( ) . zip( A . iter( ) ) . all( |( a, b) | a == b) ) ;
9393}
9494
95+ #[ deny( unsafe_code) ]
96+ #[ test]
97+ fn test_slice_ix0 ( ) {
98+ let arr = arr0 ( 5 ) ;
99+ assert_eq ! ( arr. slice( s![ ] ) , aview0( & 5 ) ) ;
100+ }
101+
95102#[ test]
96103fn test_slice_edge_cases ( ) {
97104 let mut arr = Array3 :: < u8 > :: zeros ( ( 3 , 4 , 5 ) ) ;
You can’t perform that action at this time.
0 commit comments