Skip to content

Commit 643181c

Browse files
chore: fix lints from newer clippy and nightly deprecations (#1622)
CI on `refactor` is currently red because of newer toolchains, not code changes. Since CI runs with `-D warnings`, the following are now errors: - clippy 1.99 removed `clippy::from_iter_instead_of_collect`, so our `allow` for it in `lib.rs` now errors. - clippy 1.99 `question_mark` fires in `Indices` and the `Iter`/`IndexedIter` iterators. - clippy 1.99 `manual_checked_ops` fires in `into_scalar`. - Nightly (and stable in the weekly latest-deps job) now deprecates the legacy `std::f64` / `std::isize` modules and constants. These are used in `tests/numeric.rs` and in tests in `dimension/mod.rs` and `tri.rs`. No behavior change. Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 81756e6 commit 643181c

7 files changed

Lines changed: 26 additions & 42 deletions

File tree

‎src/dimension/mod.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,17 +850,17 @@ mod test
850850
#[test]
851851
fn max_abs_offset_check_overflow_examples()
852852
{
853-
let dim = (1, ::std::isize::MAX as usize, 1).into_dimension();
853+
let dim = (1, isize::MAX as usize, 1).into_dimension();
854854
let strides = (1, 1, 1).into_dimension();
855855
max_abs_offset_check_overflow::<u8, _>(&dim, &strides).unwrap();
856-
let dim = (1, ::std::isize::MAX as usize, 2).into_dimension();
856+
let dim = (1, isize::MAX as usize, 2).into_dimension();
857857
let strides = (1, 1, 1).into_dimension();
858858
max_abs_offset_check_overflow::<u8, _>(&dim, &strides).unwrap_err();
859859
let dim = (0, 2, 2).into_dimension();
860-
let strides = (1, ::std::isize::MAX as usize, 1).into_dimension();
860+
let strides = (1, isize::MAX as usize, 1).into_dimension();
861861
max_abs_offset_check_overflow::<u8, _>(&dim, &strides).unwrap_err();
862862
let dim = (0, 2, 2).into_dimension();
863-
let strides = (1, ::std::isize::MAX as usize / 4, 1).into_dimension();
863+
let strides = (1, isize::MAX as usize / 4, 1).into_dimension();
864864
max_abs_offset_check_overflow::<i32, _>(&dim, &strides).unwrap_err();
865865
}
866866

‎src/impl_owned_array.rs‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[cfg(not(feature = "std"))]
22
use alloc::vec::Vec;
3+
use core::num::NonZeroUsize;
34
use core::ptr::NonNull;
45
use std::mem;
56
use std::mem::MaybeUninit;
@@ -36,22 +37,21 @@ impl<A> Array<A, Ix0>
3637
/// ```
3738
pub fn into_scalar(self) -> A
3839
{
39-
let size = mem::size_of::<A>();
40-
if size == 0 {
40+
let size = match NonZeroUsize::new(mem::size_of::<A>()) {
41+
Some(size) => size,
4142
// Any index in the `Vec` is fine since all elements are identical.
42-
self.data.into_vec().remove(0)
43-
} else {
44-
// Find the index in the `Vec` corresponding to `self.ptr`.
45-
// (This is necessary because the element in the array might not be
46-
// the first element in the `Vec`, such as if the array was created
47-
// by `array![1, 2, 3, 4].slice_move(s![2])`.)
48-
let first = self.parts.ptr.as_ptr() as usize;
49-
let base = self.data.as_ptr() as usize;
50-
let index = (first - base) / size;
51-
debug_assert_eq!((first - base) % size, 0);
52-
// Remove the element at the index and return it.
53-
self.data.into_vec().remove(index)
54-
}
43+
None => return self.data.into_vec().remove(0),
44+
};
45+
// Find the index in the `Vec` corresponding to `self.ptr`.
46+
// (This is necessary because the element in the array might not be
47+
// the first element in the `Vec`, such as if the array was created
48+
// by `array![1, 2, 3, 4].slice_move(s![2])`.)
49+
let first = self.parts.ptr.as_ptr() as usize;
50+
let base = self.data.as_ptr() as usize;
51+
let index = (first - base) / size;
52+
debug_assert_eq!((first - base) % size.get(), 0);
53+
// Remove the element at the index and return it.
54+
self.data.into_vec().remove(index)
5555
}
5656
}
5757

‎src/indexes.rs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ where D: Dimension
5858
#[inline]
5959
fn next(&mut self) -> Option<Self::Item>
6060
{
61-
let index = match self.index {
62-
None => return None,
63-
Some(ref ix) => ix.clone(),
64-
};
61+
let index = self.index.as_ref()?.clone();
6562
self.index = self.dim.next_for(index.clone());
6663
Some(index.into_pattern())
6764
}

‎src/iterators/mod.rs‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ impl<A, D: Dimension> Iterator for Baseiter<A, D>
7272
#[inline]
7373
fn next(&mut self) -> Option<Self::Item>
7474
{
75-
let index = match self.index {
76-
None => return None,
77-
Some(ref ix) => ix.clone(),
78-
};
75+
let index = self.index.as_ref()?.clone();
7976
let offset = D::stride_offset(&index, &self.strides);
8077
self.index = self.dim.next_for(index);
8178
unsafe { Some(self.ptr.offset(offset)) }
@@ -515,10 +512,7 @@ impl<'a, A, D: Dimension> Iterator for IndexedIter<'a, A, D>
515512
#[inline]
516513
fn next(&mut self) -> Option<Self::Item>
517514
{
518-
let index = match self.0.inner.index {
519-
None => return None,
520-
Some(ref ix) => ix.clone(),
521-
};
515+
let index = self.0.inner.index.as_ref()?.clone();
522516
match self.0.next() {
523517
None => None,
524518
Some(elem) => Some((index.into_pattern(), elem)),
@@ -698,10 +692,7 @@ impl<'a, A, D: Dimension> Iterator for IndexedIterMut<'a, A, D>
698692
#[inline]
699693
fn next(&mut self) -> Option<Self::Item>
700694
{
701-
let index = match self.0.inner.index {
702-
None => return None,
703-
Some(ref ix) => ix.clone(),
704-
};
695+
let index = self.0.inner.index.as_ref()?.clone();
705696
match self.0.next() {
706697
None => None,
707698
Some(elem) => Some((index.into_pattern(), elem)),

‎src/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
clippy::deref_addrof,
1414
clippy::manual_map, // is not an error
1515
clippy::while_let_on_iterator, // is not an error
16-
clippy::from_iter_instead_of_collect, // using from_iter is good style
1716
clippy::incompatible_msrv, // false positive PointerExt::offset
1817
)]
1918
#![doc(test(attr(deny(warnings))))]

‎src/tri.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ where
159159
#[cfg(test)]
160160
mod tests
161161
{
162-
use core::isize;
163-
164162
use crate::{array, dimension, Array0, Array1, Array2, Array3, ShapeBuilder};
165163
use alloc::vec;
166164

‎tests/numeric.rs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
use approx::assert_abs_diff_eq;
77
use ndarray::{arr0, arr1, arr2, array, aview1, Array, Array1, Array2, Array3, Axis};
8-
use std::f64;
98

109
#[test]
1110
fn test_mean_with_nan_values()
@@ -176,7 +175,7 @@ fn var_too_large_ddof()
176175
fn var_nan_ddof()
177176
{
178177
let a = Array2::<f64>::zeros((2, 3));
179-
let v = a.var(::std::f64::NAN);
178+
let v = a.var(f64::NAN);
180179
assert!(v.is_nan());
181180
}
182181

@@ -219,7 +218,7 @@ fn std_too_large_ddof()
219218
fn std_nan_ddof()
220219
{
221220
let a = Array2::<f64>::zeros((2, 3));
222-
let v = a.std(::std::f64::NAN);
221+
let v = a.std(f64::NAN);
223222
assert!(v.is_nan());
224223
}
225224

@@ -375,7 +374,7 @@ fn var_axis_too_large_ddof()
375374
fn var_axis_nan_ddof()
376375
{
377376
let a = Array2::<f64>::zeros((2, 3));
378-
let v = a.var_axis(Axis(1), ::std::f64::NAN);
377+
let v = a.var_axis(Axis(1), f64::NAN);
379378
assert_eq!(v.shape(), &[2]);
380379
v.mapv(|x| assert!(x.is_nan()));
381380
}

0 commit comments

Comments
 (0)