diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92c184ca8..42e5e6584 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ env: CARGO_TERM_COLOR: always HOST: x86_64-unknown-linux-gnu FEATURES: "test docs" + RUSTFLAGS: "-D warnings" jobs: tests: diff --git a/benches/higher-order.rs b/benches/higher-order.rs index 2ea0721af..6bbd57177 100644 --- a/benches/higher-order.rs +++ b/benches/higher-order.rs @@ -6,7 +6,6 @@ clippy::many_single_char_names )] extern crate test; -use std::iter::FromIterator; use test::black_box; use test::Bencher; diff --git a/blas-tests/tests/oper.rs b/blas-tests/tests/oper.rs index b7c2d769d..51ac7824c 100644 --- a/blas-tests/tests/oper.rs +++ b/blas-tests/tests/oper.rs @@ -8,7 +8,6 @@ use ndarray::linalg::general_mat_vec_mul; use ndarray::prelude::*; use ndarray::{Data, LinalgScalar}; use ndarray::{Ix, Ixs, SliceInfo, SliceOrIndex}; -use std::iter::FromIterator; use approx::{assert_abs_diff_eq, assert_relative_eq}; use defmac::defmac; diff --git a/examples/life.rs b/examples/life.rs index 748f16053..48f1d609f 100644 --- a/examples/life.rs +++ b/examples/life.rs @@ -6,7 +6,6 @@ )] use ndarray::prelude::*; -use std::iter::FromIterator; const INPUT: &[u8] = include_bytes!("life.txt"); diff --git a/src/data_traits.rs b/src/data_traits.rs index 2b59fcb8d..1e191c468 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -94,6 +94,7 @@ pub unsafe trait RawDataClone: RawData { pub unsafe trait Data: RawData { /// Converts the array to a uniquely owned array, cloning elements if necessary. #[doc(hidden)] + #[allow(clippy::wrong_self_convention)] fn into_owned(self_: ArrayBase) -> ArrayBase, D> where Self::Elem: Clone, @@ -102,6 +103,7 @@ pub unsafe trait Data: RawData { /// Return a shared ownership (copy on write) array based on the existing one, /// cloning elements if necessary. #[doc(hidden)] + #[allow(clippy::wrong_self_convention)] fn to_shared(self_: &ArrayBase) -> ArrayBase, D> where Self::Elem: Clone, diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index 5c9cd0d61..b75db91c5 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -51,7 +51,7 @@ impl IxDynRepr { pub fn copy_from(x: &[T]) -> Self { if x.len() <= CAP { let mut arr = [T::zero(); CAP]; - arr[..x.len()].copy_from_slice(&x[..]); + arr[..x.len()].copy_from_slice(x); IxDynRepr::Inline(x.len() as _, arr) } else { Self::from(x) diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 71ca8b32d..63688ea7f 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -73,6 +73,7 @@ where /// /// let array = Array::from_iter(0..10); /// ``` + #[allow(clippy::should_implement_trait)] pub fn from_iter>(iterable: I) -> Self { Self::from_vec(iterable.into_iter().collect()) } diff --git a/src/impl_internal_constructors.rs b/src/impl_internal_constructors.rs index 0ed60a622..5d47c9897 100644 --- a/src/impl_internal_constructors.rs +++ b/src/impl_internal_constructors.rs @@ -25,8 +25,8 @@ where /// See ArrayView::from_shape_ptr for general pointer validity documentation. pub(crate) unsafe fn from_data_ptr(data: S, ptr: NonNull) -> Self { let array = ArrayBase { - data: data, - ptr: ptr, + data, + ptr, dim: Ix1(0), strides: Ix1(1), }; diff --git a/src/linalg/impl_linalg.rs b/src/linalg/impl_linalg.rs index 878444c26..61b91eaed 100644 --- a/src/linalg/impl_linalg.rs +++ b/src/linalg/impl_linalg.rs @@ -613,6 +613,7 @@ pub fn general_mat_vec_mul( /// /// The caller must ensure that the raw view is valid for writing. /// the destination may be uninitialized iff beta is zero. +#[allow(clippy::collapsible_else_if)] unsafe fn general_mat_vec_mul_impl( alpha: A, a: &ArrayBase, diff --git a/tests/array.rs b/tests/array.rs index dddcd5e1e..6b72bb5c4 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -13,7 +13,6 @@ use ndarray::indices; use ndarray::prelude::*; use ndarray::{arr3, rcarr2}; use ndarray::{Slice, SliceInfo, SliceOrIndex}; -use std::iter::FromIterator; macro_rules! assert_panics { ($body:expr) => { @@ -1803,7 +1802,7 @@ fn test_contiguous() { #[test] fn test_contiguous_neg_strides() { let s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; - let mut a = ArrayView::from_shape((2, 3, 2).strides((1, 4, 2)), &s).unwrap(); + let a = ArrayView::from_shape((2, 3, 2).strides((1, 4, 2)), &s).unwrap(); assert_eq!( a, arr3(&[[[0, 2], [4, 6], [8, 10]], [[1, 3], [5, 7], [9, 11]]]) diff --git a/tests/azip.rs b/tests/azip.rs index 5075a89ba..6f0327f5d 100644 --- a/tests/azip.rs +++ b/tests/azip.rs @@ -8,7 +8,6 @@ use ndarray::prelude::*; use ndarray::Zip; -use std::iter::FromIterator; use itertools::{assert_equal, cloned}; diff --git a/tests/dimension.rs b/tests/dimension.rs index 7f1ee7ec5..939b4f0e3 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -2,7 +2,7 @@ use defmac::defmac; -use ndarray::{arr2, ArcArray, Array, Axis, Dim, Dimension, IntoDimension, IxDyn, RemoveAxis}; +use ndarray::{arr2, ArcArray, Array, Axis, Dim, Dimension, IxDyn, RemoveAxis}; use std::hash::{Hash, Hasher}; @@ -307,6 +307,7 @@ fn test_array_view() { #[cfg(feature = "std")] #[allow(clippy::cognitive_complexity)] fn test_all_ndindex() { + use ndarray::IntoDimension; macro_rules! ndindex { ($($i:expr),*) => { for &rev in &[false, true] { diff --git a/tests/iterator_chunks.rs b/tests/iterator_chunks.rs index 995557173..67ddd1e38 100644 --- a/tests/iterator_chunks.rs +++ b/tests/iterator_chunks.rs @@ -7,11 +7,11 @@ )] use ndarray::prelude::*; -use ndarray::NdProducer; #[test] #[cfg(feature = "std")] fn chunks() { + use ndarray::NdProducer; let a = >::linspace(1., 100., 10 * 10) .into_shape((10, 10)) .unwrap(); diff --git a/tests/iterators.rs b/tests/iterators.rs index fc345200e..4e4bbc666 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -6,12 +6,9 @@ )] use ndarray::prelude::*; -use ndarray::Ix; -use ndarray::{arr2, arr3, aview1, indices, s, Axis, Data, Dimension, Slice, Zip}; +use ndarray::{arr3, aview1, indices, s, Axis, Slice, Zip}; -use itertools::assert_equal; -use itertools::{enumerate, rev}; -use std::iter::FromIterator; +use itertools::{assert_equal, enumerate}; macro_rules! assert_panics { ($body:expr) => { @@ -37,7 +34,7 @@ fn double_ended() { assert_eq!(it.next(), Some(1.)); assert_eq!(it.rev().last(), Some(2.)); assert_equal(aview1(&[1, 2, 3]), &[1, 2, 3]); - assert_equal(rev(aview1(&[1, 2, 3])), rev(&[1, 2, 3])); + assert_equal(aview1(&[1, 2, 3]).into_iter().rev(), [1, 2, 3].iter().rev()); } #[test] @@ -63,7 +60,7 @@ fn iter_size_hint() { fn indexed() { let a = ArcArray::linspace(0., 7., 8); for (i, elt) in a.indexed_iter() { - assert_eq!(i, *elt as Ix); + assert_eq!(i, *elt as usize); } let a = a.reshape((2, 4, 1)); let (mut i, mut j, k) = (0, 0, 0); @@ -78,22 +75,24 @@ fn indexed() { } } -fn assert_slice_correct(v: &ArrayBase) -where - S: Data, - D: Dimension, - A: PartialEq + std::fmt::Debug, -{ - let slc = v.as_slice(); - assert!(slc.is_some()); - let slc = slc.unwrap(); - assert_eq!(v.len(), slc.len()); - assert_equal(v.iter(), slc); -} - #[test] #[cfg(feature = "std")] fn as_slice() { + use ndarray::Data; + + fn assert_slice_correct(v: &ArrayBase) + where + S: Data, + D: Dimension, + A: PartialEq + std::fmt::Debug, + { + let slc = v.as_slice(); + assert!(slc.is_some()); + let slc = slc.unwrap(); + assert_eq!(v.len(), slc.len()); + assert_equal(v.iter(), slc); + } + let a = ArcArray::linspace(0., 7., 8); let a = a.reshape((2, 4, 1)); @@ -544,9 +543,9 @@ fn axis_chunks_iter_corner_cases() { assert_equal( it, vec![ - arr2(&[[7.], [6.], [5.]]), - arr2(&[[4.], [3.], [2.]]), - arr2(&[[1.], [0.]]), + array![[7.], [6.], [5.]], + array![[4.], [3.], [2.]], + array![[1.], [0.]], ], ); diff --git a/tests/ixdyn.rs b/tests/ixdyn.rs index 3c96cd746..11af2c97a 100644 --- a/tests/ixdyn.rs +++ b/tests/ixdyn.rs @@ -9,7 +9,7 @@ use ndarray::Array; use ndarray::IntoDimension; use ndarray::ShapeBuilder; -use ndarray::{Ix0, Ix1, Ix2, Ix3, IxDyn}; +use ndarray::Ix3; #[test] fn test_ixdyn() { @@ -157,6 +157,8 @@ fn test_0_add_broad() { #[test] #[cfg(feature = "std")] fn test_into_dimension() { + use ndarray::{Ix0, Ix1, Ix2, IxDyn}; + let a = Array::linspace(0., 41., 6 * 7).into_shape((6, 7)).unwrap(); let a2 = a.clone().into_shape(IxDyn(&[6, 7])).unwrap(); let b = a2.clone().into_dimensionality::().unwrap(); diff --git a/tests/numeric.rs b/tests/numeric.rs index 15df53287..e08979d29 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -40,7 +40,7 @@ fn test_mean_with_array_of_floats() { #[test] fn sum_mean() { - let a = arr2(&[[1., 2.], [3., 4.]]); + let a: Array2 = arr2(&[[1., 2.], [3., 4.]]); assert_eq!(a.sum_axis(Axis(0)), arr1(&[4., 6.])); assert_eq!(a.sum_axis(Axis(1)), arr1(&[3., 7.])); assert_eq!(a.mean_axis(Axis(0)), Some(arr1(&[2., 3.]))); diff --git a/tests/oper.rs b/tests/oper.rs index 66c24c7f8..5d24de9f7 100644 --- a/tests/oper.rs +++ b/tests/oper.rs @@ -11,11 +11,9 @@ use ndarray::{rcarr1, rcarr2}; use ndarray::{Data, LinalgScalar}; use ndarray::{Ix, Ixs}; use num_traits::Zero; -use std::iter::FromIterator; use approx::assert_abs_diff_eq; use defmac::defmac; -use std::ops::Neg; fn test_oper(op: &str, a: &[f32], b: &[f32], c: &[f32]) { let aa = rcarr1(a); diff --git a/tests/windows.rs b/tests/windows.rs index d1c41f017..9fb8cc8ae 100644 --- a/tests/windows.rs +++ b/tests/windows.rs @@ -7,7 +7,6 @@ use ndarray::prelude::*; use ndarray::Zip; -use std::iter::FromIterator; // Edge Cases for Windows iterator: //