File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -604,6 +604,17 @@ macro_rules! s(
604
604
}
605
605
}
606
606
} ;
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." ) } ;
607
618
// convert range/index into SliceOrIndex
608
619
( @convert $r: expr) => {
609
620
<$crate:: SliceOrIndex as :: std:: convert:: From <_>>:: from( $r)
@@ -612,8 +623,6 @@ macro_rules! s(
612
623
( @convert $r: expr, $s: expr) => {
613
624
<$crate:: SliceOrIndex as :: std:: convert:: From <_>>:: from( $r) . step_by( $s as isize )
614
625
} ;
615
- // Catch-all clause for syntax errors
616
- ( @parse $( $t: tt) * ) => { compile_error!( "Invalid syntax in s![], expected at least one index or range" ) } ;
617
626
( $( $t: tt) * ) => {
618
627
// The extra `*&` is a workaround for this compiler bug:
619
628
// 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() {
92
92
assert ! ( vi. iter( ) . zip( A . iter( ) ) . all( |( a, b) | a == b) ) ;
93
93
}
94
94
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
+
95
102
#[ test]
96
103
fn test_slice_edge_cases ( ) {
97
104
let mut arr = Array3 :: < u8 > :: zeros ( ( 3 , 4 , 5 ) ) ;
You can’t perform that action at this time.
0 commit comments