Skip to content

Commit 1cbd309

Browse files
gnzlbgalexcrichton
authored andcommitted
[ci] enable clippy (#62)
* [ci] enable clippy * [clippy] fix clippy issues
1 parent 46d64f0 commit 1cbd309

25 files changed

+352
-222
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ matrix:
2121
script: |
2222
cargo install rustfmt-nightly
2323
cargo fmt --all -- --write-mode=diff
24+
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
25+
script: |
26+
cargo install clippy
27+
cargo clippy --all -- -D clippy-pedantic
2428
allow_failures:
2529
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
26-
30+
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
2731
install:
2832
- if [ "$NO_ADD" == "" ]; then rustup target add $TARGET; fi
2933

examples/nbody.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
//! n-body benchmark from the [benchmarks game][bg].
2+
//!
3+
//! [bg]: https://benchmarksgame.alioth.debian.org/u64q/nbody-description.
4+
//! html#nbody
5+
16
#![cfg_attr(feature = "strict", deny(warnings))]
27
#![feature(cfg_target_feature)]
38
#![feature(target_feature)]
9+
#![cfg_attr(feature = "cargo-clippy",
10+
allow(similar_names, missing_docs_in_private_items,
11+
shadow_reuse, print_stdout))]
412

513
extern crate stdsimd;
614
use self::stdsimd::simd;
715
use simd::f64x2;
816

9-
const PI: f64 = 3.141592653589793;
17+
const PI: f64 = std::f64::consts::PI;
1018
const SOLAR_MASS: f64 = 4.0 * PI * PI;
1119
const DAYS_PER_YEAR: f64 = 365.24;
1220

@@ -29,7 +37,7 @@ impl Frsqrt for f64x2 {
2937
f32x4::new(t.extract(0), t.extract(1), 0., 0.),
3038
).as_f64x4()
3139
};
32-
f64x2::new(u.extract(0), u.extract(1))
40+
Self::new(u.extract(0), u.extract(1))
3341
}
3442
#[cfg(all(any(target_arch = "arm", target_arch = "aarch64"),
3543
target_feature = "neon"))]
@@ -61,8 +69,8 @@ struct Body {
6169
impl Body {
6270
fn new(
6371
x0: f64, x1: f64, x2: f64, v0: f64, v1: f64, v2: f64, mass: f64
64-
) -> Body {
65-
Body {
72+
) -> Self {
73+
Self {
6674
x: [x0, x1, x2],
6775
_fill: 0.0,
6876
v: [v0, v1, v2],
@@ -103,8 +111,8 @@ fn advance(bodies: &mut [Body; N_BODIES], dt: f64) {
103111

104112
i = 0;
105113
while i < N {
106-
for m in 0..3 {
107-
dx[m] = f64x2::new(r[i][m], r[i + 1][m]);
114+
for (m, dx) in dx.iter_mut().enumerate() {
115+
*dx = f64x2::new(r[i][m], r[i + 1][m]);
108116
}
109117

110118
dsquared = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
@@ -144,11 +152,10 @@ fn energy(bodies: &[Body; N_BODIES]) -> f64 {
144152
e += bi.mass
145153
* (bi.v[0] * bi.v[0] + bi.v[1] * bi.v[1] + bi.v[2] * bi.v[2])
146154
/ 2.0;
147-
for j in i + 1..N_BODIES {
148-
let bj = &bodies[j];
155+
for bj in bodies.iter().take(N_BODIES).skip(i + 1) {
149156
let mut dx = [0.0; 3];
150-
for k in 0..3 {
151-
dx[k] = bi.x[k] - bj.x[k];
157+
for (k, dx) in dx.iter_mut().enumerate() {
158+
*dx = bi.x[k] - bj.x[k];
152159
}
153160
let mut distance = 0.0;
154161
for &d in &dx {
@@ -210,7 +217,7 @@ fn main() {
210217
.nth(1)
211218
.expect("need one arg")
212219
.parse()
213-
.unwrap();
220+
.expect("argument should be a usize");
214221

215222
offset_momentum(&mut bodies);
216223
println!("{:.9}", energy(&bodies));

examples/play.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![cfg_attr(feature = "strict", deny(warnings))]
22
#![feature(target_feature)]
3+
#![cfg_attr(feature = "cargo-clippy",
4+
allow(similar_names, missing_docs_in_private_items,
5+
cast_sign_loss, cast_possible_truncation,
6+
cast_possible_wrap, option_unwrap_used, use_debug,
7+
print_stdout))]
38

49
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
510
mod example {

examples/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![cfg_attr(feature = "strict", deny(warnings))]
22
#![feature(target_feature)]
3+
#![cfg_attr(feature = "cargo-clippy",
4+
allow(missing_docs_in_private_items, result_unwrap_used,
5+
option_unwrap_used, print_stdout, use_debug))]
36

47
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
58
mod example {

examples/wat.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![cfg_attr(feature = "strict", deny(warnings))]
22
#![feature(target_feature)]
3+
#![cfg_attr(feature = "cargo-clippy",
4+
allow(missing_docs_in_private_items, result_unwrap_used,
5+
option_unwrap_used, print_stdout, use_debug))]
36

47
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
58
mod example {

src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! others at:
2727
//!
2828
//! * [i686](https://rust-lang-nursery.github.io/stdsimd/i686/stdsimd/)
29-
//! * [x86_64](https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/)
29+
//! * [`x86_64`](https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/)
3030
//! * [arm](https://rust-lang-nursery.github.io/stdsimd/arm/stdsimd/)
3131
//! * [aarch64](https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/)
3232
//!
@@ -122,6 +122,12 @@
122122
simd_ffi, target_feature, cfg_target_feature, i128_type, asm,
123123
const_atomic_usize_new, stmt_expr_attributes)]
124124
#![cfg_attr(test, feature(proc_macro, test))]
125+
#![cfg_attr(feature = "cargo-clippy",
126+
allow(inline_always, too_many_arguments, cast_sign_loss,
127+
cast_lossless, cast_possible_wrap,
128+
cast_possible_truncation, cast_precision_loss,
129+
shadow_reuse, cyclomatic_complexity, similar_names,
130+
doc_markdown, many_single_char_names))]
125131

126132
#[cfg(test)]
127133
extern crate stdsimd_test;

src/macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Utility macros
2+
13
macro_rules! define_ty {
24
($name:ident, $($elty:ident),+) => {
35
#[repr(simd)]

src/simd_llvm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! LLVM's simd platform intrinsics
2+
//!
3+
//! TODO: should use `link_llvm_intrinsic` instead: issue #112
4+
15
extern "platform-intrinsic" {
26
pub fn simd_eq<T, U>(x: T, y: T) -> U;
37
pub fn simd_ne<T, U>(x: T, y: T) -> U;

src/v128.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! 128-bit wide vector types
2+
13
use simd_llvm::*;
24

35
define_ty! { f64x2, f64, f64 }

src/v256.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! 256-bit wide vector types
2+
13
use simd_llvm::*;
24

35
define_ty! { f64x4, f64, f64, f64, f64 }

0 commit comments

Comments
 (0)