From c6dde4255ca438be5c2de843fedcbdcf244f183f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 1 Nov 2024 06:40:17 -0500 Subject: [PATCH] Fix clippy lints in `crates/` and enable this on CI --- .github/workflows/main.yml | 21 +++++++++++++++------ crates/libm-macros/src/lib.rs | 2 +- crates/libm-test/src/gen/random.rs | 2 +- crates/libm-test/src/precision.rs | 2 +- crates/libm-test/src/test_traits.rs | 4 ++-- crates/musl-math-sys/build.rs | 2 +- crates/musl-math-sys/src/lib.rs | 7 +++++++ 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c79d637e..e179e31c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -105,12 +105,21 @@ jobs: rustup target add x86_64-unknown-linux-musl cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }} - - name: Clippy - # Tests and utilities can't build on no_std targets - if: "!contains(matrix.target, 'thumb')" - # Run clippy on `libm` - run: cargo clippy --target "${{ matrix.target }}" --package libm --all-targets - + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Install Rust + run: | + rustup update nightly --no-self-update + rustup default nightly + rustup component add clippy + - uses: Swatinem/rust-cache@v2 + - run: | + cargo clippy --all \ + --exclude cb \ + --features libm-test/build-musl,libm-test/test-multiprecision \ + --all-targets builtins: name: Check use with compiler-builtins diff --git a/crates/libm-macros/src/lib.rs b/crates/libm-macros/src/lib.rs index dc78598c..41d13035 100644 --- a/crates/libm-macros/src/lib.rs +++ b/crates/libm-macros/src/lib.rs @@ -353,7 +353,7 @@ fn validate(input: &StructuredInput) -> syn::Result> if !input.skip.is_empty() && input.only.is_some() { let e = syn::Error::new( input.only_span.unwrap(), - format!("only one of `skip` or `only` may be specified"), + "only one of `skip` or `only` may be specified", ); return Err(e); } diff --git a/crates/libm-test/src/gen/random.rs b/crates/libm-test/src/gen/random.rs index d03d1ff7..e347b3c6 100644 --- a/crates/libm-test/src/gen/random.rs +++ b/crates/libm-test/src/gen/random.rs @@ -37,7 +37,7 @@ static TEST_CASES: LazyLock = LazyLock::new(|| make_test_cases(NTES /// value so tests don't run forever. static TEST_CASES_JN: LazyLock = LazyLock::new(|| { // Start with regular test cases - let mut cases = (&*TEST_CASES).clone(); + let mut cases = (*TEST_CASES).clone(); // These functions are extremely slow, limit them let ntests_jn = (NTESTS / 1000).max(80); diff --git a/crates/libm-test/src/precision.rs b/crates/libm-test/src/precision.rs index 9ef0e818..5b021e94 100644 --- a/crates/libm-test/src/precision.rs +++ b/crates/libm-test/src/precision.rs @@ -238,7 +238,7 @@ fn maybe_check_nan_bits(actual: F, expected: F, ctx: &CheckCtx) -> Opt // abs and copysign require signaling NaNs to be propagated, so verify bit equality. if actual.to_bits() == expected.to_bits() { - return SKIP; + SKIP } else { Some(Err(anyhow::anyhow!("NaNs have different bitpatterns"))) } diff --git a/crates/libm-test/src/test_traits.rs b/crates/libm-test/src/test_traits.rs index 67df83fb..e69e16d2 100644 --- a/crates/libm-test/src/test_traits.rs +++ b/crates/libm-test/src/test_traits.rs @@ -214,7 +214,7 @@ macro_rules! impl_int { }; } -fn validate_int<'a, I, Input>(actual: I, expected: I, input: Input, ctx: &CheckCtx) -> TestResult +fn validate_int(actual: I, expected: I, input: Input, ctx: &CheckCtx) -> TestResult where I: Int + Hex, Input: Hex + fmt::Debug, @@ -274,7 +274,7 @@ macro_rules! impl_float { }; } -fn validate_float<'a, F, Input>(actual: F, expected: F, input: Input, ctx: &CheckCtx) -> TestResult +fn validate_float(actual: F, expected: F, input: Input, ctx: &CheckCtx) -> TestResult where F: Float + Hex, Input: Hex + fmt::Debug, diff --git a/crates/musl-math-sys/build.rs b/crates/musl-math-sys/build.rs index 03df06c7..03deb4ff 100644 --- a/crates/musl-math-sys/build.rs +++ b/crates/musl-math-sys/build.rs @@ -124,7 +124,7 @@ fn build_musl_math(cfg: &Config) { // Run configuration steps. Usually done as part of the musl `Makefile`. let obj_include = cfg.out_dir.join("musl_obj/include"); fs::create_dir_all(&obj_include).unwrap(); - fs::create_dir_all(&obj_include.join("bits")).unwrap(); + fs::create_dir_all(obj_include.join("bits")).unwrap(); let sed_stat = Command::new("sed") .arg("-f") .arg(musl_dir.join("tools/mkalltypes.sed")) diff --git a/crates/musl-math-sys/src/lib.rs b/crates/musl-math-sys/src/lib.rs index fe3c8922..db352fab 100644 --- a/crates/musl-math-sys/src/lib.rs +++ b/crates/musl-math-sys/src/lib.rs @@ -7,6 +7,7 @@ use std::ffi::{c_char, c_int, c_long}; /// unsound. macro_rules! functions { ( $( + $( #[$meta:meta] )* $pfx_name:ident: $name:ident( $($arg:ident: $aty:ty),+ ) -> $rty:ty; )* ) => { extern "C" { @@ -15,6 +16,7 @@ macro_rules! functions { $( // Expose a safe version + $( #[$meta] )* pub fn $name( $($arg: $aty),+ ) -> $rty { // SAFETY: FFI calls with no preconditions unsafe { $pfx_name( $($arg),+ ) } @@ -231,8 +233,13 @@ functions! { musl_logf: logf(a: f32) -> f32; musl_modf: modf(a: f64, b: &mut f64) -> f64; musl_modff: modff(a: f32, b: &mut f32) -> f32; + + // FIXME: these need to be unsafe + #[allow(clippy::not_unsafe_ptr_arg_deref)] musl_nan: nan(a: *const c_char) -> f64; + #[allow(clippy::not_unsafe_ptr_arg_deref)] musl_nanf: nanf(a: *const c_char) -> f32; + musl_nearbyint: nearbyint(a: f64) -> f64; musl_nearbyintf: nearbyintf(a: f32) -> f32; musl_nextafter: nextafter(a: f64, b: f64) -> f64;