Skip to content

Commit bc1d762

Browse files
committed
If-let is ok but switch to use<_>
1 parent 8944edc commit bc1d762

3 files changed

Lines changed: 44 additions & 41 deletions

File tree

src/array_serde.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,7 @@ where
237237
}
238238
};
239239

240-
match ArrayBase::from_shape_vec(dim, data) {
241-
Ok(array) => Ok(array),
242-
_ => Err(de::Error::custom("data and dimension must match in size")),
243-
}
240+
ArrayBase::from_shape_vec(dim, data).map_err(|_| de::Error::custom("data and dimension must match in size"))
244241
}
245242

246243
fn visit_map<V>(self, mut visitor: V) -> Result<ArrayBase<S, Di>, V::Error>

src/impl_methods.rs

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,13 @@ impl<A, D: Dimension> ArrayRef<A, D>
895895
#[inline]
896896
pub unsafe fn uget<I>(&self, index: I) -> &A
897897
where I: NdIndex<D>
898-
{ unsafe {
899-
arraytraits::debug_bounds_check(self, &index);
900-
let off = index.index_unchecked(&self.strides);
901-
&*self.ptr.as_ptr().offset(off)
902-
}}
898+
{
899+
unsafe {
900+
arraytraits::debug_bounds_check(self, &index);
901+
let off = index.index_unchecked(&self.strides);
902+
&*self.ptr.as_ptr().offset(off)
903+
}
904+
}
903905

904906
/// Perform *unchecked* array indexing.
905907
///
@@ -918,12 +920,14 @@ impl<A, D: Dimension> ArrayRef<A, D>
918920
#[inline]
919921
pub unsafe fn uget_mut<I>(&mut self, index: I) -> &mut A
920922
where I: NdIndex<D>
921-
{ unsafe {
922-
// debug_assert!(self.data.is_unique());
923-
arraytraits::debug_bounds_check(self, &index);
924-
let off = index.index_unchecked(&self.strides);
925-
&mut *self.ptr.as_ptr().offset(off)
926-
}}
923+
{
924+
unsafe {
925+
// debug_assert!(self.data.is_unique());
926+
arraytraits::debug_bounds_check(self, &index);
927+
let off = index.index_unchecked(&self.strides);
928+
&mut *self.ptr.as_ptr().offset(off)
929+
}
930+
}
927931

928932
/// Swap elements at indices `index1` and `index2`.
929933
///
@@ -964,14 +968,16 @@ impl<A, D: Dimension> ArrayRef<A, D>
964968
/// for `Array` and `ArrayViewMut`, but not for `ArcArray` or `CowArray`.)
965969
pub unsafe fn uswap<I>(&mut self, index1: I, index2: I)
966970
where I: NdIndex<D>
967-
{ unsafe {
968-
// debug_assert!(self.data.is_unique());
969-
arraytraits::debug_bounds_check(self, &index1);
970-
arraytraits::debug_bounds_check(self, &index2);
971-
let off1 = index1.index_unchecked(&self.strides);
972-
let off2 = index2.index_unchecked(&self.strides);
973-
std::ptr::swap(self.ptr.as_ptr().offset(off1), self.ptr.as_ptr().offset(off2));
974-
}}
971+
{
972+
unsafe {
973+
// debug_assert!(self.data.is_unique());
974+
arraytraits::debug_bounds_check(self, &index1);
975+
arraytraits::debug_bounds_check(self, &index2);
976+
let off1 = index1.index_unchecked(&self.strides);
977+
let off2 = index2.index_unchecked(&self.strides);
978+
std::ptr::swap(self.ptr.as_ptr().offset(off1), self.ptr.as_ptr().offset(off2));
979+
}
980+
}
975981

976982
// `get` for zero-dimensional arrays
977983
// panics if dimension is not zero. otherwise an element is always present.
@@ -1760,9 +1766,9 @@ where
17601766
#[inline]
17611767
pub(crate) unsafe fn raw_view_mut_unchecked(&mut self) -> RawArrayViewMut<A, D>
17621768
where S: DataOwned
1763-
{ unsafe {
1764-
RawArrayViewMut::new(self.ptr, self.dim.clone(), self.strides.clone())
1765-
}}
1769+
{
1770+
unsafe { RawArrayViewMut::new(self.ptr, self.dim.clone(), self.strides.clone()) }
1771+
}
17661772

17671773
/// Return the array’s data as a slice, if it is contiguous and in standard order.
17681774
/// Return `None` otherwise.
@@ -2442,21 +2448,21 @@ impl<A, D: Dimension> ArrayRef<A, D>
24422448
self.view()
24432449
.into_dimensionality::<<D as DimMax<E>>::Output>()
24442450
.unwrap()
2445-
} else { match self.broadcast(shape.clone()) { Some(view1) => {
2451+
} else if let Some(view1) = self.broadcast(shape.clone()) {
24462452
view1
2447-
} _ => {
2453+
} else {
24482454
return Err(from_kind(ErrorKind::IncompatibleShape));
2449-
}}};
2455+
};
24502456
let view2 = if shape.slice() == other.dim.slice() {
24512457
other
24522458
.view()
24532459
.into_dimensionality::<<D as DimMax<E>>::Output>()
24542460
.unwrap()
2455-
} else { match other.broadcast(shape) { Some(view2) => {
2461+
} else if let Some(view2) = other.broadcast(shape.clone()) {
24562462
view2
2457-
} _ => {
2463+
} else {
24582464
return Err(from_kind(ErrorKind::IncompatibleShape));
2459-
}}};
2465+
};
24602466
Ok((view1, view2))
24612467
}
24622468
}
@@ -3350,12 +3356,14 @@ impl<A, D: Dimension> ArrayRef<A, D>
33503356
#[track_caller]
33513357
#[inline]
33523358
unsafe fn unlimited_transmute<A, B>(data: A) -> B
3353-
{ unsafe {
3354-
// safe when sizes are equal and caller guarantees that representations are equal
3355-
assert_eq!(size_of::<A>(), size_of::<B>());
3356-
let old_data = ManuallyDrop::new(data);
3357-
(&*old_data as *const A as *const B).read()
3358-
}}
3359+
{
3360+
unsafe {
3361+
// safe when sizes are equal and caller guarantees that representations are equal
3362+
assert_eq!(size_of::<A>(), size_of::<B>());
3363+
let old_data = ManuallyDrop::new(data);
3364+
(&*old_data as *const A as *const B).read()
3365+
}
3366+
}
33593367

33603368
type DimMaxOf<A, B> = <A as DimMax<B>>::Output;
33613369

tests/iterators.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,7 @@ fn test_impl_iter_compiles()
10731073
let _ = slice_iter_non_empty_indices;
10741074

10751075
// ndarray case
1076-
fn array_iter_non_empty_indices<'s, 'a>(
1077-
array: &'a Array<&'s str, Ix1>,
1078-
) -> impl Iterator<Item = usize> + 'a + use<'a>
1076+
fn array_iter_non_empty_indices<'s, 'a>(array: &'a Array<&'s str, Ix1>) -> impl Iterator<Item = usize> + use<'a>
10791077
{
10801078
array
10811079
.iter()

0 commit comments

Comments
 (0)