Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat warnings as errors in CI #924

Merged
merged 3 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
CARGO_TERM_COLOR: always
HOST: x86_64-unknown-linux-gnu
FEATURES: "test docs"
RUSTFLAGS: "-D warnings"

jobs:
tests:
Expand Down
1 change: 0 additions & 1 deletion benches/higher-order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
clippy::many_single_char_names
)]
extern crate test;
use std::iter::FromIterator;
use test::black_box;
use test::Bencher;

Expand Down
1 change: 0 additions & 1 deletion blas-tests/tests/oper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion examples/life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
)]

use ndarray::prelude::*;
use std::iter::FromIterator;

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

Expand Down
2 changes: 2 additions & 0 deletions src/data_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D>(self_: ArrayBase<Self, D>) -> ArrayBase<OwnedRepr<Self::Elem>, D>
where
Self::Elem: Clone,
Expand All @@ -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<D>(self_: &ArrayBase<Self, D>) -> ArrayBase<OwnedArcRepr<Self::Elem>, D>
where
Self::Elem: Clone,
Expand Down
2 changes: 1 addition & 1 deletion src/dimension/dynindeximpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<T: Copy + Zero> IxDynRepr<T> {
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)
Expand Down
1 change: 1 addition & 0 deletions src/impl_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ where
///
/// let array = Array::from_iter(0..10);
/// ```
#[allow(clippy::should_implement_trait)]
pub fn from_iter<I: IntoIterator<Item = A>>(iterable: I) -> Self {
Self::from_vec(iterable.into_iter().collect())
}
Expand Down
4 changes: 2 additions & 2 deletions src/impl_internal_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<A>) -> Self {
let array = ArrayBase {
data: data,
ptr: ptr,
data,
ptr,
dim: Ix1(0),
strides: Ix1(1),
};
Expand Down
1 change: 1 addition & 0 deletions src/linalg/impl_linalg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ pub fn general_mat_vec_mul<A, S1, S2, S3>(
///
/// 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<A, S1, S2>(
alpha: A,
a: &ArrayBase<S1, Ix2>,
Expand Down
3 changes: 1 addition & 2 deletions tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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]]])
Expand Down
1 change: 0 additions & 1 deletion tests/azip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use ndarray::prelude::*;
use ndarray::Zip;
use std::iter::FromIterator;

use itertools::{assert_equal, cloned};

Expand Down
3 changes: 2 additions & 1 deletion tests/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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] {
Expand Down
2 changes: 1 addition & 1 deletion tests/iterator_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
)]

use ndarray::prelude::*;
use ndarray::NdProducer;

#[test]
#[cfg(feature = "std")]
fn chunks() {
use ndarray::NdProducer;
let a = <Array1<f32>>::linspace(1., 100., 10 * 10)
.into_shape((10, 10))
.unwrap();
Expand Down
45 changes: 22 additions & 23 deletions tests/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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]
Expand All @@ -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);
Expand All @@ -78,22 +75,24 @@ fn indexed() {
}
}

fn assert_slice_correct<A, S, D>(v: &ArrayBase<S, D>)
where
S: Data<Elem = A>,
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<A, S, D>(v: &ArrayBase<S, D>)
where
S: Data<Elem = A>,
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));

Expand Down Expand Up @@ -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.]]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the warning here?

Copy link
Member Author

@jturner314 jturner314 Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import of arr2 when the std feature is not enabled. There were a number of other similar unused import warnings.

array![[7.], [6.], [5.]],
array![[4.], [3.], [2.]],
array![[1.], [0.]],
],
);

Expand Down
4 changes: 3 additions & 1 deletion tests/ixdyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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::<Ix2>().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64> = 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.])));
Expand Down
2 changes: 0 additions & 2 deletions tests/oper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion tests/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use ndarray::prelude::*;
use ndarray::Zip;
use std::iter::FromIterator;

// Edge Cases for Windows iterator:
//
Expand Down