Skip to content

Commit 5bb3fd6

Browse files
committed
chore: clippy fixes
1 parent 9de79d6 commit 5bb3fd6

File tree

9 files changed

+66
-41
lines changed

9 files changed

+66
-41
lines changed

.github/workflows/simba-ci-build.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,35 @@ env:
1010
CARGO_TERM_COLOR: always
1111

1212
jobs:
13-
check-fmt:
13+
fmt:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v2
1717
- name: Check formatting
1818
run: cargo fmt -- --check
19+
clippy:
20+
runs-on: ubuntu-latest
21+
env:
22+
RUSTFLAGS: -D warnings
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: Install latest nightly
26+
uses: actions-rs/toolchain@v1
27+
with:
28+
toolchain: nightly
29+
override: true
30+
components: clippy
31+
- name: Check formatting
32+
run: cargo clippy --all-features
1933
build-native:
2034
runs-on: ubuntu-latest
2135
steps:
2236
- uses: actions/checkout@v2
37+
- name: Install latest nightly
38+
uses: actions-rs/toolchain@v1
39+
with:
40+
toolchain: nightly
41+
override: false
2342
- name: Build --no-default-feature
2443
run: cargo build --no-default-features;
2544
- name: Build libm only

src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@ with less code duplication.
1313
## Cargo features
1414
1515
Two cargo features can be optionally enabled:
16-
- With the __`packed_simd`__ feature enabled, the `simba::simd` module will export several SIMD types like `f32x2`,
17-
`f64x4`, `i32i8`, `u16i16`, etc. There types are wrappers around the SIMD types from the [__packed_simd__
18-
crate](https://docs.rs/packed_simd). This requires a nightly compiler.
16+
- With the __`portable_simd`__ feature enabled, the `simba::simd` module will export several SIMD types like `f32x2`,
17+
`f64x4`, `i32i8`, `u16i16`, etc. There types are wrappers around the SIMD types from the experimental [std::simd](https://doc.rust-lang.org/std/simd/index.html)
18+
implementation. This requires a nightly compiler and might break after updating the compiler nightly version.
1919
- With the __`wide`__ feature enabled, the `simba::simd` module will export the `WideF32x4` and `WideBoolF32x4`
2020
types. The types are wrappers around the `wide::f32x4` type from the [__wide__ crate](https://docs.rs/wide).
2121
This will work with both a stable or nightly compiler.
2222
2323
If none of those features are enabled, __simba__ will still define all the scalar and SIMD traits.
2424
However, the SIMD traits won't be implemented for any SIMD types. Therefore it is recommended to:
25-
- Use the `packed_simd` feature if you want more features, and can afford to use a nightly compiler.
25+
- Use the `portable_simd` feature if you want more features, and can afford to use a nightly compiler.
2626
- Use the `wide` feature if you only need 4-lanes 32-bits floats, and can't afford to use a nightly compiler.
27-
*/
27+
*/
2828

2929
#![deny(non_camel_case_types)]
3030
#![deny(unused_parens)]
3131
#![deny(non_upper_case_globals)]
3232
#![deny(unused_results)]
33-
#![deny(missing_docs)] // FIXME: should be denied
33+
#![deny(missing_docs)]
34+
#![allow(clippy::just_underscores_and_digits)]
35+
#![allow(clippy::too_many_arguments)]
3436
#![cfg_attr(not(feature = "std"), no_std)]
3537
#![cfg_attr(feature = "portable_simd", feature(portable_simd))]
3638

src/scalar/complex.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ macro_rules! complex_trait_methods (
156156
///
157157
/// Complex numbers are equipped with functions that are commonly used on complex numbers and reals.
158158
/// The results of those functions only have to be approximately equal to the actual theoretical values.
159-
// FIXME: SubsetOf should be removed when specialization will be supported by rustc. This will
159+
// TODO: SubsetOf should be removed when specialization will be supported by rustc. This will
160160
// allow a blanket impl: impl<T: Clone> SubsetOf<T> for T { ... }
161161
#[allow(missing_docs)]
162162
pub trait ComplexField:
@@ -305,7 +305,7 @@ macro_rules! impl_complex (
305305
#[cfg(not(feature = "std"))]
306306
#[inline]
307307
fn powi(self, n: i32) -> Self {
308-
// FIXME: is there a more accurate solution?
308+
// TODO: is there a more accurate solution?
309309
$libm::powf(self, n as $T)
310310
}
311311

@@ -1162,7 +1162,7 @@ impl<N: RealField + PartialOrd> ComplexField for num_complex::Complex<N> {
11621162

11631163
#[inline]
11641164
fn powi(self, n: i32) -> Self {
1165-
// FIXME: is there a more accurate solution?
1165+
// TODO: is there a more accurate solution?
11661166
let n = N::from_subset(&(n as f64));
11671167
self.powf(n)
11681168
}

src/scalar/fixed_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::ops::{
1717
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign,
1818
};
1919

20-
macro_rules! impl_fixed_type(
20+
macro_rules! impl_fixed_type (
2121
($($FixedI: ident, $Int: ident, $LeEqDim: ident, $LeEqDim1: ident, $LeEqDim2: ident, $LeEqDim3: ident, $LeEqDim4: ident;)*) => {$(
2222
#[derive(Copy, Clone)]
2323
#[repr(transparent)]
@@ -58,7 +58,7 @@ macro_rules! impl_fixed_type(
5858
impl<Fract: $LeEqDim> PartialOrd for $FixedI<Fract> {
5959
#[inline(always)]
6060
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
61-
self.0.partial_cmp(&other.0)
61+
Some(self.cmp(other))
6262
}
6363
}
6464

src/scalar/subset.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use num_complex::Complex;
1212
/// represent_, independently from their actual implementation details and limitations. For
1313
/// example:
1414
/// * f32 and f64 are both supposed to represent reals and are thus considered equal (even if in
15-
/// practice f64 has more elements).
15+
/// practice f64 has more elements).
1616
/// * u32 and i8 are respectively supposed to represent natural and relative numbers. Thus, u32 is
17-
/// a subset of i8.
17+
/// a subset of i8.
1818
/// * A quaternion and a 3x3 orthogonal matrix with unit determinant are both sets of rotations.
19-
/// They can thus be considered equal.
19+
/// They can thus be considered equal.
2020
///
2121
/// In other words, implementation details due to machine limitations are ignored (otherwise we
2222
/// could not even, e.g., convert a u64 to an i64). If considering those limitations are
@@ -52,11 +52,11 @@ pub trait SubsetOf<T>: Sized {
5252
/// represent_, independently from their actual implementation details and limitations. For
5353
/// example:
5454
/// * f32 and f64 are both supposed to represent reals and are thus considered equal (even if in
55-
/// practice f64 has more elements).
55+
/// practice f64 has more elements).
5656
/// * u32 and i8 are respectively supposed to represent natural and relative numbers. Thus, i8 is
57-
/// a superset of u32.
57+
/// a superset of u32.
5858
/// * A quaternion and a 3x3 orthogonal matrix with unit determinant are both sets of rotations.
59-
/// They can thus be considered equal.
59+
/// They can thus be considered equal.
6060
///
6161
/// In other words, implementation details due to machine limitations are ignored (otherwise we
6262
/// could not even, e.g., convert a u64 to an i64). If considering those limitations are
@@ -106,7 +106,7 @@ impl<SS: SubsetOf<SP>, SP> SupersetOf<SS> for SP {
106106
}
107107
}
108108

109-
macro_rules! impl_subset(
109+
macro_rules! impl_subset (
110110
($($subset: ty as $( $superset: ty),+ );* $(;)*) => {
111111
$($(
112112
impl SubsetOf<$superset> for $subset {
@@ -189,7 +189,7 @@ impl<N1, N2: SupersetOf<N1>> SubsetOf<Complex<N2>> for Complex<N1> {
189189
}
190190
}
191191

192-
macro_rules! impl_scalar_subset_of_complex(
192+
macro_rules! impl_scalar_subset_of_complex (
193193
($($t: ident),*) => {$(
194194
impl<N2: Zero + SupersetOf<$t>> SubsetOf<Complex<N2>> for $t {
195195
#[inline]

src/simd/auto_simd_impl.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{
2323
// This is a hack to allow use to reuse `_0` as integers or as identifier,
2424
// depending on whether or not `ident_to_value` has been called in scope.
2525
// This helps writing macros that define both `::new` and `From([T; lanes()])`.
26-
macro_rules! ident_to_value(
26+
macro_rules! ident_to_value (
2727
() => {
2828
const _0: usize = 0; const _1: usize = 1; const _2: usize = 2; const _3: usize = 3; const _4: usize = 4; const _5: usize = 5; const _6: usize = 6; const _7: usize = 7;
2929
const _8: usize = 8; const _9: usize = 9; const _10: usize = 10; const _11: usize = 11; const _12: usize = 12; const _13: usize = 13; const _14: usize = 14; const _15: usize = 15;
@@ -60,7 +60,7 @@ pub struct AutoSimd<N>(pub N);
6060
)]
6161
pub struct AutoBoolSimd<N>(pub N);
6262

63-
macro_rules! impl_bool_simd(
63+
macro_rules! impl_bool_simd (
6464
($($t: ty, $lanes: expr, $($i: ident),*;)*) => {$(
6565
impl_simd_value!($t, bool, $lanes, AutoSimd<$t> $(, $i)*;);
6666

@@ -200,7 +200,7 @@ macro_rules! impl_bool_simd(
200200
)*}
201201
);
202202

203-
macro_rules! impl_scalar_subset_of_simd(
203+
macro_rules! impl_scalar_subset_of_simd (
204204
($($t: ty),*) => {$(
205205
impl<N2> SubsetOf<AutoSimd<N2>> for $t
206206
where AutoSimd<N2>: SimdValue + Copy,
@@ -229,7 +229,7 @@ impl_scalar_subset_of_simd!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize,
229229
#[cfg(feature = "decimal")]
230230
impl_scalar_subset_of_simd!(d128);
231231

232-
macro_rules! impl_simd_value(
232+
macro_rules! impl_simd_value (
233233
($($t: ty, $elt: ty, $lanes: expr, $bool: ty, $($i: ident),*;)*) => ($(
234234
impl ArrTransform for AutoSimd<$t> {
235235
#[inline(always)]
@@ -332,7 +332,7 @@ macro_rules! impl_simd_value(
332332
)*)
333333
);
334334

335-
macro_rules! impl_uint_simd(
335+
macro_rules! impl_uint_simd (
336336
($($t: ty, $elt: ty, $lanes: expr, $bool: ty, $($i: ident),*;)*) => ($(
337337
impl_simd_value!($t, $elt, $lanes, $bool $(, $i)*;);
338338

@@ -617,7 +617,7 @@ macro_rules! impl_uint_simd(
617617
)*)
618618
);
619619

620-
macro_rules! impl_int_simd(
620+
macro_rules! impl_int_simd (
621621
($($t: ty, $elt: ty, $lanes: expr, $bool: ty, $($i: ident),*;)*) => ($(
622622
impl_uint_simd!($t, $elt, $lanes, $bool $(, $i)*;);
623623

@@ -632,13 +632,11 @@ macro_rules! impl_int_simd(
632632
)*)
633633
);
634634

635-
macro_rules! impl_float_simd(
635+
macro_rules! impl_float_simd (
636636
($($t: ty, $elt: ty, $lanes: expr, $int: ty, $bool: ty, $($i: ident),*;)*) => ($(
637637
impl_int_simd!($t, $elt, $lanes, $bool $(, $i)*;);
638638

639-
// FIXME: this should be part of impl_int_simd
640-
// but those methods do not seem to be implemented
641-
// by packed_simd for integers.
639+
// TODO: this should be part of impl_int_simd
642640
impl SimdSigned for AutoSimd<$t> {
643641
#[inline(always)]
644642
fn simd_abs(&self) -> Self {
@@ -1041,7 +1039,7 @@ macro_rules! impl_float_simd(
10411039
fn simd_horizontal_product(self) -> Self::Element {
10421040
let mut prod = self.extract(0);
10431041
for ii in 1..$lanes {
1044-
prod = prod * self.extract(ii)
1042+
prod *= self.extract(ii)
10451043
}
10461044
prod
10471045
}
@@ -1172,7 +1170,7 @@ macro_rules! impl_float_simd(
11721170

11731171
#[inline]
11741172
fn simd_powi(self, n: i32) -> Self {
1175-
// FIXME: is there a more accurate solution?
1173+
// TODO: is there a more accurate solution?
11761174
let n = AutoSimd::<$t>::from_subset(&(n as f64));
11771175
self.simd_powf(n)
11781176
}

src/simd/portable_simd_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ macro_rules! impl_float_simd (
656656
($($t: ty, $elt: ident, $int: ty, $bool: ty, $($i: ident),*;)*) => ($(
657657
impl_int_simd!($t, $elt, $bool $(, $i)*;);
658658

659-
// FIXME: this should be part of impl_int_simd
659+
// TODO: this should be part of impl_int_simd
660660
// but those methods do not seem to be implemented
661661
// by portable_simd for integers.
662662
impl SimdSigned for Simd<$t> {
@@ -1076,7 +1076,7 @@ macro_rules! impl_float_simd (
10761076
fn simd_horizontal_product(self) -> Self::Element {
10771077
let mut prod = self.extract(0);
10781078
for ii in 1..Self::lanes() {
1079-
prod = prod * self.extract(ii)
1079+
prod *= self.extract(ii)
10801080
}
10811081
prod
10821082
}
@@ -1207,7 +1207,7 @@ macro_rules! impl_float_simd (
12071207

12081208
#[inline]
12091209
fn simd_powi(self, n: i32) -> Self {
1210-
// FIXME: is there a more accurate solution?
1210+
// TODO: is there a more accurate solution?
12111211
let n = Simd::<$t>::from_subset(&(n as f64));
12121212
self.simd_powf(n)
12131213
}

src/simd/simd_value.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ pub trait SimdValue: Sized {
1616
/// Panics if `i >= Self::lanes()`.
1717
fn extract(&self, i: usize) -> Self::Element;
1818
/// Extracts the i-th lane of `self` without bound-checking.
19+
///
20+
/// # Safety
21+
/// Undefined behavior if `i >= Self::lanes()`.
1922
unsafe fn extract_unchecked(&self, i: usize) -> Self::Element;
2023
/// Replaces the i-th lane of `self` by `val`.
2124
///
2225
/// Panics if `i >= Self::lanes()`.
2326
fn replace(&mut self, i: usize, val: Self::Element);
2427
/// Replaces the i-th lane of `self` by `val` without bound-checking.
28+
///
29+
/// # Safety
30+
/// Undefined behavior if `i >= Self::lanes()`.
2531
unsafe fn replace_unchecked(&mut self, i: usize, val: Self::Element);
2632

2733
/// Merges `self` and `other` depending on the lanes of `cond`.
@@ -141,7 +147,7 @@ impl<N: SimdValue> SimdValue for num_complex::Complex<N> {
141147

142148
impl<N: PrimitiveSimdValue> PrimitiveSimdValue for num_complex::Complex<N> {}
143149

144-
macro_rules! impl_primitive_simd_value_for_scalar(
150+
macro_rules! impl_primitive_simd_value_for_scalar (
145151
($($t: ty),*) => {$(
146152
impl PrimitiveSimdValue for $t {}
147153
impl SimdValue for $t {

src/simd/wide_simd_impl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub struct WideBoolF64x4(pub wide::f64x4);
109109
#[cfg(feature = "rkyv")]
110110
impl_rkyv!(WideBoolF64x4, [f64; 4]);
111111

112-
macro_rules! impl_wide_f32(
112+
macro_rules! impl_wide_f32 (
113113
($f32: ident, $f32xX: ident, $WideF32xX: ident, $WideBoolF32xX: ident, $lanes: expr; $($ii: expr),+) => {
114114
impl PrimitiveSimdValue for $WideF32xX {}
115115
impl PrimitiveSimdValue for $WideBoolF32xX {}
@@ -705,7 +705,7 @@ macro_rules! impl_wide_f32(
705705

706706
#[inline(always)]
707707
fn simd_signum(&self) -> Self {
708-
// FIXME: is there a more efficient way?
708+
// TODO: is there a more efficient way?
709709
self.map(|x| x.signum())
710710
}
711711

@@ -1091,7 +1091,7 @@ macro_rules! impl_wide_f32(
10911091
fn simd_horizontal_product(self) -> Self::Element {
10921092
let mut prod = self.extract(0);
10931093
for ii in 1..Self::lanes() {
1094-
prod = prod * self.extract(ii)
1094+
prod *= self.extract(ii)
10951095
}
10961096
prod
10971097
}
@@ -1222,7 +1222,7 @@ macro_rules! impl_wide_f32(
12221222

12231223
#[inline]
12241224
fn simd_powi(self, n: i32) -> Self {
1225-
// FIXME: is there a more accurate solution?
1225+
// TODO: is there a more accurate solution?
12261226
let n = <$WideF32xX>::from_subset(&(n as f64));
12271227
self.simd_powf(n)
12281228
}
@@ -1514,7 +1514,7 @@ macro_rules! impl_wide_f32(
15141514
}
15151515
);
15161516

1517-
macro_rules! impl_scalar_subset_of_simd(
1517+
macro_rules! impl_scalar_subset_of_simd (
15181518
($WideF32xX: ty, $f32: ty, $lanes: expr; $($t: ty),*) => {$(
15191519
impl SubsetOf<$WideF32xX> for $t {
15201520
#[inline(always)]

0 commit comments

Comments
 (0)