Skip to content

Commit 065021d

Browse files
Merge pull request #272 from GabrielMajeri/fix-clippy
Fix Clippy lints
2 parents efc71ad + a4b0305 commit 065021d

File tree

26 files changed

+62
-42
lines changed

26 files changed

+62
-42
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ is-it-maintained-open-issues = { repository = "rust-lang-nursery/packed_simd" }
2121
maintenance = { status = "experimental" }
2222

2323
[dependencies]
24-
cfg-if = "^0.1.6"
25-
core_arch = { version = "^0.1.4", optional = true }
26-
libm = "0.1.2"
24+
cfg-if = "0.1.10"
25+
core_arch = { version = "0.1.5", optional = true }
26+
libm = "0.1.4"
2727

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

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

4141
[target.wasm32-unknown-unknown.dev-dependencies]

examples/aobench/benchmark.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fi
3434

3535
for alg in "${ALGS[@]}"
3636
do
37-
hyperfine "target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}"
37+
hyperfine "../target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}"
3838
done
3939

4040
echo "Benchmark 128-bit wide vectors"
@@ -43,5 +43,5 @@ RUSTFLAGS="-C target-cpu=native ${RUSTFLAGS}" \
4343
--features="${FEATURES}"
4444
for alg in "${ALGS[@]}"
4545
do
46-
hyperfine "target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}"
46+
hyperfine "../target/release/aobench ${WIDTH} ${HEIGHT} --algo ${alg}"
4747
done

examples/aobench/src/image.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ impl Image {
4848
i as u8
4949
}
5050

51-
use png::HasParameters;
5251
use std::fs::File;
5352
use std::io::BufWriter;
5453

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

63-
encoder.set(png::ColorType::RGB).set(png::BitDepth::Eight);
62+
encoder.set_color(png::ColorType::RGB);
63+
encoder.set_depth(png::BitDepth::Eight);
6464
let mut writer = encoder.write_header().unwrap();
6565

6666
if soa {

examples/aobench/src/intersection/ray_plane.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ impl Intersect<Plane> for RayxN {
5353
}
5454
}
5555

56-
debug_assert!({
56+
#[cfg(debug_assertions)]
57+
{
5758
// Check that the vector and the scalar version produce the same results
5859
// for the same inputs in debug builds
5960
for i in 0..f32xN::lanes() {
@@ -62,8 +63,7 @@ impl Intersect<Plane> for RayxN {
6263
let isect_i = ray_i.intersect(plane, old_isect_i);
6364
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);
6465
}
65-
true
66-
});
66+
}
6767

6868
isect
6969
}

examples/aobench/src/intersection/ray_sphere.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ impl Intersect<Sphere> for RayxN {
5959
}
6060
}
6161

62-
debug_assert!({
62+
#[cfg(debug_assertions)]
63+
{
6364
// Check that the vector and the scalar version produce the same results
6465
// for the same inputs in debug builds
6566
for i in 0..f32xN::lanes() {
@@ -68,8 +69,7 @@ impl Intersect<Sphere> for RayxN {
6869
let isect_i = ray_i.intersect(sphere, old_isect_i);
6970
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);
7071
}
71-
true
72-
});
72+
}
7373

7474
isect
7575
}

examples/aobench/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
clippy::cast_possible_truncation,
1313
clippy::cast_sign_loss,
1414
clippy::identity_op,
15-
clippy::erasing_op
15+
clippy::erasing_op,
16+
clippy::must_use_candidate
1617
)]
1718

1819
pub mod ambient_occlusion;

examples/aobench/src/random.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub mod scalar {
6767

6868
pub fn thread_rng() -> RngH {
6969
RngH {
70-
rng: THREAD_RNG_KEY.with(|t| t.clone()),
70+
rng: THREAD_RNG_KEY.with(Clone::clone),
7171
}
7272
}
7373
}
@@ -134,7 +134,7 @@ pub mod vector {
134134

135135
pub fn thread_rng() -> RngH {
136136
RngH {
137-
rng: THREAD_RNG_KEY.with(|t| t.clone()),
137+
rng: THREAD_RNG_KEY.with(Clone::clone),
138138
}
139139
}
140140
}

examples/dot_product/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Vector dot product
22
#![deny(warnings, rust_2018_idioms)]
33
#![feature(custom_inner_attributes)]
4+
#![allow(clippy::must_use_candidate)]
45

56
pub mod scalar;
67
pub mod simd;

examples/fannkuch_redux/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
clippy::many_single_char_names,
77
clippy::cast_possible_truncation,
88
clippy::cast_sign_loss,
9-
clippy::cast_possible_wrap
9+
clippy::cast_possible_wrap,
10+
clippy::must_use_candidate
1011
)]
1112

1213
pub mod scalar;

examples/mandelbrot/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2018"
99
packed_simd = { path = "../.." }
1010
rayon = "^1.0"
1111
ispc = { version = "^1.0.4", optional = true }
12-
structopt = "0.3.0"
12+
structopt = { version = "0.3.0", features = ["color"] }
1313

1414
[build-dependencies]
1515
ispc = { version = "^1.0.4", optional = true }

examples/mandelbrot/benchmark.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ if [[ "${NORUN}" == "1" ]]; then
2727
exit 0
2828
fi
2929

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

3333
if echo "$FEATURES" | grep -q "ispc"; then
34-
hyperfine "target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo ispc"
34+
hyperfine "../target/release/mandelbrot ${WIDTH} ${HEIGHT} --algo ispc"
3535
fi

examples/mandelbrot/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#![allow(
77
clippy::cast_precision_loss,
88
clippy::cast_sign_loss,
9-
clippy::cast_possible_truncation
9+
clippy::cast_possible_truncation,
10+
clippy::must_use_candidate
1011
)]
1112

1213
use rayon::prelude::*;

examples/mandelbrot/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use structopt::StructOpt;
1212
///
1313
/// Output is printed to `stdout`.
1414
#[derive(StructOpt)]
15-
#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))]
1615
struct Opt {
1716
/// Image width.
1817
width: usize,

examples/mandelbrot/src/simd_par.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ pub fn generate(dims: Dimensions, xr: Range, yr: Range) -> Vec<u32> {
145145
});
146146
});
147147

148+
// This is safe, we're transmuting from a more-aligned type to a
149+
// less-aligned one.
150+
#[allow(clippy::unsound_collection_transmute)]
148151
unsafe {
149152
let mut out: Vec<u32> = std::mem::transmute(out);
150-
// This is safe, we're transmuting from a more-aligned type to a
151-
// less-aligned one.
152153
out.set_len(width * height);
153154
out
154155
}

examples/matrix_inverse/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! 4x4 matrix inverse
22
#![feature(custom_inner_attributes)]
33
#![deny(warnings, rust_2018_idioms)]
4+
#![allow(clippy::must_use_candidate)]
45

56
pub mod scalar;
67
pub mod simd;

examples/nbody/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
//!
33
//! [bg]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/nbody.html#nbody
44
#![deny(warnings, rust_2018_idioms)]
5-
#![allow(clippy::similar_names, clippy::excessive_precision)]
5+
#![allow(
6+
clippy::similar_names,
7+
clippy::excessive_precision,
8+
clippy::must_use_candidate
9+
)]
610

711
pub mod scalar;
812
pub mod simd;

examples/options_pricing/benchmark.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fi
2727

2828
#for alg in "${ALGS[@]}"
2929
#do
30-
# hyperfine "target/release/options_pricing ${NUM_OPTIONS_BLACK_SCHOLES} ${alg}"
30+
# hyperfine "../target/release/options_pricing ${NUM_OPTIONS_BLACK_SCHOLES} ${alg}"
3131
#done
3232

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

4141
for alg in "${ALGS[@]}"
4242
do
43-
hyperfine "target/release/options_pricing ${NUM_OPTIONS_BINOMIAL_PUT} ${alg}"
43+
hyperfine "../target/release/options_pricing ${NUM_OPTIONS_BINOMIAL_PUT} ${alg}"
4444
done

examples/options_pricing/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
clippy::cast_precision_loss,
77
clippy::cast_possible_truncation,
88
clippy::cast_possible_wrap,
9+
clippy::must_use_candidate,
910
clippy::too_many_arguments
1011
)]
1112

examples/slice_sum/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn sum_hor(x: &[f32]) -> f32 {
2323

2424
x.chunks_exact(f32s::lanes())
2525
.map(f32s::from_slice_unaligned)
26-
.map(|vec| vec.sum())
26+
.map(f32s::sum)
2727
.sum()
2828
}
2929

examples/spectral_norm/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Spectral Norm
22
#![deny(warnings, rust_2018_idioms)]
33
#![allow(non_snake_case, non_camel_case_types)]
4-
#![allow(clippy::cast_precision_loss)]
4+
#![allow(
5+
clippy::cast_precision_loss,
6+
clippy::must_use_candidate
7+
)]
58

69
pub mod scalar;
710
pub mod simd;

examples/stencil/benchmark.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ fi
3030

3131
for alg in "${algs[@]}"
3232
do
33-
hyperfine "target/release/stencil ${alg}"
33+
hyperfine "../target/release/stencil ${alg}"
3434
done

examples/stencil/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
clippy::too_many_arguments,
88
clippy::cast_possible_wrap,
99
clippy::cast_possible_truncation,
10-
clippy::inline_always
10+
clippy::inline_always,
11+
clippy::must_use_candidate
1112
)]
1213

1314
#[cfg(feature = "ispc")]

examples/triangle_xform/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::must_use_candidate)]
2+
13
/// Simple matrix type.
24
/// The memory layout is the same as the one for Direct3D/OpenGL: fourth vector
35
/// represents the translation vector `[x, y, z]`.

src/api/minimal/ptr.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ macro_rules! impl_minimal_p {
6868

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

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

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

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

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

844844
/// Writes the values of the vector to the `slice`.
845845
///
846-
/// # Precondition
846+
/// # Safety
847847
///
848848
/// If `slice.len() < Self::lanes()` the behavior is undefined.
849849
#[inline]
@@ -1151,7 +1151,7 @@ macro_rules! impl_minimal_p {
11511151
/// As such, memory acquired directly from allocators or memory
11521152
/// mapped files may be too large to handle with this function.
11531153
///
1154-
/// Consider using wrapping_offset_from instead if these constraints
1154+
/// Consider using `wrapping_offset_from` instead if these constraints
11551155
/// are difficult to satisfy. The only advantage of this method is
11561156
/// that it enables more aggressive compiler optimizations.
11571157
#[inline]

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,12 @@
217217
clippy::cast_lossless,
218218
clippy::cast_possible_wrap,
219219
clippy::cast_precision_loss,
220+
// TODO: manually add the `#[must_use]` attribute where appropiate
221+
clippy::must_use_candidate,
220222
// This lint is currently broken for generic code
221223
// See https://github.com/rust-lang/rust-clippy/issues/3410
222-
clippy::use_self
224+
clippy::use_self,
225+
clippy::wrong_self_convention
223226
)]
224227
#![cfg_attr(test, feature(hashmap_internals))]
225228
#![deny(rust_2018_idioms, clippy::missing_inline_in_public_items)]

src/masks.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ macro_rules! impl_mask_ty {
88

99
impl crate::sealed::Seal for $id {}
1010
impl crate::sealed::Mask for $id {
11+
#[inline]
1112
fn test(&self) -> bool {
1213
$id::test(self)
1314
}

0 commit comments

Comments
 (0)