From 0faac65520d801b40915f70f2f99a83ac912266e Mon Sep 17 00:00:00 2001 From: Mike Boutin Date: Sat, 24 Jan 2026 15:35:02 -0500 Subject: [PATCH 1/3] Consistently use implicit and explicit returns. Where possible use an implicit return. Otherwise use an explicit `return` with a `;` terminating the statement. --- src/si/time.rs | 20 ++++++++++---------- src/unit.rs | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/si/time.rs b/src/si/time.rs index 574c6008..b73c99d5 100644 --- a/src/si/time.rs +++ b/src/si/time.rs @@ -173,16 +173,16 @@ mod tests { let s = ((*v).clone() - r.clone()).to_u64(); let n = (r * (V::one() / &ns)).to_u32(); - return match (s, n) { - (Some(s), Some(n)) => TestResult::from_bool( - match (Time::try_from(Duration::new(s, n)), V::from_u64(s), V::from_u32(n)) { - (Ok(t), Some(s), Some(n)) => t == Time::new::(s) + Time::new::(n), - (Err(TryFromError::Overflow), None, _) => true, - (Err(TryFromError::Overflow), _, None) => true, - _ => false, - }), - _ => TestResult::discard(), - } + match (s, n) { + (Some(s), Some(n)) => TestResult::from_bool( + match (Time::try_from(Duration::new(s, n)), V::from_u64(s), V::from_u32(n)) { + (Ok(t), Some(s), Some(n)) => t == Time::new::(s) + Time::new::(n), + (Err(TryFromError::Overflow), None, _) => true, + (Err(TryFromError::Overflow), _, None) => true, + _ => false, + }), + _ => TestResult::discard(), + } } } } diff --git a/src/unit.rs b/src/unit.rs index 3f0f1d1c..2ec7ca62 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -223,7 +223,7 @@ macro_rules! unit_units { let r = $coefficient; let c = numer / denom; - return r == c + return r == c; } } } @@ -280,7 +280,7 @@ macro_rules! unit_units { let r = $coefficient; let c = numer / denom; - return r == c + return r == c; } } } @@ -332,7 +332,7 @@ macro_rules! unit_units { let r = $coefficient; let c = numer / denom; - return r == c + return r == c; } } } From 494150d9860102332f1764b983304748b96d9e3d Mon Sep 17 00:00:00 2001 From: Mike Boutin Date: Sun, 25 Jan 2026 13:04:00 -0500 Subject: [PATCH 2/3] Correct CI tests to run for all targets. * Add `--all-targets` argument. Add separate `cargo test --doc` because `--all-targets` excludes doc tests. * Replace deprecated `--all` argument with `--workspace`. --- .github/workflows/ci-full-test-suite.yml | 5 ++++- .github/workflows/ci-min-test-matrix.yml | 2 +- .github/workflows/ci-tool-checks.yml | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-full-test-suite.yml b/.github/workflows/ci-full-test-suite.yml index 1003e3d4..5949ad81 100644 --- a/.github/workflows/ci-full-test-suite.yml +++ b/.github/workflows/ci-full-test-suite.yml @@ -30,7 +30,10 @@ jobs: key: ${{ runner.os }}-${{ steps.install-rust.outputs.cachekey }} - name: Test all crates - run: cargo test --all --verbose --features "use_serde" + run: cargo test --workspace --all-targets --verbose --features "use_serde" + + - name: Test documentation + run: cargo test --workspace --doc --verbose --features "use_serde" - name: Test si run: cargo test --verbose --no-default-features --features "f32 si" diff --git a/.github/workflows/ci-min-test-matrix.yml b/.github/workflows/ci-min-test-matrix.yml index 814cda3a..af224234 100644 --- a/.github/workflows/ci-min-test-matrix.yml +++ b/.github/workflows/ci-min-test-matrix.yml @@ -31,4 +31,4 @@ jobs: toolchain: ${{ matrix.toolchain }} - name: Test all crates - run: cargo test --all --verbose --features "use_serde" + run: cargo test --workspace --verbose --features "use_serde" diff --git a/.github/workflows/ci-tool-checks.yml b/.github/workflows/ci-tool-checks.yml index 1363a52a..9332e467 100644 --- a/.github/workflows/ci-tool-checks.yml +++ b/.github/workflows/ci-tool-checks.yml @@ -39,13 +39,13 @@ jobs: key: tools-${{ runner.os }}-${{ steps.install-rust.outputs.cachekey }} - name: Clippy - run: cargo clippy --all --tests -- -D warnings + run: cargo clippy --workspace --all-targets -- -D warnings - name: Rustfmt run: cargo fmt --all -- --check - name: Rustdoc - run: cargo doc --all --no-deps + run: cargo doc --workspace --lib --bins --examples --no-deps env: RUSTDOCFLAGS: '-D warnings' From 701c35a163cc04ff20962c19f498aae46c71b6fb Mon Sep 17 00:00:00 2001 From: John Bell Date: Fri, 6 Jun 2025 20:58:27 +0100 Subject: [PATCH 3/3] fix: enable using unit macro in foreign crate under test --- src/quantity.rs | 4 ++-- src/unit.rs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/quantity.rs b/src/quantity.rs index c9da83df..8dde0a12 100644 --- a/src/quantity.rs +++ b/src/quantity.rs @@ -137,9 +137,9 @@ macro_rules! quantity { where V: $crate::Conversion, { + test! { /// Check unit validity to ensure the unit is valid for the underlying storage type. - #[cfg(test)] - fn is_valid() -> bool; + fn is_valid() -> bool;} } unit_units! { diff --git a/src/unit.rs b/src/unit.rs index 2ec7ca62..e40c3ec1 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -166,7 +166,7 @@ macro_rules! unit_units { } impl super::Conversion for super::$unit { - #[cfg(test)] + test! { #[inline(always)] #[allow(clippy::eq_op)] #[allow(clippy::approx_constant)] @@ -177,7 +177,7 @@ macro_rules! unit_units { let c = >::coefficient().to_f64(); r == c - } + }} })+ } @@ -208,7 +208,7 @@ macro_rules! unit_units { } impl super::Conversion for super::$unit { - #[cfg(test)] + test! { #[inline(always)] #[allow(clippy::eq_op)] #[allow(clippy::approx_constant)] @@ -230,7 +230,7 @@ macro_rules! unit_units { } false - } + }} })+ } @@ -266,7 +266,7 @@ macro_rules! unit_units { } impl super::Conversion for super::$unit { - #[cfg(test)] + test! { #[inline(always)] #[allow(clippy::eq_op)] #[allow(clippy::approx_constant)] @@ -287,7 +287,7 @@ macro_rules! unit_units { } false - } + }} })+ } @@ -317,7 +317,7 @@ macro_rules! unit_units { } impl super::Conversion for super::$unit { - #[cfg(test)] + test! { #[inline(always)] #[allow(clippy::eq_op)] #[allow(clippy::approx_constant)] @@ -339,7 +339,7 @@ macro_rules! unit_units { } false - } + }} })+ } @@ -364,7 +364,7 @@ macro_rules! unit_units { } impl super::Conversion for super::$unit { - #[cfg(test)] + test! { #[inline(always)] #[allow(clippy::eq_op)] #[allow(clippy::approx_constant)] @@ -375,7 +375,7 @@ macro_rules! unit_units { let c = >::coefficient().to_f64(); r == c - } + }} })+ } };