Compare commits

...

99 Commits

Author SHA1 Message Date
David Tolnay 18dcae0a77 Release 1.0.204 2024-07-06 13:38:01 -07:00
David Tolnay 58c307f9cc Alphabetize list of rustc-check-cfg 2024-07-06 13:37:24 -07:00
David Tolnay 8cc4809414 Merge pull request #2769 from dtolnay/onunimpl
Add ui test of unsatisfied serde trait bound
2024-07-06 13:33:50 -07:00
David Tolnay 1179158def Update ui test with diagnostic::on_unimplemented from PR 2767 2024-07-06 13:29:51 -07:00
David Tolnay 91aa40e749 Add ui test of unsatisfied serde trait bound 2024-07-06 13:29:50 -07:00
David Tolnay 595019e979 Cut test_suite from workspace members in old toolchain CI jobs
The test suite's dependencies cannot be resolved by an old toolchain.

    error: failed to select a version for the requirement `toml = "^0.8"`
    candidate versions found which didn't match: 0.5.11, 0.5.10, 0.5.9, ...
    location searched: crates.io index
    required by package `trybuild v1.0.97`
        ... which satisfies dependency `trybuild = "^1.0.97"` of package `serde_test_suite v0.0.0`
2024-07-06 13:25:55 -07:00
David Tolnay b0d7917f88 Pull in trybuild 'following types implement trait' fix 2024-07-06 13:13:32 -07:00
David Tolnay 8e6637a1e4 Merge pull request #2767 from weiznich/feature/diagnostic_on_unimplemented
Use the `#[diagnostic::on_unimplemented]` attribute when possible
2024-07-06 10:29:08 -07:00
Georg Semmler 694fe05953 Use the #[diagnostic::on_unimplemented] attribute when possible
This change enables the `#[diagnostic::on_unimplemented]` attribute for
the `Serialize` and `Deserialize` trait to point the user to the
relevant derives and point out that they might want to check crates
features for external types by adding the relevant hints an note.
2024-07-02 16:39:06 +02:00
David Tolnay f3dfd2a237 Suppress dead code warning in test of unit struct remote derive
error: struct `RemoteSelf` is never constructed
       --> test_suite/tests/test_gen.rs:425:12
        |
    425 |     struct RemoteSelf;
        |            ^^^^^^^^^^
        |
    note: the lint level is defined here
       --> test_suite/tests/test_gen.rs:5:9
        |
    5   | #![deny(warnings)]
        |         ^^^^^^^^
        = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`
2024-06-26 19:41:25 -07:00
David Tolnay 9e6158e9e6 Nightly no longer requires error_in_core feature
warning: the feature `error_in_core` has been stable since 1.81.0-nightly and no longer requires an attribute to enable
       --> serde/src/lib.rs:108:43
        |
    108 | #![cfg_attr(feature = "unstable", feature(error_in_core, never_type))]
        |                                           ^^^^^^^^^^^^^
        |
        = note: `#[warn(stable_features)]` on by default
2024-06-10 09:47:24 -07:00
David Tolnay d577c4a2ce Merge pull request #2754 from bm-w/master
Fix missing close paren in crates-io.md
2024-06-06 21:32:01 -07:00
Bastiaan Marinus van de Weerd fee0b82a40 Fix missing close paren in crates-io.md 2024-06-06 23:19:04 -04:00
David Tolnay 7aafa26314 Fill in ignore reasons in all #[ignore] attributes 2024-06-01 22:13:43 -07:00
David Tolnay d5bc546ca5 Release 1.0.203 2024-05-25 10:43:27 -07:00
David Tolnay 45ae217728 Merge pull request #2747 from dtolnay/variadic
Document tuple impls as fake variadic
2024-05-25 10:15:58 -07:00
David Tolnay b7b97dda73 Unindent implementation inside tuple_impl_body macro 2024-05-25 10:11:45 -07:00
David Tolnay 5d3c563d46 Document tuple impls as fake variadic 2024-05-25 10:11:04 -07:00
David Tolnay 376185458b Merge pull request #2745 from dtolnay/docsrs
Rely on docs.rs to define --cfg=docsrs by default
2024-05-18 21:25:44 -07:00
David Tolnay a8f14840ab Rely on docs.rs to define --cfg=docsrs by default 2024-05-18 21:16:37 -07:00
David Tolnay 9e32a40b1c Release 1.0.202 2024-05-15 00:42:49 -07:00
David Tolnay 87f635e54d Release serde_derive_internals 0.29.1 2024-05-15 00:35:14 -07:00
David Tolnay d4b2dfbde2 Merge pull request #2743 from dtolnay/renameallrules
Provide public access to RenameAllRules in serde_derive_internals
2024-05-15 00:34:38 -07:00
David Tolnay f6ab0bc56f Provide public access to RenameAllRules in serde_derive_internals 2024-05-15 00:30:55 -07:00
David Tolnay 48cc2a6327 Replace use of a syn From impl
The From impls may be going away in the next version of syn.
2024-05-14 23:02:28 -07:00
David Tolnay 3202a6858a Skip rerunning build script on library code changes 2024-05-08 21:59:41 -07:00
David Tolnay b4f1bc16ff Release 1.0.201 2024-05-07 17:02:11 -07:00
David Tolnay 029ab46f71 Merge pull request #2737 from dtolnay/checkcfg
Resolve unexpected_cfgs warning
2024-05-07 17:01:43 -07:00
David Tolnay 220ca0ca9d Resolve unexpected_cfgs warning
warning: unexpected `cfg` condition name: `serde_build_from_git`
      --> serde_derive_internals/lib.rs:45:12
       |
    45 | #[cfg_attr(serde_build_from_git, path = "../serde_derive/src/internals/mod.rs")]
       |            ^^^^^^^^^^^^^^^^^^^^
       |
       = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
       = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(serde_build_from_git)");` to the top of the `build.rs`
       = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
       = note: `#[warn(unexpected_cfgs)]` on by default

    warning: unexpected `cfg` condition name: `serde_build_from_git`
      --> serde_derive_internals/lib.rs:46:16
       |
    46 | #[cfg_attr(not(serde_build_from_git), path = "src/mod.rs")]
       |                ^^^^^^^^^^^^^^^^^^^^
       |
       = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(serde_build_from_git)");` to the top of the `build.rs`
       = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition value: `deserialize_in_place`
       --> serde_derive_internals/src/attr.rs:276:11
        |
    276 |     #[cfg(feature = "deserialize_in_place")]
        |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the condition
        |
        = note: no expected values for `feature`
        = help: consider adding `deserialize_in_place` as a feature in `Cargo.toml`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
        --> serde_derive_internals/src/attr.rs:1797:31
         |
    1797 |         #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
         |                               ^^^^^^^^^^
         |
         = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
         = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive_internals/src/receiver.rs:110:35
        |
    110 |             #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                   ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive_internals/src/receiver.rs:181:47
        |
    181 |                         #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                               ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive_internals/src/receiver.rs:210:35
        |
    210 |             #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                   ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive_internals/src/receiver.rs:231:43
        |
    231 |                     #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                           ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
      --> serde_derive/src/lib.rs:62:23
       |
    62 | #![cfg_attr(all(test, exhaustive), feature(non_exhaustive_omitted_patterns_lint))]
       |                       ^^^^^^^^^^
       |
       = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
       = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
       = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
       = note: `#[warn(unexpected_cfgs)]` on by default

    warning: unexpected `cfg` condition name: `exhaustive`
        --> serde_derive/src/internals/attr.rs:1797:31
         |
    1797 |         #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
         |                               ^^^^^^^^^^
         |
         = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
         = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive/src/internals/receiver.rs:110:35
        |
    110 |             #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                   ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive/src/internals/receiver.rs:181:47
        |
    181 |                         #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                               ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive/src/internals/receiver.rs:210:35
        |
    210 |             #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                   ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive/src/internals/receiver.rs:231:43
        |
    231 |                     #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                           ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive/src/bound.rs:147:39
        |
    147 |                 #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                       ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive/src/bound.rs:199:51
        |
    199 | ...                   #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                             ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `exhaustive`
       --> serde_derive/src/bound.rs:228:39
        |
    228 |                 #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                       ^^^^^^^^^^
        |
        = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs`
        = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration

    warning: unexpected `cfg` condition name: `systemtime_checked_add`
        --> test_suite/tests/test_de_error.rs:1527:7
         |
    1527 | #[cfg(systemtime_checked_add)]
         |       ^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
         = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(systemtime_checked_add)");` to the top of the `build.rs`
         = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
         = note: `#[warn(unexpected_cfgs)]` on by default
2024-05-07 16:55:01 -07:00
David Tolnay 20306f493a Fix cfg on test_systemtime_overflow 2024-05-07 16:53:53 -07:00
David Tolnay cc865ac523 Release 1.0.200 2024-05-01 08:58:52 -07:00
David Tolnay 2d973c1805 Merge pull request #2733 from jamessan/nan-decimal
Only format Unexpected::Float with decimal point if it is finite
2024-05-01 11:57:52 -04:00
James McCoy 6ca499b2dd Only format Unexpected::Float with decimal point if it is finite
bef110b92a changed the display for unexpected floats to always append a
".0" if there was no decimal point found in the formatting of the float.

However, this should only be relevant for finite (i.e., not NaN or inf)
values.  The change introduced a test failure in the ordered-float
crate due to this:

     ---- impl_serde::test_fail_on_nan stdout ----
     thread 'impl_serde::test_fail_on_nan' panicked at 'assertion failed: `(left == right)`
       left: `Error { msg: "invalid value: floating point `NaN.0`, expected float (but not NaN)" }`,
      right: `"invalid value: floating point `NaN`, expected float (but not NaN)"`', src/lib.rs:1554:9
     stack backtrace:
        0: rust_begin_unwind
                  at /usr/src/rustc-1.70.0/library/std/src/panicking.rs:578:5
        1: core::panicking::panic_fmt
                  at /usr/src/rustc-1.70.0/library/core/src/panicking.rs:67:14
        2: core::panicking::assert_failed_inner
        3: core::panicking::assert_failed
                  at /usr/src/rustc-1.70.0/library/core/src/panicking.rs:228:5
        4: serde_test::assert::assert_de_tokens_error
                  at /usr/share/cargo/registry/serde_test-1.0.171/src/assert.rs:228:19
        5: ordered_float::impl_serde::test_fail_on_nan
                  at ./src/lib.rs:1554:9
        6: ordered_float::impl_serde::test_fail_on_nan::{{closure}}
                  at ./src/lib.rs:1553:27
        7: core::ops::function::FnOnce::call_once
                  at /usr/src/rustc-1.70.0/library/core/src/ops/function.rs:250:5
        8: core::ops::function::FnOnce::call_once
                  at /usr/src/rustc-1.70.0/library/core/src/ops/function.rs:250:5
     note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
2024-05-01 09:10:09 -04:00
David Tolnay 1477028717 Release 1.0.199 2024-04-26 21:22:11 -07:00
David Tolnay 789740be0d Merge pull request #2732 from aatifsyed/master
fix: ambiguous associated item in forward_to_deserialize_any!
2024-04-26 21:21:40 -07:00
Aatif Syed 8fe7539bb2 fix: ambiguous associated type in forward_to_deserialize_any! 2024-04-26 13:04:00 +02:00
David Tolnay f6623a3654 Ignore cast_precision_loss pedantic clippy lint
warning: casting `i32` to `f32` causes a loss of precision (`i32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide)
       --> serde/src/de/impls.rs:197:16
        |
    197 |               Ok(v as Self::Value)
        |                  ^^^^^^^^^^^^^^^^
    ...
    457 | / impl_deserialize_num! {
    458 | |     f32, deserialize_f32
    459 | |     num_self!(f32:visit_f32);
    460 | |     num_as_copysign_self!(f64:visit_f64);
    461 | |     num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
    462 | |     num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
    463 | | }
        | |_- in this macro invocation
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss
        = note: `-W clippy::cast-precision-loss` implied by `-W clippy::pedantic`
        = help: to override `-W clippy::pedantic` add `#[allow(clippy::cast_precision_loss)]`
        = note: this warning originates in the macro `num_as_self` which comes from the expansion of the macro `impl_deserialize_num` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: casting `i64` to `f32` causes a loss of precision (`i64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
       --> serde/src/de/impls.rs:197:16
        |
    197 |               Ok(v as Self::Value)
        |                  ^^^^^^^^^^^^^^^^
    ...
    457 | / impl_deserialize_num! {
    458 | |     f32, deserialize_f32
    459 | |     num_self!(f32:visit_f32);
    460 | |     num_as_copysign_self!(f64:visit_f64);
    461 | |     num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
    462 | |     num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
    463 | | }
        | |_- in this macro invocation
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss
        = note: this warning originates in the macro `num_as_self` which comes from the expansion of the macro `impl_deserialize_num` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: casting `u32` to `f32` causes a loss of precision (`u32` is 32 bits wide, but `f32`'s mantissa is only 23 bits wide)
       --> serde/src/de/impls.rs:197:16
        |
    197 |               Ok(v as Self::Value)
        |                  ^^^^^^^^^^^^^^^^
    ...
    457 | / impl_deserialize_num! {
    458 | |     f32, deserialize_f32
    459 | |     num_self!(f32:visit_f32);
    460 | |     num_as_copysign_self!(f64:visit_f64);
    461 | |     num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
    462 | |     num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
    463 | | }
        | |_- in this macro invocation
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss
        = note: this warning originates in the macro `num_as_self` which comes from the expansion of the macro `impl_deserialize_num` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: casting `u64` to `f32` causes a loss of precision (`u64` is 64 bits wide, but `f32`'s mantissa is only 23 bits wide)
       --> serde/src/de/impls.rs:197:16
        |
    197 |               Ok(v as Self::Value)
        |                  ^^^^^^^^^^^^^^^^
    ...
    457 | / impl_deserialize_num! {
    458 | |     f32, deserialize_f32
    459 | |     num_self!(f32:visit_f32);
    460 | |     num_as_copysign_self!(f64:visit_f64);
    461 | |     num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
    462 | |     num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
    463 | | }
        | |_- in this macro invocation
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss
        = note: this warning originates in the macro `num_as_self` which comes from the expansion of the macro `impl_deserialize_num` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: casting `i64` to `f64` causes a loss of precision (`i64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
       --> serde/src/de/impls.rs:197:16
        |
    197 |               Ok(v as Self::Value)
        |                  ^^^^^^^^^^^^^^^^
    ...
    465 | / impl_deserialize_num! {
    466 | |     f64, deserialize_f64
    467 | |     num_self!(f64:visit_f64);
    468 | |     num_as_copysign_self!(f32:visit_f32);
    469 | |     num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
    470 | |     num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
    471 | | }
        | |_- in this macro invocation
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss
        = note: this warning originates in the macro `num_as_self` which comes from the expansion of the macro `impl_deserialize_num` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: casting `u64` to `f64` causes a loss of precision (`u64` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)
       --> serde/src/de/impls.rs:197:16
        |
    197 |               Ok(v as Self::Value)
        |                  ^^^^^^^^^^^^^^^^
    ...
    465 | / impl_deserialize_num! {
    466 | |     f64, deserialize_f64
    467 | |     num_self!(f64:visit_f64);
    468 | |     num_as_copysign_self!(f32:visit_f32);
    469 | |     num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
    470 | |     num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
    471 | | }
        | |_- in this macro invocation
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss
        = note: this warning originates in the macro `num_as_self` which comes from the expansion of the macro `impl_deserialize_num` (in Nightly builds, run with -Z macro-backtrace for more info)
2024-04-19 20:57:45 -07:00
David Tolnay c4fb923335 Release 1.0.198 2024-04-16 14:18:01 -07:00
David Tolnay 65b7eea775 Merge pull request #2729 from dtolnay/saturating
Integrate Saturating<T> deserialization into impl_deserialize_num macro
2024-04-16 14:17:19 -07:00
David Tolnay 01cd696fd1 Integrate Saturating<T> deserialization into impl_deserialize_num macro 2024-04-16 14:09:00 -07:00
David Tolnay c13b3f7e68 Format PR 2709 2024-04-16 13:34:22 -07:00
Oli Scherer a6571ee0da Merge pull request #2709 from jbethune/master
Implement Ser+De for Saturating<T>
2024-04-11 10:18:20 +02:00
David Tolnay 6e38afff49 Revert "Temporarily disable miri on doctests"
This reverts commit 3bfab6ef7f.
2024-04-08 11:58:08 -07:00
Jörn Bethune 3d1b19ed90 Implement Ser+De for Saturating<T>
The serialization implementation is heavily
inspired by the existing trait implentation for
`std::num::Wrapping<T>`.

The deserializing implementation maps input values
that lie outside of the numerical range of the
output type to the `MIN` or `MAX` value of the
output type, depending on the sign of the input
value. This behaviour follows to the `Saturating`
semantics of the output type.

fix #2708
2024-04-06 19:58:01 +02:00
David Tolnay 5b24f88e73 Resolve legacy_numeric_constants clippy lints
warning: usage of a legacy numeric method
       --> serde_derive/src/ser.rs:292:51
        |
    292 |     assert!(fields.len() as u64 <= u64::from(u32::max_value()));
        |                                                   ^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
        = note: `#[warn(clippy::legacy_numeric_constants)]` on by default
    help: use the associated constant instead
        |
    292 |     assert!(fields.len() as u64 <= u64::from(u32::MAX));
        |                                                   ~~~

    warning: usage of a legacy numeric method
       --> serde_derive/src/ser.rs:400:53
        |
    400 |     assert!(variants.len() as u64 <= u64::from(u32::max_value()));
        |                                                     ^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
    help: use the associated constant instead
        |
    400 |     assert!(variants.len() as u64 <= u64::from(u32::MAX));
        |                                                     ~~~

    warning: usage of a legacy numeric method
        --> test_suite/tests/test_de_error.rs:1462:29
         |
    1462 |             Token::U64(u64::max_value()),
         |                             ^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
         = note: `-W clippy::legacy-numeric-constants` implied by `-W clippy::all`
         = help: to override `-W clippy::all` add `#[allow(clippy::legacy_numeric_constants)]`
    help: use the associated constant instead
         |
    1462 |             Token::U64(u64::MAX),
         |                             ~~~

    warning: usage of a legacy numeric method
        --> test_suite/tests/test_de_error.rs:1479:29
         |
    1479 |             Token::U64(u64::max_value()),
         |                             ^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
    help: use the associated constant instead
         |
    1479 |             Token::U64(u64::MAX),
         |                             ~~~

    warning: usage of a legacy numeric method
        --> test_suite/tests/test_de_error.rs:1493:29
         |
    1493 |             Token::U64(u64::max_value()),
         |                             ^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
    help: use the associated constant instead
         |
    1493 |             Token::U64(u64::MAX),
         |                             ~~~

    warning: usage of a legacy numeric method
        --> test_suite/tests/test_de_error.rs:1510:29
         |
    1510 |             Token::U64(u64::max_value()),
         |                             ^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
    help: use the associated constant instead
         |
    1510 |             Token::U64(u64::MAX),
         |                             ~~~
2024-04-05 19:19:14 -07:00
David Tolnay 74d06708dd Explicitly install a Rust toolchain for cargo-outdated job
Debugging a recent cargo-outdated bug, it would have been nice not to
wonder whether a rustc version change in GitHub's runner image was a
contributing factor.
2024-03-25 22:24:55 -07:00
David Tolnay 3bfab6ef7f Temporarily disable miri on doctests 2024-03-24 19:52:00 -07:00
David Tolnay 364cd8d8f7 Ignore dead code lint in tests
New in nightly-2024-03-24 from https://github.com/rust-lang/rust/pull/119552.

    warning: fields `nested` and `string` are never read
      --> test_suite/tests/regression/issue2371.rs:10:9
       |
    8  |     Flatten {
       |     ------- fields in this variant
    9  |         #[serde(flatten)]
    10 |         nested: Nested,
       |         ^^^^^^
    11 |         string: &'static str,
       |         ^^^^^^
       |
       = note: `#[warn(dead_code)]` on by default

    warning: fields `nested` and `string` are never read
      --> test_suite/tests/regression/issue2371.rs:20:9
       |
    18 |     Flatten {
       |     ------- fields in this variant
    19 |         #[serde(flatten)]
    20 |         nested: Nested,
       |         ^^^^^^
    21 |         string: &'static str,
       |         ^^^^^^

    warning: fields `nested` and `string` are never read
      --> test_suite/tests/regression/issue2371.rs:30:9
       |
    28 |     Flatten {
       |     ------- fields in this variant
    29 |         #[serde(flatten)]
    30 |         nested: Nested,
       |         ^^^^^^
    31 |         string: &'static str,
       |         ^^^^^^

    warning: fields `nested` and `string` are never read
      --> test_suite/tests/regression/issue2371.rs:40:9
       |
    38 |     Flatten {
       |     ------- fields in this variant
    39 |         #[serde(flatten)]
    40 |         nested: Nested,
       |         ^^^^^^
    41 |         string: &'static str,
       |         ^^^^^^

    warning: field `0` is never read
       --> test_suite/tests/test_gen.rs:690:33
        |
    690 |         Single(#[serde(borrow)] RelObject<'a>),
        |         ------                  ^^^^^^^^^^^^^
        |         |
        |         field in this variant
        |
        = note: `#[warn(dead_code)]` on by default
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    690 |         Single(#[serde(borrow)] ()),
        |                                 ~~

    warning: field `0` is never read
       --> test_suite/tests/test_gen.rs:691:31
        |
    691 |         Many(#[serde(borrow)] Vec<RelObject<'a>>),
        |         ----                  ^^^^^^^^^^^^^^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    691 |         Many(#[serde(borrow)] ()),
        |                               ~~
2024-03-23 20:26:05 -07:00
David Tolnay 9f8c579bf5 Merge pull request #2714 from Marcono1234/skipped-field-struct-len
Document that `len` does not include skipped struct fields
2024-03-16 12:49:50 -07:00
Marcono1234 eae7c2d684 Document that len does not include skipped struct fields 2024-03-16 14:40:28 +01:00
David Tolnay 3f43fca90d Fix warning on no edition set in serde_derive
New warning since nightly-2024-03-03:

    warning: serde_derive/Cargo.toml: no edition set: defaulting to the 2015 edition while 2018 is compatible with `rust-version`
    warning: serde_derive_internals/Cargo.toml: no edition set: defaulting to the 2015 edition while 2018 is compatible with `rust-version`
2024-03-11 20:18:10 -07:00
David Tolnay 76449488ca Ignore new dead_code warnings in test
Since nightly-2024-03-12.

    warning: struct `PackedC` is never constructed
        --> test_suite/tests/test_macros.rs:2237:12
         |
    2237 |     struct PackedC {
         |            ^^^^^^^
         |
         = note: `#[warn(dead_code)]` on by default

    warning: struct `CPacked` is never constructed
        --> test_suite/tests/test_macros.rs:2243:12
         |
    2243 |     struct CPacked {
         |            ^^^^^^^

    warning: struct `CPacked2` is never constructed
        --> test_suite/tests/test_macros.rs:2249:12
         |
    2249 |     struct CPacked2 {
         |            ^^^^^^^^

    warning: struct `Packed2C` is never constructed
        --> test_suite/tests/test_macros.rs:2255:12
         |
    2255 |     struct Packed2C {
         |            ^^^^^^^^

    error: struct `Packed` is never constructed
       --> test_suite/tests/test_gen.rs:733:12
        |
    733 |     struct Packed {
        |            ^^^^^^
        |
    note: the lint level is defined here
       --> test_suite/tests/test_gen.rs:5:9
        |
    5   | #![deny(warnings)]
        |         ^^^^^^^^
        = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`

    error: struct `Struct` is never constructed
       --> test_suite/tests/test_gen.rs:764:12
        |
    764 |     struct Struct {
        |            ^^^^^^

    error: function `vec_first_element` is never used
       --> test_suite/tests/test_gen.rs:846:4
        |
    846 | fn vec_first_element<T, S>(vec: &[T], serializer: S) -> StdResult<S::Ok, S::Error>
        |    ^^^^^^^^^^^^^^^^^
2024-03-11 20:10:30 -07:00
David Tolnay 00c4b0cef8 Merge pull request 2560 from Mingun/honest-test 2024-03-03 15:54:47 -08:00
David Tolnay 89139e2c11 Remove ineffective ?Sized bound on weak rc Deserialize impls
These impls have both `T: ?Sized` and `T: Deserialize<'de>`. But
`Deserialize<'de>: Sized`.
2024-02-27 22:52:20 -08:00
David Tolnay c9cab490f7 Resolve multiple_bound_locations clippy lint
warning: bound is defined in more than one place
      --> serde/src/ser/fmt.rs:77:33
       |
    77 |     fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T) -> fmt::Result
       |                                 ^
    78 |     where
    79 |         T: Serialize,
       |         ^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
       = note: `-W clippy::multiple-bound-locations` implied by `-W clippy::all`
       = help: to override `-W clippy::all` add `#[allow(clippy::multiple_bound_locations)]`

    warning: bound is defined in more than one place
      --> serde/src/ser/fmt.rs:92:23
       |
    92 |     fn serialize_some<T: ?Sized>(self, _value: &T) -> fmt::Result
       |                       ^
    93 |     where
    94 |         T: Serialize,
       |         ^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/fmt.rs:103:34
        |
    103 |     fn serialize_newtype_variant<T: ?Sized>(
        |                                  ^
    ...
    111 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/fmt.rs:164:20
        |
    164 |     fn collect_str<T: ?Sized>(self, value: &T) -> fmt::Result
        |                    ^
    165 |     where
    166 |         T: Display,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
      --> serde/src/ser/impossible.rs:75:26
       |
    75 |     fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
       |                          ^
    76 |     where
    77 |         T: Serialize,
       |         ^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
      --> serde/src/ser/impossible.rs:95:26
       |
    95 |     fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
       |                          ^
    96 |     where
    97 |         T: Serialize,
       |         ^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/impossible.rs:115:24
        |
    115 |     fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
        |                        ^
    116 |     where
    117 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/impossible.rs:135:24
        |
    135 |     fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
        |                        ^
    136 |     where
    137 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/impossible.rs:155:22
        |
    155 |     fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Error>
        |                      ^
    156 |     where
    157 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/impossible.rs:163:24
        |
    163 |     fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
        |                        ^
    164 |     where
    165 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/impossible.rs:183:24
        |
    183 |     fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
        |                        ^
    184 |     where
    185 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/impossible.rs:204:24
        |
    204 |     fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
        |                        ^
    205 |     where
    206 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/mod.rs:799:23
        |
    799 |     fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
        |                       ^
    800 |     where
    801 |         T: Serialize;
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/mod.rs:894:33
        |
    894 |     fn serialize_newtype_struct<T: ?Sized>(
        |                                 ^
    ...
    900 |         T: Serialize;
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/ser/mod.rs:928:34
        |
    928 |     fn serialize_newtype_variant<T: ?Sized>(
        |                                  ^
    ...
    936 |         T: Serialize;
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1349:20
         |
    1349 |     fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
         |                    ^
    1350 |     where
    1351 |         T: Display,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1496:26
         |
    1496 |     fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
         |                          ^
    1497 |     where
    1498 |         T: Serialize;
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1596:26
         |
    1596 |     fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
         |                          ^
    1597 |     where
    1598 |         T: Serialize;
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1641:24
         |
    1641 |     fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
         |                        ^
    1642 |     where
    1643 |         T: Serialize;
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1699:24
         |
    1699 |     fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
         |                        ^
    1700 |     where
    1701 |         T: Serialize;
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1770:22
         |
    1770 |     fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
         |                      ^
    1771 |     where
    1772 |         T: Serialize;
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1780:24
         |
    1780 |     fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
         |                        ^
    1781 |     where
    1782 |         T: Serialize;
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1801:24
         |
    1801 |     fn serialize_entry<K: ?Sized, V: ?Sized>(
         |                        ^
    ...
    1807 |         K: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1801:35
         |
    1801 |     fn serialize_entry<K: ?Sized, V: ?Sized>(
         |                                   ^
    ...
    1808 |         V: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1859:24
         |
    1859 |     fn serialize_field<T: ?Sized>(
         |                        ^
    ...
    1865 |         T: Serialize;
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/ser/mod.rs:1925:24
         |
    1925 |     fn serialize_field<T: ?Sized>(
         |                        ^
    ...
    1931 |         T: Serialize;
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:177:23
        |
    177 |     fn serialize_some<T: ?Sized>(self, _: &T) -> Result<Self::Ok, Self::Error>
        |                       ^
    178 |     where
    179 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:208:33
        |
    208 |     fn serialize_newtype_struct<T: ?Sized>(
        |                                 ^
    ...
    214 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:219:34
        |
    219 |     fn serialize_newtype_variant<T: ?Sized>(
        |                                  ^
    ...
    227 |         T: Serialize,
        |         ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:367:28
        |
    367 |         fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), M::Error>
        |                            ^
    368 |         where
    369 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:407:28
        |
    407 |         fn serialize_field<T: ?Sized>(
        |                            ^
    ...
    413 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:638:27
        |
    638 |         fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Content, E>
        |                           ^
    639 |         where
    640 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:662:37
        |
    662 |         fn serialize_newtype_struct<T: ?Sized>(
        |                                     ^
    ...
    668 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:676:38
        |
    676 |         fn serialize_newtype_variant<T: ?Sized>(
        |                                      ^
    ...
    684 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:785:30
        |
    785 |         fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
        |                              ^
    786 |         where
    787 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:811:30
        |
    811 |         fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
        |                              ^
    812 |         where
    813 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:838:28
        |
    838 |         fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
        |                            ^
    839 |         where
    840 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:867:28
        |
    867 |         fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
        |                            ^
    868 |         where
    869 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:899:26
        |
    899 |         fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), E>
        |                          ^
    900 |         where
    901 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:908:28
        |
    908 |         fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
        |                            ^
    909 |         where
    910 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:925:28
        |
    925 |         fn serialize_entry<K: ?Sized, V: ?Sized>(&mut self, key: &K, value: &V) -> Result<(), E>
        |                            ^
    926 |         where
    927 |             K: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:925:39
        |
    925 |         fn serialize_entry<K: ?Sized, V: ?Sized>(&mut self, key: &K, value: &V) -> Result<(), E>
        |                                       ^
    ...
    928 |             V: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:950:28
        |
    950 |         fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), E>
        |                            ^
    951 |         where
    952 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
       --> serde/src/private/ser.rs:979:28
        |
    979 |         fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), E>
        |                            ^
    980 |         where
    981 |             T: Serialize,
        |             ^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1091:23
         |
    1091 |     fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
         |                       ^
    1092 |     where
    1093 |         T: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1115:33
         |
    1115 |     fn serialize_newtype_struct<T: ?Sized>(
         |                                 ^
    ...
    1121 |         T: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1126:34
         |
    1126 |     fn serialize_newtype_variant<T: ?Sized>(
         |                                  ^
    ...
    1134 |         T: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1205:22
         |
    1205 |     fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
         |                      ^
    1206 |     where
    1207 |         T: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1212:24
         |
    1212 |     fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
         |                        ^
    1213 |     where
    1214 |         T: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1219:24
         |
    1219 |     fn serialize_entry<K: ?Sized, V: ?Sized>(
         |                        ^
    ...
    1225 |         K: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1219:35
         |
    1219 |     fn serialize_entry<K: ?Sized, V: ?Sized>(
         |                                   ^
    ...
    1226 |         V: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1247:24
         |
    1247 |     fn serialize_field<T: ?Sized>(
         |                        ^
    ...
    1253 |         T: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1292:24
         |
    1292 |     fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
         |                        ^
    1293 |     where
    1294 |         T: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations

    warning: bound is defined in more than one place
        --> serde/src/private/ser.rs:1338:24
         |
    1338 |     fn serialize_field<T: ?Sized>(
         |                        ^
    ...
    1344 |         T: Serialize,
         |         ^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
2024-02-27 22:45:50 -08:00
David Tolnay 5fa711d75d Release 1.0.197 2024-02-19 16:22:07 -08:00
David Tolnay f5d8ae423a Resolve prelude redundant import warnings
warning: the item `Into` is imported redundantly
       --> serde/src/lib.rs:184:47
        |
    184 |     pub use self::core::convert::{self, From, Into};
        |                                               ^^^^
        |
       ::: nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:115:13
        |
    115 |     pub use super::v1::*;
        |             --------- the item `Into` is already defined here
        |
        = note: `#[warn(unused_imports)]` on by default
2024-02-19 16:16:40 -08:00
David Tolnay 1d54973b92 Merge pull request #2697 from nyurik/format-str
A few minor `write_str` optimizations
2024-02-12 19:49:34 -08:00
Yuri Astrakhan b8fafefd85 A few minor write_str optimizations and inlining
Apparently `write!` generates more code than `write_str` when used with a simple string, so optimizing it.
2024-02-12 16:12:08 -05:00
David Tolnay c42ebb8839 Update ui test suite to nightly-2024-02-12 2024-02-11 20:00:23 -08:00
David Tolnay 9e680620b5 Ignore incompatible_msrv clippy lint for conditionally compiled code
warning: current MSRV (Minimum Supported Rust Version) is `1.31.0` but this item is stable since `1.35.0`
       --> serde/src/de/impls.rs:200:39
        |
    200 |                   Ok((v as Self::Value).copysign(sign))
        |                                         ^^^^^^^^^^^^^^
    ...
    374 | / impl_deserialize_num! {
    375 | |     f32, deserialize_f32
    376 | |     num_self!(f32:visit_f32);
    377 | |     num_as_copysign_self!(f64:visit_f64);
    378 | |     num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
    379 | |     num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
    380 | | }
        | |_- in this macro invocation
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
        = note: `-W clippy::incompatible-msrv` implied by `-W clippy::all`
        = help: to override `-W clippy::all` add `#[allow(clippy::incompatible_msrv)]`
        = note: this warning originates in the macro `num_as_copysign_self` which comes from the expansion of the macro `impl_deserialize_num` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: current MSRV (Minimum Supported Rust Version) is `1.31.0` but this item is stable since `1.35.0`
       --> serde/src/de/impls.rs:200:39
        |
    200 |                   Ok((v as Self::Value).copysign(sign))
        |                                         ^^^^^^^^^^^^^^
    ...
    382 | / impl_deserialize_num! {
    383 | |     f64, deserialize_f64
    384 | |     num_self!(f64:visit_f64);
    385 | |     num_as_copysign_self!(f32:visit_f32);
    386 | |     num_as_self!(i8:visit_i8 i16:visit_i16 i32:visit_i32 i64:visit_i64);
    387 | |     num_as_self!(u8:visit_u8 u16:visit_u16 u32:visit_u32 u64:visit_u64);
    388 | | }
        | |_- in this macro invocation
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
        = note: this warning originates in the macro `num_as_copysign_self` which comes from the expansion of the macro `impl_deserialize_num` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: current MSRV (Minimum Supported Rust Version) is `1.31.0` but this item is stable since `1.34.0`
        --> serde/src/de/impls.rs:2308:14
         |
    2308 |             .checked_add(duration)
         |              ^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv

    warning: current MSRV (Minimum Supported Rust Version) is `1.31.0` but this item is stable since `1.34.0`
       --> serde/src/ser/impls.rs:606:26
        |
    606 |                       self.get().serialize(serializer)
        |                            ^^^^^
    ...
    623 | / nonzero_integers! {
    624 | |     NonZeroI8,
    625 | |     NonZeroI16,
    626 | |     NonZeroI32,
    ...   |
    629 | |     NonZeroIsize,
    630 | | }
        | |_- in this macro invocation
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
        = note: this warning originates in the macro `nonzero_integers` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: current MSRV (Minimum Supported Rust Version) is `1.31.0` but this item is stable since `1.34.0`
        --> serde/src/ser/impls.rs:1053:26
         |
    1053 |                       self.load(Ordering::Relaxed).serialize(serializer)
         |                            ^^^^^^^^^^^^^^^^^^^^^^^
    ...
    1061 | / atomic_impl! {
    1062 | |     AtomicBool "8"
    1063 | |     AtomicI8 "8"
    1064 | |     AtomicI16 "16"
    ...    |
    1070 | |     AtomicUsize "ptr"
    1071 | | }
         | |_- in this macro invocation
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
         = note: this warning originates in the macro `atomic_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: current MSRV (Minimum Supported Rust Version) is `1.31.0` but this item is stable since `1.34.0`
        --> serde/src/ser/impls.rs:1053:26
         |
    1053 |                       self.load(Ordering::Relaxed).serialize(serializer)
         |                            ^^^^^^^^^^^^^^^^^^^^^^^
    ...
    1074 | / atomic_impl! {
    1075 | |     AtomicI64 "64"
    1076 | |     AtomicU64 "64"
    1077 | | }
         | |_- in this macro invocation
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
         = note: this warning originates in the macro `atomic_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
2024-02-09 18:55:58 -08:00
David Tolnay 846f865de2 Ignore dead_code warnings in test
warning: trait `AssertNotSerdeSerialize` is never used
      --> test_suite/tests/test_serde_path.rs:39:7
       |
    39 | trait AssertNotSerdeSerialize {}
       |       ^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `#[warn(dead_code)]` on by default

    warning: trait `AssertNotSerdeDeserialize` is never used
      --> test_suite/tests/test_serde_path.rs:43:7
       |
    43 | trait AssertNotSerdeDeserialize<'a> {}
       |       ^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: method `serialize` is never used
      --> test_suite/tests/test_serde_path.rs:31:12
       |
    30 |     pub trait Serialize {
       |               --------- method in this trait
    31 |         fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>;
       |            ^^^^^^^^^

    warning: associated function `deserialize` is never used
      --> test_suite/tests/test_serde_path.rs:35:12
       |
    34 |     pub trait Deserialize<'a>: Sized {
       |               ----------- associated function in this trait
    35 |         fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>;
       |            ^^^^^^^^^^^
2024-02-07 22:15:42 -08:00
David Tolnay ede9762a58 Release 1.0.196 2024-01-26 14:00:35 -08:00
David Tolnay d438c2d67b Merge pull request #2682 from dtolnay/decimalpoint
Format Unexpected::Float with decimal point
2024-01-26 13:59:58 -08:00
David Tolnay bef110b92a Format Unexpected::Float with decimal point 2024-01-26 13:55:13 -08:00
David Tolnay b971ef11d1 Merge pull request #2681 from dtolnay/workspacedeps
Fix workspace.dependencies default-features future compat warning
2024-01-26 13:41:27 -08:00
David Tolnay 29d9f69399 Fix workspace.dependencies default-features future compat warning
warning: serde_derive_internals/Cargo.toml: `default-features` is
    ignored for syn, since `default-features` was not specified for
    `workspace.dependencies.syn`, this could become a hard error in the
    future
2024-01-26 13:36:03 -08:00
David Tolnay aecb4083bd Sort workspace dependencies 2024-01-23 10:08:00 -08:00
David Tolnay 1c675ab3a3 Merge pull request #2678 from rodoufu/workspaceDependencies
Adding workspace dependencies
2024-01-23 10:07:38 -08:00
Rodolfo P A dd619630a3 Adding workspace dependencies 2024-01-23 12:53:29 +00:00
David Tolnay 111803ab07 Merge pull request #2673 from Sky9x/msrv-badge
Use shields.io's MSRV badges
2024-01-08 20:51:26 -08:00
Sky 0024f74f34 Use shields.io's MSRV badges 2024-01-08 22:22:03 -05:00
David Tolnay 03eec42c33 Release 1.0.195 2024-01-05 18:33:24 -08:00
David Tolnay 196f311ae2 Merge pull request #2671 from dtolnay/deadremote
Fix new dead_code warning in tuple struct and tuple variant remote defs
2024-01-05 18:30:01 -08:00
David Tolnay 38d9e0b209 Revert "Add FIXME to fix dead_code warning when using serde(remote)" 2024-01-05 18:26:24 -08:00
David Tolnay 6502b31316 Fix new dead_code warning in tuple struct and tuple variant remote defs 2024-01-05 18:26:24 -08:00
David Tolnay 6f1a8c3115 Add FIXME to fix dead_code warning when using serde(remote)
warning: field `0` is never read
       --> test_suite/tests/test_remote.rs:143:24
        |
    143 | struct PrimitivePubDef(u8);
        |        --------------- ^^
        |        |
        |        field in this struct
        |
        = note: `#[warn(dead_code)]` on by default
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    143 | struct PrimitivePubDef(());
        |                        ~~

    warning: field `0` is never read
       --> test_suite/tests/test_remote.rs:162:20
        |
    162 | struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit);
        |        ----------- ^^
        |        |
        |        field in this struct
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    162 | struct TuplePubDef((), #[serde(with = "UnitDef")] remote::Unit);
        |                    ~~

    warning: field `0` is never read
       --> test_suite/tests/test_remote.rs:200:13
        |
    200 |     Variant(u8),
        |     ------- ^^
        |     |
        |     field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    200 |     Variant(()),
        |             ~~

    error: field `0` is never read
       --> test_suite/tests/test_gen.rs:390:23
        |
    390 |     struct StrDef<'a>(&'a str);
        |            ------     ^^^^^^^
        |            |
        |            field in this struct
        |
    note: the lint level is defined here
       --> test_suite/tests/test_gen.rs:5:9
        |
    5   | #![deny(warnings)]
        |         ^^^^^^^^
        = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    390 |     struct StrDef<'a>(());
        |                       ~~
2024-01-05 18:12:26 -08:00
David Tolnay d883c94cc9 Work around dead_code warning in tests
error: field `0` is never read
       --> test_suite/tests/test_gen.rs:690:33
        |
    690 |         Single(#[serde(borrow)] RelObject<'a>),
        |         ------                  ^^^^^^^^^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    690 |         Single(#[serde(borrow)] ()),
        |                                 ~~

    error: field `0` is never read
       --> test_suite/tests/test_gen.rs:691:31
        |
    691 |         Many(#[serde(borrow)] Vec<RelObject<'a>>),
        |         ----                  ^^^^^^^^^^^^^^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    691 |         Many(#[serde(borrow)] ()),
        |                               ~~
2024-01-05 18:11:07 -08:00
David Tolnay 961fa59a74 Merge pull request #2670 from serde-rs/exhaustive
Pick up changes to non_exhaustive_omitted_patterns lint
2024-01-03 18:42:59 -08:00
David Tolnay 8bc71def55 Fill in omitted patterns for GenericArguments match
error: some variants are not matched explicitly
        --> serde_derive/src/internals/attr.rs:1823:31
         |
    1823 |                         match arg {
         |                               ^^^ patterns `&GenericArgument::Const(_)`, `&GenericArgument::AssocConst(_)` and `&GenericArgument::Constraint(_)` not covered
         |
         = help: ensure that all variants are matched explicitly by adding the suggested match arms
         = note: the matched value is of type `&GenericArgument` and the `non_exhaustive_omitted_patterns` attribute was found
    note: the lint level is defined here
        --> serde_derive/src/internals/attr.rs:1797:49
         |
    1797 |         #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
         |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-03 18:38:58 -08:00
David Tolnay 7c65a9dc0e Pick up changes to non_exhaustive_omitted_patterns lint
warning: the lint level must be set on the whole match
        --> serde_derive/src/internals/attr.rs:1855:9
         |
    1854 |         #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
         |                                                ------------------------------- remove this attribute
    1855 |         _ => {}
         |         ^
         |
         = help: it no longer has any effect to set the lint level on an individual match arm
    help: set the lint level on the whole match
         |
    1796 +     #[deny(non_exhaustive_omitted_patterns)]
    1797 |     match ty {
         |

    warning: the lint level must be set on the whole match
       --> serde_derive/src/internals/receiver.rs:151:13
        |
    150 |             #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                                    ------------------------------- remove this attribute
    151 |             _ => {}
        |             ^
        |
        = help: it no longer has any effect to set the lint level on an individual match arm
    help: set the lint level on the whole match
        |
    109 +         #[deny(non_exhaustive_omitted_patterns)]
    110 |         match ty {
        |

    warning: the lint level must be set on the whole match
       --> serde_derive/src/internals/receiver.rs:188:25
        |
    187 |                         #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                                                ------------------------------- remove this attribute
    188 |                         _ => {}
        |                         ^
        |
        = help: it no longer has any effect to set the lint level on an individual match arm
    help: set the lint level on the whole match
        |
    180 +                     #[deny(non_exhaustive_omitted_patterns)]
    181 |                     match arg {
        |

    warning: the lint level must be set on the whole match
       --> serde_derive/src/internals/receiver.rs:213:13
        |
    212 |             #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                                    ------------------------------- remove this attribute
    213 |             _ => {}
        |             ^
        |
        = help: it no longer has any effect to set the lint level on an individual match arm
    help: set the lint level on the whole match
        |
    209 +         #[deny(non_exhaustive_omitted_patterns)]
    210 |         match bound {
        |

    warning: the lint level must be set on the whole match
       --> serde_derive/src/internals/receiver.rs:239:21
        |
    238 |                     #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                                            ------------------------------- remove this attribute
    239 |                     _ => {}
        |                     ^
        |
        = help: it no longer has any effect to set the lint level on an individual match arm
    help: set the lint level on the whole match
        |
    230 +                 #[deny(non_exhaustive_omitted_patterns)]
    231 |                 match predicate {
        |

    warning: the lint level must be set on the whole match
       --> serde_derive/src/bound.rs:185:17
        |
    184 |                 #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                                        ------------------------------- remove this attribute
    185 |                 _ => {}
        |                 ^
        |
        = help: it no longer has any effect to set the lint level on an individual match arm
    help: set the lint level on the whole match
        |
    146 +             #[deny(non_exhaustive_omitted_patterns)]
    147 |             match ty {
        |

    warning: the lint level must be set on the whole match
       --> serde_derive/src/bound.rs:209:29
        |
    207 | ...                       deny(non_exhaustive_omitted_patterns)
        |                                ------------------------------- remove this attribute
    208 | ...                   )]
    209 | ...                   _ => {}
        |                       ^
        |
        = help: it no longer has any effect to set the lint level on an individual match arm
    help: set the lint level on the whole match
        |
    198 +                         #[deny(non_exhaustive_omitted_patterns)]
    199 |                         match arg {
        |

    warning: the lint level must be set on the whole match
       --> serde_derive/src/bound.rs:234:17
        |
    233 |                 #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                                        ------------------------------- remove this attribute
    234 |                 _ => {}
        |                 ^
        |
        = help: it no longer has any effect to set the lint level on an individual match arm
    help: set the lint level on the whole match
        |
    230 +             #[deny(non_exhaustive_omitted_patterns)]
    231 |             match bound {
        |
2024-01-03 18:38:58 -08:00
David Tolnay d2d977a6c6 Release 1.0.194 2024-01-01 23:07:27 -08:00
David Tolnay a9a6ee9d7f Pull in proc-macro2 sccache fix 2024-01-01 23:03:34 -08:00
David Tolnay 28c5d215c1 Merge pull request #2669 from dtolnay/optionifletelse
Remove option_if_let_else clippy suppression
2023-12-30 14:49:23 -08:00
David Tolnay 3d6a789562 Remove option_if_let_else clippy suppression 2023-12-30 14:46:51 -08:00
David Tolnay a0e68698e3 Work around doc_link_with_quotes pedantic clippy lint
warning: possible intra-doc link using quotes instead of backticks
      --> serde/src/de/mod.rs:67:41
       |
    67 | //!    - Rc\<T\>&emsp;*(if* features = ["rc"] *is enabled)*
       |                                         ^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes
       = note: `-W clippy::doc-link-with-quotes` implied by `-W clippy::pedantic`
       = help: to override `-W clippy::pedantic` add `#[allow(clippy::doc_link_with_quotes)]`

    warning: possible intra-doc link using quotes instead of backticks
      --> serde/src/de/mod.rs:68:42
       |
    68 | //!    - Arc\<T\>&emsp;*(if* features = ["rc"] *is enabled)*
       |                                          ^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes

    warning: possible intra-doc link using quotes instead of backticks
      --> serde/src/ser/mod.rs:64:41
       |
    64 | //!    - Rc\<T\>&emsp;*(if* features = ["rc"] *is enabled)*
       |                                         ^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes

    warning: possible intra-doc link using quotes instead of backticks
      --> serde/src/ser/mod.rs:65:42
       |
    65 | //!    - Arc\<T\>&emsp;*(if* features = ["rc"] *is enabled)*
       |                                          ^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes
2023-12-02 18:25:35 -08:00
David Tolnay 44613c7d01 Release 1.0.193 2023-11-20 17:34:20 -08:00
David Tolnay c706281df3 Merge pull request #2655 from dtolnay/rangestartend
Add RangeFrom and RangeTo tests
2023-11-20 17:33:42 -08:00
David Tolnay 65d75b8fe3 Add RangeFrom and RangeTo tests 2023-11-20 17:28:38 -08:00
David Tolnay 332b0cba40 Merge pull request #2654 from dtolnay/rangestartend
Fix more RangeFrom / RangeEnd mixups
2023-11-20 17:27:31 -08:00
David Tolnay 8c4af41296 Fix more RangeFrom / RangeEnd mixups 2023-11-20 17:21:59 -08:00
David Tolnay 24a78f071b Merge pull request #2653 from emilbonnek/fix/range-to-from-de-mixup
Fix Range{From,To} deserialize mixup
2023-11-20 17:20:04 -08:00
Emil Bonne Kristiansen c91c33436d Fix Range{From,To} deserialize mixup 2023-11-21 02:13:18 +01:00
David Tolnay 2083f43a28 Update ui test suite to nightly-2023-11-19 2023-11-18 18:13:57 -08:00
David Tolnay 4676abdc9e Release 1.0.192 2023-11-06 18:49:17 -08:00
David Tolnay 35700eb23e Merge pull request #2646 from robsdedude/fix/2643/allow-tag-field-in-untagged
Allow internal tag field in untagged variant
2023-11-06 18:48:46 -08:00
Robsdedude 589549d7e6 Allow internal tag field in untagged variant 2023-11-06 12:14:49 +01:00
Mingun 6a097eca93 Add canary test to ensure that we use adequate enum representation 2023-08-07 20:33:12 +05:00
Mingun 84d1c5385d Use correct tokens in test to represent an enum variant
Unit variant of externally tagged enum cannot be deserialized from the string
token by itself. It is ContentDeserializer + serde_test::Deserializer that makes
this possible, because serde_test::Deserializer produces Content::Str() from
Token::BorrowedStr() and ContentDeserializer produces unit variant from Content::Str().

The following tokens all produces Content::String(variant):
- Token::String(variant)
- Token::Str(variant)
- Token::UnitVariant { variant, .. }

Token::BorrowedStr(variant) produces Content::Str(variant) that was the real purpose to
use it in test in #933. This actually makes this test testing `Content` rather than type itself.

Correct way to represent enum one of:
- [xxxVariant { .. }]
- [Enum { .. }, xxxVariant { variant, .. }]
- [Enum { .. }, String(variant), <variant content>]
- [Enum { .. }, Str(variant), <variant content>]
- [Enum { .. }, BorrowedStr(variant), <variant content>]
2023-08-07 19:19:00 +05:00
44 changed files with 1166 additions and 571 deletions
+4
View File
@@ -84,6 +84,7 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
- run: sed -i '/"test_suite"/d' Cargo.toml
- run: cd serde && cargo build --features rc
- run: cd serde && cargo build --no-default-features
- run: cd serde && cargo build
@@ -95,6 +96,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.56.0
- run: sed -i '/"test_suite"/d' Cargo.toml
- run: cd serde && cargo check --no-default-features
- run: cd serde && cargo check
- run: cd serde_derive && cargo check
@@ -106,6 +108,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.36.0
- run: sed -i '/"test_suite"/d' Cargo.toml
- run: cd serde && cargo build --no-default-features --features alloc
minimal:
@@ -168,5 +171,6 @@ jobs:
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/install@cargo-outdated
- run: cargo outdated --workspace --exit-code 1
+5
View File
@@ -8,3 +8,8 @@ members = [
[patch.crates-io]
serde = { path = "serde" }
[workspace.dependencies]
proc-macro2 = { version = "1.0.74", default-features = false }
quote = { version = "1.0.35", default-features = false }
syn = { version = "2.0.46", default-features = false }
+3 -3
View File
@@ -1,11 +1,11 @@
# Serde &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.31+]][Rust 1.31] [![serde_derive: rustc 1.56+]][Rust 1.56]
# Serde &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.31] [![serde_derive msrv]][Rust 1.56]
[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master
[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster
[Latest Version]: https://img.shields.io/crates/v/serde.svg
[crates.io]: https://crates.io/crates/serde
[serde: rustc 1.31+]: https://img.shields.io/badge/serde-rustc_1.31+-lightgray.svg
[serde_derive: rustc 1.56+]: https://img.shields.io/badge/serde_derive-rustc_1.56+-lightgray.svg
[serde msrv]: https://img.shields.io/crates/msrv/serde.svg?label=serde%20msrv&color=lightgray
[serde_derive msrv]: https://img.shields.io/crates/msrv/serde_derive.svg?label=serde_derive%20msrv&color=lightgray
[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
+2 -2
View File
@@ -46,8 +46,8 @@ fn main() {
Serde is one of the most widely used Rust libraries so any place that Rustaceans
congregate will be able to help you out. For chat, consider trying the
[#rust-questions] or [#rust-beginners] channels of the unofficial community
Discord (invite: <https://discord.gg/rust-lang-community>, the [#rust-usage] or
[#beginners] channels of the official Rust Project Discord (invite:
Discord (invite: <https://discord.gg/rust-lang-community>), the [#rust-usage]
or [#beginners] channels of the official Rust Project Discord (invite:
<https://discord.gg/rust-lang>), or the [#general][zulip] stream in Zulip. For
asynchronous, consider the [\[rust\] tag on StackOverflow][stackoverflow], the
[/r/rust] subreddit which has a pinned weekly easy questions post, or the Rust
+3 -3
View File
@@ -1,6 +1,6 @@
[package]
name = "serde"
version = "1.0.191"
version = "1.0.204"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
build = "build.rs"
categories = ["encoding", "no-std", "no-std::no-alloc"]
@@ -29,7 +29,7 @@ features = ["derive", "rc"]
[package.metadata.docs.rs]
features = ["derive", "rc", "unstable"]
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
rustdoc-args = ["--generate-link-to-definition"]
# This cfg cannot be enabled, but it still forces Cargo to keep serde_derive's
# version in lockstep with serde's, even if someone depends on the two crates
@@ -37,7 +37,7 @@ rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
# is compatible with exactly one serde release because the generated code
# involves nonpublic APIs which are not bound by semver.
[target.'cfg(any())'.dependencies]
serde_derive = { version = "=1.0.191", path = "../serde_derive" }
serde_derive = { version = "=1.0.204", path = "../serde_derive" }
### FEATURES #################################################################
+27
View File
@@ -13,6 +13,21 @@ fn main() {
None => return,
};
if minor >= 77 {
println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");
println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)");
println!("cargo:rustc-check-cfg=cfg(no_core_try_from)");
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
println!("cargo:rustc-check-cfg=cfg(no_float_copysign)");
println!("cargo:rustc-check-cfg=cfg(no_num_nonzero_signed)");
println!("cargo:rustc-check-cfg=cfg(no_relaxed_trait_bounds)");
println!("cargo:rustc-check-cfg=cfg(no_serde_derive)");
println!("cargo:rustc-check-cfg=cfg(no_std_atomic)");
println!("cargo:rustc-check-cfg=cfg(no_std_atomic64)");
println!("cargo:rustc-check-cfg=cfg(no_systemtime_checked_add)");
println!("cargo:rustc-check-cfg=cfg(no_target_has_atomic)");
}
let target = env::var("TARGET").unwrap();
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
@@ -64,6 +79,18 @@ fn main() {
if minor < 64 {
println!("cargo:rustc-cfg=no_core_cstr");
}
// Support for core::num::Saturating and std::num::Saturating stabilized in Rust 1.74
// https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html#stabilized-apis
if minor < 74 {
println!("cargo:rustc-cfg=no_core_num_saturating");
}
// Support for the `#[diagnostic]` tool attribute namespace
// https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html#diagnostic-attributes
if minor < 78 {
println!("cargo:rustc-cfg=no_diagnostic_namespace");
}
}
fn rustc_minor_version() -> Option<u32> {
+379 -253
View File
@@ -39,7 +39,7 @@ impl<'de> Deserialize<'de> for () {
}
#[cfg(feature = "unstable")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
impl<'de> Deserialize<'de> for ! {
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
where
@@ -104,6 +104,28 @@ macro_rules! impl_deserialize_num {
deserializer.$deserialize(NonZeroVisitor)
}
}
#[cfg(not(no_core_num_saturating))]
impl<'de> Deserialize<'de> for Saturating<$primitive> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct SaturatingVisitor;
impl<'de> Visitor<'de> for SaturatingVisitor {
type Value = Saturating<$primitive>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("integer with support for saturating semantics")
}
$($($method!(saturating $primitive $val : $visit);)*)*
}
deserializer.$deserialize(SaturatingVisitor)
}
}
};
($primitive:ident, $deserialize:ident $($method:ident!($($val:ident : $visit:ident)*);)*) => {
@@ -154,6 +176,15 @@ macro_rules! num_self {
}
}
};
(saturating $primitive:ident $ty:ident : $visit:ident) => {
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
where
E: Error,
{
Ok(Saturating(v))
}
};
}
macro_rules! num_as_self {
@@ -179,6 +210,15 @@ macro_rules! num_as_self {
}
}
};
(saturating $primitive:ident $ty:ident : $visit:ident) => {
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
where
E: Error,
{
Ok(Saturating(v as $primitive))
}
};
}
macro_rules! num_as_copysign_self {
@@ -235,6 +275,21 @@ macro_rules! int_to_int {
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
}
};
(saturating $primitive:ident $ty:ident : $visit:ident) => {
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
where
E: Error,
{
if (v as i64) < $primitive::MIN as i64 {
Ok(Saturating($primitive::MIN))
} else if ($primitive::MAX as i64) < v as i64 {
Ok(Saturating($primitive::MAX))
} else {
Ok(Saturating(v as $primitive))
}
}
};
}
macro_rules! int_to_uint {
@@ -265,6 +320,21 @@ macro_rules! int_to_uint {
Err(Error::invalid_value(Unexpected::Signed(v as i64), &self))
}
};
(saturating $primitive:ident $ty:ident : $visit:ident) => {
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
where
E: Error,
{
if v < 0 {
Ok(Saturating(0))
} else if ($primitive::MAX as u64) < v as u64 {
Ok(Saturating($primitive::MAX))
} else {
Ok(Saturating(v as $primitive))
}
}
};
}
macro_rules! uint_to_self {
@@ -295,6 +365,19 @@ macro_rules! uint_to_self {
Err(Error::invalid_value(Unexpected::Unsigned(v as u64), &self))
}
};
(saturating $primitive:ident $ty:ident : $visit:ident) => {
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
where
E: Error,
{
if v as u64 <= $primitive::MAX as u64 {
Ok(Saturating(v as $primitive))
} else {
Ok(Saturating($primitive::MAX))
}
}
};
}
impl_deserialize_num! {
@@ -427,6 +510,21 @@ macro_rules! num_128 {
}
}
};
(saturating $primitive:ident $ty:ident : $visit:ident) => {
fn $visit<E>(self, v: $ty) -> Result<Self::Value, E>
where
E: Error,
{
if (v as i128) < $primitive::MIN as i128 {
Ok(Saturating($primitive::MIN))
} else if ($primitive::MAX as u128) < v as u128 {
Ok(Saturating($primitive::MAX))
} else {
Ok(Saturating(v as $primitive))
}
}
};
}
impl_deserialize_num! {
@@ -597,7 +695,7 @@ impl<'a, 'de> Visitor<'de> for StringInPlaceVisitor<'a> {
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de> Deserialize<'de> for String {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -741,7 +839,7 @@ impl<'de> Visitor<'de> for CStringVisitor {
}
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de> Deserialize<'de> for CString {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -770,7 +868,7 @@ macro_rules! forwarded_impl {
forwarded_impl! {
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
(), Box<CStr>, CString::into_boxed_c_str
}
@@ -852,7 +950,10 @@ struct PhantomDataVisitor<T: ?Sized> {
marker: PhantomData<T>,
}
impl<'de, T: ?Sized> Visitor<'de> for PhantomDataVisitor<T> {
impl<'de, T> Visitor<'de> for PhantomDataVisitor<T>
where
T: ?Sized,
{
type Value = PhantomData<T>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
@@ -868,7 +969,10 @@ impl<'de, T: ?Sized> Visitor<'de> for PhantomDataVisitor<T> {
}
}
impl<'de, T: ?Sized> Deserialize<'de> for PhantomData<T> {
impl<'de, T> Deserialize<'de> for PhantomData<T>
where
T: ?Sized,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
@@ -982,7 +1086,7 @@ fn nop_reserve<T>(_seq: T, _n: usize) {}
seq_impl!(
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BinaryHeap<T: Ord>,
seq,
BinaryHeap::clear,
@@ -993,7 +1097,7 @@ seq_impl!(
seq_impl!(
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BTreeSet<T: Eq + Ord>,
seq,
BTreeSet::clear,
@@ -1004,7 +1108,7 @@ seq_impl!(
seq_impl!(
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
LinkedList<T>,
seq,
LinkedList::clear,
@@ -1015,7 +1119,7 @@ seq_impl!(
seq_impl!(
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashSet<T: Eq + Hash, S: BuildHasher + Default>,
seq,
HashSet::clear,
@@ -1026,7 +1130,7 @@ seq_impl!(
seq_impl!(
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
VecDeque<T>,
seq,
VecDeque::clear,
@@ -1038,7 +1142,7 @@ seq_impl!(
////////////////////////////////////////////////////////////////////////////////
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de, T> Deserialize<'de> for Vec<T>
where
T: Deserialize<'de>,
@@ -1289,82 +1393,103 @@ array_impls! {
macro_rules! tuple_impls {
($($len:tt => ($($n:tt $name:ident)+))+) => {
$(
impl<'de, $($name: Deserialize<'de>),+> Deserialize<'de> for ($($name,)+) {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct TupleVisitor<$($name,)+> {
marker: PhantomData<($($name,)+)>,
}
impl<'de, $($name: Deserialize<'de>),+> Visitor<'de> for TupleVisitor<$($name,)+> {
type Value = ($($name,)+);
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(concat!("a tuple of size ", $len))
}
#[inline]
#[allow(non_snake_case)]
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
$(
let $name = match tri!(seq.next_element()) {
Some(value) => value,
None => return Err(Error::invalid_length($n, &self)),
};
)+
Ok(($($name,)+))
}
}
deserializer.deserialize_tuple($len, TupleVisitor { marker: PhantomData })
}
#[inline]
fn deserialize_in_place<D>(deserializer: D, place: &mut Self) -> Result<(), D::Error>
where
D: Deserializer<'de>,
{
struct TupleInPlaceVisitor<'a, $($name: 'a,)+>(&'a mut ($($name,)+));
impl<'a, 'de, $($name: Deserialize<'de>),+> Visitor<'de> for TupleInPlaceVisitor<'a, $($name,)+> {
type Value = ();
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(concat!("a tuple of size ", $len))
}
#[inline]
#[allow(non_snake_case)]
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
$(
if tri!(seq.next_element_seed(InPlaceSeed(&mut (self.0).$n))).is_none() {
return Err(Error::invalid_length($n, &self));
}
)+
Ok(())
}
}
deserializer.deserialize_tuple($len, TupleInPlaceVisitor(place))
}
#[cfg_attr(docsrs, doc(hidden))]
impl<'de, $($name),+> Deserialize<'de> for ($($name,)+)
where
$($name: Deserialize<'de>,)+
{
tuple_impl_body!($len => ($($n $name)+));
}
)+
}
};
}
macro_rules! tuple_impl_body {
($len:tt => ($($n:tt $name:ident)+)) => {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct TupleVisitor<$($name,)+> {
marker: PhantomData<($($name,)+)>,
}
impl<'de, $($name: Deserialize<'de>),+> Visitor<'de> for TupleVisitor<$($name,)+> {
type Value = ($($name,)+);
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(concat!("a tuple of size ", $len))
}
#[inline]
#[allow(non_snake_case)]
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
$(
let $name = match tri!(seq.next_element()) {
Some(value) => value,
None => return Err(Error::invalid_length($n, &self)),
};
)+
Ok(($($name,)+))
}
}
deserializer.deserialize_tuple($len, TupleVisitor { marker: PhantomData })
}
#[inline]
fn deserialize_in_place<D>(deserializer: D, place: &mut Self) -> Result<(), D::Error>
where
D: Deserializer<'de>,
{
struct TupleInPlaceVisitor<'a, $($name: 'a,)+>(&'a mut ($($name,)+));
impl<'a, 'de, $($name: Deserialize<'de>),+> Visitor<'de> for TupleInPlaceVisitor<'a, $($name,)+> {
type Value = ();
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(concat!("a tuple of size ", $len))
}
#[inline]
#[allow(non_snake_case)]
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
$(
if tri!(seq.next_element_seed(InPlaceSeed(&mut (self.0).$n))).is_none() {
return Err(Error::invalid_length($n, &self));
}
)+
Ok(())
}
}
deserializer.deserialize_tuple($len, TupleInPlaceVisitor(place))
}
};
}
#[cfg_attr(docsrs, doc(fake_variadic))]
#[cfg_attr(
docsrs,
doc = "This trait is implemented for tuples up to 16 items long."
)]
impl<'de, T> Deserialize<'de> for (T,)
where
T: Deserialize<'de>,
{
tuple_impl_body!(1 => (0 T));
}
tuple_impls! {
1 => (0 T0)
2 => (0 T0 1 T1)
3 => (0 T0 1 T1 2 T2)
4 => (0 T0 1 T1 2 T2 3 T3)
@@ -1442,7 +1567,7 @@ macro_rules! map_impl {
map_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BTreeMap<K: Ord, V>,
map,
BTreeMap::new(),
@@ -1450,7 +1575,7 @@ map_impl! {
map_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashMap<K: Eq + Hash, V, S: BuildHasher + Default>,
map,
HashMap::with_capacity_and_hasher(size_hint::cautious::<(K, V)>(map.size_hint()), S::default()),
@@ -1592,7 +1717,7 @@ macro_rules! deserialize_enum {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de> Deserialize<'de> for net::IpAddr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -1613,13 +1738,13 @@ impl<'de> Deserialize<'de> for net::IpAddr {
parse_ip_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
net::Ipv4Addr, "IPv4 address", 4
}
parse_ip_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
net::Ipv6Addr, "IPv6 address", 16
}
@@ -1646,7 +1771,7 @@ macro_rules! parse_socket_impl {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de> Deserialize<'de> for net::SocketAddr {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -1667,14 +1792,14 @@ impl<'de> Deserialize<'de> for net::SocketAddr {
parse_socket_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
net::SocketAddrV4, "IPv4 socket address",
|(ip, port)| net::SocketAddrV4::new(ip, port),
}
parse_socket_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
net::SocketAddrV6, "IPv6 socket address",
|(ip, port)| net::SocketAddrV6::new(ip, port, 0, 0),
}
@@ -1710,7 +1835,7 @@ impl<'a> Visitor<'a> for PathVisitor {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de: 'a, 'a> Deserialize<'de> for &'a Path {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -1765,7 +1890,7 @@ impl<'de> Visitor<'de> for PathBufVisitor {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de> Deserialize<'de> for PathBuf {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -1777,7 +1902,7 @@ impl<'de> Deserialize<'de> for PathBuf {
forwarded_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
(), Box<Path>, PathBuf::into_boxed_path
}
@@ -1839,7 +1964,7 @@ impl<'de> Visitor<'de> for OsStringVisitor {
}
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
impl<'de> Deserialize<'de> for OsString {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -1853,33 +1978,33 @@ impl<'de> Deserialize<'de> for OsString {
forwarded_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
(T), Box<T>, Box::new
}
forwarded_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
(T), Box<[T]>, Vec::into_boxed_slice
}
forwarded_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
(), Box<str>, String::into_boxed_str
}
forwarded_impl! {
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
(), Box<OsStr>, OsString::into_boxed_os_str
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de, 'a, T: ?Sized> Deserialize<'de> for Cow<'a, T>
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
where
T: ToOwned,
T: ?Sized + ToOwned,
T::Owned: Deserialize<'de>,
{
#[inline]
@@ -1899,10 +2024,10 @@ where
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(
doc_cfg,
docsrs,
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
)]
impl<'de, T: ?Sized> Deserialize<'de> for RcWeak<T>
impl<'de, T> Deserialize<'de> for RcWeak<T>
where
T: Deserialize<'de>,
{
@@ -1921,10 +2046,10 @@ where
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(
doc_cfg,
docsrs,
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
)]
impl<'de, T: ?Sized> Deserialize<'de> for ArcWeak<T>
impl<'de, T> Deserialize<'de> for ArcWeak<T>
where
T: Deserialize<'de>,
{
@@ -1945,8 +2070,9 @@ macro_rules! box_forwarded_impl {
$t:ident
) => {
$(#[$attr])*
impl<'de, T: ?Sized> Deserialize<'de> for $t<T>
impl<'de, T> Deserialize<'de> for $t<T>
where
T: ?Sized,
Box<T>: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@@ -1968,7 +2094,7 @@ box_forwarded_impl! {
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
Rc
}
@@ -1981,7 +2107,7 @@ box_forwarded_impl! {
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
Arc
}
@@ -2005,13 +2131,13 @@ forwarded_impl! {
forwarded_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
(T), Mutex<T>, Mutex::new
}
forwarded_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
(T), RwLock<T>, RwLock::new
}
@@ -2166,7 +2292,7 @@ impl<'de> Deserialize<'de> for Duration {
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de> Deserialize<'de> for SystemTime {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -2526,144 +2652,6 @@ mod range_from {
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
pub const FIELDS: &[&str] = &["end"];
// If this were outside of the serde crate, it would just use:
//
// #[derive(Deserialize)]
// #[serde(field_identifier, rename_all = "lowercase")]
enum Field {
End,
}
impl<'de> Deserialize<'de> for Field {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct FieldVisitor;
impl<'de> Visitor<'de> for FieldVisitor {
type Value = Field;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("`end`")
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: Error,
{
match value {
"end" => Ok(Field::End),
_ => Err(Error::unknown_field(value, FIELDS)),
}
}
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
where
E: Error,
{
match value {
b"end" => Ok(Field::End),
_ => {
let value = crate::__private::from_utf8_lossy(value);
Err(Error::unknown_field(&*value, FIELDS))
}
}
}
}
deserializer.deserialize_identifier(FieldVisitor)
}
}
pub struct RangeFromVisitor<Idx> {
pub expecting: &'static str,
pub phantom: PhantomData<Idx>,
}
impl<'de, Idx> Visitor<'de> for RangeFromVisitor<Idx>
where
Idx: Deserialize<'de>,
{
type Value = Idx;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(self.expecting)
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let end: Idx = match tri!(seq.next_element()) {
Some(value) => value,
None => {
return Err(Error::invalid_length(0, &self));
}
};
Ok(end)
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'de>,
{
let mut end: Option<Idx> = None;
while let Some(key) = tri!(map.next_key()) {
match key {
Field::End => {
if end.is_some() {
return Err(<A::Error as Error>::duplicate_field("end"));
}
end = Some(tri!(map.next_value()));
}
}
}
let end = match end {
Some(end) => end,
None => return Err(<A::Error as Error>::missing_field("end")),
};
Ok(end)
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Similar to:
//
// #[derive(Deserialize)]
// #[serde(deny_unknown_fields)]
// struct RangeTo<Idx> {
// start: Idx,
// }
impl<'de, Idx> Deserialize<'de> for RangeTo<Idx>
where
Idx: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let end = tri!(deserializer.deserialize_struct(
"RangeTo",
range_to::FIELDS,
range_to::RangeToVisitor {
expecting: "struct RangeTo",
phantom: PhantomData,
},
));
Ok(..end)
}
}
mod range_to {
use crate::lib::*;
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
pub const FIELDS: &[&str] = &["start"];
// If this were outside of the serde crate, it would just use:
@@ -2716,12 +2704,12 @@ mod range_to {
}
}
pub struct RangeToVisitor<Idx> {
pub struct RangeFromVisitor<Idx> {
pub expecting: &'static str,
pub phantom: PhantomData<Idx>,
}
impl<'de, Idx> Visitor<'de> for RangeToVisitor<Idx>
impl<'de, Idx> Visitor<'de> for RangeFromVisitor<Idx>
where
Idx: Deserialize<'de>,
{
@@ -2770,6 +2758,144 @@ mod range_to {
////////////////////////////////////////////////////////////////////////////////
// Similar to:
//
// #[derive(Deserialize)]
// #[serde(deny_unknown_fields)]
// struct RangeTo<Idx> {
// end: Idx,
// }
impl<'de, Idx> Deserialize<'de> for RangeTo<Idx>
where
Idx: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let end = tri!(deserializer.deserialize_struct(
"RangeTo",
range_to::FIELDS,
range_to::RangeToVisitor {
expecting: "struct RangeTo",
phantom: PhantomData,
},
));
Ok(..end)
}
}
mod range_to {
use crate::lib::*;
use crate::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
pub const FIELDS: &[&str] = &["end"];
// If this were outside of the serde crate, it would just use:
//
// #[derive(Deserialize)]
// #[serde(field_identifier, rename_all = "lowercase")]
enum Field {
End,
}
impl<'de> Deserialize<'de> for Field {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct FieldVisitor;
impl<'de> Visitor<'de> for FieldVisitor {
type Value = Field;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("`end`")
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: Error,
{
match value {
"end" => Ok(Field::End),
_ => Err(Error::unknown_field(value, FIELDS)),
}
}
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
where
E: Error,
{
match value {
b"end" => Ok(Field::End),
_ => {
let value = crate::__private::from_utf8_lossy(value);
Err(Error::unknown_field(&*value, FIELDS))
}
}
}
}
deserializer.deserialize_identifier(FieldVisitor)
}
}
pub struct RangeToVisitor<Idx> {
pub expecting: &'static str,
pub phantom: PhantomData<Idx>,
}
impl<'de, Idx> Visitor<'de> for RangeToVisitor<Idx>
where
Idx: Deserialize<'de>,
{
type Value = Idx;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(self.expecting)
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let end: Idx = match tri!(seq.next_element()) {
Some(value) => value,
None => {
return Err(Error::invalid_length(0, &self));
}
};
Ok(end)
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'de>,
{
let mut end: Option<Idx> = None;
while let Some(key) = tri!(map.next_key()) {
match key {
Field::End => {
if end.is_some() {
return Err(<A::Error as Error>::duplicate_field("end"));
}
end = Some(tri!(map.next_value()));
}
}
}
let end = match end {
Some(end) => end,
None => return Err(<A::Error as Error>::missing_field("end")),
};
Ok(end)
}
}
}
////////////////////////////////////////////////////////////////////////////////
impl<'de, T> Deserialize<'de> for Bound<T>
where
T: Deserialize<'de>,
@@ -3002,7 +3128,7 @@ macro_rules! atomic_impl {
($($ty:ident $size:expr)*) => {
$(
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", target_has_atomic = $size))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", target_has_atomic = $size))))]
impl<'de> Deserialize<'de> for $ty {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
+66 -22
View File
@@ -64,8 +64,8 @@
//! - RefCell\<T\>
//! - Mutex\<T\>
//! - RwLock\<T\>
//! - Rc\<T\>&emsp;*(if* features = ["rc"] *is enabled)*
//! - Arc\<T\>&emsp;*(if* features = ["rc"] *is enabled)*
//! - Rc\<T\>&emsp;*(if* features = \["rc"\] *is enabled)*
//! - Arc\<T\>&emsp;*(if* features = \["rc"\] *is enabled)*
//! - **Collection types**:
//! - BTreeMap\<K, V\>
//! - BTreeSet\<T\>
@@ -402,20 +402,20 @@ impl<'a> fmt::Display for Unexpected<'a> {
Bool(b) => write!(formatter, "boolean `{}`", b),
Unsigned(i) => write!(formatter, "integer `{}`", i),
Signed(i) => write!(formatter, "integer `{}`", i),
Float(f) => write!(formatter, "floating point `{}`", f),
Float(f) => write!(formatter, "floating point `{}`", WithDecimalPoint(f)),
Char(c) => write!(formatter, "character `{}`", c),
Str(s) => write!(formatter, "string {:?}", s),
Bytes(_) => write!(formatter, "byte array"),
Unit => write!(formatter, "unit value"),
Option => write!(formatter, "Option value"),
NewtypeStruct => write!(formatter, "newtype struct"),
Seq => write!(formatter, "sequence"),
Map => write!(formatter, "map"),
Enum => write!(formatter, "enum"),
UnitVariant => write!(formatter, "unit variant"),
NewtypeVariant => write!(formatter, "newtype variant"),
TupleVariant => write!(formatter, "tuple variant"),
StructVariant => write!(formatter, "struct variant"),
Bytes(_) => formatter.write_str("byte array"),
Unit => formatter.write_str("unit value"),
Option => formatter.write_str("Option value"),
NewtypeStruct => formatter.write_str("newtype struct"),
Seq => formatter.write_str("sequence"),
Map => formatter.write_str("map"),
Enum => formatter.write_str("enum"),
UnitVariant => formatter.write_str("unit variant"),
NewtypeVariant => formatter.write_str("newtype variant"),
TupleVariant => formatter.write_str("tuple variant"),
StructVariant => formatter.write_str("struct variant"),
Other(other) => formatter.write_str(other),
}
}
@@ -532,6 +532,13 @@ impl<'a> Display for Expected + 'a {
/// deserializer lifetimes] for a more detailed explanation of these lifetimes.
///
/// [Understanding deserializer lifetimes]: https://serde.rs/lifetimes.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
note = "for local types consider adding `#[derive(serde::Deserialize)]` to your `{Self}` type",
note = "for types from other crates check whether the crate offers a `serde` feature flag",
)
)]
pub trait Deserialize<'de>: Sized {
/// Deserialize this value from the given Serde deserializer.
///
@@ -1525,7 +1532,7 @@ pub trait Visitor<'de>: Sized {
/// `String`.
#[inline]
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
where
E: Error,
@@ -1584,7 +1591,7 @@ pub trait Visitor<'de>: Sized {
/// The default implementation forwards to `visit_bytes` and then drops the
/// `Vec<u8>`.
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
where
E: Error,
@@ -1735,9 +1742,9 @@ pub trait SeqAccess<'de> {
}
}
impl<'de, 'a, A: ?Sized> SeqAccess<'de> for &'a mut A
impl<'de, 'a, A> SeqAccess<'de> for &'a mut A
where
A: SeqAccess<'de>,
A: ?Sized + SeqAccess<'de>,
{
type Error = A::Error;
@@ -1888,9 +1895,9 @@ pub trait MapAccess<'de> {
}
}
impl<'de, 'a, A: ?Sized> MapAccess<'de> for &'a mut A
impl<'de, 'a, A> MapAccess<'de> for &'a mut A
where
A: MapAccess<'de>,
A: ?Sized + MapAccess<'de>,
{
type Error = A::Error;
@@ -2278,10 +2285,10 @@ impl Display for OneOf {
1 => write!(formatter, "`{}`", self.names[0]),
2 => write!(formatter, "`{}` or `{}`", self.names[0], self.names[1]),
_ => {
tri!(write!(formatter, "one of "));
tri!(formatter.write_str("one of "));
for (i, alt) in self.names.iter().enumerate() {
if i > 0 {
tri!(write!(formatter, ", "));
tri!(formatter.write_str(", "));
}
tri!(write!(formatter, "`{}`", alt));
}
@@ -2290,3 +2297,40 @@ impl Display for OneOf {
}
}
}
struct WithDecimalPoint(f64);
impl Display for WithDecimalPoint {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
struct LookForDecimalPoint<'f, 'a> {
formatter: &'f mut fmt::Formatter<'a>,
has_decimal_point: bool,
}
impl<'f, 'a> fmt::Write for LookForDecimalPoint<'f, 'a> {
fn write_str(&mut self, fragment: &str) -> fmt::Result {
self.has_decimal_point |= fragment.contains('.');
self.formatter.write_str(fragment)
}
fn write_char(&mut self, ch: char) -> fmt::Result {
self.has_decimal_point |= ch == '.';
self.formatter.write_char(ch)
}
}
if self.0.is_finite() {
let mut writer = LookForDecimalPoint {
formatter,
has_decimal_point: false,
};
tri!(write!(writer, "{}", self.0));
if !writer.has_decimal_point {
tri!(formatter.write_str(".0"));
}
} else {
tri!(write!(formatter, "{}", self.0));
}
Ok(())
}
}
+14 -14
View File
@@ -112,7 +112,7 @@ impl Debug for Error {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl error::Error for Error {
fn description(&self) -> &str {
&self.err
@@ -185,14 +185,14 @@ impl<E> Debug for UnitDeserializer<E> {
/// A deserializer that cannot be instantiated.
#[cfg(feature = "unstable")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
pub struct NeverDeserializer<E> {
never: !,
marker: PhantomData<E>,
}
#[cfg(feature = "unstable")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
impl<'de, E> IntoDeserializer<'de, E> for !
where
E: de::Error,
@@ -565,7 +565,7 @@ impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
/// A deserializer holding a `String`.
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
pub struct StringDeserializer<E> {
value: String,
marker: PhantomData<E>,
@@ -582,7 +582,7 @@ impl<E> Clone for StringDeserializer<E> {
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de, E> IntoDeserializer<'de, E> for String
where
E: de::Error,
@@ -670,7 +670,7 @@ impl<E> Debug for StringDeserializer<E> {
/// A deserializer holding a `Cow<str>`.
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
pub struct CowStrDeserializer<'a, E> {
value: Cow<'a, str>,
marker: PhantomData<E>,
@@ -687,7 +687,7 @@ impl<'a, E> Clone for CowStrDeserializer<'a, E> {
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>
where
E: de::Error,
@@ -983,7 +983,7 @@ struct ExpectedInSeq(usize);
impl Expected for ExpectedInSeq {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
if self.0 == 1 {
write!(formatter, "1 element in sequence")
formatter.write_str("1 element in sequence")
} else {
write!(formatter, "{} elements in sequence", self.0)
}
@@ -1006,7 +1006,7 @@ where
////////////////////////////////////////////////////////////////////////////////
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de, T, E> IntoDeserializer<'de, E> for Vec<T>
where
T: IntoDeserializer<'de, E>,
@@ -1020,7 +1020,7 @@ where
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de, T, E> IntoDeserializer<'de, E> for BTreeSet<T>
where
T: IntoDeserializer<'de, E> + Eq + Ord,
@@ -1034,7 +1034,7 @@ where
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de, T, S, E> IntoDeserializer<'de, E> for HashSet<T, S>
where
T: IntoDeserializer<'de, E> + Eq + Hash,
@@ -1411,7 +1411,7 @@ struct ExpectedInMap(usize);
impl Expected for ExpectedInMap {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
if self.0 == 1 {
write!(formatter, "1 element in map")
formatter.write_str("1 element in map")
} else {
write!(formatter, "{} elements in map", self.0)
}
@@ -1421,7 +1421,7 @@ impl Expected for ExpectedInMap {
////////////////////////////////////////////////////////////////////////////////
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl<'de, K, V, E> IntoDeserializer<'de, E> for BTreeMap<K, V>
where
K: IntoDeserializer<'de, E> + Eq + Ord,
@@ -1436,7 +1436,7 @@ where
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>
where
K: IntoDeserializer<'de, E> + Eq + Hash,
+16 -11
View File
@@ -95,16 +95,17 @@
////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde/1.0.191")]
#![doc(html_root_url = "https://docs.rs/serde/1.0.204")]
// Support using Serde without the standard library!
#![cfg_attr(not(feature = "std"), no_std)]
// Show which crate feature enables conditionally compiled APIs in documentation.
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_cfg, rustdoc_internals))]
#![cfg_attr(docsrs, allow(internal_features))]
// Unstable functionality only if the user asks for it. For tracking and
// discussion of these features please refer to this issue:
//
// https://github.com/serde-rs/serde/issues/812
#![cfg_attr(feature = "unstable", feature(error_in_core, never_type))]
#![cfg_attr(feature = "unstable", feature(never_type))]
#![allow(unknown_lints, bare_trait_objects, deprecated)]
// Ignored clippy and clippy_pedantic lints
#![allow(
@@ -118,11 +119,11 @@
// integer and float ser/de requires these sorts of casts
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::cast_precision_loss,
clippy::cast_sign_loss,
// things are often more readable this way
clippy::cast_lossless,
clippy::module_name_repetitions,
clippy::option_if_let_else,
clippy::single_match_else,
clippy::type_complexity,
clippy::use_self,
@@ -131,6 +132,7 @@
clippy::derive_partial_eq_without_eq,
clippy::enum_glob_use,
clippy::explicit_auto_deref,
clippy::incompatible_msrv,
clippy::let_underscore_untyped,
clippy::map_err_ignore,
clippy::new_without_default,
@@ -179,16 +181,16 @@ mod lib {
pub use self::core::{cmp, mem, slice};
pub use self::core::cell::{Cell, RefCell};
pub use self::core::clone::{self, Clone};
pub use self::core::clone;
pub use self::core::cmp::Reverse;
pub use self::core::convert::{self, From, Into};
pub use self::core::default::{self, Default};
pub use self::core::fmt::{self, Debug, Display};
pub use self::core::convert;
pub use self::core::default;
pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
pub use self::core::marker::{self, PhantomData};
pub use self::core::num::Wrapping;
pub use self::core::ops::{Bound, Range, RangeFrom, RangeInclusive, RangeTo};
pub use self::core::option::{self, Option};
pub use self::core::result::{self, Result};
pub use self::core::option;
pub use self::core::result;
pub use self::core::time::Duration;
#[cfg(all(feature = "alloc", not(feature = "std")))]
@@ -274,6 +276,9 @@ mod lib {
pub use std::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "ptr"))]
pub use std::sync::atomic::{AtomicIsize, AtomicUsize};
#[cfg(not(no_core_num_saturating))]
pub use self::core::num::Saturating;
}
// None of this crate's error handling needs the `From::from` error conversion
@@ -326,7 +331,7 @@ extern crate serde_derive;
/// Derive macro available if serde is built with `features = ["derive"]`.
#[cfg(feature = "serde_derive")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
pub use serde_derive::{Deserialize, Serialize};
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
+1 -1
View File
@@ -123,7 +123,7 @@ macro_rules! forward_to_deserialize_any {
macro_rules! forward_to_deserialize_any_method {
($func:ident<$l:tt, $v:ident>($($arg:ident : $ty:ty),*)) => {
#[inline]
fn $func<$v>(self, $($arg: $ty,)* visitor: $v) -> $crate::__private::Result<$v::Value, Self::Error>
fn $func<$v>(self, $($arg: $ty,)* visitor: $v) -> $crate::__private::Result<$v::Value, <Self as $crate::de::Deserializer<$l>>::Error>
where
$v: $crate::de::Visitor<$l>,
{
+7
View File
@@ -313,6 +313,8 @@ mod content {
}
}
/// Used to capture data in [`Content`] from other deserializers.
/// Cannot capture externally tagged enums, `i128` and `u128`.
struct ContentVisitor<'de> {
value: PhantomData<Content<'de>>,
}
@@ -528,6 +530,8 @@ mod content {
Content(Content<'de>),
}
/// Serves as a seed for deserializing a key of internally tagged enum.
/// Cannot capture externally tagged enums, `i128` and `u128`.
struct TagOrContentVisitor<'de> {
name: &'static str,
value: PhantomData<TagOrContent<'de>>,
@@ -814,6 +818,9 @@ mod content {
/// Used by generated code to deserialize an internally tagged enum.
///
/// Captures map or sequence from the original deserializer and searches
/// a tag in it (in case of sequence, tag is the first element of sequence).
///
/// Not public API.
pub struct TaggedContentVisitor<T> {
tag_name: &'static str,
+4 -1
View File
@@ -56,7 +56,10 @@ macro_rules! __serialize_unimplemented {
#[macro_export]
macro_rules! __serialize_unimplemented_method {
($func:ident $(<$t:ident>)* ($($arg:ty),*) -> $ret:ident) => {
fn $func $(<$t: ?Sized + $crate::Serialize>)* (self $(, _: $arg)*) -> $crate::__private::Result<Self::$ret, Self::Error> {
fn $func $(<$t>)* (self $(, _: $arg)*) -> $crate::__private::Result<Self::$ret, Self::Error>
where
$($t: ?Sized + $crate::Serialize,)*
{
unimplemented!()
}
};
+56 -76
View File
@@ -174,9 +174,9 @@ where
Err(self.bad_type(Unsupported::Optional))
}
fn serialize_some<T: ?Sized>(self, _: &T) -> Result<Self::Ok, Self::Error>
fn serialize_some<T>(self, _: &T) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
Err(self.bad_type(Unsupported::Optional))
}
@@ -205,18 +205,18 @@ where
map.end()
}
fn serialize_newtype_struct<T: ?Sized>(
fn serialize_newtype_struct<T>(
self,
_: &'static str,
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
value.serialize(self)
}
fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
_: &'static str,
_: u32,
@@ -224,7 +224,7 @@ where
inner_value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let mut map = tri!(self.delegate.serialize_map(Some(2)));
tri!(map.serialize_entry(self.tag, self.variant_name));
@@ -327,9 +327,9 @@ where
}
#[cfg(not(any(feature = "std", feature = "alloc")))]
fn collect_str<T: ?Sized>(self, _: &T) -> Result<Self::Ok, Self::Error>
fn collect_str<T>(self, _: &T) -> Result<Self::Ok, Self::Error>
where
T: Display,
T: ?Sized + Display,
{
Err(self.bad_type(Unsupported::String))
}
@@ -364,9 +364,9 @@ mod content {
type Ok = M::Ok;
type Error = M::Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), M::Error>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), M::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
self.fields.push(value);
@@ -404,13 +404,9 @@ mod content {
type Ok = M::Ok;
type Error = M::Error;
fn serialize_field<T: ?Sized>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), M::Error>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), M::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
self.fields.push((key, value));
@@ -635,9 +631,9 @@ mod content {
Ok(Content::None)
}
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Content, E>
fn serialize_some<T>(self, value: &T) -> Result<Content, E>
where
T: Serialize,
T: ?Sized + Serialize,
{
Ok(Content::Some(Box::new(tri!(value.serialize(self)))))
}
@@ -659,13 +655,9 @@ mod content {
Ok(Content::UnitVariant(name, variant_index, variant))
}
fn serialize_newtype_struct<T: ?Sized>(
self,
name: &'static str,
value: &T,
) -> Result<Content, E>
fn serialize_newtype_struct<T>(self, name: &'static str, value: &T) -> Result<Content, E>
where
T: Serialize,
T: ?Sized + Serialize,
{
Ok(Content::NewtypeStruct(
name,
@@ -673,7 +665,7 @@ mod content {
))
}
fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
name: &'static str,
variant_index: u32,
@@ -681,7 +673,7 @@ mod content {
value: &T,
) -> Result<Content, E>
where
T: Serialize,
T: ?Sized + Serialize,
{
Ok(Content::NewtypeVariant(
name,
@@ -782,9 +774,9 @@ mod content {
type Ok = Content;
type Error = E;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
fn serialize_element<T>(&mut self, value: &T) -> Result<(), E>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.elements.push(value);
@@ -808,9 +800,9 @@ mod content {
type Ok = Content;
type Error = E;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
fn serialize_element<T>(&mut self, value: &T) -> Result<(), E>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.elements.push(value);
@@ -835,9 +827,9 @@ mod content {
type Ok = Content;
type Error = E;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), E>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.fields.push(value);
@@ -864,9 +856,9 @@ mod content {
type Ok = Content;
type Error = E;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), E>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.fields.push(value);
@@ -896,18 +888,18 @@ mod content {
type Ok = Content;
type Error = E;
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), E>
fn serialize_key<T>(&mut self, key: &T) -> Result<(), E>
where
T: Serialize,
T: ?Sized + Serialize,
{
let key = tri!(key.serialize(ContentSerializer::<E>::new()));
self.key = Some(key);
Ok(())
}
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), E>
fn serialize_value<T>(&mut self, value: &T) -> Result<(), E>
where
T: Serialize,
T: ?Sized + Serialize,
{
let key = self
.key
@@ -922,10 +914,10 @@ mod content {
Ok(Content::Map(self.entries))
}
fn serialize_entry<K: ?Sized, V: ?Sized>(&mut self, key: &K, value: &V) -> Result<(), E>
fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), E>
where
K: Serialize,
V: Serialize,
K: ?Sized + Serialize,
V: ?Sized + Serialize,
{
let key = tri!(key.serialize(ContentSerializer::<E>::new()));
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
@@ -947,9 +939,9 @@ mod content {
type Ok = Content;
type Error = E;
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), E>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), E>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.fields.push((key, value));
@@ -976,9 +968,9 @@ mod content {
type Ok = Content;
type Error = E;
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), E>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), E>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.fields.push((key, value));
@@ -1088,9 +1080,9 @@ where
Ok(())
}
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
value.serialize(self)
}
@@ -1112,18 +1104,18 @@ where
Err(Self::bad_type(Unsupported::Enum))
}
fn serialize_newtype_struct<T: ?Sized>(
fn serialize_newtype_struct<T>(
self,
_: &'static str,
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
value.serialize(self)
}
fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
_: &'static str,
_: u32,
@@ -1131,7 +1123,7 @@ where
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
tri!(self.0.serialize_key(variant));
self.0.serialize_value(value)
@@ -1202,28 +1194,24 @@ where
type Ok = ();
type Error = M::Error;
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
self.0.serialize_key(key)
}
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
self.0.serialize_value(value)
}
fn serialize_entry<K: ?Sized, V: ?Sized>(
&mut self,
key: &K,
value: &V,
) -> Result<(), Self::Error>
fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), Self::Error>
where
K: Serialize,
V: Serialize,
K: ?Sized + Serialize,
V: ?Sized + Serialize,
{
self.0.serialize_entry(key, value)
}
@@ -1244,13 +1232,9 @@ where
type Ok = ();
type Error = M::Error;
fn serialize_field<T: ?Sized>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
self.0.serialize_entry(key, value)
}
@@ -1289,9 +1273,9 @@ where
type Ok = ();
type Error = M::Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
self.fields.push(value);
@@ -1335,13 +1319,9 @@ where
type Ok = ();
type Error = M::Error;
fn serialize_field<T: ?Sized>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
self.fields.push((key, value));
+8 -8
View File
@@ -74,9 +74,9 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
Display::fmt(variant, self)
}
fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T) -> fmt::Result
fn serialize_newtype_struct<T>(self, _name: &'static str, value: &T) -> fmt::Result
where
T: Serialize,
T: ?Sized + Serialize,
{
Serialize::serialize(value, self)
}
@@ -89,9 +89,9 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
Err(fmt::Error)
}
fn serialize_some<T: ?Sized>(self, _value: &T) -> fmt::Result
fn serialize_some<T>(self, _value: &T) -> fmt::Result
where
T: Serialize,
T: ?Sized + Serialize,
{
Err(fmt::Error)
}
@@ -100,7 +100,7 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
Err(fmt::Error)
}
fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
_name: &'static str,
_variant_index: u32,
@@ -108,7 +108,7 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
_value: &T,
) -> fmt::Result
where
T: Serialize,
T: ?Sized + Serialize,
{
Err(fmt::Error)
}
@@ -161,9 +161,9 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
Err(fmt::Error)
}
fn collect_str<T: ?Sized>(self, value: &T) -> fmt::Result
fn collect_str<T>(self, value: &T) -> fmt::Result
where
T: Display,
T: ?Sized + Display,
{
Display::fmt(value, self)
}
+97 -62
View File
@@ -48,7 +48,7 @@ impl Serialize for str {
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl Serialize for String {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -71,7 +71,7 @@ impl<'a> Serialize for fmt::Arguments<'a> {
////////////////////////////////////////////////////////////////////////////////
#[cfg(any(feature = "std", not(no_core_cstr)))]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for CStr {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -83,7 +83,7 @@ impl Serialize for CStr {
}
#[cfg(any(feature = "std", all(not(no_core_cstr), feature = "alloc")))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
impl Serialize for CString {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -114,7 +114,10 @@ where
////////////////////////////////////////////////////////////////////////////////
impl<T: ?Sized> Serialize for PhantomData<T> {
impl<T> Serialize for PhantomData<T>
where
T: ?Sized,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -229,37 +232,37 @@ macro_rules! seq_impl {
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BinaryHeap<T: Ord>
}
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BTreeSet<T: Ord>
}
seq_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashSet<T: Eq + Hash, H: BuildHasher>
}
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
LinkedList<T>
}
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
Vec<T>
}
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
VecDeque<T>
}
@@ -368,7 +371,7 @@ impl Serialize for () {
}
#[cfg(feature = "unstable")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "unstable")))]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
impl Serialize for ! {
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
where
@@ -383,28 +386,46 @@ impl Serialize for ! {
macro_rules! tuple_impls {
($($len:expr => ($($n:tt $name:ident)+))+) => {
$(
#[cfg_attr(docsrs, doc(hidden))]
impl<$($name),+> Serialize for ($($name,)+)
where
$($name: Serialize,)+
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut tuple = tri!(serializer.serialize_tuple($len));
$(
tri!(tuple.serialize_element(&self.$n));
)+
tuple.end()
}
tuple_impl_body!($len => ($($n)+));
}
)+
}
};
}
macro_rules! tuple_impl_body {
($len:expr => ($($n:tt)+)) => {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut tuple = tri!(serializer.serialize_tuple($len));
$(
tri!(tuple.serialize_element(&self.$n));
)+
tuple.end()
}
};
}
#[cfg_attr(docsrs, doc(fake_variadic))]
#[cfg_attr(
docsrs,
doc = "This trait is implemented for tuples up to 16 items long."
)]
impl<T> Serialize for (T,)
where
T: Serialize,
{
tuple_impl_body!(1 => (0));
}
tuple_impls! {
1 => (0 T0)
2 => (0 T0 1 T1)
3 => (0 T0 1 T1 2 T2)
4 => (0 T0 1 T1 2 T2 3 T3)
@@ -473,13 +494,13 @@ macro_rules! map_impl {
map_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BTreeMap<K: Ord, V>
}
map_impl! {
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashMap<K: Eq + Hash, V, H: BuildHasher>
}
@@ -504,17 +525,17 @@ macro_rules! deref_impl {
}
deref_impl! {
<'a, T: ?Sized> Serialize for &'a T where T: Serialize
<'a, T> Serialize for &'a T where T: ?Sized + Serialize
}
deref_impl! {
<'a, T: ?Sized> Serialize for &'a mut T where T: Serialize
<'a, T> Serialize for &'a mut T where T: ?Sized + Serialize
}
deref_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
<T: ?Sized> Serialize for Box<T> where T: Serialize
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
<T> Serialize for Box<T> where T: ?Sized + Serialize
}
deref_impl! {
@@ -527,8 +548,8 @@ deref_impl! {
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
<T: ?Sized> Serialize for Rc<T> where T: Serialize
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
<T> Serialize for Rc<T> where T: ?Sized + Serialize
}
deref_impl! {
@@ -541,14 +562,14 @@ deref_impl! {
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
<T: ?Sized> Serialize for Arc<T> where T: Serialize
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
<T> Serialize for Arc<T> where T: ?Sized + Serialize
}
deref_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "alloc"))))]
<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
<'a, T> Serialize for Cow<'a, T> where T: ?Sized + Serialize + ToOwned
}
////////////////////////////////////////////////////////////////////////////////
@@ -558,12 +579,12 @@ deref_impl! {
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(
doc_cfg,
docsrs,
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
)]
impl<T: ?Sized> Serialize for RcWeak<T>
impl<T> Serialize for RcWeak<T>
where
T: Serialize,
T: ?Sized + Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -578,12 +599,12 @@ where
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(
doc_cfg,
docsrs,
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
)]
impl<T: ?Sized> Serialize for ArcWeak<T>
impl<T> Serialize for ArcWeak<T>
where
T: Serialize,
T: ?Sized + Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -641,9 +662,9 @@ where
}
}
impl<T: ?Sized> Serialize for RefCell<T>
impl<T> Serialize for RefCell<T>
where
T: Serialize,
T: ?Sized + Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -657,10 +678,10 @@ where
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
impl<T: ?Sized> Serialize for Mutex<T>
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<T> Serialize for Mutex<T>
where
T: Serialize,
T: ?Sized + Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -674,10 +695,10 @@ where
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
impl<T: ?Sized> Serialize for RwLock<T>
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<T> Serialize for RwLock<T>
where
T: Serialize,
T: ?Sized + Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -728,7 +749,7 @@ impl Serialize for Duration {
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for SystemTime {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -773,7 +794,7 @@ macro_rules! serialize_display_bounded_length {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for net::IpAddr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -844,7 +865,7 @@ fn test_format_u8() {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for net::Ipv4Addr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -869,7 +890,7 @@ impl Serialize for net::Ipv4Addr {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for net::Ipv6Addr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -886,7 +907,7 @@ impl Serialize for net::Ipv6Addr {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for net::SocketAddr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -911,7 +932,7 @@ impl Serialize for net::SocketAddr {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for net::SocketAddrV4 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -928,7 +949,7 @@ impl Serialize for net::SocketAddrV4 {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for net::SocketAddrV6 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -950,7 +971,7 @@ impl Serialize for net::SocketAddrV6 {
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for Path {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -964,7 +985,7 @@ impl Serialize for Path {
}
#[cfg(feature = "std")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for PathBuf {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -975,7 +996,7 @@ impl Serialize for PathBuf {
}
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
impl Serialize for OsStr {
#[cfg(unix)]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -998,7 +1019,7 @@ impl Serialize for OsStr {
}
#[cfg(all(feature = "std", any(unix, windows)))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", any(unix, windows)))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", any(unix, windows)))))]
impl Serialize for OsString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -1023,6 +1044,20 @@ where
}
}
#[cfg(not(no_core_num_saturating))]
impl<T> Serialize for Saturating<T>
where
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(serializer)
}
}
impl<T> Serialize for Reverse<T>
where
T: Serialize,
@@ -1043,7 +1078,7 @@ macro_rules! atomic_impl {
($($ty:ident $size:expr)*) => {
$(
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", target_has_atomic = $size))))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", target_has_atomic = $size))))]
impl Serialize for $ty {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
+16 -16
View File
@@ -72,9 +72,9 @@ where
type Ok = Ok;
type Error = Error;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let _ = value;
match self.void {}
@@ -92,9 +92,9 @@ where
type Ok = Ok;
type Error = Error;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let _ = value;
match self.void {}
@@ -112,9 +112,9 @@ where
type Ok = Ok;
type Error = Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let _ = value;
match self.void {}
@@ -132,9 +132,9 @@ where
type Ok = Ok;
type Error = Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let _ = value;
match self.void {}
@@ -152,17 +152,17 @@ where
type Ok = Ok;
type Error = Error;
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Error>
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let _ = key;
match self.void {}
}
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let _ = value;
match self.void {}
@@ -180,9 +180,9 @@ where
type Ok = Ok;
type Error = Error;
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let _ = key;
let _ = value;
@@ -201,9 +201,9 @@ where
type Ok = Ok;
type Error = Error;
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let _ = key;
let _ = value;
+46 -44
View File
@@ -61,8 +61,8 @@
//! - RefCell\<T\>
//! - Mutex\<T\>
//! - RwLock\<T\>
//! - Rc\<T\>&emsp;*(if* features = ["rc"] *is enabled)*
//! - Arc\<T\>&emsp;*(if* features = ["rc"] *is enabled)*
//! - Rc\<T\>&emsp;*(if* features = \["rc"\] *is enabled)*
//! - Arc\<T\>&emsp;*(if* features = \["rc"\] *is enabled)*
//! - **Collection types**:
//! - BTreeMap\<K, V\>
//! - BTreeSet\<T\>
@@ -215,6 +215,13 @@ declare_error_trait!(Error: Sized + Debug + Display);
/// [`linked-hash-map`]: https://crates.io/crates/linked-hash-map
/// [`serde_derive`]: https://crates.io/crates/serde_derive
/// [derive section of the manual]: https://serde.rs/derive.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
note = "for local types consider adding `#[derive(serde::Serialize)]` to your `{Self}` type",
note = "for types from other crates check whether the crate offers a `serde` feature flag",
)
)]
pub trait Serialize {
/// Serialize this value into the given Serde serializer.
///
@@ -796,9 +803,9 @@ pub trait Serializer: Sized {
/// ```
///
/// [`Some(T)`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.Some
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Serialize a `()` value.
///
@@ -891,13 +898,13 @@ pub trait Serializer: Sized {
/// }
/// }
/// ```
fn serialize_newtype_struct<T: ?Sized>(
fn serialize_newtype_struct<T>(
self,
name: &'static str,
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Serialize a newtype variant like `E::N` in `enum E { N(u8) }`.
///
@@ -925,7 +932,7 @@ pub trait Serializer: Sized {
/// }
/// }
/// ```
fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
name: &'static str,
variant_index: u32,
@@ -933,7 +940,7 @@ pub trait Serializer: Sized {
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Begin to serialize a variably sized sequence. This call must be
/// followed by zero or more calls to `serialize_element`, then a call to
@@ -1170,7 +1177,8 @@ pub trait Serializer: Sized {
/// then a call to `end`.
///
/// The `name` is the name of the struct and the `len` is the number of
/// data fields that will be serialized.
/// data fields that will be serialized. `len` does not include fields
/// which are skipped with [`SerializeStruct::skip_field`].
///
/// ```edition2021
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
@@ -1207,6 +1215,8 @@ pub trait Serializer: Sized {
/// The `name` is the name of the enum, the `variant_index` is the index of
/// this variant within the enum, the `variant` is the name of the variant,
/// and the `len` is the number of data fields that will be serialized.
/// `len` does not include fields which are skipped with
/// [`SerializeStructVariant::skip_field`].
///
/// ```edition2021
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
@@ -1346,9 +1356,9 @@ pub trait Serializer: Sized {
/// [`String`]: https://doc.rust-lang.org/std/string/struct.String.html
/// [`serialize_str`]: #tymethod.serialize_str
#[cfg(any(feature = "std", feature = "alloc"))]
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: Display,
T: ?Sized + Display,
{
self.serialize_str(&value.to_string())
}
@@ -1379,9 +1389,9 @@ pub trait Serializer: Sized {
/// }
/// ```
#[cfg(not(any(feature = "std", feature = "alloc")))]
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: Display;
T: ?Sized + Display;
/// Determine whether `Serialize` implementations should serialize in
/// human-readable form.
@@ -1493,9 +1503,9 @@ pub trait SerializeSeq {
type Error: Error;
/// Serialize a sequence element.
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Finish serializing a sequence.
fn end(self) -> Result<Self::Ok, Self::Error>;
@@ -1593,9 +1603,9 @@ pub trait SerializeTuple {
type Error: Error;
/// Serialize a tuple element.
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Finish serializing a tuple.
fn end(self) -> Result<Self::Ok, Self::Error>;
@@ -1638,9 +1648,9 @@ pub trait SerializeTupleStruct {
type Error: Error;
/// Serialize a tuple struct field.
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Finish serializing a tuple struct.
fn end(self) -> Result<Self::Ok, Self::Error>;
@@ -1696,9 +1706,9 @@ pub trait SerializeTupleVariant {
type Error: Error;
/// Serialize a tuple variant field.
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Finish serializing a tuple variant.
fn end(self) -> Result<Self::Ok, Self::Error>;
@@ -1767,9 +1777,9 @@ pub trait SerializeMap {
/// `serialize_entry` instead as it may be implemented more efficiently in
/// some formats compared to a pair of calls to `serialize_key` and
/// `serialize_value`.
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Serialize a map value.
///
@@ -1777,9 +1787,9 @@ pub trait SerializeMap {
///
/// Calling `serialize_value` before `serialize_key` is incorrect and is
/// allowed to panic or produce bogus results.
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Serialize a map entry consisting of a key and a value.
///
@@ -1798,14 +1808,10 @@ pub trait SerializeMap {
/// [`Serialize`]: ../trait.Serialize.html
/// [`serialize_key`]: #tymethod.serialize_key
/// [`serialize_value`]: #tymethod.serialize_value
fn serialize_entry<K: ?Sized, V: ?Sized>(
&mut self,
key: &K,
value: &V,
) -> Result<(), Self::Error>
fn serialize_entry<K, V>(&mut self, key: &K, value: &V) -> Result<(), Self::Error>
where
K: Serialize,
V: Serialize,
K: ?Sized + Serialize,
V: ?Sized + Serialize,
{
tri!(self.serialize_key(key));
self.serialize_value(value)
@@ -1856,15 +1862,13 @@ pub trait SerializeStruct {
type Error: Error;
/// Serialize a struct field.
fn serialize_field<T: ?Sized>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Indicate that a struct field has been skipped.
///
/// The default implementation does nothing.
#[inline]
fn skip_field(&mut self, key: &'static str) -> Result<(), Self::Error> {
let _ = key;
@@ -1922,15 +1926,13 @@ pub trait SerializeStructVariant {
type Error: Error;
/// Serialize a struct variant field.
fn serialize_field<T: ?Sized>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Indicate that a struct variant field has been skipped.
///
/// The default implementation does nothing.
#[inline]
fn skip_field(&mut self, key: &'static str) -> Result<(), Self::Error> {
let _ = key;
+6 -4
View File
@@ -1,10 +1,12 @@
[package]
name = "serde_derive"
version = "1.0.191"
version = "1.0.204"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
categories = ["no-std", "no-std::no-alloc"]
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
documentation = "https://serde.rs/derive.html"
edition = "2015"
exclude = ["build.rs"]
homepage = "https://serde.rs"
keywords = ["serde", "serialization", "no_std", "derive"]
license = "MIT OR Apache-2.0"
@@ -21,9 +23,9 @@ name = "serde_derive"
proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0.28"
proc-macro2 = { workspace = true, features = ["proc-macro"] }
quote = { workspace = true, features = ["proc-macro"] }
syn = { workspace = true, features = ["clone-impls", "derive", "parsing", "printing", "proc-macro"] }
[dev-dependencies]
serde = { version = "1", path = "../serde" }
+8
View File
@@ -0,0 +1,8 @@
fn main() {
// Warning: build.rs is not published to crates.io.
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-cfg=check_cfg");
println!("cargo:rustc-check-cfg=cfg(check_cfg)");
println!("cargo:rustc-check-cfg=cfg(exhaustive)");
}
+3 -6
View File
@@ -144,6 +144,7 @@ pub fn with_bound(
fn visit_type(&mut self, ty: &'ast syn::Type) {
match ty {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
syn::Type::Array(ty) => self.visit_type(&ty.elem),
syn::Type::BareFn(ty) => {
for arg in &ty.inputs {
@@ -181,7 +182,6 @@ pub fn with_bound(
syn::Type::Infer(_) | syn::Type::Never(_) | syn::Type::Verbatim(_) => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => {}
}
}
@@ -196,16 +196,13 @@ pub fn with_bound(
syn::PathArguments::AngleBracketed(arguments) => {
for arg in &arguments.args {
match arg {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
syn::GenericArgument::Type(arg) => self.visit_type(arg),
syn::GenericArgument::AssocType(arg) => self.visit_type(&arg.ty),
syn::GenericArgument::Lifetime(_)
| syn::GenericArgument::Const(_)
| syn::GenericArgument::AssocConst(_)
| syn::GenericArgument::Constraint(_) => {}
#[cfg_attr(
all(test, exhaustive),
deny(non_exhaustive_omitted_patterns)
)]
_ => {}
}
}
@@ -228,9 +225,9 @@ pub fn with_bound(
fn visit_type_param_bound(&mut self, bound: &'ast syn::TypeParamBound) {
match bound {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
syn::TypeParamBound::Trait(bound) => self.visit_path(&bound.path),
syn::TypeParamBound::Lifetime(_) | syn::TypeParamBound::Verbatim(_) => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => {}
}
}
+7 -4
View File
@@ -185,8 +185,8 @@ impl Name {
#[derive(Copy, Clone)]
pub struct RenameAllRules {
serialize: RenameRule,
deserialize: RenameRule,
pub serialize: RenameRule,
pub deserialize: RenameRule,
}
impl RenameAllRules {
@@ -1794,6 +1794,7 @@ fn borrowable_lifetimes(
fn collect_lifetimes(ty: &syn::Type, out: &mut BTreeSet<syn::Lifetime>) {
match ty {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
syn::Type::Slice(ty) => {
collect_lifetimes(&ty.elem, out);
}
@@ -1829,7 +1830,10 @@ fn collect_lifetimes(ty: &syn::Type, out: &mut BTreeSet<syn::Lifetime>) {
syn::GenericArgument::AssocType(binding) => {
collect_lifetimes(&binding.ty, out);
}
_ => {}
syn::GenericArgument::Const(_)
| syn::GenericArgument::AssocConst(_)
| syn::GenericArgument::Constraint(_)
| _ => {}
}
}
}
@@ -1851,7 +1855,6 @@ fn collect_lifetimes(ty: &syn::Type, out: &mut BTreeSet<syn::Lifetime>) {
| syn::Type::Infer(_)
| syn::Type::Verbatim(_) => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => {}
}
}
+3
View File
@@ -318,6 +318,9 @@ fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
for variant in variants {
match variant.style {
Style::Struct => {
if variant.attrs.untagged() {
continue;
}
for field in &variant.fields {
let check_ser =
!(field.attrs.skip_serializing() || variant.attrs.skip_serializing());
+5 -5
View File
@@ -84,7 +84,7 @@ impl ReplaceReceiver<'_> {
self.visit_type_mut_impl(ty);
return;
};
*ty = self.self_ty(span).into();
*ty = Type::Path(self.self_ty(span));
}
// `Self::Assoc` -> `<Receiver>::Assoc`
@@ -107,6 +107,7 @@ impl ReplaceReceiver<'_> {
fn visit_type_mut_impl(&mut self, ty: &mut Type) {
match ty {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Type::Array(ty) => {
self.visit_type_mut(&mut ty.elem);
self.visit_expr_mut(&mut ty.len);
@@ -147,7 +148,6 @@ impl ReplaceReceiver<'_> {
Type::Infer(_) | Type::Never(_) | Type::Verbatim(_) => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => {}
}
}
@@ -178,13 +178,13 @@ impl ReplaceReceiver<'_> {
PathArguments::AngleBracketed(arguments) => {
for arg in &mut arguments.args {
match arg {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
GenericArgument::Type(arg) => self.visit_type_mut(arg),
GenericArgument::AssocType(arg) => self.visit_type_mut(&mut arg.ty),
GenericArgument::Lifetime(_)
| GenericArgument::Const(_)
| GenericArgument::AssocConst(_)
| GenericArgument::Constraint(_) => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => {}
}
}
@@ -207,9 +207,9 @@ impl ReplaceReceiver<'_> {
fn visit_type_param_bound_mut(&mut self, bound: &mut TypeParamBound) {
match bound {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
TypeParamBound::Trait(bound) => self.visit_path_mut(&mut bound.path),
TypeParamBound::Lifetime(_) | TypeParamBound::Verbatim(_) => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => {}
}
}
@@ -228,6 +228,7 @@ impl ReplaceReceiver<'_> {
if let Some(where_clause) = &mut generics.where_clause {
for predicate in &mut where_clause.predicates {
match predicate {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
WherePredicate::Type(predicate) => {
self.visit_type_mut(&mut predicate.bounded_ty);
for bound in &mut predicate.bounds {
@@ -235,7 +236,6 @@ impl ReplaceReceiver<'_> {
}
}
WherePredicate::Lifetime(_) => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => {}
}
}
+2 -2
View File
@@ -13,7 +13,8 @@
//!
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.191")]
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.204")]
#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
// Ignored clippy lints
#![allow(
// clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7054
@@ -50,7 +51,6 @@
clippy::match_wildcard_for_single_variants,
clippy::module_name_repetitions,
clippy::must_use_candidate,
clippy::option_if_let_else,
clippy::similar_names,
clippy::single_match_else,
clippy::struct_excessive_bools,
+4 -4
View File
@@ -64,14 +64,14 @@ pub fn pretend_used(cont: &Container, is_packed: bool) -> TokenStream {
fn pretend_fields_used(cont: &Container, is_packed: bool) -> TokenStream {
match &cont.data {
Data::Enum(variants) => pretend_fields_used_enum(cont, variants),
Data::Struct(Style::Struct, fields) => {
Data::Struct(Style::Struct | Style::Tuple | Style::Newtype, fields) => {
if is_packed {
pretend_fields_used_struct_packed(cont, fields)
} else {
pretend_fields_used_struct(cont, fields)
}
}
Data::Struct(_, _) => quote!(),
Data::Struct(Style::Unit, _) => quote!(),
}
}
@@ -115,13 +115,13 @@ fn pretend_fields_used_enum(cont: &Container, variants: &[Variant]) -> TokenStre
let patterns = variants
.iter()
.filter_map(|variant| match variant.style {
Style::Struct => {
Style::Struct | Style::Tuple | Style::Newtype => {
let variant_ident = &variant.ident;
let members = variant.fields.iter().map(|field| &field.member);
let placeholders = (0usize..).map(|i| format_ident!("__v{}", i));
Some(quote!(#type_ident::#variant_ident { #(#members: #placeholders),* }))
}
_ => None,
Style::Unit => None,
})
.collect::<Vec<_>>();
+2 -2
View File
@@ -289,7 +289,7 @@ fn serialize_tuple_struct(
}
fn serialize_struct(params: &Parameters, fields: &[Field], cattrs: &attr::Container) -> Fragment {
assert!(fields.len() as u64 <= u64::from(u32::max_value()));
assert!(fields.len() as u64 <= u64::from(u32::MAX));
if cattrs.has_flatten() {
serialize_struct_as_map(params, fields, cattrs)
@@ -397,7 +397,7 @@ fn serialize_struct_as_map(
}
fn serialize_enum(params: &Parameters, variants: &[Variant], cattrs: &attr::Container) -> Fragment {
assert!(variants.len() as u64 <= u64::from(u32::max_value()));
assert!(variants.len() as u64 <= u64::from(u32::MAX));
let self_var = &params.self_var;
+5 -4
View File
@@ -1,9 +1,10 @@
[package]
name = "serde_derive_internals"
version = "0.29.0"
version = "0.29.1"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
description = "AST representation used by Serde derive macros. Unstable."
documentation = "https://docs.rs/serde_derive_internals"
edition = "2015"
exclude = ["build.rs"]
homepage = "https://serde.rs"
keywords = ["serde", "serialization"]
@@ -15,9 +16,9 @@ rust-version = "1.56"
path = "lib.rs"
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "2.0.28", default-features = false, features = ["clone-impls", "derive", "parsing", "printing"] }
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn = { workspace = true, features = ["clone-impls", "derive", "parsing", "printing"] }
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
+8
View File
@@ -1,9 +1,17 @@
use std::path::Path;
fn main() {
// Warning: build.rs is not published to crates.io.
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/mod.rs");
println!("cargo:rustc-cfg=check_cfg");
println!("cargo:rustc-check-cfg=cfg(check_cfg)");
println!("cargo:rustc-check-cfg=cfg(exhaustive)");
println!("cargo:rustc-check-cfg=cfg(serde_build_from_git)");
println!("cargo:rustc-check-cfg=cfg(feature, values(\"deserialize_in_place\"))");
// Sometimes on Windows the git checkout does not correctly wire up the
// symlink from serde_derive_internals/src to serde_derive/src/internals.
// When this happens we'll just build based on relative paths within the git
+2 -1
View File
@@ -1,4 +1,5 @@
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.29.0")]
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.29.1")]
#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
// Ignored clippy lints
#![allow(
clippy::cognitive_complexity,
+1 -1
View File
@@ -18,4 +18,4 @@ rustversion = "1.0"
serde = { path = "../serde", features = ["rc"] }
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
serde_test = "1.0.176"
trybuild = { version = "1.0.66", features = ["diff"] }
trybuild = { version = "1.0.97", features = ["diff"] }
+3 -3
View File
@@ -1,6 +1,6 @@
#[cfg_attr(target_os = "emscripten", ignore)]
#[rustversion::attr(not(nightly), ignore)]
#[cfg_attr(miri, ignore)]
#[cfg_attr(target_os = "emscripten", ignore = "disabled on Emscripten")]
#[rustversion::attr(not(nightly), ignore = "requires nightly")]
#[cfg_attr(miri, ignore = "incompatible with miri")]
#[allow(unused_attributes)]
#[test]
fn ui() {
+8
View File
@@ -7,7 +7,9 @@ pub struct Nested;
pub enum ExternallyTagged {
Flatten {
#[serde(flatten)]
#[allow(dead_code)]
nested: Nested,
#[allow(dead_code)]
string: &'static str,
},
}
@@ -17,7 +19,9 @@ pub enum ExternallyTagged {
pub enum InternallyTagged {
Flatten {
#[serde(flatten)]
#[allow(dead_code)]
nested: Nested,
#[allow(dead_code)]
string: &'static str,
},
}
@@ -27,7 +31,9 @@ pub enum InternallyTagged {
pub enum AdjacentlyTagged {
Flatten {
#[serde(flatten)]
#[allow(dead_code)]
nested: Nested,
#[allow(dead_code)]
string: &'static str,
},
}
@@ -37,7 +43,9 @@ pub enum AdjacentlyTagged {
pub enum UntaggedWorkaround {
Flatten {
#[serde(flatten)]
#[allow(dead_code)]
nested: Nested,
#[allow(dead_code)]
string: &'static str,
},
}
+78 -1
View File
@@ -23,7 +23,7 @@ use std::iter;
use std::net;
use std::num::{
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, Wrapping,
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, Saturating, Wrapping,
};
use std::ops::Bound;
use std::path::{Path, PathBuf};
@@ -1898,6 +1898,46 @@ fn test_range_inclusive() {
);
}
#[test]
fn test_range_from() {
test(
1u32..,
&[
Token::Struct {
name: "RangeFrom",
len: 1,
},
Token::Str("start"),
Token::U32(1),
Token::StructEnd,
],
);
test(
1u32..,
&[Token::Seq { len: Some(1) }, Token::U32(1), Token::SeqEnd],
);
}
#[test]
fn test_range_to() {
test(
..2u32,
&[
Token::Struct {
name: "RangeTo",
len: 1,
},
Token::Str("end"),
Token::U32(2),
Token::StructEnd,
],
);
test(
..2u32,
&[Token::Seq { len: Some(1) }, Token::U32(2), Token::SeqEnd],
);
}
#[test]
fn test_bound() {
test(
@@ -2025,6 +2065,43 @@ fn test_wrapping() {
test(Wrapping(1usize), &[Token::U64(1)]);
}
#[test]
fn test_saturating() {
test(Saturating(1usize), &[Token::U32(1)]);
test(Saturating(1usize), &[Token::U64(1)]);
test(Saturating(0u8), &[Token::I8(0)]);
test(Saturating(0u16), &[Token::I16(0)]);
// saturate input values at the minimum or maximum value
test(Saturating(u8::MAX), &[Token::U16(u16::MAX)]);
test(Saturating(u8::MAX), &[Token::U16(u8::MAX as u16 + 1)]);
test(Saturating(u16::MAX), &[Token::U32(u32::MAX)]);
test(Saturating(u32::MAX), &[Token::U64(u64::MAX)]);
test(Saturating(u8::MIN), &[Token::I8(i8::MIN)]);
test(Saturating(u16::MIN), &[Token::I16(i16::MIN)]);
test(Saturating(u32::MIN), &[Token::I32(i32::MIN)]);
test(Saturating(i8::MIN), &[Token::I16(i16::MIN)]);
test(Saturating(i16::MIN), &[Token::I32(i32::MIN)]);
test(Saturating(i32::MIN), &[Token::I64(i64::MIN)]);
test(Saturating(u8::MIN), &[Token::I8(-1)]);
test(Saturating(u16::MIN), &[Token::I16(-1)]);
#[cfg(target_pointer_width = "64")]
{
test(Saturating(usize::MIN), &[Token::U64(u64::MIN)]);
test(Saturating(usize::MAX), &[Token::U64(u64::MAX)]);
test(Saturating(isize::MIN), &[Token::I64(i64::MIN)]);
test(Saturating(isize::MAX), &[Token::I64(i64::MAX)]);
test(Saturating(0usize), &[Token::I64(i64::MIN)]);
test(
Saturating(9_223_372_036_854_775_807usize),
&[Token::I64(i64::MAX)],
);
}
}
#[test]
fn test_rc_dst() {
test(Rc::<str>::from("s"), &[Token::Str("s")]);
+14 -7
View File
@@ -1434,7 +1434,15 @@ fn test_number_from_string() {
fn test_integer_from_float() {
assert_de_tokens_error::<isize>(
&[Token::F32(0.0)],
"invalid type: floating point `0`, expected isize",
"invalid type: floating point `0.0`, expected isize",
);
}
#[test]
fn test_nan_no_decimal_point() {
assert_de_tokens_error::<isize>(
&[Token::F32(f32::NAN)],
"invalid type: floating point `NaN`, expected isize",
);
}
@@ -1459,7 +1467,7 @@ fn test_duration_overflow_seq() {
assert_de_tokens_error::<Duration>(
&[
Token::Seq { len: Some(2) },
Token::U64(u64::max_value()),
Token::U64(u64::MAX),
Token::U32(1_000_000_000),
Token::SeqEnd,
],
@@ -1476,7 +1484,7 @@ fn test_duration_overflow_struct() {
len: 2,
},
Token::Str("secs"),
Token::U64(u64::max_value()),
Token::U64(u64::MAX),
Token::Str("nanos"),
Token::U32(1_000_000_000),
Token::StructEnd,
@@ -1490,7 +1498,7 @@ fn test_systemtime_overflow_seq() {
assert_de_tokens_error::<SystemTime>(
&[
Token::Seq { len: Some(2) },
Token::U64(u64::max_value()),
Token::U64(u64::MAX),
Token::U32(1_000_000_000),
Token::SeqEnd,
],
@@ -1507,7 +1515,7 @@ fn test_systemtime_overflow_struct() {
len: 2,
},
Token::Str("secs_since_epoch"),
Token::U64(u64::max_value()),
Token::U64(u64::MAX),
Token::Str("nanos_since_epoch"),
Token::U32(1_000_000_000),
Token::StructEnd,
@@ -1516,13 +1524,12 @@ fn test_systemtime_overflow_struct() {
);
}
#[cfg(systemtime_checked_add)]
#[test]
fn test_systemtime_overflow() {
assert_de_tokens_error::<SystemTime>(
&[
Token::Seq { len: Some(2) },
Token::U64(u64::max_value()),
Token::U64(u64::MAX),
Token::U32(0),
Token::SeqEnd,
],
+14 -3
View File
@@ -422,6 +422,7 @@ fn test_gen() {
#[derive(Serialize, Deserialize)]
#[serde(remote = "Self")]
#[allow(dead_code)]
struct RemoteSelf;
#[derive(Serialize, Deserialize)]
@@ -686,9 +687,17 @@ fn test_gen() {
#[derive(Deserialize)]
#[serde(untagged)]
enum UntaggedWithBorrow<'a> {
Single(#[serde(borrow)] RelObject<'a>),
Many(#[serde(borrow)] Vec<RelObject<'a>>),
pub enum UntaggedWithBorrow<'a> {
Single(
#[serde(borrow)]
#[allow(dead_code)]
RelObject<'a>,
),
Many(
#[serde(borrow)]
#[allow(dead_code)]
Vec<RelObject<'a>>,
),
}
#[derive(Deserialize)]
@@ -730,6 +739,7 @@ fn test_gen() {
#[derive(Serialize)]
#[repr(packed)]
#[allow(dead_code)]
struct Packed {
x: u8,
y: u16,
@@ -761,6 +771,7 @@ fn test_gen() {
}
#[derive(Serialize)]
#[allow(dead_code)]
struct Struct {
#[serde(serialize_with = "vec_first_element")]
vec: Vec<Self>,
+113
View File
@@ -814,6 +814,100 @@ fn test_internally_tagged_enum() {
);
}
#[test]
fn test_internally_tagged_enum_with_untagged_variant() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind")]
enum InternallyTagged {
Tagged {
a: u8,
},
#[serde(untagged)]
Untagged {
kind: String,
b: u8,
},
}
assert_de_tokens(
&InternallyTagged::Tagged { a: 1 },
&[
Token::Map { len: Some(2) },
Token::Str("kind"),
Token::Str("Tagged"),
Token::Str("a"),
Token::U8(1),
Token::MapEnd,
],
);
assert_tokens(
&InternallyTagged::Tagged { a: 1 },
&[
Token::Struct {
name: "InternallyTagged",
len: 2,
},
Token::Str("kind"),
Token::Str("Tagged"),
Token::Str("a"),
Token::U8(1),
Token::StructEnd,
],
);
assert_de_tokens(
&InternallyTagged::Untagged {
kind: "Foo".to_owned(),
b: 2,
},
&[
Token::Map { len: Some(2) },
Token::Str("kind"),
Token::Str("Foo"),
Token::Str("b"),
Token::U8(2),
Token::MapEnd,
],
);
assert_tokens(
&InternallyTagged::Untagged {
kind: "Foo".to_owned(),
b: 2,
},
&[
Token::Struct {
name: "InternallyTagged",
len: 2,
},
Token::Str("kind"),
Token::Str("Foo"),
Token::Str("b"),
Token::U8(2),
Token::StructEnd,
],
);
assert_tokens(
&InternallyTagged::Untagged {
kind: "Tagged".to_owned(),
b: 2,
},
&[
Token::Struct {
name: "InternallyTagged",
len: 2,
},
Token::Str("kind"),
Token::Str("Tagged"),
Token::Str("b"),
Token::U8(2),
Token::StructEnd,
],
);
}
#[test]
fn test_internally_tagged_bytes() {
#[derive(Debug, PartialEq, Deserialize)]
@@ -987,6 +1081,15 @@ fn test_internally_tagged_struct_variant_containing_unit_variant() {
Log { level: Level },
}
assert_de_tokens(
&Level::Info,
&[
Token::Enum { name: "Level" },
Token::BorrowedStr("Info"),
Token::Unit,
],
);
assert_de_tokens(
&Message::Log { level: Level::Info },
&[
@@ -997,7 +1100,9 @@ fn test_internally_tagged_struct_variant_containing_unit_variant() {
Token::Str("action"),
Token::Str("Log"),
Token::Str("level"),
Token::Enum { name: "Level" },
Token::BorrowedStr("Info"),
Token::Unit,
Token::StructEnd,
],
);
@@ -1009,7 +1114,9 @@ fn test_internally_tagged_struct_variant_containing_unit_variant() {
Token::Str("action"),
Token::Str("Log"),
Token::Str("level"),
Token::Enum { name: "Level" },
Token::BorrowedStr("Info"),
Token::Unit,
Token::MapEnd,
],
);
@@ -1019,7 +1126,9 @@ fn test_internally_tagged_struct_variant_containing_unit_variant() {
&[
Token::Seq { len: Some(2) },
Token::Str("Log"),
Token::Enum { name: "Level" },
Token::BorrowedStr("Info"),
Token::Unit,
Token::SeqEnd,
],
);
@@ -2125,24 +2234,28 @@ fn test_internally_tagged_newtype_variant_containing_unit_struct() {
fn test_packed_struct_can_derive_serialize() {
#[derive(Copy, Clone, Serialize)]
#[repr(packed, C)]
#[allow(dead_code)]
struct PackedC {
t: f32,
}
#[derive(Copy, Clone, Serialize)]
#[repr(C, packed)]
#[allow(dead_code)]
struct CPacked {
t: f32,
}
#[derive(Copy, Clone, Serialize)]
#[repr(C, packed(2))]
#[allow(dead_code)]
struct CPacked2 {
t: f32,
}
#[derive(Copy, Clone, Serialize)]
#[repr(packed(2), C)]
#[allow(dead_code)]
struct Packed2C {
t: f32,
}
+38 -1
View File
@@ -8,7 +8,7 @@ use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::ffi::CString;
use std::net;
use std::num::Wrapping;
use std::num::{Saturating, Wrapping};
use std::ops::Bound;
use std::path::{Path, PathBuf};
use std::rc::{Rc, Weak as RcWeak};
@@ -500,6 +500,38 @@ fn test_range_inclusive() {
);
}
#[test]
fn test_range_from() {
assert_ser_tokens(
&(1u32..),
&[
Token::Struct {
name: "RangeFrom",
len: 1,
},
Token::Str("start"),
Token::U32(1),
Token::StructEnd,
],
);
}
#[test]
fn test_range_to() {
assert_ser_tokens(
&(..2u32),
&[
Token::Struct {
name: "RangeTo",
len: 1,
},
Token::Str("end"),
Token::U32(2),
Token::StructEnd,
],
);
}
#[test]
fn test_bound() {
assert_ser_tokens(
@@ -592,6 +624,11 @@ fn test_wrapping() {
assert_ser_tokens(&Wrapping(1usize), &[Token::U64(1)]);
}
#[test]
fn test_saturating() {
assert_ser_tokens(&Saturating(1usize), &[Token::U64(1)]);
}
#[test]
fn test_rc_dst() {
assert_ser_tokens(&Rc::<str>::from("s"), &[Token::Str("s")]);
+4 -2
View File
@@ -27,19 +27,21 @@ mod fake_serde {
{
}
#[allow(dead_code)]
pub trait Serialize {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>;
}
#[allow(dead_code)]
pub trait Deserialize<'a>: Sized {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error>;
}
}
trait AssertNotSerdeSerialize {}
pub trait AssertNotSerdeSerialize {}
impl<T: serde::Serialize> AssertNotSerdeSerialize for T {}
trait AssertNotSerdeDeserialize<'a> {}
pub trait AssertNotSerdeDeserialize<'a> {}
impl<'a, T: serde::Deserialize<'a>> AssertNotSerdeDeserialize<'a> for T {}
+1 -1
View File
@@ -63,7 +63,7 @@ fn test_map_access_to_enum() {
type Value = Potential;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "a map")
formatter.write_str("a map")
}
fn visit_map<A>(self, map: A) -> Result<Self::Value, A::Error>
+23
View File
@@ -0,0 +1,23 @@
use serde::de::Deserialize;
use serde::ser::Serialize;
fn to_string<T>(_: &T) -> String
where
T: Serialize,
{
unimplemented!()
}
fn from_str<'de, T>(_: &'de str) -> T
where
T: Deserialize<'de>,
{
unimplemented!()
}
struct MyStruct;
fn main() {
to_string(&MyStruct);
let _: MyStruct = from_str("");
}
@@ -0,0 +1,55 @@
error[E0277]: the trait bound `MyStruct: Serialize` is not satisfied
--> tests/ui/on_unimplemented.rs:21:15
|
21 | to_string(&MyStruct);
| --------- ^^^^^^^^^ the trait `Serialize` is not implemented for `MyStruct`
| |
| required by a bound introduced by this call
|
= note: for local types consider adding `#[derive(serde::Serialize)]` to your `MyStruct` type
= note: for types from other crates check whether the crate offers a `serde` feature flag
= help: the following other types implement trait `Serialize`:
&'a T
&'a mut T
()
(T,)
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
(T0, T1, T2, T3, T4)
and $N others
note: required by a bound in `to_string`
--> tests/ui/on_unimplemented.rs:6:8
|
4 | fn to_string<T>(_: &T) -> String
| --------- required by a bound in this function
5 | where
6 | T: Serialize,
| ^^^^^^^^^ required by this bound in `to_string`
error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied
--> tests/ui/on_unimplemented.rs:22:23
|
22 | let _: MyStruct = from_str("");
| ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct`
|
= note: for local types consider adding `#[derive(serde::Deserialize)]` to your `MyStruct` type
= note: for types from other crates check whether the crate offers a `serde` feature flag
= help: the following other types implement trait `Deserialize<'de>`:
&'a Path
&'a [u8]
&'a str
()
(T,)
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
and $N others
note: required by a bound in `from_str`
--> tests/ui/on_unimplemented.rs:13:8
|
11 | fn from_str<'de, T>(_: &'de str) -> T
| -------- required by a bound in this function
12 | where
13 | T: Deserialize<'de>,
| ^^^^^^^^^^^^^^^^ required by this bound in `from_str`
@@ -3,6 +3,11 @@ error[E0609]: no field `b` on type `&remote::S`
|
12 | b: u8,
| ^ unknown field
|
help: a field with a similar name exists
|
12 | a: u8,
| ~
error[E0560]: struct `remote::S` has no field named `b`
--> tests/ui/remote/unknown_field.rs:12:5
@@ -12,7 +12,3 @@ note: tuple struct defined here
4 | pub struct S(pub u16);
| ^
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you can convert a `u8` to a `u16`
|
7 | #[derive(Deserialize.into())]
| +++++++