Skip to content

Fix Clippy lints #272

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

Merged
merged 7 commits into from
Sep 23, 2020
Merged
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
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -21,9 +21,9 @@ is-it-maintained-open-issues = { repository = "rust-lang-nursery/packed_simd" }
maintenance = { status = "experimental" }

[dependencies]
cfg-if = "^0.1.6"
core_arch = { version = "^0.1.4", optional = true }
libm = "0.1.2"
cfg-if = "0.1.10"
core_arch = { version = "0.1.5", optional = true }
libm = "0.1.4"

[features]
default = []
@@ -35,7 +35,7 @@ paste = "^0.1.3"
arrayvec = { version = "^0.5", default-features = false }

[target.'cfg(target_arch = "x86_64")'.dependencies.sleef-sys]
version = "^0.1.2"
version = "0.1.2"
optional = true

[target.wasm32-unknown-unknown.dev-dependencies]
4 changes: 2 additions & 2 deletions examples/aobench/benchmark.sh
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ fi

for alg in "${ALGS[@]}"
do
hyperfine "target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}"
hyperfine "../target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}"
done

echo "Benchmark 128-bit wide vectors"
@@ -43,5 +43,5 @@ RUSTFLAGS="-C target-cpu=native ${RUSTFLAGS}" \
--features="${FEATURES}"
for alg in "${ALGS[@]}"
do
hyperfine "target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}"
hyperfine "../target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}"
done
4 changes: 2 additions & 2 deletions examples/aobench/src/image.rs
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@ impl Image {
i as u8
}

use png::HasParameters;
use std::fs::File;
use std::io::BufWriter;

@@ -60,7 +59,8 @@ impl Image {
self.height as u32,
);

encoder.set(png::ColorType::RGB).set(png::BitDepth::Eight);
encoder.set_color(png::ColorType::RGB);
encoder.set_depth(png::BitDepth::Eight);
let mut writer = encoder.write_header().unwrap();

if soa {
6 changes: 3 additions & 3 deletions examples/aobench/src/intersection/ray_plane.rs
Original file line number Diff line number Diff line change
@@ -53,7 +53,8 @@ impl Intersect<Plane> for RayxN {
}
}

debug_assert!({
#[cfg(debug_assertions)]
{
// Check that the vector and the scalar version produce the same results
// for the same inputs in debug builds
for i in 0..f32xN::lanes() {
@@ -62,8 +63,7 @@ impl Intersect<Plane> for RayxN {
let isect_i = ray_i.intersect(plane, old_isect_i);
assert!(isect_i.almost_eq(&isect.get(i)), "{:?} !~= {:?}\n\nplane: {:?}\n\nold_isect: {:?}\n\nrays: {:?}\n\ni: {:?}\nold_isect_i: {:?}\nray_i: {:?}\n\n", isect_i, isect.get(i), plane, old_isect, self, i, old_isect_i, ray_i);
}
true
});
}

isect
}
6 changes: 3 additions & 3 deletions examples/aobench/src/intersection/ray_sphere.rs
Original file line number Diff line number Diff line change
@@ -59,7 +59,8 @@ impl Intersect<Sphere> for RayxN {
}
}

debug_assert!({
#[cfg(debug_assertions)]
{
// Check that the vector and the scalar version produce the same results
// for the same inputs in debug builds
for i in 0..f32xN::lanes() {
@@ -68,8 +69,7 @@ impl Intersect<Sphere> for RayxN {
let isect_i = ray_i.intersect(sphere, old_isect_i);
assert!(isect_i.almost_eq(&isect.get(i)), "{:?} !~= {:?}\n\nsphere: {:?}\n\nold_isect: {:?}\n\nrays: {:?}\n\ni: {:?}\nold_isect_i: {:?}\nray_i: {:?}\n\n", isect_i, isect.get(i), sphere, old_isect, self, i, old_isect_i, ray_i);
}
true
});
}

isect
}
3 changes: 2 additions & 1 deletion examples/aobench/src/lib.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::identity_op,
clippy::erasing_op
clippy::erasing_op,
clippy::must_use_candidate
)]

pub mod ambient_occlusion;
4 changes: 2 additions & 2 deletions examples/aobench/src/random.rs
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ pub mod scalar {

pub fn thread_rng() -> RngH {
RngH {
rng: THREAD_RNG_KEY.with(|t| t.clone()),
rng: THREAD_RNG_KEY.with(Clone::clone),
}
}
}
@@ -134,7 +134,7 @@ pub mod vector {

pub fn thread_rng() -> RngH {
RngH {
rng: THREAD_RNG_KEY.with(|t| t.clone()),
rng: THREAD_RNG_KEY.with(Clone::clone),
}
}
}
1 change: 1 addition & 0 deletions examples/dot_product/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Vector dot product
#![deny(warnings, rust_2018_idioms)]
#![feature(custom_inner_attributes)]
#![allow(clippy::must_use_candidate)]

pub mod scalar;
pub mod simd;
3 changes: 2 additions & 1 deletion examples/fannkuch_redux/src/lib.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@
clippy::many_single_char_names,
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::cast_possible_wrap
clippy::cast_possible_wrap,
clippy::must_use_candidate
)]

pub mod scalar;
2 changes: 1 addition & 1 deletion examples/mandelbrot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ edition = "2018"
packed_simd = { path = "../.." }
rayon = "^1.0"
ispc = { version = "^1.0.4", optional = true }
structopt = "0.3.0"
structopt = { version = "0.3.0", features = ["color"] }

[build-dependencies]
ispc = { version = "^1.0.4", optional = true }
6 changes: 3 additions & 3 deletions examples/mandelbrot/benchmark.sh
Original file line number Diff line number Diff line change
@@ -27,9 +27,9 @@ if [[ "${NORUN}" == "1" ]]; then
exit 0
fi

hyperfine "target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo scalar"
hyperfine "target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo simd"
hyperfine "../target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo scalar"
hyperfine "../target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo simd"

if echo "$FEATURES" | grep -q "ispc"; then
hyperfine "target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo ispc"
hyperfine "../target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo ispc"
fi
3 changes: 2 additions & 1 deletion examples/mandelbrot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@
#![allow(
clippy::cast_precision_loss,
clippy::cast_sign_loss,
clippy::cast_possible_truncation
clippy::cast_possible_truncation,
clippy::must_use_candidate
)]

use rayon::prelude::*;
1 change: 0 additions & 1 deletion examples/mandelbrot/src/main.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ use structopt::StructOpt;
///
/// Output is printed to `stdout`.
#[derive(StructOpt)]
#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))]
struct Opt {
/// Image width.
width: usize,
5 changes: 3 additions & 2 deletions examples/mandelbrot/src/simd_par.rs
Original file line number Diff line number Diff line change
@@ -145,10 +145,11 @@ pub fn generate(dims: Dimensions, xr: Range, yr: Range) -> Vec<u32> {
});
});

// This is safe, we're transmuting from a more-aligned type to a
// less-aligned one.
#[allow(clippy::unsound_collection_transmute)]
unsafe {
let mut out: Vec<u32> = std::mem::transmute(out);
// This is safe, we're transmuting from a more-aligned type to a
// less-aligned one.
out.set_len(width * height);
out
}
1 change: 1 addition & 0 deletions examples/matrix_inverse/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! 4x4 matrix inverse
#![feature(custom_inner_attributes)]
#![deny(warnings, rust_2018_idioms)]
#![allow(clippy::must_use_candidate)]

pub mod scalar;
pub mod simd;
6 changes: 5 additions & 1 deletion examples/nbody/src/lib.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,11 @@
//!
//! [bg]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/nbody.html#nbody
#![deny(warnings, rust_2018_idioms)]
#![allow(clippy::similar_names, clippy::excessive_precision)]
#![allow(
clippy::similar_names,
clippy::excessive_precision,
clippy::must_use_candidate
)]

pub mod scalar;
pub mod simd;
4 changes: 2 additions & 2 deletions examples/options_pricing/benchmark.sh
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ fi

#for alg in "${ALGS[@]}"
#do
# hyperfine "target/release/options_pricing ${NUM_OPTIONS_BLACK_SCHOLES} ${alg}"
# hyperfine "../target/release/options_pricing ${NUM_OPTIONS_BLACK_SCHOLES} ${alg}"
#done

# Binomial put:
@@ -40,5 +40,5 @@ NUM_OPTIONS_BINOMIAL_PUT=500000

for alg in "${ALGS[@]}"
do
hyperfine "target/release/options_pricing ${NUM_OPTIONS_BINOMIAL_PUT} ${alg}"
hyperfine "../target/release/options_pricing ${NUM_OPTIONS_BINOMIAL_PUT} ${alg}"
done
1 change: 1 addition & 0 deletions examples/options_pricing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::must_use_candidate,
clippy::too_many_arguments
)]

2 changes: 1 addition & 1 deletion examples/slice_sum/src/main.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ fn sum_hor(x: &[f32]) -> f32 {

x.chunks_exact(f32s::lanes())
.map(f32s::from_slice_unaligned)
.map(|vec| vec.sum())
.map(f32s::sum)
.sum()
}

5 changes: 4 additions & 1 deletion examples/spectral_norm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Spectral Norm
#![deny(warnings, rust_2018_idioms)]
#![allow(non_snake_case, non_camel_case_types)]
#![allow(clippy::cast_precision_loss)]
#![allow(
clippy::cast_precision_loss,
clippy::must_use_candidate
)]

pub mod scalar;
pub mod simd;
2 changes: 1 addition & 1 deletion examples/stencil/benchmark.sh
Original file line number Diff line number Diff line change
@@ -30,5 +30,5 @@ fi

for alg in "${algs[@]}"
do
hyperfine "target/release/stencil ${alg}"
hyperfine "../target/release/stencil ${alg}"
done
3 changes: 2 additions & 1 deletion examples/stencil/src/lib.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,8 @@
clippy::too_many_arguments,
clippy::cast_possible_wrap,
clippy::cast_possible_truncation,
clippy::inline_always
clippy::inline_always,
clippy::must_use_candidate
)]

#[cfg(feature = "ispc")]
2 changes: 2 additions & 0 deletions examples/triangle_xform/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::must_use_candidate)]

/// Simple matrix type.
/// The memory layout is the same as the one for Direct3D/OpenGL: fourth vector
/// represents the translation vector `[x, y, z]`.
16 changes: 8 additions & 8 deletions src/api/minimal/ptr.rs
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ macro_rules! impl_minimal_p {

/// Extracts the value at `index`.
///
/// # Precondition
/// # Safety
///
/// If `index >= Self::lanes()` the behavior is undefined.
#[inline]
@@ -96,7 +96,7 @@ macro_rules! impl_minimal_p {

/// Returns a new vector where the value at `index` is replaced by `new_value`.
///
/// # Precondition
/// # Safety
///
/// If `index >= Self::lanes()` the behavior is undefined.
#[inline]
@@ -215,7 +215,7 @@ macro_rules! impl_minimal_p {
f,
"{}<{}>(",
stringify!($id),
unsafe { crate::intrinsics::type_name::<T>() }
crate::intrinsics::type_name::<T>()
)?;
for i in 0..$elem_count {
if i > 0 {
@@ -611,7 +611,7 @@ macro_rules! impl_minimal_p {

/// Instantiates a new vector with the values of the `slice`.
///
/// # Precondition
/// # Safety
///
/// If `slice.len() < Self::lanes()` or `&slice[0]` is not aligned
/// to an `align_of::<Self>()` boundary, the behavior is undefined.
@@ -624,7 +624,7 @@ macro_rules! impl_minimal_p {

/// Instantiates a new vector with the values of the `slice`.
///
/// # Precondition
/// # Safety
///
/// If `slice.len() < Self::lanes()` the behavior is undefined.
#[inline]
@@ -827,7 +827,7 @@ macro_rules! impl_minimal_p {

/// Writes the values of the vector to the `slice`.
///
/// # Precondition
/// # Safety
///
/// If `slice.len() < Self::lanes()` or `&slice[0]` is not
/// aligned to an `align_of::<Self>()` boundary, the behavior is
@@ -843,7 +843,7 @@ macro_rules! impl_minimal_p {

/// Writes the values of the vector to the `slice`.
///
/// # Precondition
/// # Safety
///
/// If `slice.len() < Self::lanes()` the behavior is undefined.
#[inline]
@@ -1151,7 +1151,7 @@ macro_rules! impl_minimal_p {
/// As such, memory acquired directly from allocators or memory
/// mapped files may be too large to handle with this function.
///
/// Consider using wrapping_offset_from instead if these constraints
/// Consider using `wrapping_offset_from` instead if these constraints
/// are difficult to satisfy. The only advantage of this method is
/// that it enables more aggressive compiler optimizations.
#[inline]
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -218,9 +218,12 @@
clippy::cast_lossless,
clippy::cast_possible_wrap,
clippy::cast_precision_loss,
// TODO: manually add the `#[must_use]` attribute where appropiate
clippy::must_use_candidate,
// This lint is currently broken for generic code
// See https://github.com/rust-lang/rust-clippy/issues/3410
clippy::use_self
clippy::use_self,
clippy::wrong_self_convention
)]
#![cfg_attr(test, feature(hashmap_internals))]
#![deny(rust_2018_idioms, clippy::missing_inline_in_public_items)]
1 change: 1 addition & 0 deletions src/masks.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ macro_rules! impl_mask_ty {

impl crate::sealed::Seal for $id {}
impl crate::sealed::Mask for $id {
#[inline]
fn test(&self) -> bool {
$id::test(self)
}