Skip to content

Commit ac4eeb4

Browse files
committed
more lints
1 parent 09e4edf commit ac4eeb4

20 files changed

+67
-25
lines changed

src/dimension/axes.rs

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ impl AxisDescription {
6262
pub fn stride(self) -> Ixs {
6363
self.2
6464
}
65+
pub fn is_empty(self) -> bool {
66+
self.len() == 0
67+
}
6568
}
6669

6770
copy_and_clone!(['a, D] Axes<'a, D>);

src/dimension/axis.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct Axis(pub usize);
2121
impl Axis {
2222
/// Return the index of the axis.
2323
#[inline(always)]
24-
pub fn index(&self) -> usize {
24+
pub fn index(self) -> usize {
2525
self.0
2626
}
2727
}

src/dimension/dynindeximpl.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ impl<T: Copy + Zero> IxDynRepr<T> {
4848
pub fn copy_from(x: &[T]) -> Self {
4949
if x.len() <= CAP {
5050
let mut arr = [T::zero(); CAP];
51-
for i in 0..x.len() {
52-
arr[i] = x[i];
53-
}
51+
arr[..x.len()].clone_from_slice(&x[..]);
5452
IxDynRepr::Inline(x.len() as _, arr)
5553
} else {
5654
Self::from(x)
@@ -121,7 +119,7 @@ impl IxDynImpl {
121119
IxDynImpl(if len < CAP {
122120
let mut out = [1; CAP];
123121
out[0..i].copy_from_slice(&self[0..i]);
124-
out[i + 1..len + 1].copy_from_slice(&self[i..len]);
122+
out[i + 1..=len].copy_from_slice(&self[i..len]);
125123
IxDynRepr::Inline((len + 1) as u32, out)
126124
} else {
127125
let mut out = Vec::with_capacity(len + 1);
@@ -206,7 +204,7 @@ impl<'a> IntoIterator for &'a IxDynImpl {
206204
type IntoIter = <&'a [Ix] as IntoIterator>::IntoIter;
207205
#[inline]
208206
fn into_iter(self) -> Self::IntoIter {
209-
self[..].into_iter()
207+
self[..].iter()
210208
}
211209
}
212210

src/impl_1d.rs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ where
2323
if let Some(slc) = self.as_slice() {
2424
slc.to_vec()
2525
} else {
26+
// clippy suggests this but
27+
// the trait `iterators::TrustedIterator` is not implemented for `std::iter::Cloned<iterators::Iter<'_, A, dimension::dim::Dim<[usize; 1]>>>`
28+
// crate::iterators::to_vec(self.iter().cloned())
2629
crate::iterators::to_vec(self.iter().map(|x| x.clone()))
2730
}
2831
}

src/impl_methods.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ where
375375
let mut new_strides = Do::zeros(out_ndim);
376376
izip!(self.dim.slice(), self.strides.slice(), indices)
377377
.filter_map(|(d, s, slice_or_index)| match slice_or_index {
378-
&SliceOrIndex::Slice { .. } => Some((d, s)),
379-
&SliceOrIndex::Index(_) => None,
378+
SliceOrIndex::Slice { .. } => Some((d, s)),
379+
SliceOrIndex::Index(_) => None,
380380
})
381381
.zip(izip!(new_dim.slice_mut(), new_strides.slice_mut()))
382382
.for_each(|((d, s), (new_d, new_s))| {
@@ -413,6 +413,7 @@ where
413413
.iter()
414414
.enumerate()
415415
.for_each(|(axis, slice_or_index)| match slice_or_index {
416+
// Clippy insists we can remove the `&`, but this fails if we try
416417
&SliceOrIndex::Slice { start, end, step } => {
417418
self.slice_axis_inplace(Axis(axis), Slice { start, end, step })
418419
}

src/impl_views.rs

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ where
135135
}
136136
}
137137

138+
// Should this be `to_slice` if taking a reference?
139+
// https://rust-lang.github.io/rust-clippy/master/#wrong_self_convention
140+
138141
/// Return the array’s data as a slice, if it is contiguous and in standard order.
139142
/// Return `None` otherwise.
140143
pub fn into_slice(&self) -> Option<&'a [A]> {

src/indexes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ impl<D: Dimension + Copy> NdProducer for Indices<D> {
140140
private_impl! {}
141141

142142
#[doc(hidden)]
143+
#[allow(clippy::clone_on_copy)]
143144
fn raw_dim(&self) -> Self::Dim {
144145
self.dim.clone()
145146
}

src/linalg/impl_linalg.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ where
7878
let mut sum = A::zero();
7979
for i in 0..self.len() {
8080
unsafe {
81-
sum = sum + self.uget(i).clone() * rhs.uget(i).clone();
81+
sum = sum + *self.uget(i) * *rhs.uget(i);
8282
}
8383
}
8484
sum
@@ -586,6 +586,7 @@ pub fn general_mat_mul<A, S1, S2, S3>(
586586
/// ***Panics*** if array shapes are not compatible<br>
587587
/// *Note:* If enabled, uses blas `gemv` for elements of `f32, f64` when memory
588588
/// layout allows.
589+
#[allow(clippy::collapsible_if)]
589590
pub fn general_mat_vec_mul<A, S1, S2, S3>(
590591
alpha: A,
591592
a: &ArrayBase<S1, Ix2>,

src/numeric/impl_numeric.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ where
184184
let axis_length =
185185
A::from_usize(axis_length).expect("Converting axis length to `A` must not fail.");
186186
let sum = self.sum_axis(axis);
187-
Some(sum / &aview0(&axis_length))
187+
Some(sum / aview0(&axis_length))
188188
}
189189
}
190190

src/numeric_util.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ where
4848

4949
// make it clear to the optimizer that this loop is short
5050
// and can not be autovectorized.
51-
for i in 0..xs.len() {
51+
for (i, x) in xs.iter().enumerate() {
5252
if i >= 7 {
5353
break;
5454
}
55-
acc = f(acc.clone(), xs[i].clone())
55+
acc = f(acc.clone(), x.clone())
5656
}
5757
acc
5858
}
@@ -99,13 +99,13 @@ where
9999
sum = sum + (p2 + p6);
100100
sum = sum + (p3 + p7);
101101

102-
for i in 0..xs.len() {
102+
for (i, x) in xs.iter().enumerate() {
103103
if i >= 7 {
104104
break;
105105
}
106106
unsafe {
107107
// get_unchecked is needed to avoid the bounds check
108-
sum = sum + xs[i] * *ys.get_unchecked(i);
108+
sum = sum + *x * *ys.get_unchecked(i);
109109
}
110110
}
111111
sum

src/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ impl SliceOrIndex {
110110
/// Returns `true` if `self` is a `Slice` value.
111111
pub fn is_slice(&self) -> bool {
112112
match self {
113-
&SliceOrIndex::Slice { .. } => true,
113+
SliceOrIndex::Slice { .. } => true,
114114
_ => false,
115115
}
116116
}
117117

118118
/// Returns `true` if `self` is an `Index` value.
119119
pub fn is_index(&self) -> bool {
120120
match self {
121-
&SliceOrIndex::Index(_) => true,
121+
SliceOrIndex::Index(_) => true,
122122
_ => false,
123123
}
124124
}

tests/array.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
clippy::many_single_char_names,
44
clippy::deref_addrof,
55
clippy::unreadable_literal,
6-
clippy::many_single_char_names
6+
clippy::many_single_char_names,
7+
clippy::float_cmp
78
)]
89

910
extern crate defmac;
@@ -968,11 +969,11 @@ fn iter_size_hint() {
968969
fn zero_axes() {
969970
let mut a = arr1::<f32>(&[]);
970971
for _ in a.iter() {
971-
assert!(false);
972+
panic!();
972973
}
973-
a.map(|_| assert!(false));
974-
a.map_inplace(|_| assert!(false));
975-
a.visit(|_| assert!(false));
974+
a.map(|_| panic!());
975+
a.map_inplace(|_| panic!());
976+
a.visit(|_| panic!());
976977
println!("{:?}", a);
977978
let b = arr2::<f32, _>(&[[], [], [], []]);
978979
println!("{:?}\n{:?}", b.shape(), b);

tests/azip.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
clippy::many_single_char_names,
33
clippy::deref_addrof,
44
clippy::unreadable_literal,
5-
clippy::many_single_char_names
5+
clippy::many_single_char_names,
6+
clippy::float_cmp
67
)]
78
extern crate itertools;
89
extern crate ndarray;

tests/into-ixdyn.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#![allow(
2+
clippy::many_single_char_names,
3+
clippy::deref_addrof,
4+
clippy::unreadable_literal,
5+
clippy::many_single_char_names,
6+
clippy::float_cmp
7+
)]
18
extern crate ndarray;
29

310
use ndarray::prelude::*;

tests/iterator_chunks.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
clippy::many_single_char_names,
33
clippy::deref_addrof,
44
clippy::unreadable_literal,
5-
clippy::many_single_char_names
5+
clippy::many_single_char_names,
6+
clippy::float_cmp
67
)]
78
extern crate ndarray;
89

tests/ix0.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#![allow(
2+
clippy::many_single_char_names,
3+
clippy::deref_addrof,
4+
clippy::unreadable_literal,
5+
clippy::many_single_char_names,
6+
clippy::float_cmp
7+
)]
8+
19
extern crate ndarray;
210

311
use ndarray::Array;

tests/ixdyn.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
clippy::many_single_char_names,
33
clippy::deref_addrof,
44
clippy::unreadable_literal,
5-
clippy::many_single_char_names
5+
clippy::many_single_char_names,
6+
clippy::float_cmp
67
)]
78
extern crate ndarray;
89

tests/numeric.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
clippy::many_single_char_names,
33
clippy::deref_addrof,
44
clippy::unreadable_literal,
5-
clippy::many_single_char_names
5+
clippy::many_single_char_names,
6+
clippy::float_cmp
67
)]
78
extern crate approx;
89
use approx::assert_abs_diff_eq;

tests/s.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#![allow(
2+
clippy::many_single_char_names,
3+
clippy::deref_addrof,
4+
clippy::unreadable_literal,
5+
clippy::many_single_char_names
6+
)]
17
extern crate ndarray;
28

39
use ndarray::{s, Array};

tests/windows.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#![allow(
2+
clippy::many_single_char_names,
3+
clippy::deref_addrof,
4+
clippy::unreadable_literal,
5+
clippy::many_single_char_names
6+
)]
17
extern crate itertools;
28
extern crate ndarray;
39

0 commit comments

Comments
 (0)