Skip to content

Commit cbee1bd

Browse files
Fix various lints
Mostly allowing correct mathematical operations and fixing some pointer casts to clippy's preferences. Also: Remove superfluous unit return Allow mut of const temporaries Use more precise PI const Don't index in loop
1 parent ec54d1b commit cbee1bd

File tree

16 files changed

+67
-39
lines changed

16 files changed

+67
-39
lines changed

examples/stencil/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Data {
9797
pub fn exec<F>(&mut self, f: F)
9898
where
9999
F: Fn(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
100-
&[f32; 4], &[f32], &mut [f32], &mut [f32]) -> (),
100+
&[f32; 4], &[f32], &mut [f32], &mut [f32]),
101101
{
102102
f(
103103
self.t.0, self.t.1,

examples/stencil/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::env;
88
fn run<F>(name: &str, f: F)
99
where
1010
F: Fn(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32,
11-
&[f32; 4], &[f32], &mut [f32], &mut [f32]) -> (),
11+
&[f32; 4], &[f32], &mut [f32], &mut [f32]),
1212
{
1313
let mut d = Data::benchmark();
1414
let t = time::Duration::span(move || d.exec(f));

examples/stencil/src/simd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ pub(crate) fn step_x8(
3636

3737
let sum = {
3838
let i = i as i32;
39-
(a_cur!(i, 0, 0)
39+
a_cur!(i, 0, 0)
4040
+ a_cur!(-i, 0, 0)
4141
+ a_cur!(0, i, 0)
4242
+ a_cur!(0, -i, 0)
4343
+ a_cur!(0, 0, i)
44-
+ a_cur!(0, 0, -i))
44+
+ a_cur!(0, 0, -i)
4545
};
4646

4747
div = coef.mul_adde(sum, div);

src/api/bit_manip.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ macro_rules! impl_bit_manip {
3737
paste::item_with_macros! {
3838
#[allow(overflowing_literals)]
3939
pub mod [<$id _bit_manip>] {
40+
#![allow(const_item_mutation)]
4041
use super::*;
4142

4243
const LANE_WIDTH: usize = mem::size_of::<$elem_ty>() * 8;

src/api/default.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ macro_rules! impl_default {
1212
test_if!{
1313
$test_tt:
1414
paste::item! {
15+
// Comparisons use integer casts within mantissa^1 range.
16+
#[allow(clippy::float_cmp)]
1517
pub mod [<$id _default>] {
1618
use super::*;
1719
#[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]

src/api/from/from_array.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ macro_rules! impl_from_array {
5656
test_if! {
5757
$test_tt:
5858
paste::item! {
59+
// Comparisons use integer casts within mantissa^1 range.
60+
#[allow(clippy::float_cmp)]
5961
mod [<$id _from>] {
6062
use super::*;
6163
#[test]

src/api/hash.rs

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ macro_rules! impl_hash {
3636
let mut v_hash = a_hash.clone();
3737
a.hash(&mut a_hash);
3838

39+
// Integer within mantissa^1 range.
40+
#[allow(clippy::float_cmp)]
3941
let v = $id::splat(42 as $elem_ty);
4042
v.hash(&mut v_hash);
4143
assert_eq!(a_hash.finish(), v_hash.finish());

src/api/minimal/iuf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ macro_rules! impl_minimal_iuf {
101101
test_if!{
102102
$test_tt:
103103
paste::item! {
104+
// Comparisons use integer casts within mantissa^1 range.
105+
#[allow(clippy::float_cmp)]
104106
pub mod [<$id _minimal>] {
105107
use super::*;
106108
#[cfg_attr(not(target_arch = "wasm32"), test)]

src/api/minimal/ptr.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,7 @@ macro_rules! impl_minimal_p {
550550
];
551551

552552
for i in 0..$elem_count {
553-
let ptr = unsafe {
554-
crate::mem::transmute(
555-
&values[i] as *const i32
556-
)
557-
};
553+
let ptr = &values[i] as *const i32 as *mut i32;
558554
vec = vec.replace(i, ptr);
559555
array[i] = ptr;
560556
}
@@ -1025,11 +1021,7 @@ macro_rules! impl_minimal_p {
10251021
];
10261022

10271023
for i in 0..$elem_count {
1028-
let ptr = unsafe {
1029-
crate::mem::transmute(
1030-
&values[i] as *const i32
1031-
)
1032-
};
1024+
let ptr = &values[i] as *const i32 as *mut i32;
10331025
vec = vec.replace(i, ptr);
10341026
array[i] = ptr;
10351027
}

src/api/ptr/gather_scatter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ macro_rules! impl_ptr_read {
4949
let mut ptr = $id::<i32>::null();
5050

5151
for i in 0..$elem_count {
52-
ptr = ptr.replace(i, unsafe {
53-
crate::mem::transmute(&v[i] as *const i32)
54-
});
52+
ptr = ptr.replace(i,
53+
&v[i] as *const i32 as *mut i32
54+
);
5555
}
5656

5757
// all mask elements are true:
@@ -161,7 +161,7 @@ macro_rules! impl_ptr_write {
161161
let mut ptr = $id::<i32>::null();
162162
for i in 0..$elem_count {
163163
ptr = ptr.replace(i, unsafe {
164-
crate::mem::transmute(arr.as_ptr().add(i))
164+
arr.as_ptr().add(i) as *mut i32
165165
});
166166
}
167167
// ptr = [&arr[0], &arr[1], ...]

src/api/reductions/float_arithmetic.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ macro_rules! impl_reduction_float_arithmetic {
9393
test_if! {
9494
$test_tt:
9595
paste::item! {
96+
// Comparisons use integer casts within mantissa^1 range.
97+
#[allow(clippy::float_cmp)]
9698
pub mod [<$id _reduction_float_arith>] {
9799
use super::*;
98100
fn alternating(x: usize) -> $id {
@@ -225,7 +227,7 @@ macro_rules! impl_reduction_float_arithmetic {
225227
let mut v = $id::splat(0. as $elem_ty);
226228
for i in 0..$id::lanes() {
227229
let c = if i % 2 == 0 { 1e3 } else { -1. };
228-
start *= 3.14 * c;
230+
start *= ::core::$elem_ty::consts::PI * c;
229231
scalar_reduction += start;
230232
v = v.replace(i, start);
231233
}
@@ -278,7 +280,7 @@ macro_rules! impl_reduction_float_arithmetic {
278280
let mut v = $id::splat(0. as $elem_ty);
279281
for i in 0..$id::lanes() {
280282
let c = if i % 2 == 0 { 1e3 } else { -1. };
281-
start *= 3.14 * c;
283+
start *= ::core::$elem_ty::consts::PI * c;
282284
scalar_reduction *= start;
283285
v = v.replace(i, start);
284286
}

src/api/reductions/min_max.rs

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ macro_rules! impl_reduction_min_max {
7676
}
7777
test_if! {$test_tt:
7878
paste::item! {
79+
// Comparisons use integer casts within mantissa^1 range.
80+
#[allow(clippy::float_cmp)]
7981
pub mod [<$id _reduction_min_max>] {
8082
use super::*;
8183
#[cfg_attr(not(target_arch = "wasm32"), test)]
@@ -124,6 +126,8 @@ macro_rules! test_reduction_float_min_max {
124126
test_if!{
125127
$test_tt:
126128
paste::item! {
129+
// Comparisons use integer casts within mantissa^1 range.
130+
#[allow(clippy::float_cmp)]
127131
pub mod [<$id _reduction_min_max_nan>] {
128132
use super::*;
129133
#[cfg_attr(not(target_arch = "wasm32"), test)]

src/api/slice/from_slice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ macro_rules! impl_slice_from_slice {
8484
test_if! {
8585
$test_tt:
8686
paste::item! {
87+
// Comparisons use integer casts within mantissa^1 range.
88+
#[allow(clippy::float_cmp)]
8789
pub mod [<$id _slice_from_slice>] {
8890
use super::*;
8991
use crate::iter::Iterator;

src/api/slice/write_to_slice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ macro_rules! impl_slice_write_to_slice {
8686
test_if! {
8787
$test_tt:
8888
paste::item! {
89+
// Comparisons use integer casts within mantissa^1 range.
90+
#[allow(clippy::float_cmp)]
8991
pub mod [<$id _slice_write_to_slice>] {
9092
use super::*;
9193
use crate::iter::Iterator;

src/testing/utils.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Testing utilities
22
33
#![allow(dead_code)]
4+
// FIXME: Or don't. But it's true this is a problematic comparison.
5+
#![allow(clippy::neg_cmp_op_on_partial_ord)]
46

57
use crate::{cmp::PartialOrd, fmt::Debug, LexicographicallyOrdered};
68

@@ -19,14 +21,19 @@ pub fn test_lt<T>(
1921
assert!(a <= b, "{:?}, {:?}", a, b);
2022
assert!(b >= a, "{:?}, {:?}", a, b);
2123

22-
// Irreflexivity
23-
assert!(!(a < a), "{:?}, {:?}", a, b);
24-
assert!(!(b < b), "{:?}, {:?}", a, b);
25-
assert!(!(a > a), "{:?}, {:?}", a, b);
26-
assert!(!(b > b), "{:?}, {:?}", a, b);
24+
// The elegance of the mathematical expression of irreflexivity is more
25+
// than clippy can handle.
26+
#[allow(clippy::eq_op)]
27+
{
28+
// Irreflexivity
29+
assert!(!(a < a), "{:?}, {:?}", a, b);
30+
assert!(!(b < b), "{:?}, {:?}", a, b);
31+
assert!(!(a > a), "{:?}, {:?}", a, b);
32+
assert!(!(b > b), "{:?}, {:?}", a, b);
2733

28-
assert!(a <= a, "{:?}, {:?}", a, b);
29-
assert!(b <= b, "{:?}, {:?}", a, b);
34+
assert!(a <= a, "{:?}, {:?}", a, b);
35+
assert!(b <= b, "{:?}, {:?}", a, b);
36+
}
3037
}
3138

3239
/// Tests PartialOrd for `a` and `b` where `a <= b` is true.
@@ -38,8 +45,8 @@ pub fn test_le<T>(
3845
assert!(a <= b, "{:?}, {:?}", a, b);
3946
assert!(b >= a, "{:?}, {:?}", a, b);
4047

41-
assert!(a == b || a < b, "{:?}, {:?}", a, b);
42-
assert!(a == b || b > a, "{:?}, {:?}", a, b);
48+
assert!(a <= b, "{:?}, {:?}", a, b);
49+
assert!(b >= a, "{:?}, {:?}", a, b);
4350

4451
if a == b {
4552
assert!(!(a < b), "{:?}, {:?}", a, b);

tests/endianness.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ fn endian_array_union() {
8282
vec: f32x4,
8383
}
8484
let x: [f32; 4] = unsafe { A { vec: f32x4::new(0., 1., 2., 3.) }.data };
85-
assert_eq!(x[0], 0_f32);
86-
assert_eq!(x[1], 1_f32);
87-
assert_eq!(x[2], 2_f32);
88-
assert_eq!(x[3], 3_f32);
85+
// As all of these are integer values within the mantissa^1 range, it
86+
// would be very unusual for them to actually fail to compare.
87+
#[allow(clippy::float_cmp)]
88+
{
89+
assert_eq!(x[0], 0_f32);
90+
assert_eq!(x[1], 1_f32);
91+
assert_eq!(x[2], 2_f32);
92+
assert_eq!(x[3], 3_f32);
93+
}
8994
let y: f32x4 = unsafe { A { data: [3., 2., 1., 0.] }.vec };
9095
assert_eq!(y, f32x4::new(3., 2., 1., 0.));
9196

@@ -100,8 +105,8 @@ fn endian_array_union() {
100105
);
101106
let x: [i8; 16] = unsafe { B { vec: x }.data };
102107

103-
for i in 0..16 {
104-
assert_eq!(x[i], i as i8);
108+
for (i, v) in x.iter().enumerate() {
109+
assert_eq!(i as i8, *v);
105110
}
106111

107112
#[rustfmt::skip]
@@ -145,10 +150,15 @@ fn endian_tuple_access() {
145150
vec: f32x4,
146151
}
147152
let x: F32x4T = unsafe { A { vec: f32x4::new(0., 1., 2., 3.) }.data };
148-
assert_eq!(x.0, 0_f32);
149-
assert_eq!(x.1, 1_f32);
150-
assert_eq!(x.2, 2_f32);
151-
assert_eq!(x.3, 3_f32);
153+
// As all of these are integer values within the mantissa^1 range, it
154+
// would be very unusual for them to actually fail to compare.
155+
#[allow(clippy::float_cmp)]
156+
{
157+
assert_eq!(x.0, 0_f32);
158+
assert_eq!(x.1, 1_f32);
159+
assert_eq!(x.2, 2_f32);
160+
assert_eq!(x.3, 3_f32);
161+
}
152162
let y: f32x4 = unsafe { A { data: (3., 2., 1., 0.) }.vec };
153163
assert_eq!(y, f32x4::new(3., 2., 1., 0.));
154164

0 commit comments

Comments
 (0)