Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit c4c8dca

Browse files
committed
Silence clippy warnings for libm and add clippy to CI
1 parent ae3ab74 commit c4c8dca

File tree

7 files changed

+74
-15
lines changed

7 files changed

+74
-15
lines changed

azure-pipelines.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
variables:
5555
TOOLCHAIN: nightly
5656

57-
- job: rustfmt
57+
- job: tools
5858
pool:
5959
vmImage: ubuntu-16.04
6060
steps:
@@ -63,6 +63,10 @@ jobs:
6363
displayName: "install rustfmt"
6464
- bash: cargo fmt --all -- --check
6565
displayName: "check formatting"
66+
- bash: rustup component add clippy
67+
displayName: "install clippy"
68+
- bash: cargo clippy --all -- -D clippy::pedantic
69+
displayName: "check clippy"
6670

6771
- job: compiler_builtins_works
6872
pool:

crates/libm-analyze/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,18 @@ fn get_functions(files: &[syn::File]) -> Vec<FnSig> {
208208
));
209209
}
210210
if attrs.is_empty() {
211-
err!(format!("missing `#[inline]` and `#[no_panic]` attributes"));
211+
err!("missing `#[inline]` and `#[no_panic]` attributes");
212212
} else {
213213
let attrs = attrs
214214
.iter()
215215
.map(|a| syn_to_str!(a))
216216
.collect::<Vec<_>>()
217217
.join(",");
218218
if !attrs.contains("inline") {
219-
err!(format!("missing `#[inline]` attribute"));
219+
err!("missing `#[inline]` attribute");
220220
}
221221
if !attrs.contains("no_panic") {
222-
err!(format!("missing `#[no_panic]` attributes"));
222+
err!("missing `#[no_panic]` attributes");
223223
}
224224
}
225225
// Validate and parse output parameters and function arguments:

crates/libm-test/src/lib.rs

+27-8
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl_tuple_vec!((i32, f32): x: x.0, x.1);
115115
impl_tuple_vec!((f32, f32, f32): x: x.0, x.1, x.2);
116116
impl_tuple_vec!((f64, f64, f64): x: x.0, x.1, x.2);
117117

118-
/// Kind of LibmApi - used to handle generating tests
118+
/// Kind of libm API - used to handle generating tests
119119
/// for some functions slightly differently.
120120
#[derive(Copy, Clone, Debug, PartialEq)]
121121
pub enum ApiKind {
@@ -155,7 +155,7 @@ macro_rules! assert_approx_eq {
155155
if !$crate::WithinUlps::within_ulps($result, $expected, $ulps) {
156156
panic!("{:?} != {:?}", $result, $expected);
157157
}
158-
}
158+
};
159159
}
160160

161161
pub trait Toward: Sized {
@@ -190,8 +190,10 @@ pub trait RandSeq: Sized {
190190

191191
macro_rules! impl_rand_seq_f {
192192
($float_ty:ident) => {
193+
#[allow(clippy::use_self)]
193194
impl RandSeq for $float_ty {
194195
fn rand_seq<R: rand::Rng>(rng: &mut R, _api_kind: ApiKind, len: usize) -> Vec<Self> {
196+
use rand::seq::SliceRandom;
195197
use std::$float_ty::*;
196198
let mut vec = Vec::with_capacity(len);
197199

@@ -212,12 +214,12 @@ macro_rules! impl_rand_seq_f {
212214
const NSTEPS: usize = 1_000;
213215
vec.extend(INFINITY.toward(0., NSTEPS));
214216
vec.extend(NEG_INFINITY.toward(0., NSTEPS));
215-
vec.extend((0. as $float_ty).toward(MIN_POSITIVE, NSTEPS));
216-
vec.extend((0. as $float_ty).toward(-MIN_POSITIVE, NSTEPS));
217+
vec.extend((0. as Self).toward(MIN_POSITIVE, NSTEPS));
218+
vec.extend((0. as Self).toward(-MIN_POSITIVE, NSTEPS));
217219

218220
for i in 0..=NSTEPS {
219-
let dx = 2. / NSTEPS as $float_ty;
220-
let next = (-1. as $float_ty) + (i as $float_ty) * dx;
221+
let dx = 2. / NSTEPS as Self;
222+
let next = (-1. as Self) + (i as Self) * dx;
221223
vec.push(next);
222224
}
223225

@@ -227,10 +229,18 @@ macro_rules! impl_rand_seq_f {
227229
let remaining_len = len.checked_sub(current_len).unwrap();
228230

229231
for _ in 0..remaining_len {
230-
let n = rng.gen::<$float_ty>();
232+
let n = rng.gen::<Self>();
231233
vec.push(n);
232234
}
233235
assert_eq!(vec.len(), len);
236+
237+
// Duplicate the vector, randomly shuffle it, and
238+
// concatenate it. Otherwise for n-ary functions
239+
// all vectors might have the same values. But
240+
// testing with the same values is also worth doing.
241+
let mut vec2 = vec.clone();
242+
vec2.shuffle(rng);
243+
vec.extend(vec2);
234244
vec
235245
}
236246
}
@@ -242,15 +252,24 @@ impl_rand_seq_f!(f64);
242252

243253
impl RandSeq for i32 {
244254
fn rand_seq<R: rand::Rng>(rng: &mut R, api_kind: ApiKind, len: usize) -> Vec<Self> {
255+
use rand::seq::SliceRandom;
245256
let mut v = Vec::with_capacity(len);
246257
for _ in 0..len {
247-
let mut r = rng.gen::<i32>();
258+
let mut r = rng.gen::<Self>();
248259
if let ApiKind::Jx = api_kind {
249260
r &= 0xffff;
250261
}
251262
v.push(r);
252263
}
253264
assert_eq!(v.len(), len);
265+
266+
// Duplicate the vector, randomly shuffle it, and
267+
// concatenate it. Otherwise for n-ary functions
268+
// all vectors might have the same values. But
269+
// testing with the same values is also worth doing.
270+
let mut v2 = v.clone();
271+
v2.shuffle(rng);
272+
v.extend(v2);
254273
v
255274
}
256275
}

crates/libm-test/tests/system_libm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Compare the results of the `libm` implementation against the system's libm.
22
#![cfg(test)]
3-
#![cfg(feature = "system_libm")]
3+
//#![cfg(feature = "system_libm")]
44

55
use libm_test::{assert_approx_eq, get_api_kind, Call, RandSeq, TupleVec};
66

crates/libm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! libm in pure Rust
22
#![deny(warnings)]
3-
//#![no_std]
3+
#![no_std]
44
#![cfg_attr(
55
all(target_arch = "wasm32", not(feature = "stable")),
66
feature(core_intrinsics)

crates/libm/src/math/exp2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use super::scalbn;
2828

2929
const TBLSIZE: usize = 256;
3030

31-
#[cfg_attr(rustfmt, rustfmt_skip)]
31+
#[rustfmt::skip]
3232
static TBL: [u64; TBLSIZE * 2] = [
3333
// exp2(z + eps) eps
3434
0x3fe6a09e667f3d5d, 0x3d39880000000000,

crates/libm/src/math/mod.rs

+36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
#![allow(
2+
clippy::many_single_char_names,
3+
clippy::similar_names,
4+
clippy::unreadable_literal,
5+
clippy::unseparated_literal_suffix,
6+
clippy::doc_markdown,
7+
clippy::needless_return,
8+
clippy::if_not_else,
9+
clippy::int_plus_one,
10+
clippy::large_digit_groups,
11+
clippy::items_after_statements,
12+
clippy::collapsible_if,
13+
clippy::mixed_case_hex_literals,
14+
clippy::precedence,
15+
clippy::suspicious_else_formatting,
16+
clippy::cast_lossless,
17+
clippy::cast_possible_truncation,
18+
clippy::cast_precision_loss,
19+
clippy::cast_sign_loss,
20+
clippy::cast_possible_wrap,
21+
clippy::excessive_precision,
22+
clippy::range_minus_one,
23+
clippy::cognitive_complexity,
24+
clippy::eq_op,
25+
clippy::shadow_unrelated,
26+
clippy::needless_range_loop,
27+
clippy::float_cmp,
28+
clippy::assign_op_pattern,
29+
clippy::zero_divided_by_zero,
30+
clippy::misrefactored_assign_op,
31+
clippy::if_same_then_else,
32+
clippy::verbose_bit_mask,
33+
clippy::replace_consts,
34+
clippy::used_underscore_binding,
35+
)]
36+
137
macro_rules! force_eval {
238
($e:expr) => {
339
#[allow(unused_unsafe)]

0 commit comments

Comments
 (0)