From c91ffe0c80a5aeca51d6ab735a1624838bb55fde Mon Sep 17 00:00:00 2001 From: akern40 Date: Sun, 18 Oct 2026 22:21:30 +0000 Subject: [PATCH] chore: fix lints from newer clippy and nightly deprecations Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- src/dimension/mod.rs | 8 ++++---- src/impl_owned_array.rs | 30 +++++++++++++++--------------- src/indexes.rs | 5 +---- src/iterators/mod.rs | 15 +++------------ src/lib.rs | 1 - src/tri.rs | 2 -- tests/numeric.rs | 7 +++---- 7 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/dimension/mod.rs b/src/dimension/mod.rs index 4ada0b127..68f625115 100644 --- a/src/dimension/mod.rs +++ b/src/dimension/mod.rs @@ -850,17 +850,17 @@ mod test #[test] fn max_abs_offset_check_overflow_examples() { - let dim = (1, ::std::isize::MAX as usize, 1).into_dimension(); + let dim = (1, isize::MAX as usize, 1).into_dimension(); let strides = (1, 1, 1).into_dimension(); max_abs_offset_check_overflow::(&dim, &strides).unwrap(); - let dim = (1, ::std::isize::MAX as usize, 2).into_dimension(); + let dim = (1, isize::MAX as usize, 2).into_dimension(); let strides = (1, 1, 1).into_dimension(); max_abs_offset_check_overflow::(&dim, &strides).unwrap_err(); let dim = (0, 2, 2).into_dimension(); - let strides = (1, ::std::isize::MAX as usize, 1).into_dimension(); + let strides = (1, isize::MAX as usize, 1).into_dimension(); max_abs_offset_check_overflow::(&dim, &strides).unwrap_err(); let dim = (0, 2, 2).into_dimension(); - let strides = (1, ::std::isize::MAX as usize / 4, 1).into_dimension(); + let strides = (1, isize::MAX as usize / 4, 1).into_dimension(); max_abs_offset_check_overflow::(&dim, &strides).unwrap_err(); } diff --git a/src/impl_owned_array.rs b/src/impl_owned_array.rs index fb06f9656..c721b7dfa 100644 --- a/src/impl_owned_array.rs +++ b/src/impl_owned_array.rs @@ -1,5 +1,6 @@ #[cfg(not(feature = "std"))] use alloc::vec::Vec; +use core::num::NonZeroUsize; use core::ptr::NonNull; use std::mem; use std::mem::MaybeUninit; @@ -36,22 +37,21 @@ impl Array /// ``` pub fn into_scalar(self) -> A { - let size = mem::size_of::(); - if size == 0 { + let size = match NonZeroUsize::new(mem::size_of::()) { + Some(size) => size, // Any index in the `Vec` is fine since all elements are identical. - self.data.into_vec().remove(0) - } else { - // Find the index in the `Vec` corresponding to `self.ptr`. - // (This is necessary because the element in the array might not be - // the first element in the `Vec`, such as if the array was created - // by `array![1, 2, 3, 4].slice_move(s![2])`.) - let first = self.parts.ptr.as_ptr() as usize; - let base = self.data.as_ptr() as usize; - let index = (first - base) / size; - debug_assert_eq!((first - base) % size, 0); - // Remove the element at the index and return it. - self.data.into_vec().remove(index) - } + None => return self.data.into_vec().remove(0), + }; + // Find the index in the `Vec` corresponding to `self.ptr`. + // (This is necessary because the element in the array might not be + // the first element in the `Vec`, such as if the array was created + // by `array![1, 2, 3, 4].slice_move(s![2])`.) + let first = self.parts.ptr.as_ptr() as usize; + let base = self.data.as_ptr() as usize; + let index = (first - base) / size; + debug_assert_eq!((first - base) % size.get(), 0); + // Remove the element at the index and return it. + self.data.into_vec().remove(index) } } diff --git a/src/indexes.rs b/src/indexes.rs index 5b0346208..ca91b65ec 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -58,10 +58,7 @@ where D: Dimension #[inline] fn next(&mut self) -> Option { - let index = match self.index { - None => return None, - Some(ref ix) => ix.clone(), - }; + let index = self.index.as_ref()?.clone(); self.index = self.dim.next_for(index.clone()); Some(index.into_pattern()) } diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 85ef78c8c..1eaf579b0 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -72,10 +72,7 @@ impl Iterator for Baseiter #[inline] fn next(&mut self) -> Option { - let index = match self.index { - None => return None, - Some(ref ix) => ix.clone(), - }; + let index = self.index.as_ref()?.clone(); let offset = D::stride_offset(&index, &self.strides); self.index = self.dim.next_for(index); unsafe { Some(self.ptr.offset(offset)) } @@ -515,10 +512,7 @@ impl<'a, A, D: Dimension> Iterator for IndexedIter<'a, A, D> #[inline] fn next(&mut self) -> Option { - let index = match self.0.inner.index { - None => return None, - Some(ref ix) => ix.clone(), - }; + let index = self.0.inner.index.as_ref()?.clone(); match self.0.next() { None => None, Some(elem) => Some((index.into_pattern(), elem)), @@ -698,10 +692,7 @@ impl<'a, A, D: Dimension> Iterator for IndexedIterMut<'a, A, D> #[inline] fn next(&mut self) -> Option { - let index = match self.0.inner.index { - None => return None, - Some(ref ix) => ix.clone(), - }; + let index = self.0.inner.index.as_ref()?.clone(); match self.0.next() { None => None, Some(elem) => Some((index.into_pattern(), elem)), diff --git a/src/lib.rs b/src/lib.rs index f12417ce7..4cfb6ddb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,6 @@ clippy::deref_addrof, clippy::manual_map, // is not an error clippy::while_let_on_iterator, // is not an error - clippy::from_iter_instead_of_collect, // using from_iter is good style clippy::incompatible_msrv, // false positive PointerExt::offset )] #![doc(test(attr(deny(warnings))))] diff --git a/src/tri.rs b/src/tri.rs index 9f15db71a..1e10c3b6a 100644 --- a/src/tri.rs +++ b/src/tri.rs @@ -159,8 +159,6 @@ where #[cfg(test)] mod tests { - use core::isize; - use crate::{array, dimension, Array0, Array1, Array2, Array3, ShapeBuilder}; use alloc::vec; diff --git a/tests/numeric.rs b/tests/numeric.rs index 7e6964812..ea1cdf2b5 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -5,7 +5,6 @@ use approx::assert_abs_diff_eq; use ndarray::{arr0, arr1, arr2, array, aview1, Array, Array1, Array2, Array3, Axis}; -use std::f64; #[test] fn test_mean_with_nan_values() @@ -176,7 +175,7 @@ fn var_too_large_ddof() fn var_nan_ddof() { let a = Array2::::zeros((2, 3)); - let v = a.var(::std::f64::NAN); + let v = a.var(f64::NAN); assert!(v.is_nan()); } @@ -219,7 +218,7 @@ fn std_too_large_ddof() fn std_nan_ddof() { let a = Array2::::zeros((2, 3)); - let v = a.std(::std::f64::NAN); + let v = a.std(f64::NAN); assert!(v.is_nan()); } @@ -375,7 +374,7 @@ fn var_axis_too_large_ddof() fn var_axis_nan_ddof() { let a = Array2::::zeros((2, 3)); - let v = a.var_axis(Axis(1), ::std::f64::NAN); + let v = a.var_axis(Axis(1), f64::NAN); assert_eq!(v.shape(), &[2]); v.mapv(|x| assert!(x.is_nan())); }