Skip to content

Commit

Permalink
Fix different warnings (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb committed Apr 7, 2024
2 parents bcda3fa + c57670c commit ba956eb
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions serde_with/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,8 @@ 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<DurationSigned, &'static str> {
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);
Expand Down
4 changes: 2 additions & 2 deletions serde_with/src/utils/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ where
{
source
.sign
.apply(utils::duration_as_secs_f64(&source.duration))
.apply(source.duration.as_secs_f64())
.serialize(serializer)
}
}
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions serde_with/tests/schemars_0_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ mod derive {
field: u32,
}

#[allow(dead_code)]
#[serde_as]
#[derive(Serialize)]
#[cfg_attr(any(), derive(JsonSchema))]
Expand Down
6 changes: 3 additions & 3 deletions serde_with/tests/serde_as/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ fn test_serialize_reference() {
#[derive(Debug, Serialize)]
struct S1a<'a>(#[serde_as(as = "&Vec<DisplayFromStr>")] &'a Vec<u32>);
check_serialization(
S1(&vec![1, 2]),
S1a(&vec![1, 2]),
expect![[r#"
[
"1",
Expand All @@ -592,7 +592,7 @@ fn test_serialize_reference() {
#[derive(Debug, Serialize)]
struct S1Mut<'a>(#[serde_as(as = "Vec<DisplayFromStr>")] &'a mut Vec<u32>);
check_serialization(
S1(&vec![1, 2]),
S1Mut(&mut vec![1, 2]),
expect![[r#"
[
"1",
Expand All @@ -604,7 +604,7 @@ fn test_serialize_reference() {
#[derive(Debug, Serialize)]
struct S1aMut<'a>(#[serde_as(as = "&mut Vec<DisplayFromStr>")] &'a mut Vec<u32>);
check_serialization(
S1(&vec![1, 2]),
S1aMut(&mut vec![1, 2]),
expect![[r#"
[
"1",
Expand Down
5 changes: 5 additions & 0 deletions serde_with_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ where
/// ```rust
/// # use serde::Serialize;
/// #
/// # #[allow(dead_code)]
/// #[derive(Serialize)]
/// struct Data {
/// #[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -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 {
Expand Down Expand Up @@ -278,8 +281,10 @@ where
/// ```rust
/// # use serde::Serialize;
/// # use serde_with_macros::skip_serializing_none;
/// # #[allow(dead_code)]
/// type MyOption<T> = Option<T>;
///
/// # #[allow(dead_code)]
/// #[skip_serializing_none]
/// #[derive(Serialize)]
/// struct Data {
Expand Down

0 comments on commit ba956eb

Please sign in to comment.