From 4c01734dd0bbe7b5294841852d30ab1706f2a264 Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Sun, 7 Apr 2024 14:07:20 +0200 Subject: [PATCH 1/5] Fix dead_code warnings --- serde_with/tests/schemars_0_8.rs | 1 + serde_with/tests/serde_as/lib.rs | 6 +++--- serde_with_macros/src/lib.rs | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/serde_with/tests/schemars_0_8.rs b/serde_with/tests/schemars_0_8.rs index 64242820..b9d3f30e 100644 --- a/serde_with/tests/schemars_0_8.rs +++ b/serde_with/tests/schemars_0_8.rs @@ -374,6 +374,7 @@ mod derive { field: u32, } + #[allow(dead_code)] #[serde_as] #[derive(Serialize)] #[cfg_attr(any(), derive(JsonSchema))] diff --git a/serde_with/tests/serde_as/lib.rs b/serde_with/tests/serde_as/lib.rs index 6ac1c385..1ca1a070 100644 --- a/serde_with/tests/serde_as/lib.rs +++ b/serde_with/tests/serde_as/lib.rs @@ -580,7 +580,7 @@ fn test_serialize_reference() { #[derive(Debug, Serialize)] struct S1a<'a>(#[serde_as(as = "&Vec")] &'a Vec); check_serialization( - S1(&vec![1, 2]), + S1a(&vec![1, 2]), expect![[r#" [ "1", @@ -592,7 +592,7 @@ fn test_serialize_reference() { #[derive(Debug, Serialize)] struct S1Mut<'a>(#[serde_as(as = "Vec")] &'a mut Vec); check_serialization( - S1(&vec![1, 2]), + S1Mut(&mut vec![1, 2]), expect![[r#" [ "1", @@ -604,7 +604,7 @@ fn test_serialize_reference() { #[derive(Debug, Serialize)] struct S1aMut<'a>(#[serde_as(as = "&mut Vec")] &'a mut Vec); check_serialization( - S1(&vec![1, 2]), + S1aMut(&mut vec![1, 2]), expect![[r#" [ "1", diff --git a/serde_with_macros/src/lib.rs b/serde_with_macros/src/lib.rs index 50015b4f..f2163da5 100644 --- a/serde_with_macros/src/lib.rs +++ b/serde_with_macros/src/lib.rs @@ -229,6 +229,7 @@ where /// ```rust /// # use serde::Serialize; /// # +/// # #[allow(dead_code)] /// #[derive(Serialize)] /// struct Data { /// #[serde(skip_serializing_if = "Option::is_none")] @@ -248,6 +249,8 @@ where /// ```rust /// # use serde::Serialize; /// # use serde_with_macros::skip_serializing_none; +/// # +/// # #[allow(dead_code)] /// #[skip_serializing_none] /// #[derive(Serialize)] /// struct Data { @@ -278,8 +281,10 @@ where /// ```rust /// # use serde::Serialize; /// # use serde_with_macros::skip_serializing_none; +/// # #[allow(dead_code)] /// type MyOption = Option; /// +/// # #[allow(dead_code)] /// #[skip_serializing_none] /// #[derive(Serialize)] /// struct Data { From b331d6752d871d3dd4ee1908b899c076b737085d Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Sun, 7 Apr 2024 14:07:35 +0200 Subject: [PATCH 2/5] Fix problem with clippy:manual_unwrap_or_default It triggers in generated code by the darling crate and it is hard to work around otherwise. https://github.com/rust-lang/rust-clippy/issues/12643 --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index abb110dc..d19cda8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,9 @@ variant_size_differences = "warn" # explicit_auto_deref suggests code that does not compile # https://github.com/rust-lang/rust-clippy/issues/9841 explicit_auto_deref = "allow" +# Triggers in macro generated code of darling +# https://github.com/rust-lang/rust-clippy/issues/12643 +manual-unwrap-or-default = "allow" # alloc_instead_of_core = "warn" # Checks for usage of `cloned()` on an `Iterator` or `Option` where `copied()` could be used instead. From df94c12acd1f35e92a9e5bd7a33600c73307b89c Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Sun, 7 Apr 2024 14:09:15 +0200 Subject: [PATCH 3/5] Fix clippy::legacy_numeric_constants --- serde_with/src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serde_with/src/utils.rs b/serde_with/src/utils.rs index b5746e80..9578a879 100644 --- a/serde_with/src/utils.rs +++ b/serde_with/src/utils.rs @@ -118,7 +118,7 @@ pub(crate) fn duration_as_secs_f64(dur: &Duration) -> f64 { } pub(crate) fn duration_signed_from_secs_f64(secs: f64) -> Result { - const MAX_NANOS_F64: f64 = ((u64::max_value() as u128 + 1) * (NANOS_PER_SEC as u128)) as f64; + const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1) * (NANOS_PER_SEC as u128)) as f64; // TODO why are the seconds converted to nanoseconds first? // Does it make sense to just truncate the value? let mut nanos = secs * (NANOS_PER_SEC as f64); From ed51a9fe453fff5a50d3085e9822ca16aa2fe711 Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Sun, 7 Apr 2024 14:14:19 +0200 Subject: [PATCH 4/5] Replace duration_as_secs_f64 with native as_secs_f64 --- serde_with/src/utils.rs | 4 ---- serde_with/src/utils/duration.rs | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/serde_with/src/utils.rs b/serde_with/src/utils.rs index 9578a879..256ef948 100644 --- a/serde_with/src/utils.rs +++ b/serde_with/src/utils.rs @@ -113,10 +113,6 @@ where } } -pub(crate) fn duration_as_secs_f64(dur: &Duration) -> f64 { - (dur.as_secs() as f64) + (dur.subsec_nanos() as f64) / (NANOS_PER_SEC as f64) -} - pub(crate) fn duration_signed_from_secs_f64(secs: f64) -> Result { const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1) * (NANOS_PER_SEC as u128)) as f64; // TODO why are the seconds converted to nanoseconds first? diff --git a/serde_with/src/utils/duration.rs b/serde_with/src/utils/duration.rs index 7d8702fc..2e6aecb9 100644 --- a/serde_with/src/utils/duration.rs +++ b/serde_with/src/utils/duration.rs @@ -225,7 +225,7 @@ where { source .sign - .apply(utils::duration_as_secs_f64(&source.duration)) + .apply(source.duration.as_secs_f64()) .serialize(serializer) } } @@ -241,7 +241,7 @@ where { source .sign - .apply(utils::duration_as_secs_f64(&source.duration)) + .apply(source.duration.as_secs_f64()) .to_string() .serialize(serializer) } From c57670c29861d1f6957373015a0dcc61d41b643a Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Sun, 7 Apr 2024 14:42:14 +0200 Subject: [PATCH 5/5] Tarpaulin needs debug info to work --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f23db7dd..15ee7153 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -113,6 +113,9 @@ jobs: run: | cargo install cargo-tarpaulin cargo tarpaulin --out xml --workspace --all-features -- --test-threads=1 + env: + # https://github.com/xd009642/tarpaulin/issues/1499 + CARGO_PROFILE_DEV_DEBUG: 1 - name: Upload to codecov.io uses: codecov/codecov-action@v4 if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest'