Skip to content

Commit 61acbd3

Browse files
authored
Merge pull request #924 from jturner314/warnings-as-errors
Treat warnings as errors in CI
2 parents cef3901 + 87a6448 commit 61acbd3

18 files changed

+38
-39
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010
CARGO_TERM_COLOR: always
1111
HOST: x86_64-unknown-linux-gnu
1212
FEATURES: "test docs"
13+
RUSTFLAGS: "-D warnings"
1314

1415
jobs:
1516
tests:

benches/higher-order.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
clippy::many_single_char_names
77
)]
88
extern crate test;
9-
use std::iter::FromIterator;
109
use test::black_box;
1110
use test::Bencher;
1211

blas-tests/tests/oper.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use ndarray::linalg::general_mat_vec_mul;
88
use ndarray::prelude::*;
99
use ndarray::{Data, LinalgScalar};
1010
use ndarray::{Ix, Ixs, SliceInfo, SliceOrIndex};
11-
use std::iter::FromIterator;
1211

1312
use approx::{assert_abs_diff_eq, assert_relative_eq};
1413
use defmac::defmac;

examples/life.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
)]
77

88
use ndarray::prelude::*;
9-
use std::iter::FromIterator;
109

1110
const INPUT: &[u8] = include_bytes!("life.txt");
1211

src/data_traits.rs

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub unsafe trait RawDataClone: RawData {
9494
pub unsafe trait Data: RawData {
9595
/// Converts the array to a uniquely owned array, cloning elements if necessary.
9696
#[doc(hidden)]
97+
#[allow(clippy::wrong_self_convention)]
9798
fn into_owned<D>(self_: ArrayBase<Self, D>) -> ArrayBase<OwnedRepr<Self::Elem>, D>
9899
where
99100
Self::Elem: Clone,
@@ -102,6 +103,7 @@ pub unsafe trait Data: RawData {
102103
/// Return a shared ownership (copy on write) array based on the existing one,
103104
/// cloning elements if necessary.
104105
#[doc(hidden)]
106+
#[allow(clippy::wrong_self_convention)]
105107
fn to_shared<D>(self_: &ArrayBase<Self, D>) -> ArrayBase<OwnedArcRepr<Self::Elem>, D>
106108
where
107109
Self::Elem: Clone,

src/dimension/dynindeximpl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<T: Copy + Zero> IxDynRepr<T> {
5151
pub fn copy_from(x: &[T]) -> Self {
5252
if x.len() <= CAP {
5353
let mut arr = [T::zero(); CAP];
54-
arr[..x.len()].copy_from_slice(&x[..]);
54+
arr[..x.len()].copy_from_slice(x);
5555
IxDynRepr::Inline(x.len() as _, arr)
5656
} else {
5757
Self::from(x)

src/impl_constructors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ where
7373
///
7474
/// let array = Array::from_iter(0..10);
7575
/// ```
76+
#[allow(clippy::should_implement_trait)]
7677
pub fn from_iter<I: IntoIterator<Item = A>>(iterable: I) -> Self {
7778
Self::from_vec(iterable.into_iter().collect())
7879
}

src/impl_internal_constructors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ where
2525
/// See ArrayView::from_shape_ptr for general pointer validity documentation.
2626
pub(crate) unsafe fn from_data_ptr(data: S, ptr: NonNull<A>) -> Self {
2727
let array = ArrayBase {
28-
data: data,
29-
ptr: ptr,
28+
data,
29+
ptr,
3030
dim: Ix1(0),
3131
strides: Ix1(1),
3232
};

src/linalg/impl_linalg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ pub fn general_mat_vec_mul<A, S1, S2, S3>(
613613
///
614614
/// The caller must ensure that the raw view is valid for writing.
615615
/// the destination may be uninitialized iff beta is zero.
616+
#[allow(clippy::collapsible_else_if)]
616617
unsafe fn general_mat_vec_mul_impl<A, S1, S2>(
617618
alpha: A,
618619
a: &ArrayBase<S1, Ix2>,

tests/array.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use ndarray::indices;
1313
use ndarray::prelude::*;
1414
use ndarray::{arr3, rcarr2};
1515
use ndarray::{Slice, SliceInfo, SliceOrIndex};
16-
use std::iter::FromIterator;
1716

1817
macro_rules! assert_panics {
1918
($body:expr) => {
@@ -1803,7 +1802,7 @@ fn test_contiguous() {
18031802
#[test]
18041803
fn test_contiguous_neg_strides() {
18051804
let s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
1806-
let mut a = ArrayView::from_shape((2, 3, 2).strides((1, 4, 2)), &s).unwrap();
1805+
let a = ArrayView::from_shape((2, 3, 2).strides((1, 4, 2)), &s).unwrap();
18071806
assert_eq!(
18081807
a,
18091808
arr3(&[[[0, 2], [4, 6], [8, 10]], [[1, 3], [5, 7], [9, 11]]])

tests/azip.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use ndarray::prelude::*;
1010
use ndarray::Zip;
11-
use std::iter::FromIterator;
1211

1312
use itertools::{assert_equal, cloned};
1413

tests/dimension.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use defmac::defmac;
44

5-
use ndarray::{arr2, ArcArray, Array, Axis, Dim, Dimension, IntoDimension, IxDyn, RemoveAxis};
5+
use ndarray::{arr2, ArcArray, Array, Axis, Dim, Dimension, IxDyn, RemoveAxis};
66

77
use std::hash::{Hash, Hasher};
88

@@ -307,6 +307,7 @@ fn test_array_view() {
307307
#[cfg(feature = "std")]
308308
#[allow(clippy::cognitive_complexity)]
309309
fn test_all_ndindex() {
310+
use ndarray::IntoDimension;
310311
macro_rules! ndindex {
311312
($($i:expr),*) => {
312313
for &rev in &[false, true] {

tests/iterator_chunks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
)]
88

99
use ndarray::prelude::*;
10-
use ndarray::NdProducer;
1110

1211
#[test]
1312
#[cfg(feature = "std")]
1413
fn chunks() {
14+
use ndarray::NdProducer;
1515
let a = <Array1<f32>>::linspace(1., 100., 10 * 10)
1616
.into_shape((10, 10))
1717
.unwrap();

tests/iterators.rs

+22-23
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
)]
77

88
use ndarray::prelude::*;
9-
use ndarray::Ix;
10-
use ndarray::{arr2, arr3, aview1, indices, s, Axis, Data, Dimension, Slice, Zip};
9+
use ndarray::{arr3, aview1, indices, s, Axis, Slice, Zip};
1110

12-
use itertools::assert_equal;
13-
use itertools::{enumerate, rev};
14-
use std::iter::FromIterator;
11+
use itertools::{assert_equal, enumerate};
1512

1613
macro_rules! assert_panics {
1714
($body:expr) => {
@@ -37,7 +34,7 @@ fn double_ended() {
3734
assert_eq!(it.next(), Some(1.));
3835
assert_eq!(it.rev().last(), Some(2.));
3936
assert_equal(aview1(&[1, 2, 3]), &[1, 2, 3]);
40-
assert_equal(rev(aview1(&[1, 2, 3])), rev(&[1, 2, 3]));
37+
assert_equal(aview1(&[1, 2, 3]).into_iter().rev(), [1, 2, 3].iter().rev());
4138
}
4239

4340
#[test]
@@ -63,7 +60,7 @@ fn iter_size_hint() {
6360
fn indexed() {
6461
let a = ArcArray::linspace(0., 7., 8);
6562
for (i, elt) in a.indexed_iter() {
66-
assert_eq!(i, *elt as Ix);
63+
assert_eq!(i, *elt as usize);
6764
}
6865
let a = a.reshape((2, 4, 1));
6966
let (mut i, mut j, k) = (0, 0, 0);
@@ -78,22 +75,24 @@ fn indexed() {
7875
}
7976
}
8077

81-
fn assert_slice_correct<A, S, D>(v: &ArrayBase<S, D>)
82-
where
83-
S: Data<Elem = A>,
84-
D: Dimension,
85-
A: PartialEq + std::fmt::Debug,
86-
{
87-
let slc = v.as_slice();
88-
assert!(slc.is_some());
89-
let slc = slc.unwrap();
90-
assert_eq!(v.len(), slc.len());
91-
assert_equal(v.iter(), slc);
92-
}
93-
9478
#[test]
9579
#[cfg(feature = "std")]
9680
fn as_slice() {
81+
use ndarray::Data;
82+
83+
fn assert_slice_correct<A, S, D>(v: &ArrayBase<S, D>)
84+
where
85+
S: Data<Elem = A>,
86+
D: Dimension,
87+
A: PartialEq + std::fmt::Debug,
88+
{
89+
let slc = v.as_slice();
90+
assert!(slc.is_some());
91+
let slc = slc.unwrap();
92+
assert_eq!(v.len(), slc.len());
93+
assert_equal(v.iter(), slc);
94+
}
95+
9796
let a = ArcArray::linspace(0., 7., 8);
9897
let a = a.reshape((2, 4, 1));
9998

@@ -544,9 +543,9 @@ fn axis_chunks_iter_corner_cases() {
544543
assert_equal(
545544
it,
546545
vec![
547-
arr2(&[[7.], [6.], [5.]]),
548-
arr2(&[[4.], [3.], [2.]]),
549-
arr2(&[[1.], [0.]]),
546+
array![[7.], [6.], [5.]],
547+
array![[4.], [3.], [2.]],
548+
array![[1.], [0.]],
550549
],
551550
);
552551

tests/ixdyn.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use ndarray::Array;
1010
use ndarray::IntoDimension;
1111
use ndarray::ShapeBuilder;
12-
use ndarray::{Ix0, Ix1, Ix2, Ix3, IxDyn};
12+
use ndarray::Ix3;
1313

1414
#[test]
1515
fn test_ixdyn() {
@@ -157,6 +157,8 @@ fn test_0_add_broad() {
157157
#[test]
158158
#[cfg(feature = "std")]
159159
fn test_into_dimension() {
160+
use ndarray::{Ix0, Ix1, Ix2, IxDyn};
161+
160162
let a = Array::linspace(0., 41., 6 * 7).into_shape((6, 7)).unwrap();
161163
let a2 = a.clone().into_shape(IxDyn(&[6, 7])).unwrap();
162164
let b = a2.clone().into_dimensionality::<Ix2>().unwrap();

tests/numeric.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn test_mean_with_array_of_floats() {
4040

4141
#[test]
4242
fn sum_mean() {
43-
let a = arr2(&[[1., 2.], [3., 4.]]);
43+
let a: Array2<f64> = arr2(&[[1., 2.], [3., 4.]]);
4444
assert_eq!(a.sum_axis(Axis(0)), arr1(&[4., 6.]));
4545
assert_eq!(a.sum_axis(Axis(1)), arr1(&[3., 7.]));
4646
assert_eq!(a.mean_axis(Axis(0)), Some(arr1(&[2., 3.])));

tests/oper.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ use ndarray::{rcarr1, rcarr2};
1111
use ndarray::{Data, LinalgScalar};
1212
use ndarray::{Ix, Ixs};
1313
use num_traits::Zero;
14-
use std::iter::FromIterator;
1514

1615
use approx::assert_abs_diff_eq;
1716
use defmac::defmac;
18-
use std::ops::Neg;
1917

2018
fn test_oper(op: &str, a: &[f32], b: &[f32], c: &[f32]) {
2119
let aa = rcarr1(a);

tests/windows.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use ndarray::prelude::*;
99
use ndarray::Zip;
10-
use std::iter::FromIterator;
1110

1211
// Edge Cases for Windows iterator:
1312
//

0 commit comments

Comments
 (0)