Skip to content

Commit

Permalink
Merge pull request #715 from jturner314/empty-s-macro
Browse files Browse the repository at this point in the history
Add support for empty s![] call
  • Loading branch information
jturner314 committed Sep 16, 2019
2 parents a9c4392 + 13f636f commit d4dd6f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,17 @@ macro_rules! s(
}
}
};
// empty call, i.e. `s![]`
(@parse ::std::marker::PhantomData::<$crate::Ix0>, []) => {
{
#[allow(unsafe_code)]
unsafe {
$crate::SliceInfo::new_unchecked([], ::std::marker::PhantomData::<$crate::Ix0>)
}
}
};
// Catch-all clause for syntax errors
(@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![] call.") };
// convert range/index into SliceOrIndex
(@convert $r:expr) => {
<$crate::SliceOrIndex as ::std::convert::From<_>>::from($r)
Expand All @@ -612,8 +623,6 @@ macro_rules! s(
(@convert $r:expr, $s:expr) => {
<$crate::SliceOrIndex as ::std::convert::From<_>>::from($r).step_by($s as isize)
};
// Catch-all clause for syntax errors
(@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![], expected at least one index or range") };
($($t:tt)*) => {
// The extra `*&` is a workaround for this compiler bug:
// https://github.com/rust-lang/rust/issues/23014
Expand Down
7 changes: 7 additions & 0 deletions tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ fn test_slice() {
assert!(vi.iter().zip(A.iter()).all(|(a, b)| a == b));
}

#[deny(unsafe_code)]
#[test]
fn test_slice_ix0() {
let arr = arr0(5);
assert_eq!(arr.slice(s![]), aview0(&5));
}

#[test]
fn test_slice_edge_cases() {
let mut arr = Array3::<u8>::zeros((3, 4, 5));
Expand Down

0 comments on commit d4dd6f5

Please sign in to comment.