Skip to content

Commit 12351ab

Browse files
authored
Merge pull request #422 from jturner314/slice-infer
Fix type inference for slicing in some cases
2 parents 0d337ea + b0998e6 commit 12351ab

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/slice.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -440,31 +440,31 @@ macro_rules! impl_slicenextdim_for_index_type {
440440
PhantomData
441441
}
442442
}
443-
444-
impl<D1: Dimension> SliceNextDim<D1, D1::Larger> for Range<$index> {
445-
fn next_dim(&self, _: PhantomData<D1>) -> PhantomData<D1::Larger> {
446-
PhantomData
447-
}
448-
}
449-
450-
impl<D1: Dimension> SliceNextDim<D1, D1::Larger> for RangeFrom<$index> {
451-
fn next_dim(&self, _: PhantomData<D1>) -> PhantomData<D1::Larger> {
452-
PhantomData
453-
}
454-
}
455-
456-
impl<D1: Dimension> SliceNextDim<D1, D1::Larger> for RangeTo<$index> {
457-
fn next_dim(&self, _: PhantomData<D1>) -> PhantomData<D1::Larger> {
458-
PhantomData
459-
}
460-
}
461443
}
462444
}
463445

464446
impl_slicenextdim_for_index_type!(isize);
465447
impl_slicenextdim_for_index_type!(usize);
466448
impl_slicenextdim_for_index_type!(i32);
467449

450+
impl<D1: Dimension, T> SliceNextDim<D1, D1::Larger> for Range<T> {
451+
fn next_dim(&self, _: PhantomData<D1>) -> PhantomData<D1::Larger> {
452+
PhantomData
453+
}
454+
}
455+
456+
impl<D1: Dimension, T> SliceNextDim<D1, D1::Larger> for RangeFrom<T> {
457+
fn next_dim(&self, _: PhantomData<D1>) -> PhantomData<D1::Larger> {
458+
PhantomData
459+
}
460+
}
461+
462+
impl<D1: Dimension, T> SliceNextDim<D1, D1::Larger> for RangeTo<T> {
463+
fn next_dim(&self, _: PhantomData<D1>) -> PhantomData<D1::Larger> {
464+
PhantomData
465+
}
466+
}
467+
468468
impl<D1: Dimension> SliceNextDim<D1, D1::Larger> for RangeFull {
469469
fn next_dim(&self, _: PhantomData<D1>) -> PhantomData<D1::Larger> {
470470
PhantomData

tests/array.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ fn test_slice()
8282
assert!(vi.iter().zip(A.iter()).all(|(a, b)| a == b));
8383
}
8484

85+
/// Test that the compiler can infer a type for a sliced array from the
86+
/// arguments to `s![]`.
87+
///
88+
/// This test relies on the fact that `.dot()` is implemented for both
89+
/// `ArrayView1` and `ArrayView2`, so the compiler needs to determine which
90+
/// type is the correct result for the `.slice()` call.
91+
#[test]
92+
fn test_slice_infer()
93+
{
94+
let a = array![1., 2.];
95+
let b = array![[3., 4.], [5., 6.]];
96+
b.slice(s![..-1, ..]).dot(&a);
97+
// b.slice(s![0, ..]).dot(&a);
98+
}
99+
85100
#[test]
86101
fn test_slice_with_many_dim() {
87102
let mut A = RcArray::<usize, _>::zeros(&[3, 1, 4, 1, 3, 2, 1][..]);

0 commit comments

Comments
 (0)