Skip to content

Commit

Permalink
Fix clippy lints in crates/ and enable this on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Nov 2, 2024
1 parent 4cd303d commit c6dde42
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/libm-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ fn validate(input: &StructuredInput) -> syn::Result<Vec<&'static FunctionInfo>>
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);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/libm-test/src/gen/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static TEST_CASES: LazyLock<CachedInput> = LazyLock::new(|| make_test_cases(NTES
/// value so tests don't run forever.
static TEST_CASES_JN: LazyLock<CachedInput> = 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);
Expand Down
2 changes: 1 addition & 1 deletion crates/libm-test/src/precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn maybe_check_nan_bits<F: Float>(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")))
}
Expand Down
4 changes: 2 additions & 2 deletions crates/libm-test/src/test_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I, Input>(actual: I, expected: I, input: Input, ctx: &CheckCtx) -> TestResult
where
I: Int + Hex,
Input: Hex + fmt::Debug,
Expand Down Expand Up @@ -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<F, Input>(actual: F, expected: F, input: Input, ctx: &CheckCtx) -> TestResult
where
F: Float + Hex,
Input: Hex + fmt::Debug,
Expand Down
2 changes: 1 addition & 1 deletion crates/musl-math-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
7 changes: 7 additions & 0 deletions crates/musl-math-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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),+ ) }
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c6dde42

Please sign in to comment.