Compare commits

...

640 Commits

Author SHA1 Message Date
David Tolnay 1799547846 Release 1.0.226 2025-09-20 16:34:44 -07:00
David Tolnay 2dbeefb11b Merge pull request #2935 from Mingun/dedupe-adj-enums
Remove code duplication when deriving Deserialize for adjacently tagged enums
2025-09-20 16:33:32 -07:00
David Tolnay 8a3c29ff19 Merge pull request #2986 from dtolnay/didnotwork
Remove "did not work" comment from test suite
2025-09-20 12:30:39 -07:00
David Tolnay defc24d361 Remove "did not work" comment from test suite 2025-09-20 12:23:01 -07:00
Oli Scherer 2316610760 Merge pull request #2929 from Mingun/flatten-enum-tests
Add more tests for flatten enums to increase test coverage
2025-09-18 13:15:10 +00:00
Mingun c09e2bd690 Add tests for flatten unit variant in adjacently tagged (tag + content) enums 2025-09-17 23:53:07 +05:00
Mingun fe7dcc4cd8 Test all possible orders of map entries for enum-flatten-in-struct representations 2025-09-17 23:51:30 +05:00
Mingun a20e66e131 Check serialization in flatten::enum_::internally_tagged::unit_enum_with_unknown_fields 2025-09-17 23:50:00 +05:00
Mingun 1c1a5d95cd Reorder struct_ and newtype tests of adjacently_tagged enums to match order in Enum 2025-09-17 23:48:23 +05:00
David Tolnay ee3c2372fb Opt in to generate-macro-expansion when building on docs.rs 2025-09-16 16:29:21 -07:00
Mingun bfb020d975 Use variant name for field instead of field 2025-09-17 00:09:51 +05:00
Mingun 6805bba308 Inline variables that used only once 2025-09-17 00:09:14 +05:00
Mingun 2659b94a62 Create deserializer only when needed 2025-09-17 00:08:07 +05:00
Mingun c451415d9f Do not duplicate variant deserialization code 2025-09-17 00:07:00 +05:00
Mingun 553a9ff15f Document functions that are entry points for generating bodies of different deserialization forms 2025-09-17 00:05:53 +05:00
David Tolnay 6f5eb7d207 Merge pull request #2983 from Mingun/fix-test-instructions
Fix instructions for testing contributions
2025-09-16 09:24:04 -07:00
Mingun 55615e8f8e Fix instructions for testing contributions
Since separation of serde_core from serde, all doctests lives in serde_core project,
which also does not have the `derive` feature. Following the old instructions does not
run any tests.
2025-09-16 21:15:49 +05:00
David Tolnay 1d7899d671 Release 1.0.225 2025-09-15 20:43:08 -07:00
David Tolnay 97168d3a24 Touch up PR 2879 2025-09-15 20:38:57 -07:00
David Tolnay 373b11dda7 Merge pull request 2879 from rcrisanti/fix/silence-deprecation-warnings-derive 2025-09-15 20:26:40 -07:00
David Tolnay 69072f2423 Merge pull request 2931 from Mingun/unify-serde-access 2025-09-15 13:22:24 -07:00
David Tolnay 5b37e8a531 Merge pull request #2980 from dtolnay/private
Use differently named __private module per patch release
2025-09-15 13:20:54 -07:00
Mingun b47f4dfa96 Unify access to the serde namespace
In other places `_serde` name is used to access the `serde` crate, so use it there
2025-09-16 00:36:12 +05:00
David Tolnay cbe98a9888 Use differently named __private module per patch release 2025-09-15 09:53:14 -07:00
David Tolnay 957996f5fb Make all use of __private go through interpolation 2025-09-15 09:48:26 -07:00
David Tolnay 169988206a Release 1.0.224 2025-09-15 08:46:21 -07:00
David Tolnay 840f6ec9b8 Merge pull request #2979 from dtolnay/private
Mark every trait impl for a private type with do_not_recommend
2025-09-15 08:45:06 -07:00
David Tolnay bf9ebea392 Mark every trait impl for a private type with do_not_recommend 2025-09-14 19:47:36 -07:00
David Tolnay 6c316d7cb5 Release 1.0.223 2025-09-14 13:20:31 -07:00
David Tolnay a4ac0c2bc6 Merge pull request #2978 from dtolnay/htmlrooturl
Change serde_core's html_root_url to docs.rs/serde_core
2025-09-14 13:19:52 -07:00
David Tolnay ed76364f87 Change serde_core's html_root_url to docs.rs/serde_core 2025-09-14 12:54:38 -07:00
David Tolnay 57e21a1afa Release 1.0.222 2025-09-14 11:09:08 -07:00
David Tolnay bb58726133 Merge pull request #2950 from aytey/fix_lifetime_issue_2024
Fix temporary value lifetime in `serialize_struct`
2025-09-14 11:08:16 -07:00
David Tolnay 3f6925125b Delete unneeded field of MapDeserializer 2025-09-14 08:39:57 -07:00
David Tolnay fd4decf2fe Merge pull request #2976 from dtolnay/content
Move Content's Deserialize impl from serde_core to serde
2025-09-14 08:39:46 -07:00
David Tolnay 00b1b6b2b5 Move Content's Deserialize impl from serde_core to serde 2025-09-14 08:35:53 -07:00
David Tolnay cf141aa8c7 Move Content's Clone impl from serde_core to serde 2025-09-14 08:35:32 -07:00
David Tolnay ff3aee490a Release 1.0.221 2025-09-13 17:25:20 -07:00
David Tolnay 10bcfc0047 Merge pull request #2975 from dtolnay/integer128
Deprecate serde_if_integer128 macro
2025-09-13 17:25:14 -07:00
David Tolnay 2f03899197 Deprecate serde_if_integer128 macro 2025-09-13 17:19:10 -07:00
David Tolnay 3bea3b6989 Move serde_if_integer128 macro to serde 2025-09-13 17:12:58 -07:00
David Tolnay 85bf29c446 Merge pull request #2973 from dtolnay/timings
Illustrate build timings in serde_core readme
2025-09-13 17:12:51 -07:00
David Tolnay 900c922f41 Illustrate build timings in serde_core readme 2025-09-13 17:09:47 -07:00
David Tolnay 9cf3f2ed7d Merge pull request #2974 from dtolnay/patchserdecore
Patch serde_core at workspace level
2025-09-13 17:04:36 -07:00
David Tolnay 1ffbeb9516 Patch serde_core at workspace level 2025-09-13 16:59:44 -07:00
David Tolnay 1051c5e6b7 Enforce trybuild >= 1.0.108
Older versions produce slightly differently normalized output
when run against 1.90.0+ Rust compiler.
2025-09-13 14:49:14 -07:00
David Tolnay be255d62c8 Release 1.0.220 2025-09-13 14:45:43 -07:00
David Tolnay 263a1dbdd7 Link to serde.rs without trailing slash 2025-09-13 14:40:22 -07:00
David Tolnay 23dea60e1a Merge pull request #2971 from dtolnay/serdecoreci
Add CI coverage of serde_core
2025-09-13 14:40:13 -07:00
David Tolnay 690785f129 Add CI coverage of serde_core 2025-09-13 14:36:11 -07:00
David Tolnay 69aa109fd3 Merge pull request #2970 from dtolnay/coredoctest
Fix serde_core doc tests
2025-09-13 14:36:00 -07:00
David Tolnay 6bea2e04e4 Move doc helper macros to serde_core 2025-09-13 14:32:21 -07:00
David Tolnay a1a82c3c55 Replace serde_core::* glob export 2025-09-13 14:32:21 -07:00
David Tolnay 7987ad700e Fix serde_core doc tests 2025-09-13 14:32:21 -07:00
David Tolnay 0990d97a77 Merge pull request #2969 from dtolnay/coreprivate
Reduce visibility of serde_core implementation details
2025-09-13 14:32:12 -07:00
David Tolnay a9150aad74 Make serde_core::Result private 2025-09-13 14:29:23 -07:00
David Tolnay 5ac3d84d99 Make InPlaceSeed private 2025-09-13 14:29:23 -07:00
David Tolnay f916ec6baa Make size_hint private 2025-09-13 14:29:22 -07:00
David Tolnay 7f831225a9 Make from_utf8_lossy private 2025-09-13 14:29:01 -07:00
David Tolnay a16893429b Make module for Content-related private code 2025-09-13 14:26:58 -07:00
David Tolnay 260511d149 Merge pull request #2968 from dtolnay/deserializecontent
Restore `__deserialize_content` optimization
2025-09-13 14:26:50 -07:00
David Tolnay 7659fb686d Inline SeqDeserializer and MapDeserializer for Content
Greatly shrinks symbol sizes: keep all those generic type parameters
(and even closures) out of symbol names. A good change even independent
of serde_core.
2025-09-13 14:22:33 -07:00
David Tolnay f669f16127 Restore __deserialize_content optimization 2025-09-13 14:22:33 -07:00
David Tolnay 93f43cedaa Merge pull request #2967 from dtolnay/tricfg
Specify the cfg in which `tri!` is used
2025-09-13 14:22:25 -07:00
David Tolnay b6c7ce8ec3 Specify the cfg in which 'tri!' is used 2025-09-13 14:19:07 -07:00
David Tolnay 35c963101b Merge pull request #2966 from dtolnay/noserdecore
Enforce derive cannot be used against serde_core
2025-09-13 14:19:01 -07:00
David Tolnay 8909fc0c60 Enforce derive cannot be used against serde_core
Even for a simple data structure that would ordinarily expand to an impl
that only refers to the public Serde traits without serde::__private, we
still disallow a (renamed) serde_core dependency. This leaves the
liberty to new usage of private helpers in such impls over time. For
example, similar to the optimization of the standard library's
derive(Debug) that introduced debug_struct_field1_finish to improve
compile time of derived impls.
2025-09-13 14:15:44 -07:00
David Tolnay 3c747e4585 Relocate serde_derive version constraint from serde to serde_core
This disallows using an old version of serde_derive against a new
version of serde_core (with a rename to serde in Cargo.toml).
2025-09-13 14:15:44 -07:00
David Tolnay 1b89ff50a9 Merge pull request #2965 from dtolnay/enableresult
Forcibly enable serde_core/result when using serde
2025-09-13 14:15:38 -07:00
David Tolnay c069b5c640 Forcibly enable serde_core/result when using serde
Making Result impls get disabled when using `serde = { version = "1",
default-features = false }` would have been a breaking change.
2025-09-13 14:11:44 -07:00
David Tolnay 79f3484ab8 Merge pull request #2964 from dtolnay/serdecoredoc
Update documentation of serde_core
2025-09-13 14:11:33 -07:00
David Tolnay ac8b7ea052 Update serde_core package.description in Cargo.toml 2025-09-13 14:07:54 -07:00
David Tolnay c1b2f43917 Tweak explanation of "result" feature 2025-09-13 14:07:54 -07:00
David Tolnay 51f8b0c52d Rewrite serde_core readme 2025-09-13 14:07:53 -07:00
David Tolnay 6c4cae6b09 Point API documentation to docs.rs/serde 2025-09-13 14:07:53 -07:00
David Tolnay 4da055a286 Fix broken link in serde_core crates.io readme 2025-09-13 14:07:53 -07:00
David Tolnay 66c5d2b153 Merge pull request #2963 from dtolnay/diagnosticpath
Override diagnostic::on_unimplemented message for all serde_core traits
2025-09-13 14:07:43 -07:00
David Tolnay 4bddf1b953 Override diagnostic::on_unimplemented message of all serde_core traits
This prevents diagnostics being rendered like `serde_core::ser::Serialize`
and `serde_core::de::Deserialize` in projects that have no direct
dependency on serde_core.

The attributes make error messages arguably sometimes worse than
pre-serde_core by always rendering `serde::Serialize` and never
`Serialize` when `use serde::Serialize` is in scope, which rustc's
default message construction knows to recognize. But this is probably
negligible.

I explored the alternative of setting `[lib] name = "serde"` in
serde_core/Cargo.toml which also prevents `serde_core::ser::Serialize`
in messages, but has the unwanted effect of also inserting the following
noise into every such error:

    note: there are multiple different versions of crate `serde` in the dependency graph
        --> $WORKSPACE/serde_core/src/ser/mod.rs:225:1
         |
     225 | pub trait Serialize {
         | ^^^^^^^^^^^^^^^^^^^ this is the required trait
         |
        ::: src/main.rs:1:1
         |
       1 | struct MyStruct;
         | --------------- this type doesn't implement the required trait
    ...
       4 |     let _ = serde_json::to_string(&MyStruct);
         |             ----------
         |             |
         |             one version of crate `serde` used here, as a dependency of crate `serde`
         |             one version of crate `serde` used here, as a dependency of crate `serde_json`
         |
        ::: $WORKSPACE/serde/src/private/de.rs:2347:1
         |
    2347 | pub trait IdentifierDeserializer<'de, E: Error> {
         | ----------------------------------------------- this is the found trait
         = help: you can use `cargo tree` to explore your dependency tree

The "this is the found trait" pointing to `IdentifierDeserializer` seems
like a compiler bug...
2025-09-13 13:59:52 -07:00
David Tolnay 908f32175a Add ui test of unimplemented trait required by dependency 2025-09-13 13:59:52 -07:00
David Tolnay 3e1cf11060 Organize on_unimplemented ui test into directory 2025-09-13 13:59:52 -07:00
David Tolnay 723fcacad7 Merge pull request #2608 from osiewicz/extract_serde_core
feat: Extract serde_core out of serde crate
2025-09-13 13:59:17 -07:00
David Tolnay 94acfe19e6 Format with rustfmt 1.8.0-nightly 2025-09-13 10:16:16 -07:00
Oli Scherer b4677fde9d Bump outdated test dependency 2025-08-26 08:02:38 +00:00
Oli Scherer c85e4240be Allow more dead code 2025-08-26 07:19:59 +00:00
Oli Scherer 363deb84cc Work around dead code warnings 2025-08-26 07:10:49 +00:00
Andrew V. Teylu 106da4905f Fix temporary value lifetime in serialize_struct
In the 2024 edition of Rust, `serde`s macros for `serialize_with` can
lead to a temporary lifetime error such as:

```
error[E0716]: temporary value dropped while borrowed
 --> my-binary/src/main.rs:6:10
  |
6 | #[derive(MyDerive)]
  |          ^^^^^^^-
  |          |      |
  |          |      temporary value is freed at the end of this statement
  |          creates a temporary value which is freed while still in use
  |          borrow later used by call
  |          in this derive macro expansion
  |
 ::: /private/tmp/life/my-project/my-macro/src/lib.rs:6:1
  |
6 | pub fn my_derive(_input: TokenStream) -> TokenStream {
  | ---------------------------------------------------- in this expansion of `#[derive(MyDerive)]`
  |
  = note: consider using a `let` binding to create a longer lived value
```

This is because the macro code takes a reference to struct inside of a
block, which then goes out of scope when `serde` passes it to a
function.

To resolve this, we move the reference to outside of the block, to
ensure that the lifetime extends into the function call.

Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
2025-08-01 10:03:16 +01:00
Piotr Osiewicz f9baf39dc3 review: Update crates-io.md 2025-06-06 12:15:59 +02:00
Piotr Osiewicz 3deb08946e review: Gate Result impls behind a feature gate 2025-06-06 11:57:32 +02:00
Piotr Osiewicz 43f5eb5c69 review: Bring back old doc comment for serde_core 2025-06-06 11:57:32 +02:00
Piotr Osiewicz 5fcfbed3ea review: Update license symlinks 2025-06-06 11:57:32 +02:00
Piotr Osiewicz f3869307cc feat: extract serde_core out of serde 2025-06-06 11:57:32 +02:00
Oli Scherer babafa54d2 Merge pull request #2939 from Mingun/remove-actually-private
Remove `actually_private::T`
2025-06-06 06:39:39 +00:00
Mingun ad6c548573 Use associated type in signature to not repeat concrete type 2025-06-06 10:39:51 +05:00
Mingun 80b2f5f9e1 Remove actually_private::T
It just makes life harder in some cases without any benefits
2025-06-06 10:39:51 +05:00
David Tolnay 2130ba5788 Ignore mismatched_lifetime_syntaxes lint
warning: lifetime flowing from input to output with different syntax can be confusing
       --> serde/src/private/de.rs:266:23
        |
    266 |         fn unexpected(&self) -> Unexpected {
        |                       ^^^^^     ---------- the lifetime gets resolved as `'_`
        |                       |
        |                       this lifetime flows to the output
        |
        = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
    help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
        |
    266 |         fn unexpected(&self) -> Unexpected<'_> {
        |                                           ++++

    warning: lifetime flowing from input to output with different syntax can be confusing
      --> serde/src/private/mod.rs:27:35
       |
    27 |     pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
       |                                   ^^^^^     -------- the lifetime gets resolved as `'_`
       |                                   |
       |                                   this lifetime flows to the output
       |
    help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
       |
    27 |     pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<'_, str> {
       |                                                 +++

    warning: lifetime flowing from input to output with different syntax can be confusing
       --> serde_derive/src/internals/attr.rs:612:23
        |
    612 |     pub fn serde_path(&self) -> Cow<syn::Path> {
        |                       ^^^^^     -------------- the lifetime gets resolved as `'_`
        |                       |
        |                       this lifetime flows to the output
        |
        = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
    help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
        |
    612 |     pub fn serde_path(&self) -> Cow<'_, syn::Path> {
        |                                     +++

    warning: lifetime flowing from input to output with different syntax can be confusing
      --> serde_derive/src/internals/case.rs:45:37
       |
    45 |     pub fn from_str(rename_all_str: &str) -> Result<Self, ParseError> {
       |                                     ^^^^                  ---------- the lifetime gets resolved as `'_`
       |                                     |
       |                                     this lifetime flows to the output
       |
    help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
       |
    45 |     pub fn from_str(rename_all_str: &str) -> Result<Self, ParseError<'_>> {
       |                                                                     ++++

    warning: lifetime flowing from input to output with different syntax can be confusing
        --> serde_derive/src/de.rs:3228:13
         |
    3228 |     params: &Parameters,
         |             ^^^^^^^^^^^ this lifetime flows to the output
    3229 | ) -> (
    3230 |     DeImplGenerics,
         |     -------------- the lifetimes get resolved as `'_`
    3231 |     DeTypeGenerics,
         |     -------------- the lifetimes get resolved as `'_`
    3232 |     syn::TypeGenerics,
         |     ----------------- the lifetimes get resolved as `'_`
    3233 |     Option<&syn::WhereClause>,
         |            ----------------- the lifetimes get resolved as `'_`
         |
    help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
         |
    3230 ~     DeImplGenerics<'_>,
    3231 ~     DeTypeGenerics<'_>,
    3232 ~     syn::TypeGenerics<'_>,
         |
2025-06-05 22:11:48 -07:00
David Tolnay a1ddb18c92 Resolve new dead_code warnings in test suite
Bisects to https://github.com/rust-lang/rust/pull/141407.

    warning: struct `Struct` is never constructed
       --> test_suite/tests/test_gen.rs:803:16
        |
    803 |     pub struct Struct {
        |                ^^^^^^
        |
        = note: `#[warn(dead_code)]` on by default

    warning: function `vec_first_element` is never used
       --> test_suite/tests/test_gen.rs:885:4
        |
    885 | fn vec_first_element<T, S>(vec: &[T], serializer: S) -> StdResult<S::Ok, S::Error>
        |    ^^^^^^^^^^^^^^^^^

    warning: struct `S` is never constructed
     --> test_suite/tests/regression/issue2415.rs:5:12
      |
    5 | pub struct S;
      |            ^
      |
      = note: `#[warn(dead_code)]` on by default
2025-05-31 10:09:26 -07:00
Ryan Crisanti ae38b27aee add #[allow(deprecated)] to derive implementations
Allow deprecated in the `Serialize`/`Deserialize`
derive implementations. This allows you to
deprecate structs, enums, struct fields, or enum
variants and not get compiler warnings/errors
about use of deprecated thing. We only do this
if `#[deprecated]` or `#[allow(deprecated)]` exist
on the root object or the variants of the root
object (if it is an enum).

Resolves #2195
2025-05-30 15:01:14 -04:00
David Tolnay da3998acfb Pin nightly toolchain used for miri job 2025-05-17 23:14:01 +02:00
Oli Scherer b9de3658ad Merge pull request #2919 from vishal-kr-barnwal/master
Update a Rust edition to 2021 across project files
2025-04-27 08:13:10 +00:00
Vishal Kumar 16af2d9ce7 Update a Rust edition to 2021 across project files
Updated the Cargo.toml files for test suites and a link in the README to use Rust edition 2021 instead of 2018. This ensures compatibility with the latest Rust features and standards.
2025-04-27 12:31:12 +05:30
David Tolnay b426ff81e3 Merge pull request #2913 from dtolnay/nightlywindows
Drop trailing whitespace from CI job name
2025-03-26 09:24:38 +00:00
David Tolnay b0e87aeecd Drop trailing whitespace from CI job name 2025-03-26 02:19:55 -07:00
David Tolnay a685dcf680 Merge pull request #2910 from jimmycathy/master
chore: fix the incorrect symbol
2025-03-16 00:05:43 -07:00
jimmycathy 88da17ca21 chore: fix the incorrect symbol
Signed-off-by: jimmycathy <clonecode@outlook.com>
2025-03-16 13:42:10 +08:00
David Tolnay d91f8ba950 Drop unused no_float_copysign cfg
Stable since Rust 1.35.
2025-03-09 12:39:05 -07:00
David Tolnay aa5aa611d4 Touch up PR 2901 2025-03-09 12:37:59 -07:00
David Tolnay da0b473d60 Merge pull request #2901 from serde-rs/msrv-and-edition-bump
MSRV (1.56) and edition (2021) bump
2025-03-09 15:37:44 -04:00
David Tolnay 49d098debd Release 1.0.219 2025-03-09 12:05:01 -07:00
David Tolnay 40f1d19dbe Wrap dummy.rs to 80 columns 2025-03-09 12:04:24 -07:00
David Tolnay 514848b584 Merge pull request #2906 from davidzeng0/master
fix clippy absolute paths warning
2025-03-09 15:03:19 -04:00
ilikdoge 168b6cf789 fix clippy absolute paths warning 2025-03-08 22:25:23 -08:00
Oli Scherer 8b0e95b6de clippy 2025-03-05 10:07:07 +00:00
Oli Scherer e3a4165363 Switch all crates to edition 2021 2025-03-05 09:51:32 +00:00
Oli Scherer 6ac8049b92 clippy 2025-03-05 09:58:12 +00:00
Oli Scherer 13a33b3c33 Bump MSRV to 1.56
This is the first cargo version that actually enforces the rust-version field in Cargo.toml
2025-03-05 09:23:29 +00:00
David Tolnay a8bdd17333 Remove unused Punctuated import
warning: unused import: `syn::punctuated::Punctuated`
     --> serde_derive/src/internals/receiver.rs:5:5
      |
    5 | use syn::punctuated::Punctuated;
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = note: `#[warn(unused_imports)]` on by default

Left by the previous commit.

-        let segments = mem::replace(&mut path.segments, Punctuated::new());
+        let segments = mem::take(&mut path.segments);
2025-03-03 00:05:40 -08:00
David Tolnay 1c9601358b Resolve mem_replace_with_default clippy lint
warning: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
      --> serde_derive/src/internals/receiver.rs:52:24
       |
    52 |         let segments = mem::replace(&mut path.segments, Punctuated::new());
       |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut path.segments)`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default
       = note: `-W clippy::mem-replace-with-default` implied by `-W clippy::all`
       = help: to override `-W clippy::all` add `#[allow(clippy::mem_replace_with_default)]`
2025-03-03 00:00:24 -08:00
David Tolnay f0d1ae08f3 Ignore elidable_lifetime_names pedantic clippy lint
warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:124:6
        |
    124 | impl<'de, E> IntoDeserializer<'de, E> for ()
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
        = note: `-W clippy::elidable-lifetime-names` implied by `-W clippy::pedantic`
        = help: to override `-W clippy::pedantic` add `#[allow(clippy::elidable_lifetime_names)]`
    help: elide the lifetimes
        |
    124 - impl<'de, E> IntoDeserializer<'de, E> for ()
    124 + impl<E> IntoDeserializer<'_, E> for ()
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:178:6
        |
    178 | impl<'de, E> IntoDeserializer<'de, E> for UnitDeserializer<E>
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    178 - impl<'de, E> IntoDeserializer<'de, E> for UnitDeserializer<E>
    178 + impl<E> IntoDeserializer<'_, E> for UnitDeserializer<E>
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:207:6
        |
    207 | impl<'de, E> IntoDeserializer<'de, E> for !
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    207 - impl<'de, E> IntoDeserializer<'de, E> for !
    207 + impl<E> IntoDeserializer<'_, E> for !
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:240:6
        |
    240 | impl<'de, E> IntoDeserializer<'de, E> for NeverDeserializer<E>
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    240 - impl<'de, E> IntoDeserializer<'de, E> for NeverDeserializer<E>
    240 + impl<E> IntoDeserializer<'_, E> for NeverDeserializer<E>
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:351:6
        |
    351 | impl<'de, E> IntoDeserializer<'de, E> for u32
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    351 - impl<'de, E> IntoDeserializer<'de, E> for u32
    351 + impl<E> IntoDeserializer<'_, E> for u32
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:406:6
        |
    406 | impl<'de, E> IntoDeserializer<'de, E> for U32Deserializer<E>
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    406 - impl<'de, E> IntoDeserializer<'de, E> for U32Deserializer<E>
    406 + impl<E> IntoDeserializer<'_, E> for U32Deserializer<E>
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:451:6
        |
    451 | impl<'de, 'a, E> IntoDeserializer<'de, E> for &'a str
        |      ^^^                          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    451 - impl<'de, 'a, E> IntoDeserializer<'de, E> for &'a str
    451 + impl<'a, E> IntoDeserializer<'_, E> for &'a str
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:472:11
        |
    472 | impl<'de, 'a, E> de::Deserializer<'de> for StrDeserializer<'a, E>
        |           ^^                                               ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    472 - impl<'de, 'a, E> de::Deserializer<'de> for StrDeserializer<'a, E>
    472 + impl<'de, E> de::Deserializer<'de> for StrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'de, 'a
       --> serde/src/de/value.rs:506:6
        |
    506 | impl<'de, 'a, E> IntoDeserializer<'de, E> for StrDeserializer<'a, E>
        |      ^^^  ^^                      ^^^                         ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    506 - impl<'de, 'a, E> IntoDeserializer<'de, E> for StrDeserializer<'a, E>
    506 + impl<E> IntoDeserializer<'_, E> for StrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:517:11
        |
    517 | impl<'de, 'a, E> de::EnumAccess<'de> for StrDeserializer<'a, E>
        |           ^^                                             ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    517 - impl<'de, 'a, E> de::EnumAccess<'de> for StrDeserializer<'a, E>
    517 + impl<'de, E> de::EnumAccess<'de> for StrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:532:6
        |
    532 | impl<'a, E> Debug for StrDeserializer<'a, E> {
        |      ^^                               ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    532 - impl<'a, E> Debug for StrDeserializer<'a, E> {
    532 + impl<E> Debug for StrDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:622:6
        |
    622 | impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
        |      ^^^                                       ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    622 - impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
    622 + impl<E> Debug for BorrowedStrDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:653:6
        |
    653 | impl<'de, E> IntoDeserializer<'de, E> for String
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    653 - impl<'de, E> IntoDeserializer<'de, E> for String
    653 + impl<E> IntoDeserializer<'_, E> for String
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:711:6
        |
    711 | impl<'de, E> IntoDeserializer<'de, E> for StringDeserializer<E>
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    711 - impl<'de, E> IntoDeserializer<'de, E> for StringDeserializer<E>
    711 + impl<E> IntoDeserializer<'_, E> for StringDeserializer<E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:759:6
        |
    759 | impl<'a, E> Clone for CowStrDeserializer<'a, E> {
        |      ^^                                  ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    759 - impl<'a, E> Clone for CowStrDeserializer<'a, E> {
    759 + impl<E> Clone for CowStrDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:770:6
        |
    770 | impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>
        |      ^^^                          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    770 - impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>
    770 + impl<'a, E> IntoDeserializer<'_, E> for Cow<'a, str>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:793:11
        |
    793 | impl<'de, 'a, E> de::Deserializer<'de> for CowStrDeserializer<'a, E>
        |           ^^                                                  ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    793 - impl<'de, 'a, E> de::Deserializer<'de> for CowStrDeserializer<'a, E>
    793 + impl<'de, E> de::Deserializer<'de> for CowStrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'de, 'a
       --> serde/src/de/value.rs:831:6
        |
    831 | impl<'de, 'a, E> IntoDeserializer<'de, E> for CowStrDeserializer<'a, E>
        |      ^^^  ^^                      ^^^                            ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    831 - impl<'de, 'a, E> IntoDeserializer<'de, E> for CowStrDeserializer<'a, E>
    831 + impl<E> IntoDeserializer<'_, E> for CowStrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:843:11
        |
    843 | impl<'de, 'a, E> de::EnumAccess<'de> for CowStrDeserializer<'a, E>
        |           ^^                                                ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    843 - impl<'de, 'a, E> de::EnumAccess<'de> for CowStrDeserializer<'a, E>
    843 + impl<'de, E> de::EnumAccess<'de> for CowStrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:859:6
        |
    859 | impl<'a, E> Debug for CowStrDeserializer<'a, E> {
        |      ^^                                  ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    859 - impl<'a, E> Debug for CowStrDeserializer<'a, E> {
    859 + impl<E> Debug for CowStrDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:888:6
        |
    888 | impl<'de, 'a, E> IntoDeserializer<'de, E> for &'a [u8]
        |      ^^^                          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    888 - impl<'de, 'a, E> IntoDeserializer<'de, E> for &'a [u8]
    888 + impl<'a, E> IntoDeserializer<'_, E> for &'a [u8]
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:899:11
        |
    899 | impl<'de, 'a, E> Deserializer<'de> for BytesDeserializer<'a, E>
        |           ^^                                             ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    899 - impl<'de, 'a, E> Deserializer<'de> for BytesDeserializer<'a, E>
    899 + impl<'de, E> Deserializer<'de> for BytesDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'de, 'a
       --> serde/src/de/value.rs:919:6
        |
    919 | impl<'de, 'a, E> IntoDeserializer<'de, E> for BytesDeserializer<'a, E>
        |      ^^^  ^^                      ^^^                           ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    919 - impl<'de, 'a, E> IntoDeserializer<'de, E> for BytesDeserializer<'a, E>
    919 + impl<E> IntoDeserializer<'_, E> for BytesDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:930:6
        |
    930 | impl<'a, E> Debug for BytesDeserializer<'a, E> {
        |      ^^                                 ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    930 - impl<'a, E> Debug for BytesDeserializer<'a, E> {
    930 + impl<E> Debug for BytesDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:989:6
        |
    989 | impl<'de, E> Debug for BorrowedBytesDeserializer<'de, E> {
        |      ^^^                                         ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    989 - impl<'de, E> Debug for BorrowedBytesDeserializer<'de, E> {
    989 + impl<E> Debug for BorrowedBytesDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1238:6
         |
    1238 | impl<'de, I, E> MapDeserializer<'de, I, E>
         |      ^^^                        ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1238 - impl<'de, I, E> MapDeserializer<'de, I, E>
    1238 + impl<I, E> MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1255:6
         |
    1255 | impl<'de, I, E> MapDeserializer<'de, I, E>
         |      ^^^                        ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1255 - impl<'de, I, E> MapDeserializer<'de, I, E>
    1255 + impl<I, E> MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1278:6
         |
    1278 | impl<'de, I, E> MapDeserializer<'de, I, E>
         |      ^^^                        ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1278 - impl<'de, I, E> MapDeserializer<'de, I, E>
    1278 + impl<I, E> MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1439:6
         |
    1439 | impl<'de, I, E> Clone for MapDeserializer<'de, I, E>
         |      ^^^                                  ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1439 - impl<'de, I, E> Clone for MapDeserializer<'de, I, E>
    1439 + impl<I, E> Clone for MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1456:6
         |
    1456 | impl<'de, I, E> Debug for MapDeserializer<'de, I, E>
         |      ^^^                                  ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1456 - impl<'de, I, E> Debug for MapDeserializer<'de, I, E>
    1456 + impl<I, E> Debug for MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
      --> serde/src/de/impls.rs:17:6
       |
    17 | impl<'de> Visitor<'de> for UnitVisitor {
       |      ^^^          ^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
       |
    17 - impl<'de> Visitor<'de> for UnitVisitor {
    17 + impl Visitor<'_> for UnitVisitor {
       |

    warning: the following explicit lifetimes could be elided: 'de
      --> serde/src/de/impls.rs:56:6
       |
    56 | impl<'de> Visitor<'de> for BoolVisitor {
       |      ^^^          ^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
       |
    56 - impl<'de> Visitor<'de> for BoolVisitor {
    56 + impl Visitor<'_> for BoolVisitor {
       |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/impls.rs:550:6
        |
    550 | impl<'de> Visitor<'de> for CharVisitor {
        |      ^^^          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    550 - impl<'de> Visitor<'de> for CharVisitor {
    550 + impl Visitor<'_> for CharVisitor {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/impls.rs:596:6
        |
    596 | impl<'de> Visitor<'de> for StringVisitor {
        |      ^^^          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    596 - impl<'de> Visitor<'de> for StringVisitor {
    596 + impl Visitor<'_> for StringVisitor {
        |

    warning: the following explicit lifetimes could be elided: 'a, 'de
       --> serde/src/de/impls.rs:642:6
        |
    642 | impl<'a, 'de> Visitor<'de> for StringInPlaceVisitor<'a> {
        |      ^^  ^^^          ^^^                           ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    642 - impl<'a, 'de> Visitor<'de> for StringInPlaceVisitor<'a> {
    642 + impl Visitor<'_> for StringInPlaceVisitor<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/impls.rs:953:6
        |
    953 | impl<'de, T> Visitor<'de> for PhantomDataVisitor<T>
        |      ^^^             ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    953 - impl<'de, T> Visitor<'de> for PhantomDataVisitor<T>
    953 + impl<T> Visitor<'_> for PhantomDataVisitor<T>
        |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/de/impls.rs:1195:14
         |
    1195 |         impl<'a, 'de, T> Visitor<'de> for VecInPlaceVisitor<'a, T>
         |              ^^                                             ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1195 -         impl<'a, 'de, T> Visitor<'de> for VecInPlaceVisitor<'a, T>
    1195 +         impl<'de, T> Visitor<'de> for VecInPlaceVisitor<'_, T>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:1838:6
         |
    1838 | impl<'de> Visitor<'de> for PathBufVisitor {
         |      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1838 - impl<'de> Visitor<'de> for PathBufVisitor {
    1838 + impl Visitor<'_> for PathBufVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/de/impls.rs:1991:11
         |
    1991 | impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
         |           ^^                              ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1991 - impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
    1991 + impl<'de, T> Deserialize<'de> for Cow<'_, T>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2161:22
         |
    2161 |                 impl<'de> Visitor<'de> for FieldVisitor {
         |                      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2161 -                 impl<'de> Visitor<'de> for FieldVisitor {
    2161 +                 impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2300:22
         |
    2300 |                 impl<'de> Visitor<'de> for FieldVisitor {
         |                      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2300 -                 impl<'de> Visitor<'de> for FieldVisitor {
    2300 +                 impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2501:18
         |
    2501 |             impl<'de> Visitor<'de> for FieldVisitor {
         |                  ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2501 -             impl<'de> Visitor<'de> for FieldVisitor {
    2501 +             impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2658:18
         |
    2658 |             impl<'de> Visitor<'de> for FieldVisitor {
         |                  ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2658 -             impl<'de> Visitor<'de> for FieldVisitor {
    2658 +             impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2796:18
         |
    2796 |             impl<'de> Visitor<'de> for FieldVisitor {
         |                  ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2796 -             impl<'de> Visitor<'de> for FieldVisitor {
    2796 +             impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2907:22
         |
    2907 |                 impl<'de> Visitor<'de> for FieldVisitor {
         |                      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2907 -                 impl<'de> Visitor<'de> for FieldVisitor {
    2907 +                 impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:3018:22
         |
    3018 |                 impl<'de> Visitor<'de> for FieldVisitor {
         |                      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    3018 -                 impl<'de> Visitor<'de> for FieldVisitor {
    3018 +                 impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:3166:6
         |
    3166 | impl<'de, T> Visitor<'de> for FromStrVisitor<T>
         |      ^^^             ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    3166 - impl<'de, T> Visitor<'de> for FromStrVisitor<T>
    3166 + impl<T> Visitor<'_> for FromStrVisitor<T>
         |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/mod.rs:397:6
        |
    397 | impl<'a> fmt::Display for Unexpected<'a> {
        |      ^^                              ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    397 - impl<'a> fmt::Display for Unexpected<'a> {
    397 + impl fmt::Display for Unexpected<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'f, 'a
        --> serde/src/de/mod.rs:2309:14
         |
    2309 |         impl<'f, 'a> fmt::Write for LookForDecimalPoint<'f, 'a> {
         |              ^^  ^^                                     ^^  ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2309 -         impl<'f, 'a> fmt::Write for LookForDecimalPoint<'f, 'a> {
    2309 +         impl fmt::Write for LookForDecimalPoint<'_, '_> {
         |

    warning: the following explicit lifetimes could be elided: 'a
      --> serde/src/ser/fmt.rs:38:6
       |
    38 | impl<'a> Serializer for &mut fmt::Formatter<'a> {
       |      ^^                                     ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
       |
    38 - impl<'a> Serializer for &mut fmt::Formatter<'a> {
    38 + impl Serializer for &mut fmt::Formatter<'_> {
       |

    warning: the following explicit lifetimes could be elided: 'a
      --> serde/src/ser/impls.rs:62:6
       |
    62 | impl<'a> Serialize for fmt::Arguments<'a> {
       |      ^^                               ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
       |
    62 - impl<'a> Serialize for fmt::Arguments<'a> {
    62 + impl Serialize for fmt::Arguments<'_> {
       |

    warning: the following explicit lifetimes could be elided: 'a
      --> serde/src/format.rs:20:6
       |
    20 | impl<'a> Write for Buf<'a> {
       |      ^^                ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
       |
    20 - impl<'a> Write for Buf<'a> {
    20 + impl Write for Buf<'_> {
       |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/private/de.rs:254:10
        |
    254 |     impl<'de> Content<'de> {
        |          ^^^          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    254 -     impl<'de> Content<'de> {
    254 +     impl Content<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/private/de.rs:333:10
        |
    333 |     impl<'de> ContentVisitor<'de> {
        |          ^^^                 ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    333 -     impl<'de> ContentVisitor<'de> {
    333 +     impl ContentVisitor<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/private/de.rs:553:10
        |
    553 |     impl<'de> TagOrContentVisitor<'de> {
        |          ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    553 -     impl<'de> TagOrContentVisitor<'de> {
    553 +     impl TagOrContentVisitor<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/private/de.rs:937:10
        |
    937 |     impl<'de> Visitor<'de> for TagOrContentFieldVisitor {
        |          ^^^          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
        |
    937 -     impl<'de> Visitor<'de> for TagOrContentFieldVisitor {
    937 +     impl Visitor<'_> for TagOrContentFieldVisitor {
        |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/private/de.rs:1014:10
         |
    1014 |     impl<'de> Visitor<'de> for TagContentOtherFieldVisitor {
         |          ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1014 -     impl<'de> Visitor<'de> for TagContentOtherFieldVisitor {
    1014 +     impl Visitor<'_> for TagContentOtherFieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:1652:10
         |
    1652 |     impl<'a, 'de, E> ContentRefDeserializer<'a, 'de, E>
         |          ^^                                 ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1652 -     impl<'a, 'de, E> ContentRefDeserializer<'a, 'de, E>
    1652 +     impl<'de, E> ContentRefDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:1735:15
         |
    1735 |     impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, 'de, E>
         |               ^^                                                  ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    1735 -     impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, 'de, E>
    1735 +     impl<'de, E> Deserializer<'de> for ContentRefDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2162:15
         |
    2162 |     impl<'de, 'a, E> de::VariantAccess<'de> for VariantRefDeserializer<'a, 'de, E>
         |               ^^                                                       ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2162 -     impl<'de, 'a, E> de::VariantAccess<'de> for VariantRefDeserializer<'a, 'de, E>
    2162 +     impl<'de, E> de::VariantAccess<'de> for VariantRefDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2259:15
         |
    2259 |     impl<'de, 'a, E> de::IntoDeserializer<'de, E> for ContentRefDeserializer<'a, 'de, E>
         |               ^^                                                             ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2259 -     impl<'de, 'a, E> de::IntoDeserializer<'de, E> for ContentRefDeserializer<'a, 'de, E>
    2259 +     impl<'de, E> de::IntoDeserializer<'de, E> for ContentRefDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2288:15
         |
    2288 |     impl<'de, 'a> Visitor<'de> for InternallyTaggedUnitVisitor<'a> {
         |               ^^                                               ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2288 -     impl<'de, 'a> Visitor<'de> for InternallyTaggedUnitVisitor<'a> {
    2288 +     impl<'de> Visitor<'de> for InternallyTaggedUnitVisitor<'_> {
         |

    warning: the following explicit lifetimes could be elided: 'de, 'a
        --> serde/src/private/de.rs:2333:10
         |
    2333 |     impl<'de, 'a> Visitor<'de> for UntaggedUnitVisitor<'a> {
         |          ^^^  ^^          ^^^                          ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2333 -     impl<'de, 'a> Visitor<'de> for UntaggedUnitVisitor<'a> {
    2333 +     impl Visitor<'_> for UntaggedUnitVisitor<'_> {
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2396:11
         |
    2396 | impl<'de, 'a, E> Deserializer<'de> for StrDeserializer<'a, E>
         |           ^^                                           ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2396 - impl<'de, 'a, E> Deserializer<'de> for StrDeserializer<'a, E>
    2396 + impl<'de, E> Deserializer<'de> for StrDeserializer<'_, E>
         |

    warning: the following explicit lifetimes could be elided: 'a, 'de
        --> serde/src/private/de.rs:2498:6
         |
    2498 | impl<'a, 'de, E> FlatMapDeserializer<'a, 'de, E>
         |      ^^  ^^^                         ^^  ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2498 - impl<'a, 'de, E> FlatMapDeserializer<'a, 'de, E>
    2498 + impl<E> FlatMapDeserializer<'_, '_, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2522:6
         |
    2522 | impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
         |      ^^                                                    ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2522 - impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
    2522 + impl<'de, E> Deserializer<'de> for FlatMapDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2658:6
         |
    2658 | impl<'a, 'de, E> MapAccess<'de> for FlatMapAccess<'a, 'de, E>
         |      ^^                                           ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2658 - impl<'a, 'de, E> MapAccess<'de> for FlatMapAccess<'a, 'de, E>
    2658 + impl<'de, E> MapAccess<'de> for FlatMapAccess<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2702:6
         |
    2702 | impl<'a, 'de, E> MapAccess<'de> for FlatStructAccess<'a, 'de, E>
         |      ^^                                              ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    2702 - impl<'a, 'de, E> MapAccess<'de> for FlatStructAccess<'a, 'de, E>
    2702 + impl<'de, E> MapAccess<'de> for FlatStructAccess<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
     --> serde/src/de/seed.rs:8:6
      |
    8 | impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>
      |      ^^                                               ^^
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
      |
    8 - impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>
    8 + impl<'de, T> DeserializeSeed<'de> for InPlaceSeed<'_, T>
      |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde_derive/src/internals/case.rs:124:6
        |
    124 | impl<'a> Display for ParseError<'a> {
        |      ^^                         ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
        = note: `-W clippy::elidable-lifetime-names` implied by `-W clippy::pedantic`
        = help: to override `-W clippy::pedantic` add `#[allow(clippy::elidable_lifetime_names)]`
    help: elide the lifetimes
        |
    124 - impl<'a> Display for ParseError<'a> {
    124 + impl Display for ParseError<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde_derive/src/de.rs:3109:6
         |
    3109 | impl<'a> ToTokens for DeImplGenerics<'a> {
         |      ^^                              ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    3109 - impl<'a> ToTokens for DeImplGenerics<'a> {
    3109 + impl ToTokens for DeImplGenerics<'_> {
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde_derive/src/de.rs:3191:6
         |
    3191 | impl<'a> ToTokens for DeTypeGenerics<'a> {
         |      ^^                              ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
    help: elide the lifetimes
         |
    3191 - impl<'a> ToTokens for DeTypeGenerics<'a> {
    3191 + impl ToTokens for DeTypeGenerics<'_> {
         |

    warning: the following explicit lifetimes could be elided: 'a
      --> test_suite/tests/test_serde_path.rs:16:10
       |
    16 |     impl<'a> AssertNotSerdeDeserialize<'a> for Foo {}
       |          ^^                            ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names
       = note: `-W clippy::elidable-lifetime-names` implied by `-W clippy::pedantic`
       = help: to override `-W clippy::pedantic` add `#[allow(clippy::elidable_lifetime_names)]`
    help: elide the lifetimes
       |
    16 -     impl<'a> AssertNotSerdeDeserialize<'a> for Foo {}
    16 +     impl AssertNotSerdeDeserialize<'_> for Foo {}
       |
2025-03-03 00:00:21 -08:00
David Tolnay e3eaa6a3dd Merge pull request #2896 from dtolnay/stabledoc
Also link to stable proc_macro
2025-02-20 05:30:47 +00:00
David Tolnay 6a630cf283 Also link to stable proc_macro 2025-02-19 21:26:32 -08:00
David Tolnay 7bfd518dd4 Release 1.0.218 2025-02-19 21:20:03 -08:00
David Tolnay 723a9491e2 Merge pull request #2895 from dtolnay/stabledoc
Point standard library links to stable
2025-02-20 05:14:52 +00:00
David Tolnay 2b44efb085 Point standard library links to stable 2025-02-19 21:08:50 -08:00
David Tolnay 03dc0fc137 Merge pull request #2894 from dtolnay/doclink
Convert html links to intra-doc links
2025-02-20 05:01:07 +00:00
David Tolnay 85cb0c478e Convert html links to intra-doc links 2025-02-19 20:51:41 -08:00
David Tolnay abe7194480 Update ui test suite to nightly-2025-02-12 2025-02-11 18:19:51 -08:00
David Tolnay aaccac7413 Unset doc-scrape-examples for lib target
False is the default value since Cargo PR 11499.
2025-02-09 17:52:36 -08:00
David Tolnay 7cd4d84cac Update ui test suite to nightly-2025-02-07 2025-02-06 19:35:51 -08:00
David Tolnay 04ff3e8f95 More precise gitignore patterns 2025-01-23 01:41:05 -08:00
David Tolnay dc3031b614 Remove *.sw[po] from gitignore
This belongs in someone's global gitignore.
2025-01-22 19:36:55 -08:00
David Tolnay 1e2f931d0c Remove **/*.rs.bk from project-specific gitignore
Cargo stopped generating this in its project template 5 years ago. It
would belong in a global gitignore instead.
2025-01-22 19:30:32 -08:00
David Tolnay 930401b0dd Release 1.0.217 2024-12-27 12:41:22 -08:00
Mingun cb6eaea151 Fix roundtrip inconsistency:
- deserialization of flatten unit variant is possible
- serialization of such variant gives Err("can only flatten structs and maps (got an enum)")
2024-12-27 08:21:07 +00:00
David Tolnay b6f339ca36 Resolve repr_packed_without_abi clippy lint in tests
warning: item uses `packed` representation without ABI-qualification
       --> test_suite/tests/test_gen.rs:774:5
        |
    772 |       #[repr(packed)]
        |              ------ `packed` representation set here
    773 |       #[allow(dead_code)]
    774 | /     struct Packed {
    775 | |         x: u8,
    776 | |         y: u16,
    777 | |     }
        | |_____^
        |
        = warning: unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI
        = help: qualify the desired ABI explicity via `#[repr(C, packed)]` or `#[repr(Rust, packed)]`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#repr_packed_without_abi
    note: the lint level is defined here
       --> test_suite/tests/test_gen.rs:5:9
        |
    5   | #![deny(warnings)]
        |         ^^^^^^^^
        = note: `#[warn(clippy::repr_packed_without_abi)]` implied by `#[warn(warnings)]`

    warning: item uses `packed` representation without ABI-qualification
       --> test_suite/tests/test_gen.rs:919:1
        |
    918 |   #[repr(packed)]
        |          ------ `packed` representation set here
    919 | / pub struct RemotePacked {
    920 | |     pub a: u16,
    921 | |     pub b: u32,
    922 | | }
        | |_^
        |
        = warning: unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI
        = help: qualify the desired ABI explicity via `#[repr(C, packed)]` or `#[repr(Rust, packed)]`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#repr_packed_without_abi

    warning: item uses `packed` representation without ABI-qualification
       --> test_suite/tests/test_gen.rs:927:1
        |
    925 |   #[repr(packed)]
        |          ------ `packed` representation set here
    926 |   #[serde(remote = "RemotePacked")]
    927 | / pub struct RemotePackedDef {
    928 | |     a: u16,
    929 | |     b: u32,
    930 | | }
        | |_^
        |
        = warning: unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI
        = help: qualify the desired ABI explicity via `#[repr(C, packed)]` or `#[repr(Rust, packed)]`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#repr_packed_without_abi

    warning: item uses `packed` representation without ABI-qualification
       --> test_suite/tests/test_gen.rs:937:1
        |
    936 |   #[repr(packed)]
        |          ------ `packed` representation set here
    937 | / pub struct RemotePackedNonCopy {
    938 | |     pub a: u16,
    939 | |     pub b: String,
    940 | | }
        | |_^
        |
        = warning: unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI
        = help: qualify the desired ABI explicity via `#[repr(C, packed)]` or `#[repr(Rust, packed)]`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#repr_packed_without_abi

    warning: item uses `packed` representation without ABI-qualification
       --> test_suite/tests/test_gen.rs:945:1
        |
    943 |   #[repr(packed)]
        |          ------ `packed` representation set here
    944 |   #[serde(remote = "RemotePackedNonCopy")]
    945 | / pub struct RemotePackedNonCopyDef {
    946 | |     a: u16,
    947 | |     b: String,
    948 | | }
        | |_^
        |
        = warning: unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI
        = help: qualify the desired ABI explicity via `#[repr(C, packed)]` or `#[repr(Rust, packed)]`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#repr_packed_without_abi
2024-12-26 18:33:33 -08:00
David Tolnay 2a5caea1a8 Merge pull request #2872 from dtolnay/ehpersonality
Drop #[lang = "eh_personality"] from no-std test
2024-12-20 04:33:24 -08:00
David Tolnay b9f93f99aa Add no-std CI on stable compiler 2024-12-20 04:30:14 -08:00
David Tolnay eb5cd476ba Drop #[lang = "eh_personality"] from no-std test 2024-12-20 04:28:35 -08:00
David Tolnay 8478a3b7dd Merge pull request #2871 from dtolnay/nostdstart
Replace #[start] with extern fn main
2024-12-20 04:28:27 -08:00
David Tolnay dbb909136e Replace #[start] with extern fn main 2024-12-20 04:20:26 -08:00
David Tolnay ad8dd4148b Release 1.0.216 2024-12-10 18:05:39 -08:00
David Tolnay f91d2ed9ae Merge pull request #2868 from dtolnay/automaticallyderived
Mark all generated trait impls as #[automatically_derived]
2024-12-10 18:04:42 -08:00
David Tolnay 9497463718 Mark all generated trait impls as #[automatically_derived] 2024-12-10 17:57:05 -08:00
Oli Scherer 46e9ecfcdd Merge pull request #2866 from tdittr/mark-visitors-as-generated
Mark generated `impl de::Visitor` blocks as `#[automatically_derived]`
2024-12-09 11:58:24 +01:00
Tamme Dittrich e9c399c822 Mark generated impl de::Visitor blocks as #[automatically_derived]
This hides the generated visitors and field visitors from code
coverage.
2024-12-05 17:26:13 +01:00
David Tolnay b9dbfcb4ac Switch out fnv in favor of foldhash in test 2024-11-16 12:24:05 -08:00
David Tolnay c270e27a4d Use BuildHasher instead of Hasher in collection macros 2024-11-16 12:23:34 -08:00
David Tolnay 0307f604ea Resolve question_mark clippy lint in build script
warning: this `match` expression can be replaced with `?`
       --> serde/build.rs:111:17
        |
    111 |       let rustc = match env::var_os("RUSTC") {
        |  _________________^
    112 | |         Some(rustc) => rustc,
    113 | |         None => return None,
    114 | |     };
        | |_____^ help: try instead: `env::var_os("RUSTC")?`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
        = note: `-W clippy::question-mark` implied by `-W clippy::all`
        = help: to override `-W clippy::all` add `#[allow(clippy::question_mark)]`

    warning: this `match` expression can be replaced with `?`
       --> serde/build.rs:131:16
        |
    131 |       let next = match pieces.next() {
        |  ________________^
    132 | |         Some(next) => next,
    133 | |         None => return None,
    134 | |     };
        | |_____^ help: try instead: `pieces.next()?`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
2024-11-15 18:57:00 -08:00
David Tolnay 8939af48fe Release 1.0.215 2024-11-11 13:03:35 -08:00
David Tolnay fa5d58cd00 Use ui test syntax that does not interfere with rustfmt 2024-11-10 23:50:37 -08:00
David Tolnay 1a3cf4b3c1 Update PR 2562 ui tests 2024-11-10 23:46:31 -08:00
David Tolnay 7d96352e96 Merge pull request #2857 from dtolnay/collide
Revert the colliding aliases hard error (PRs #2562 & #2853)
2024-11-10 23:37:01 -08:00
David Tolnay 111ecc5d8c Update ui tests for warning on colliding aliases 2024-11-10 23:31:55 -08:00
David Tolnay edd6fe954b Revert "Add checks for conflicts for aliases"
This reverts commit 5f9fffa53e.
2024-11-10 23:31:55 -08:00
David Tolnay a20e9249c5 Revert "pacify clippy"
This reverts commit 951ca5ace0.
2024-11-10 23:31:55 -08:00
David Tolnay b1353a99cd Merge pull request #2856 from dtolnay/dename
Produce a separate warning for every colliding name
2024-11-10 23:31:44 -08:00
David Tolnay c59e876bb3 Produce a separate warning for every colliding name 2024-11-10 23:23:09 -08:00
David Tolnay 7f1e697c0d Merge pull request #2855 from dtolnay/namespan
Produce unreachable_patterns warning when deserialization names collide
2024-11-10 23:21:46 -08:00
David Tolnay 373edcd055 Keep track of a span for alias strings 2024-11-10 23:08:40 -08:00
David Tolnay f0b5c4f857 Move MultiName to a new module 2024-11-10 22:32:49 -08:00
David Tolnay 3035d4fa34 Rename Name -> MultiName 2024-11-10 22:32:49 -08:00
David Tolnay 60ac737439 Prevent upload-artifact step from causing CI failure
This step has been failing way more than reasonable across my various repos.

    With the provided path, there will be 1 file uploaded
    Artifact name is valid!
    Root directory input is valid!
    Attempt 1 of 5 failed with error: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact. Retrying request in 3000 ms...
    Attempt 2 of 5 failed with error: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact. Retrying request in 6029 ms...
    Attempt 3 of 5 failed with error: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact. Retrying request in 8270 ms...
    Attempt 4 of 5 failed with error: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact. Retrying request in 12577 ms...
    Error: Failed to CreateArtifact: Failed to make request after 5 attempts: Request timeout: /twirp/github.actions.results.api.v1.ArtifactService/CreateArtifact
2024-11-08 21:45:52 -05:00
Oli Scherer a95b0d301e Merge pull request #2853 from serde-rs/oli-obk-patch-1
pacify clippy
2024-11-01 15:25:08 +01:00
Oli Scherer 951ca5ace0 pacify clippy 2024-11-01 15:20:51 +01:00
Oli Scherer adf05a5bf6 Merge pull request #2562 from Mingun/alias-check
Add checks for conflicts for aliases
2024-11-01 15:14:15 +01:00
David Tolnay 418062165f Release 1.0.214 2024-10-28 09:41:44 -07:00
David Tolnay 210373b3b6 Merge pull request #2568 from Mingun/into_deserializer-for-deserializers
Implement `IntoDeserializer` for all `Deserializer`s in `serde::de::value` module
2024-10-28 09:40:57 -07:00
Mingun 5f9fffa53e Add checks for conflicts for aliases
- Check that alias is not the same as name of other field (it still can be the name of owning field/variant)
- Check that aliases are unique, i. e. two different fields does not use the same alias
2024-10-25 19:18:31 +05:00
Mingun 9cda015733 Implement IntoDeserializer for all Deserializers in serde::de::value module
Unfortunately, blanket implementation IntoDeserializer for Deserializer is impossible
right now because this would be a breaking change. External crates may have this
such implementation (and serde_json actually have it for Value)
2024-10-25 19:17:50 +05:00
David Tolnay 58a8d22931 Release 1.0.213 2024-10-22 11:14:58 -07:00
David Tolnay ef0ed22593 Merge pull request #2847 from dtolnay/newtypewith
Hygiene for macro-generated newtype struct deserialization with `with` attr
2024-10-22 11:14:18 -07:00
David Tolnay 79925ac394 Ignore dead_code warning in regression test
warning: field `0` is never read
      --> test_suite/tests/regression/issue2846.rs:8:45
       |
    8  |         pub struct S(#[serde(with = $with)] i32);
       |                    - field in this struct   ^^^
    ...
    12 | declare_in_macro!("with");
       | ------------------------- in this macro invocation
       |
       = help: consider removing this field
       = note: `#[warn(dead_code)]` on by default
       = note: this warning originates in the macro `declare_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
2024-10-22 11:10:52 -07:00
David Tolnay b60e4092ec Hygiene for macro-generated newtype struct deserialization with 'with' attr 2024-10-22 11:10:40 -07:00
David Tolnay fdc36e5c06 Add regression test for issue 2846
error[E0425]: cannot find value `__e` in this scope
      --> test_suite/tests/regression/issue2846.rs:12:19
       |
    12 | declare_in_macro!("with");
       |                   ^^^^^^ not found in this scope
2024-10-22 11:08:22 -07:00
David Tolnay 49e11ce1ba Ignore trivially_copy_pass_by_ref pedantic clippy lint in test
warning: this argument (4 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)
      --> test_suite/tests/regression/issue2844.rs:18:28
       |
    18 |     pub fn serialize<S>(_: &i32, _: S) -> Result<S::Ok, S::Error>
       |                            ^^^^ help: consider passing by value instead: `i32`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref
       = note: `-W clippy::trivially-copy-pass-by-ref` implied by `-W clippy::pedantic`
       = help: to override `-W clippy::pedantic` add `#[allow(clippy::trivially_copy_pass_by_ref)]`
2024-10-22 09:56:12 -07:00
David Tolnay 7ae1b5f8f3 Release 1.0.212 2024-10-22 09:41:55 -07:00
David Tolnay 1ac054b34a Merge pull request #2845 from dtolnay/withlocal
Fix hygiene of macro-generated local variable accesses in serde(with) wrappers
2024-10-22 09:41:27 -07:00
David Tolnay 1e36ef551d Fix hygiene of macro-generated local variable accesses in serde(with) wrappers 2024-10-22 09:38:06 -07:00
David Tolnay 0058c7226e Add regression test for issue 2844
error[E0424]: expected value, found module `self`
      --> test_suite/tests/regression/issue2844.rs:13:19
       |
    5  |         #[derive(Serialize, Deserialize)]
       |                  --------- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
    ...
    13 | declare_in_macro!("with");
       |                   ^^^^^^ `self` value is a keyword only available in methods with a `self` parameter

    error[E0425]: cannot find value `__s` in this scope
      --> test_suite/tests/regression/issue2844.rs:13:19
       |
    13 | declare_in_macro!("with");
       |                   ^^^^^^ not found in this scope

    error[E0425]: cannot find value `__deserializer` in this scope
      --> test_suite/tests/regression/issue2844.rs:13:19
       |
    13 | declare_in_macro!("with");
       |                   ^^^^^^ not found in this scope
2024-10-22 09:37:58 -07:00
David Tolnay 29d4f3e887 Format regression tests with rustfmt 2024-10-22 09:28:10 -07:00
David Tolnay 1b8310d98a Release 1.0.211 2024-10-21 23:27:57 -07:00
David Tolnay af4c388dff Merge pull request #2843 from dtolnay/fieldwithaliases
Collect field ident and aliases into a struct
2024-10-21 23:23:28 -07:00
David Tolnay 09f6d9361d Collect field ident and aliases into a struct 2024-10-21 23:16:05 -07:00
David Tolnay 1f9eb8300f Merge pull request #2842 from dtolnay/identsaliases
Rename field_names_idents -> field_idents_aliases
2024-10-21 23:13:23 -07:00
David Tolnay c6a5be7f6a Rename variant_names_idents -> variant_idents_aliases 2024-10-21 22:56:07 -07:00
David Tolnay 0a06af8d21 Rename field_names_idents -> field_idents_aliases 2024-10-21 22:48:02 -07:00
David Tolnay 3393ad6760 Make most of prepare_enum_variant_enum independent of variant_names_idents item type 2024-10-21 22:47:42 -07:00
David Tolnay 830309fcb5 Merge pull request #2841 from dtolnay/serializewith
Reduce scope of quote_spanned on SerializeWith wrapper
2024-10-21 21:56:51 -07:00
David Tolnay ab4f3f3111 Reduce scope of quote_spanned on SerializeWith wrapper 2024-10-21 21:09:18 -07:00
David Tolnay 00460b8dee Fix wording in comments from PR 2558 2024-10-21 21:07:13 -07:00
David Tolnay d4486be2b9 Format all ui tests from PR 2558 using rustfmt 2024-10-21 19:43:45 -07:00
David Tolnay 991e344804 Raise required compiler for serde_derive to 1.61
This is the rust-version declared by recent versions of Syn.
2024-10-21 19:30:51 -07:00
David Tolnay 6a7de26e5a Ignore uninlined_format_args pedantic clippy lint
warning: variables can be used directly in the `format!` string
       --> serde_derive/src/internals/attr.rs:546:36
        |
    546 |                         meta.error(format_args!("unknown serde container attribute `{}`", path))
        |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
        = note: `-W clippy::uninlined-format-args` implied by `-W clippy::pedantic`
        = help: to override `-W clippy::pedantic` add `#[allow(clippy::uninlined_format_args)]`
    help: change this to
        |
    546 -                         meta.error(format_args!("unknown serde container attribute `{}`", path))
    546 +                         meta.error(format_args!("unknown serde container attribute `{path}`"))
        |

    warning: variables can be used directly in the `format!` string
       --> serde_derive/src/internals/attr.rs:940:36
        |
    940 |                         meta.error(format_args!("unknown serde variant attribute `{}`", path))
        |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    940 -                         meta.error(format_args!("unknown serde variant attribute `{}`", path))
    940 +                         meta.error(format_args!("unknown serde variant attribute `{path}`"))
        |

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/internals/attr.rs:1095:33
         |
    1095 | ...                   format!("field `{}` does not have lifetime {}", ident, lifetime);
         |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
         |
    1095 -                                 format!("field `{}` does not have lifetime {}", ident, lifetime);
    1095 +                                 format!("field `{ident}` does not have lifetime {lifetime}");
         |

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/internals/attr.rs:1196:47
         |
    1196 |   ...                   let msg = format!(
         |  _________________________________^
    1197 | | ...                       "field `{}` does not have lifetime {}",
    1198 | | ...                       ident, lifetime,
    1199 | | ...                   );
         | |_______________________^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/internals/attr.rs:1222:36
         |
    1222 |                         meta.error(format_args!("unknown serde field attribute `{}`", path))
         |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
         |
    1222 -                         meta.error(format_args!("unknown serde field attribute `{}`", path))
    1222 +                         meta.error(format_args!("unknown serde field attribute `{path}`"))
         |

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/internals/attr.rs:1415:39
         |
    1415 |                   return Err(meta.error(format_args!(
         |  _______________________________________^
    1416 | |                     "malformed {0} attribute, expected `{0}(serialize = ..., deserialize = ...)`",
    1417 | |                     attr_name,
    1418 | |                 )));
         | |_________________^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/internals/attr.rs:1482:17
         |
    1482 |                 format!("unexpected suffix `{}` on string literal", suffix),
         |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
         |
    1482 -                 format!("unexpected suffix `{}` on string literal", suffix),
    1482 +                 format!("unexpected suffix `{suffix}` on string literal"),
         |

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/internals/attr.rs:1489:13
         |
    1489 | /             format!(
    1490 | |                 "expected serde {} attribute to be a string: `{} = \"...\"`",
    1491 | |                 attr_name, meta_item_name
    1492 | |             ),
         | |_____________^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/internals/attr.rs:1604:21
         |
    1604 |                     format!("duplicate borrowed lifetime `{}`", lifetime),
         |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
         |
    1604 -                     format!("duplicate borrowed lifetime `{}`", lifetime),
    1604 +                     format!("duplicate borrowed lifetime `{lifetime}`"),
         |

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/internals/attr.rs:1778:19
         |
    1778 |         let msg = format!("field `{}` has no lifetimes to borrow", name);
         |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
         |
    1778 -         let msg = format!("field `{}` has no lifetimes to borrow", name);
    1778 +         let msg = format!("field `{name}` has no lifetimes to borrow");
         |

    warning: variables can be used directly in the `format!` string
      --> serde_derive/src/internals/check.rs:41:29
       |
    41 | ...   format!("field must have #[serde(default)] because previous field {} has #[serde(default)]", first),
       |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
       |
    41 -                             format!("field must have #[serde(default)] because previous field {} has #[serde(default)]", first),
    41 +                             format!("field must have #[serde(default)] because previous field {first} has #[serde(default)]"),
       |

    warning: variables can be used directly in the `format!` string
       --> serde_derive/src/internals/check.rs:314:13
        |
    314 |             format!("variant field name `{}` conflicts with internal tag", tag),
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    314 -             format!("variant field name `{}` conflicts with internal tag", tag),
    314 +             format!("variant field name `{tag}` conflicts with internal tag"),
        |

    warning: variables can be used directly in the `format!` string
       --> serde_derive/src/internals/check.rs:361:13
        |
    361 | /             format!(
    362 | |                 "enum tags `{}` for type and content conflict with each other",
    363 | |                 type_tag
    364 | |             ),
        | |_____________^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args

    warning: variables can be used directly in the `format!` string
       --> serde_derive/src/internals/check.rs:450:33
        |
    450 |         Member::Named(ident) => format!("`{}`", ident),
        |                                 ^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    450 -         Member::Named(ident) => format!("`{}`", ident),
    450 +         Member::Named(ident) => format!("`{ident}`"),
        |

    warning: variables can be used directly in the `format!` string
       --> serde_derive/src/de.rs:697:9
        |
    697 |         format!("{} with 1 element", expecting)
        |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    697 -         format!("{} with 1 element", expecting)
    697 +         format!("{expecting} with 1 element")
        |

    warning: variables can be used directly in the `format!` string
       --> serde_derive/src/de.rs:699:9
        |
    699 |         format!("{} with {} elements", expecting, deserialized_count)
        |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    699 -         format!("{} with {} elements", expecting, deserialized_count)
    699 +         format!("{expecting} with {deserialized_count} elements")
        |

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/de.rs:1442:21
         |
    1442 |     let expecting = format!("adjacently tagged enum {}", rust_name);
         |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
         |
    1442 -     let expecting = format!("adjacently tagged enum {}", rust_name);
    1442 +     let expecting = format!("adjacently tagged enum {rust_name}");
         |

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/de.rs:2842:17
         |
    2842 |     Ident::new(&format!("__field{}", i), Span::call_site())
         |                 ^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
         |
    2842 -     Ident::new(&format!("__field{}", i), Span::call_site())
    2842 +     Ident::new(&format!("__field{i}"), Span::call_site())
         |

    warning: variables can be used directly in the `format!` string
       --> serde_derive/src/ser.rs:457:42
        |
    457 |                     .map(|i| Ident::new(&format!("__field{}", i), Span::call_site()));
        |                                          ^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    457 -                     .map(|i| Ident::new(&format!("__field{}", i), Span::call_site()));
    457 +                     .map(|i| Ident::new(&format!("__field{i}"), Span::call_site()));
        |

    warning: variables can be used directly in the `format!` string
       --> serde_derive/src/ser.rs:714:48
        |
    714 |             .map(|i| Member::Named(Ident::new(&format!("__field{}", i), Span::call_site())))
        |                                                ^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    714 -             .map(|i| Member::Named(Ident::new(&format!("__field{}", i), Span::call_site())))
    714 +             .map(|i| Member::Named(Ident::new(&format!("__field{i}"), Span::call_site())))
        |

    warning: variables can be used directly in the `format!` string
       --> serde_derive/src/ser.rs:832:46
        |
    832 |                 let field_expr = Ident::new(&format!("__field{}", i), Span::call_site());
        |                                              ^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    832 -                 let field_expr = Ident::new(&format!("__field{}", i), Span::call_site());
    832 +                 let field_expr = Ident::new(&format!("__field{i}"), Span::call_site());
        |

    warning: variables can be used directly in the `format!` string
        --> serde_derive/src/ser.rs:1062:38
         |
    1062 |                 let id = Ident::new(&format!("__field{}", i), Span::call_site());
         |                                      ^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
         |
    1062 -                 let id = Ident::new(&format!("__field{}", i), Span::call_site());
    1062 +                 let id = Ident::new(&format!("__field{i}"), Span::call_site());
         |
2024-10-21 19:30:51 -07:00
David Tolnay 5382ef3b0b Merge pull request #2840 from dtolnay/needlesslifetimes
Ignore needless_lifetimes clippy lint in generated code
2024-10-21 19:25:40 -07:00
David Tolnay a8cbc9184e Ignore needless_lifetimes clippy lint in generated code 2024-10-21 19:12:52 -07:00
David Tolnay 966e9ccf0c Merge pull request #2839 from dtolnay/pr2558
Update ui tests from PR 2558
2024-10-21 18:58:21 -07:00
David Tolnay 53ade10137 Update ui tests from PR 2558 2024-10-21 18:52:49 -07:00
David Tolnay 422c719352 Temporarily disable 1.56 CI
While fixing other errors from recently merged PRs.
2024-10-21 18:47:54 -07:00
Oli Scherer 3415619bfd Merge pull request #2566 from Mingun/variant-aliases
Show variant aliases in error message
2024-10-21 21:40:57 +02:00
Oli Scherer 04bb76bc00 Merge pull request #2558 from Mingun/correct-span
Improve error reporting about mismatched signature in `with` and `default` attributes
2024-10-21 21:38:09 +02:00
David Tolnay 8b0f482666 Update for precise capture bounds
warning: some variants are not matched explicitly
       --> serde_derive/src/internals/receiver.rs:209:15
        |
    209 |         match bound {
        |               ^^^^^ pattern `&mut TypeParamBound::PreciseCapture(_)` not covered
        |
        = help: ensure that all variants are matched explicitly by adding the suggested match arms
        = note: the matched value is of type `&mut TypeParamBound` and the `non_exhaustive_omitted_patterns` attribute was found
    note: the lint level is defined here
       --> serde_derive/src/internals/receiver.rs:210:53
        |
    210 |             #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: some variants are not matched explicitly
       --> serde_derive/src/bound.rs:227:19
        |
    227 |             match bound {
        |                   ^^^^^ pattern `&TypeParamBound::PreciseCapture(_)` not covered
        |
        = help: ensure that all variants are matched explicitly by adding the suggested match arms
        = note: the matched value is of type `&TypeParamBound` and the `non_exhaustive_omitted_patterns` attribute was found
    note: the lint level is defined here
       --> serde_derive/src/bound.rs:228:57
        |
    228 |                 #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
        |                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-10-20 20:35:48 -07:00
David Tolnay 4b3178b053 Ignore needless_lifetimes clippy lint
warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:124:6
        |
    124 | impl<'de, E> IntoDeserializer<'de, E> for ()
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
        = note: `-W clippy::needless-lifetimes` implied by `-W clippy::all`
        = help: to override `-W clippy::all` add `#[allow(clippy::needless_lifetimes)]`
    help: elide the lifetimes
        |
    124 - impl<'de, E> IntoDeserializer<'de, E> for ()
    124 + impl<E> IntoDeserializer<'_, E> for ()
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:196:6
        |
    196 | impl<'de, E> IntoDeserializer<'de, E> for !
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    196 - impl<'de, E> IntoDeserializer<'de, E> for !
    196 + impl<E> IntoDeserializer<'_, E> for !
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:317:6
        |
    317 | impl<'de, E> IntoDeserializer<'de, E> for u32
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    317 - impl<'de, E> IntoDeserializer<'de, E> for u32
    317 + impl<E> IntoDeserializer<'_, E> for u32
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:406:6
        |
    406 | impl<'de, 'a, E> IntoDeserializer<'de, E> for &'a str
        |      ^^^                          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    406 - impl<'de, 'a, E> IntoDeserializer<'de, E> for &'a str
    406 + impl<'a, E> IntoDeserializer<'_, E> for &'a str
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:427:11
        |
    427 | impl<'de, 'a, E> de::Deserializer<'de> for StrDeserializer<'a, E>
        |           ^^                                               ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    427 - impl<'de, 'a, E> de::Deserializer<'de> for StrDeserializer<'a, E>
    427 + impl<'de, E> de::Deserializer<'de> for StrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:461:11
        |
    461 | impl<'de, 'a, E> de::EnumAccess<'de> for StrDeserializer<'a, E>
        |           ^^                                             ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    461 - impl<'de, 'a, E> de::EnumAccess<'de> for StrDeserializer<'a, E>
    461 + impl<'de, E> de::EnumAccess<'de> for StrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:476:6
        |
    476 | impl<'a, E> Debug for StrDeserializer<'a, E> {
        |      ^^                               ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    476 - impl<'a, E> Debug for StrDeserializer<'a, E> {
    476 + impl<E> Debug for StrDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:555:6
        |
    555 | impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
        |      ^^^                                       ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    555 - impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
    555 + impl<E> Debug for BorrowedStrDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:586:6
        |
    586 | impl<'de, E> IntoDeserializer<'de, E> for String
        |      ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    586 - impl<'de, E> IntoDeserializer<'de, E> for String
    586 + impl<E> IntoDeserializer<'_, E> for String
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:680:6
        |
    680 | impl<'a, E> Clone for CowStrDeserializer<'a, E> {
        |      ^^                                  ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    680 - impl<'a, E> Clone for CowStrDeserializer<'a, E> {
    680 + impl<E> Clone for CowStrDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:691:6
        |
    691 | impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>
        |      ^^^                          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    691 - impl<'de, 'a, E> IntoDeserializer<'de, E> for Cow<'a, str>
    691 + impl<'a, E> IntoDeserializer<'_, E> for Cow<'a, str>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:714:11
        |
    714 | impl<'de, 'a, E> de::Deserializer<'de> for CowStrDeserializer<'a, E>
        |           ^^                                                  ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    714 - impl<'de, 'a, E> de::Deserializer<'de> for CowStrDeserializer<'a, E>
    714 + impl<'de, E> de::Deserializer<'de> for CowStrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:752:11
        |
    752 | impl<'de, 'a, E> de::EnumAccess<'de> for CowStrDeserializer<'a, E>
        |           ^^                                                ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    752 - impl<'de, 'a, E> de::EnumAccess<'de> for CowStrDeserializer<'a, E>
    752 + impl<'de, E> de::EnumAccess<'de> for CowStrDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:768:6
        |
    768 | impl<'a, E> Debug for CowStrDeserializer<'a, E> {
        |      ^^                                  ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    768 - impl<'a, E> Debug for CowStrDeserializer<'a, E> {
    768 + impl<E> Debug for CowStrDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:797:6
        |
    797 | impl<'de, 'a, E> IntoDeserializer<'de, E> for &'a [u8]
        |      ^^^                          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    797 - impl<'de, 'a, E> IntoDeserializer<'de, E> for &'a [u8]
    797 + impl<'a, E> IntoDeserializer<'_, E> for &'a [u8]
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:808:11
        |
    808 | impl<'de, 'a, E> Deserializer<'de> for BytesDeserializer<'a, E>
        |           ^^                                             ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    808 - impl<'de, 'a, E> Deserializer<'de> for BytesDeserializer<'a, E>
    808 + impl<'de, E> Deserializer<'de> for BytesDeserializer<'_, E>
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/value.rs:828:6
        |
    828 | impl<'a, E> Debug for BytesDeserializer<'a, E> {
        |      ^^                                 ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    828 - impl<'a, E> Debug for BytesDeserializer<'a, E> {
    828 + impl<E> Debug for BytesDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/value.rs:876:6
        |
    876 | impl<'de, E> Debug for BorrowedBytesDeserializer<'de, E> {
        |      ^^^                                         ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    876 - impl<'de, E> Debug for BorrowedBytesDeserializer<'de, E> {
    876 + impl<E> Debug for BorrowedBytesDeserializer<'_, E> {
        |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1101:6
         |
    1101 | impl<'de, I, E> MapDeserializer<'de, I, E>
         |      ^^^                        ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1101 - impl<'de, I, E> MapDeserializer<'de, I, E>
    1101 + impl<I, E> MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1118:6
         |
    1118 | impl<'de, I, E> MapDeserializer<'de, I, E>
         |      ^^^                        ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1118 - impl<'de, I, E> MapDeserializer<'de, I, E>
    1118 + impl<I, E> MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1141:6
         |
    1141 | impl<'de, I, E> MapDeserializer<'de, I, E>
         |      ^^^                        ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1141 - impl<'de, I, E> MapDeserializer<'de, I, E>
    1141 + impl<I, E> MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1287:6
         |
    1287 | impl<'de, I, E> Clone for MapDeserializer<'de, I, E>
         |      ^^^                                  ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1287 - impl<'de, I, E> Clone for MapDeserializer<'de, I, E>
    1287 + impl<I, E> Clone for MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/value.rs:1304:6
         |
    1304 | impl<'de, I, E> Debug for MapDeserializer<'de, I, E>
         |      ^^^                                  ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1304 - impl<'de, I, E> Debug for MapDeserializer<'de, I, E>
    1304 + impl<I, E> Debug for MapDeserializer<'_, I, E>
         |

    warning: the following explicit lifetimes could be elided: 'de
      --> serde/src/de/impls.rs:17:6
       |
    17 | impl<'de> Visitor<'de> for UnitVisitor {
       |      ^^^          ^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
       |
    17 - impl<'de> Visitor<'de> for UnitVisitor {
    17 + impl Visitor<'_> for UnitVisitor {
       |

    warning: the following explicit lifetimes could be elided: 'de
      --> serde/src/de/impls.rs:56:6
       |
    56 | impl<'de> Visitor<'de> for BoolVisitor {
       |      ^^^          ^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
       |
    56 - impl<'de> Visitor<'de> for BoolVisitor {
    56 + impl Visitor<'_> for BoolVisitor {
       |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/impls.rs:550:6
        |
    550 | impl<'de> Visitor<'de> for CharVisitor {
        |      ^^^          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    550 - impl<'de> Visitor<'de> for CharVisitor {
    550 + impl Visitor<'_> for CharVisitor {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/impls.rs:596:6
        |
    596 | impl<'de> Visitor<'de> for StringVisitor {
        |      ^^^          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    596 - impl<'de> Visitor<'de> for StringVisitor {
    596 + impl Visitor<'_> for StringVisitor {
        |

    warning: the following explicit lifetimes could be elided: 'de, 'a
       --> serde/src/de/impls.rs:642:6
        |
    642 | impl<'a, 'de> Visitor<'de> for StringInPlaceVisitor<'a> {
        |      ^^  ^^^          ^^^                           ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    642 - impl<'a, 'de> Visitor<'de> for StringInPlaceVisitor<'a> {
    642 + impl Visitor<'_> for StringInPlaceVisitor<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/de/impls.rs:953:6
        |
    953 | impl<'de, T> Visitor<'de> for PhantomDataVisitor<T>
        |      ^^^             ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    953 - impl<'de, T> Visitor<'de> for PhantomDataVisitor<T>
    953 + impl<T> Visitor<'_> for PhantomDataVisitor<T>
        |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/de/impls.rs:1195:14
         |
    1195 |         impl<'a, 'de, T> Visitor<'de> for VecInPlaceVisitor<'a, T>
         |              ^^                                             ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1195 -         impl<'a, 'de, T> Visitor<'de> for VecInPlaceVisitor<'a, T>
    1195 +         impl<'de, T> Visitor<'de> for VecInPlaceVisitor<'_, T>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:1838:6
         |
    1838 | impl<'de> Visitor<'de> for PathBufVisitor {
         |      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1838 - impl<'de> Visitor<'de> for PathBufVisitor {
    1838 + impl Visitor<'_> for PathBufVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/de/impls.rs:1991:11
         |
    1991 | impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
         |           ^^                              ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1991 - impl<'de, 'a, T> Deserialize<'de> for Cow<'a, T>
    1991 + impl<'de, T> Deserialize<'de> for Cow<'_, T>
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2161:22
         |
    2161 |                 impl<'de> Visitor<'de> for FieldVisitor {
         |                      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2161 -                 impl<'de> Visitor<'de> for FieldVisitor {
    2161 +                 impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2300:22
         |
    2300 |                 impl<'de> Visitor<'de> for FieldVisitor {
         |                      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2300 -                 impl<'de> Visitor<'de> for FieldVisitor {
    2300 +                 impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2501:18
         |
    2501 |             impl<'de> Visitor<'de> for FieldVisitor {
         |                  ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2501 -             impl<'de> Visitor<'de> for FieldVisitor {
    2501 +             impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2658:18
         |
    2658 |             impl<'de> Visitor<'de> for FieldVisitor {
         |                  ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2658 -             impl<'de> Visitor<'de> for FieldVisitor {
    2658 +             impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2796:18
         |
    2796 |             impl<'de> Visitor<'de> for FieldVisitor {
         |                  ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2796 -             impl<'de> Visitor<'de> for FieldVisitor {
    2796 +             impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:2907:22
         |
    2907 |                 impl<'de> Visitor<'de> for FieldVisitor {
         |                      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2907 -                 impl<'de> Visitor<'de> for FieldVisitor {
    2907 +                 impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:3018:22
         |
    3018 |                 impl<'de> Visitor<'de> for FieldVisitor {
         |                      ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    3018 -                 impl<'de> Visitor<'de> for FieldVisitor {
    3018 +                 impl Visitor<'_> for FieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/de/impls.rs:3166:6
         |
    3166 | impl<'de, T> Visitor<'de> for FromStrVisitor<T>
         |      ^^^             ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    3166 - impl<'de, T> Visitor<'de> for FromStrVisitor<T>
    3166 + impl<T> Visitor<'_> for FromStrVisitor<T>
         |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/mod.rs:397:6
        |
    397 | impl<'a> fmt::Display for Unexpected<'a> {
        |      ^^                              ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    397 - impl<'a> fmt::Display for Unexpected<'a> {
    397 + impl fmt::Display for Unexpected<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'f, 'a
        --> serde/src/de/mod.rs:2309:14
         |
    2309 |         impl<'f, 'a> fmt::Write for LookForDecimalPoint<'f, 'a> {
         |              ^^  ^^                                     ^^  ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2309 -         impl<'f, 'a> fmt::Write for LookForDecimalPoint<'f, 'a> {
    2309 +         impl fmt::Write for LookForDecimalPoint<'_, '_> {
         |

    warning: the following explicit lifetimes could be elided: 'a
      --> serde/src/ser/fmt.rs:38:6
       |
    38 | impl<'a> Serializer for &mut fmt::Formatter<'a> {
       |      ^^                                     ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
       |
    38 - impl<'a> Serializer for &mut fmt::Formatter<'a> {
    38 + impl Serializer for &mut fmt::Formatter<'_> {
       |

    warning: the following explicit lifetimes could be elided: 'a
      --> serde/src/ser/impls.rs:62:6
       |
    62 | impl<'a> Serialize for fmt::Arguments<'a> {
       |      ^^                               ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
       |
    62 - impl<'a> Serialize for fmt::Arguments<'a> {
    62 + impl Serialize for fmt::Arguments<'_> {
       |

    warning: the following explicit lifetimes could be elided: 'a
      --> serde/src/format.rs:20:6
       |
    20 | impl<'a> Write for Buf<'a> {
       |      ^^                ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
       |
    20 - impl<'a> Write for Buf<'a> {
    20 + impl Write for Buf<'_> {
       |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/private/de.rs:254:10
        |
    254 |     impl<'de> Content<'de> {
        |          ^^^          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    254 -     impl<'de> Content<'de> {
    254 +     impl Content<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/private/de.rs:333:10
        |
    333 |     impl<'de> ContentVisitor<'de> {
        |          ^^^                 ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    333 -     impl<'de> ContentVisitor<'de> {
    333 +     impl ContentVisitor<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/private/de.rs:553:10
        |
    553 |     impl<'de> TagOrContentVisitor<'de> {
        |          ^^^                      ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    553 -     impl<'de> TagOrContentVisitor<'de> {
    553 +     impl TagOrContentVisitor<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'de
       --> serde/src/private/de.rs:937:10
        |
    937 |     impl<'de> Visitor<'de> for TagOrContentFieldVisitor {
        |          ^^^          ^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    937 -     impl<'de> Visitor<'de> for TagOrContentFieldVisitor {
    937 +     impl Visitor<'_> for TagOrContentFieldVisitor {
        |

    warning: the following explicit lifetimes could be elided: 'de
        --> serde/src/private/de.rs:1014:10
         |
    1014 |     impl<'de> Visitor<'de> for TagContentOtherFieldVisitor {
         |          ^^^          ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1014 -     impl<'de> Visitor<'de> for TagContentOtherFieldVisitor {
    1014 +     impl Visitor<'_> for TagContentOtherFieldVisitor {
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:1652:10
         |
    1652 |     impl<'a, 'de, E> ContentRefDeserializer<'a, 'de, E>
         |          ^^                                 ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1652 -     impl<'a, 'de, E> ContentRefDeserializer<'a, 'de, E>
    1652 +     impl<'de, E> ContentRefDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:1735:15
         |
    1735 |     impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, 'de, E>
         |               ^^                                                  ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1735 -     impl<'de, 'a, E> Deserializer<'de> for ContentRefDeserializer<'a, 'de, E>
    1735 +     impl<'de, E> Deserializer<'de> for ContentRefDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2162:15
         |
    2162 |     impl<'de, 'a, E> de::VariantAccess<'de> for VariantRefDeserializer<'a, 'de, E>
         |               ^^                                                       ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2162 -     impl<'de, 'a, E> de::VariantAccess<'de> for VariantRefDeserializer<'a, 'de, E>
    2162 +     impl<'de, E> de::VariantAccess<'de> for VariantRefDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2259:15
         |
    2259 |     impl<'de, 'a, E> de::IntoDeserializer<'de, E> for ContentRefDeserializer<'a, 'de, E>
         |               ^^                                                             ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2259 -     impl<'de, 'a, E> de::IntoDeserializer<'de, E> for ContentRefDeserializer<'a, 'de, E>
    2259 +     impl<'de, E> de::IntoDeserializer<'de, E> for ContentRefDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2288:15
         |
    2288 |     impl<'de, 'a> Visitor<'de> for InternallyTaggedUnitVisitor<'a> {
         |               ^^                                               ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2288 -     impl<'de, 'a> Visitor<'de> for InternallyTaggedUnitVisitor<'a> {
    2288 +     impl<'de> Visitor<'de> for InternallyTaggedUnitVisitor<'_> {
         |

    warning: the following explicit lifetimes could be elided: 'a, 'de
        --> serde/src/private/de.rs:2333:10
         |
    2333 |     impl<'de, 'a> Visitor<'de> for UntaggedUnitVisitor<'a> {
         |          ^^^  ^^          ^^^                          ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2333 -     impl<'de, 'a> Visitor<'de> for UntaggedUnitVisitor<'a> {
    2333 +     impl Visitor<'_> for UntaggedUnitVisitor<'_> {
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2396:11
         |
    2396 | impl<'de, 'a, E> Deserializer<'de> for StrDeserializer<'a, E>
         |           ^^                                           ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2396 - impl<'de, 'a, E> Deserializer<'de> for StrDeserializer<'a, E>
    2396 + impl<'de, E> Deserializer<'de> for StrDeserializer<'_, E>
         |

    warning: the following explicit lifetimes could be elided: 'a, 'de
        --> serde/src/private/de.rs:2498:6
         |
    2498 | impl<'a, 'de, E> FlatMapDeserializer<'a, 'de, E>
         |      ^^  ^^^                         ^^  ^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2498 - impl<'a, 'de, E> FlatMapDeserializer<'a, 'de, E>
    2498 + impl<E> FlatMapDeserializer<'_, '_, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2522:6
         |
    2522 | impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
         |      ^^                                                    ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2522 - impl<'a, 'de, E> Deserializer<'de> for FlatMapDeserializer<'a, 'de, E>
    2522 + impl<'de, E> Deserializer<'de> for FlatMapDeserializer<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2658:6
         |
    2658 | impl<'a, 'de, E> MapAccess<'de> for FlatMapAccess<'a, 'de, E>
         |      ^^                                           ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2658 - impl<'a, 'de, E> MapAccess<'de> for FlatMapAccess<'a, 'de, E>
    2658 + impl<'de, E> MapAccess<'de> for FlatMapAccess<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/private/de.rs:2702:6
         |
    2702 | impl<'a, 'de, E> MapAccess<'de> for FlatStructAccess<'a, 'de, E>
         |      ^^                                              ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    2702 - impl<'a, 'de, E> MapAccess<'de> for FlatStructAccess<'a, 'de, E>
    2702 + impl<'de, E> MapAccess<'de> for FlatStructAccess<'_, 'de, E>
         |

    warning: the following explicit lifetimes could be elided: 'a
     --> serde/src/de/seed.rs:8:6
      |
    8 | impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>
      |      ^^                                               ^^
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
      |
    8 - impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>
    8 + impl<'de, T> DeserializeSeed<'de> for InPlaceSeed<'_, T>
      |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde_derive/src/internals/case.rs:124:6
        |
    124 | impl<'a> Display for ParseError<'a> {
        |      ^^                         ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
        = note: `-W clippy::needless-lifetimes` implied by `-W clippy::all`
        = help: to override `-W clippy::all` add `#[allow(clippy::needless_lifetimes)]`
    help: elide the lifetimes
        |
    124 - impl<'a> Display for ParseError<'a> {
    124 + impl Display for ParseError<'_> {
        |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde_derive/src/de.rs:3042:6
         |
    3042 | impl<'a> ToTokens for DeImplGenerics<'a> {
         |      ^^                              ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    3042 - impl<'a> ToTokens for DeImplGenerics<'a> {
    3042 + impl ToTokens for DeImplGenerics<'_> {
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde_derive/src/de.rs:3124:6
         |
    3124 | impl<'a> ToTokens for DeTypeGenerics<'a> {
         |      ^^                              ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    3124 - impl<'a> ToTokens for DeTypeGenerics<'a> {
    3124 + impl ToTokens for DeTypeGenerics<'_> {
         |

    warning: the following explicit lifetimes could be elided: 'a
      --> test_suite/tests/test_serde_path.rs:15:10
       |
    15 |     impl<'a> AssertNotSerdeDeserialize<'a> for Foo {}
       |          ^^                            ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
       = note: `-W clippy::needless-lifetimes` implied by `-W clippy::all`
       = help: to override `-W clippy::all` add `#[allow(clippy::needless_lifetimes)]`
    help: elide the lifetimes
       |
    15 -     impl<'a> AssertNotSerdeDeserialize<'a> for Foo {}
    15 +     impl AssertNotSerdeDeserialize<'_> for Foo {}
       |
2024-10-07 21:02:22 +02:00
David Tolnay 8e1ae68569 Resolve some needless_lifetimes clippy lints
warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/mod.rs:489:6
        |
    489 | impl<'a> Expected for &'a str {
        |      ^^                ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    489 - impl<'a> Expected for &'a str {
    489 + impl Expected for &str {
        |

    warning: the following explicit lifetimes could be elided: 'a
       --> serde/src/de/mod.rs:495:6
        |
    495 | impl<'a> Display for Expected + 'a {
        |      ^^                         ^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
        |
    495 - impl<'a> Display for Expected + 'a {
    495 + impl Display for Expected + '_ {
        |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/de/mod.rs:1744:11
         |
    1744 | impl<'de, 'a, A> SeqAccess<'de> for &'a mut A
         |           ^^                         ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1744 - impl<'de, 'a, A> SeqAccess<'de> for &'a mut A
    1744 + impl<'de, A> SeqAccess<'de> for &mut A
         |

    warning: the following explicit lifetimes could be elided: 'a
        --> serde/src/de/mod.rs:1897:11
         |
    1897 | impl<'de, 'a, A> MapAccess<'de> for &'a mut A
         |           ^^                         ^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
         |
    1897 - impl<'de, 'a, A> MapAccess<'de> for &'a mut A
    1897 + impl<'de, A> MapAccess<'de> for &mut A
         |

    warning: the following explicit lifetimes could be elided: 'a, 'b
      --> serde/src/ser/fmt.rs:38:6
       |
    38 | impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
       |      ^^  ^^                  ^^                    ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
       |
    38 - impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
    38 + impl Serializer for &mut fmt::Formatter<'_> {
       |

    warning: the following explicit lifetimes could be elided: 'a
      --> serde_derive/src/internals/symbol.rs:49:6
       |
    49 | impl<'a> PartialEq<Symbol> for &'a Ident {
       |      ^^                         ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
       |
    49 - impl<'a> PartialEq<Symbol> for &'a Ident {
    49 + impl PartialEq<Symbol> for &Ident {
       |

    warning: the following explicit lifetimes could be elided: 'a
      --> serde_derive/src/internals/symbol.rs:61:6
       |
    61 | impl<'a> PartialEq<Symbol> for &'a Path {
       |      ^^                         ^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    help: elide the lifetimes
       |
    61 - impl<'a> PartialEq<Symbol> for &'a Path {
    61 + impl PartialEq<Symbol> for &Path {
       |
2024-10-07 20:58:23 +02:00
David Tolnay 31000e1874 Add a funding file 2024-09-23 15:38:18 -07:00
David Tolnay 4487cb26c7 Merge pull request #2822 from dtolnay/mapcontentdeserializer
Remove explicit ContentDeserializer construction in visit functions
2024-09-07 16:41:38 -07:00
David Tolnay aba4e18553 Remove explicit ContentDeserializer construction in visit functions 2024-09-07 16:31:03 -07:00
David Tolnay c82f2580b4 Merge pull request #2821 from dtolnay/clos
Eliminate closures capturing needlessly many type parameters
2024-09-06 16:54:36 -07:00
David Tolnay 1d7b009aec Eliminate closures capturing needlessly many type parameters 2024-09-06 16:29:41 -07:00
David Tolnay 89c4b02bf3 Release 1.0.210 2024-09-06 11:17:20 -07:00
David Tolnay eeb8e44cda Merge pull request #2818 from dtolnay/coreerror
Stabilize no-std Error trait
2024-09-06 11:16:43 -07:00
David Tolnay 785c2d9605 Stabilize no-std StdError trait 2024-09-06 11:12:13 -07:00
David Tolnay d549f048e1 Reformat parse_ip_impl definition and calls 2024-09-06 11:05:54 -07:00
David Tolnay 4c0dd63011 Delete attr support from core::net deserialization macros 2024-09-06 11:05:54 -07:00
David Tolnay 26fb134165 Relocate cfg attrs out of parse_ip_impl and parse_socket_impl 2024-09-06 11:05:53 -07:00
David Tolnay 07e614b52b Merge pull request #2817 from dtolnay/corenet
Delete doc(cfg) attribute from impls that are supported in no-std
2024-09-06 11:05:48 -07:00
David Tolnay b1f899fbe8 Delete doc(cfg) attribute from impls that are supported in no-std 2024-09-06 11:00:55 -07:00
David Tolnay b4f860e627 Merge pull request #2816 from MathiasKoch/chore/core-net
Implement serialize/deserialize for core::net instead of std::net
2024-09-06 10:59:24 -07:00
Mathias d940fe1b49 Reuse existing Buf wrapper as replacement for std::io::Write 2024-09-05 14:24:44 +02:00
Mathias f2899a9e06 Implement serialize/deserialize for core::net instead of std::net if running rust version newer than 1.77, where core::net was stabilized 2024-09-05 11:07:09 +02:00
David Tolnay 3aca38d2d3 Upload CI Cargo.lock for reproducing failures 2024-08-25 12:12:25 -07:00
David Tolnay 30752ac4ff Release 1.0.209 2024-08-23 20:29:05 -07:00
David Tolnay b84e6ca4f5 Improve wording of PR 2805 comments 2024-08-23 20:28:11 -07:00
David Tolnay 87a2fb0f1a Wrap comments from PR 2805 to 80 columns 2024-08-23 20:25:16 -07:00
David Tolnay 9eaf7b9824 Merge pull request #2805 from Mingun/untagged-tests
Fix deserialization of empty structs and tuples in untagged enums
2024-08-23 20:25:07 -07:00
Mingun 7bde100237 Replace MapRefDeserializer with value::MapDeserializer
Although they are slightly different, this difference is irrelevant:
- MapDeserializer has a specialization for deserialize_seq and deserialize_tuple, but
  only MapRefDeserializer::deserialize_any is used by the code which is almost the same
- MapDeserializer checks that map was consumed after visit_map, but MapRefDeserializer
  does not. Actually, each derived implementation consumes map and each manual implementation
  also should consume it

Also, MapDeserializer already used when value deserialized from ContentRefDeserializer
directly and MapRefDeserializer was only used to deserialize Struct variants of enums.
There are no reasons why the behavior should be different in those two cases
2024-08-24 04:52:26 +05:00
Mingun da7fc795ee Fix deserialization of empty struct variant in untagged enums
SeqRefDeserializer::deserialize_any has a special condition for empty sequence, which
emits visit_unit. That condition assumes that type would be able to deserialized from
unit, but:
1) struct variants was never able to deserialize from it (they expect only visit_map or visit_seq)
2) tuple variants even with zero fields expect visit_seq only. The suggestion to accept visit_unit
   instead was rejected in #2520

Fixes (2):
    newtype_enum::tuple0
    newtype_enum::empty_struct_from_seq
2024-08-24 04:52:26 +05:00
Mingun 4c5fec1363 Test special cases that reaches SeqRefDeserializer::deserialize_any len==0 condition
failures (2):
    newtype_enum::empty_struct_from_seq
    newtype_enum::tuple0
2024-08-24 04:52:25 +05:00
Mingun 6588b0ad37 Cover Content::Seq case in VariantRefDeserializer::struct_variant 2024-08-24 04:52:25 +05:00
Mingun 0093f74cfe Split test newtype_enum into four tests for each variant
(review this commit with "ignore whitespace changes" option on)
2024-08-24 04:52:25 +05:00
Mingun 171c6da57a Complete coverage of ContentRefDeserializer::deserialize_newtype_struct 2024-08-24 04:52:25 +05:00
Mingun 2dddc7796d Cover ContentRefDeserializer::deserialize_option 2024-08-24 04:52:25 +05:00
Mingun 8514f4119a Remove unnecessary generics 2024-08-24 04:52:24 +05:00
Mingun 98fb7d94aa Move all untagged enum tests (except flatten) into a dedicated module
Moved and renamed:
From test_annotations
- test_expecting_message_untagged_tagged_enum                  => expecting_message
- flatten::enum_::untagged::straitforward                      => contains_flatten

From test_macros
- test_untagged_newtype_struct                                 => newtype_struct
- test_untagged_enum                                           => complex
- test_untagged_enum_with_flattened_integer_key                => contains_flatten_with_integer_key
- test_enum_in_untagged_enum                                   => newtype_enum
- test_untagged_bytes                                          => string_and_bytes
- test_untagged_newtype_variant_containing_unit_struct_not_map => newtype_unit_and_empty_map
2024-08-24 04:52:22 +05:00
David Tolnay 31ca16d9bc Merge pull request #2804 from Mingun/adjacently-tagged-tests
Consolidate and add new tests of adjacently tagged enums
2024-08-23 14:12:41 -07:00
Mingun 9f72ce695e Struct: add tests for deserialization from sequence
(review this commit with "ignore whitespace changes" option on)
2024-08-16 22:51:42 +05:00
Mingun c383e4f953 Tuple: add tests for deserialization from sequence
(review this commit with "ignore whitespace changes" option on)
2024-08-16 22:51:16 +05:00
Mingun a94d8750fb Newtype: move up the test with tag only 2024-08-16 22:51:13 +05:00
Mingun b0d651be40 Newtype: add tests for deserialization from sequence
(review this commit with "ignore whitespace changes" option on)
2024-08-16 22:51:13 +05:00
Mingun d5a9c11b5c No need to test integer and byte array field names, they already tested for Unit case
There is no difference what variant is deserialized so we can test only one kind of variant
2024-08-16 22:51:10 +05:00
Mingun 6bfe1c435a Unit: add tests for deserialization from bytes tag and content fields 2024-08-16 22:43:15 +05:00
Mingun a02da49b87 Unit: add tests for deserialization from integer tag and content fields 2024-08-16 22:43:15 +05:00
Mingun 29dc6c3367 Unit: add tests for deserialization from sequence
(review this commit with "ignore whitespace changes" option on)
2024-08-16 22:38:02 +05:00
Mingun a7f0bab078 Document fields in internal structs used to deserialize adjacently tagged enums 2024-08-16 21:39:55 +05:00
Mingun 3dc6829303 Integrate bytes test into struct_ test
`newtype` test also integrates test with `Bytes` tag, so be like

Removed the first assert_tokens because it is the same as the first assert in the merged method
2024-08-16 21:39:53 +05:00
Mingun 42e63ff942 Reuse AdjacentlyTagged enum in bytes test
Change 0i32 to 1u8 so the test can be merged with the previous in the next commit
2024-08-16 21:38:23 +05:00
Mingun df07751e6f Group newtype and newtype_with_newtype tests 2024-08-16 21:36:56 +05:00
Mingun 5445f1741b Reuse AdjacentlyTagged enum in newtype_with_newtype test 2024-08-16 21:36:56 +05:00
Mingun 9d0f811221 Remove unnecessary generic 2024-08-16 21:36:56 +05:00
Mingun 36b9a859c4 Test deserialization of the serialized unit format for adjacently tagged enum 2024-08-16 21:36:55 +05:00
Mingun 59628d1712 Create only one value for all checks 2024-08-16 21:36:55 +05:00
Mingun bee7470715 Split test test_adjacently_tagged_enum into four tests for each variant
(review this commit with "ignore whitespace changes" option on)
2024-08-16 21:36:55 +05:00
Mingun 5a359e10f4 Group Newtype variant checks in test_adjacently_tagged_enum together 2024-08-16 21:36:55 +05:00
Mingun 5e37ade519 Move all adjacently tagged enum tests (except flatten) into a dedicated module
Moved and renamed:
From test_annotatons
- test_adjacently_tagged_enum_bytes               => bytes
- flatten::enum_::adjacently_tagged::straitforward=> struct_with_flatten
- test_expecting_message_adjacently_tagged_enum   => expecting_message
- test_partially_untagged_adjacently_tagged_enum  => partially_untagged

From test_macros
- test_adjacently_tagged_newtype_struct           => newtype_with_newtype
- test_adjacently_tagged_enum
- test_adjacently_tagged_enum_deny_unknown_fields => deny_unknown_fields
2024-08-16 21:36:52 +05:00
David Tolnay 1a9ffdbd0c Merge pull request #2788 from Mingun/internally-tagged-enum-tests
Consolidate and add new tests of internally tagged enums
2024-08-15 14:42:28 -07:00
Mingun 2adb0e99b0 Add additional checks for unit and newtype_unit tests
- check that unit variant can be deserialized from a map
- check that newtype variant with unit can be deserialized from a struct
2024-08-15 23:39:14 +05:00
Mingun 71ed1f2f12 Add tests for special and general cases for internally tagged enums
Special case is the tag field first (so the enum variant are known after reading the first entry from map).
General case is the tag field not the first (so we need to buffer entries until we found an entry with tag)
2024-08-15 23:39:13 +05:00
Mingun 47954502af Add tests with borrowed strings for the tag field name and tag value 2024-08-15 23:39:13 +05:00
Mingun 4987fd15f7 Convert newtype_enum and struct_enum tests into modules
Separate testing each variant kind of enum (unit, newtype, tuple, struct) results
in more specific information if that checks fail

(review this commit with "ignore whitespace changes" option on)
2024-08-15 23:39:12 +05:00
Mingun 8bfe0d0ac0 Move and rename tests:
- newtype_variant_containing_unit                   -> newtype_unit
- newtype_variant_containing_unit_struct            -> newtype_unit_struct
- newtype_variant_containing_externally_tagged_enum -> newtype_enum
- struct_variant_containing_unit_variant            -> struct_enum
2024-08-15 23:39:12 +05:00
Mingun 7c0e6bd18f Reuse type in struct_variant_containing_unit_variant 2024-08-15 23:39:11 +05:00
Mingun 41b9c33c2b Reuse type in newtype_variant_containing_externally_tagged_enum 2024-08-15 23:39:11 +05:00
Mingun 28a775db22 Share externally tagged enum Enum between all tests and reuse in struct_variant_containing_unit_variant 2024-08-15 23:39:10 +05:00
Mingun e999600f8f Rename externally tagged enum Inner to Enum 2024-08-15 23:39:10 +05:00
Mingun d3492d8d36 Reuse type in newtype_variant_containing_unit_struct 2024-08-15 23:39:09 +05:00
Mingun 48de0c51b0 Share unit struct Unit between all tests 2024-08-15 23:39:09 +05:00
Mingun 93bda5f1dc Rename unit struct to a generic name: Info->Unit 2024-08-15 23:39:09 +05:00
Mingun 2d75ef6b30 Reuse type in newtype_variant_containing_unit 2024-08-15 23:39:07 +05:00
Mingun f97160f715 Reuse type in unit_variant_with_unknown_fields and add test for sequence 2024-08-15 23:39:06 +05:00
Mingun eb59c776ca Use name "tag" to refer to tag field 2024-08-15 23:39:06 +05:00
Mingun 9128201c78 Use the same order of derives 2024-08-15 23:39:05 +05:00
Mingun 2cbfd37072 Move all other internally tagged enum tests into a dedicated file
Moved all except flattened tests:
- test_internally_tagged_enum_with_skipped_conflict    => with_skipped_conflict
- test_internally_tagged_enum_new_type_with_unit       => newtype_variant_containing_unit
- test_internally_tagged_unit_enum_with_unknown_fields => unit_variant_with_unknown_fields
- test_expecting_message_internally_tagged_enum        => expecting_message
- flatten::enum_::internally_tagged::straightforward   => containing_flatten
2024-08-15 23:39:05 +05:00
Mingun 0939214c51 Move internally tagged enum tests into a dedicated file
Ctrl+X, Ctrl+V
2024-08-15 23:34:01 +05:00
Mingun 8c60f5aea7 Reorder enum variants and tests to canonical order (Unit, Newtype, Tuple, Struct) 2024-08-15 23:34:00 +05:00
Mingun da0ed4021d Give meaningful names to enum variants 2024-08-15 23:34:00 +05:00
Mingun 99f905403b Move all internally tagged enum tests of test_macros into a dedicated module
Moved:
- test_internally_tagged_enum_with_untagged_variant             => untagged_variant
- test_internally_tagged_bytes                                  => string_and_bytes mod
- test_internally_tagged_struct_variant_containing_unit_variant => struct_variant_containing_unit_variant
- test_internally_tagged_borrow                                 => borrow
- test_enum_in_internally_tagged_enum                           => newtype_variant_containing_externally_tagged_enum
- test_internally_tagged_newtype_variant_containing_unit_struct => newtype_variant_containing_unit_struct

(review this commit with "ignore whitespace changes" option on)
2024-08-15 23:34:00 +05:00
Mingun aa0654332d Convert test_internally_tagged_enum into module
(review this commit with "ignore whitespace changes" option on)
2024-08-15 23:33:59 +05:00
David Tolnay af376c22c3 Merge pull request #2803 from jonhoo/mv-flatten-tests
Group flatten tests
2024-08-15 10:53:49 -07:00
Jon Gjengset 477eb7b70e Group flatten tests 2024-08-15 18:28:49 +02:00
David Tolnay 026e91a68c Release 1.0.208 2024-08-15 08:41:27 -07:00
David Tolnay bfbedac919 Merge pull request #2802 from jonhoo/flatten-unit-struct
Support (de-)serializing flattened unit struct
2024-08-15 08:40:11 -07:00
Jon Gjengset 4036ff88ed Support (de-)serializing flattened unit struct
Fixes #2801.
2024-08-15 15:50:54 +02:00
David Tolnay 1b4da41f97 Release 1.0.207 2024-08-12 13:06:46 -07:00
David Tolnay f61d452814 Touch up PR 2795 2024-08-12 13:03:10 -07:00
David Tolnay f9866097a0 Merge pull request #2795 from Mingun/has-flatten-rework
`has_flatten` rework
2024-08-12 13:02:58 -07:00
Mingun 8b769fcc20 Remove unused component from tuple 2024-08-12 19:05:57 +05:00
Mingun 9c954264f4 Include variant aliases in error messages 2024-08-12 19:05:04 +05:00
Mingun 77a6a9d4e1 Take into account only not skipped flatten fields when choose serialization form
Consequence: `FlattenSkipSerializing`
- uses `serialize_struct` instead of `serialize_map`
2024-08-11 20:12:09 +05:00
Mingun 547d843cca Remove dead code - serialize_struct_as_map always called when cattrs.has_flatten()==true 2024-08-11 20:12:08 +05:00
Mingun 005cb84593 Fail with an understandable message is number of fields for serialization is too many 2024-08-11 20:12:07 +05:00
Mingun fd5b5e9aa5 Correctly calculate has_flatten attribute in all cases for deserialization
Consequence: `FlattenSkipDeserializing[DenyUnknown]`
- does not collect data in Field, because do not read them anyway
- gets `deserialize_in_place` method
- gets ability to deserialize from sequence (visit_seq method)
- uses `deserialize_struct` instead of `deserialize_map`
2024-08-11 20:01:33 +05:00
Mingun 0647a7c1fe Fix creating and filling a collections that was not read 2024-08-11 20:01:00 +05:00
David Tolnay 85c73ef8de Release 1.0.206 2024-08-11 00:08:37 -07:00
David Tolnay 5ba1796a7e Resolve doc_markdown pedantic lint on regression test function
warning: you should put bare URLs between `<`/`>` or make a proper Markdown link
        --> test_suite/tests/test_annotations.rs:2383:25
         |
    2383 | /// Regression test for https://github.com/serde-rs/serde/issues/1904
         |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `<https://github.com/serde-rs/serde/issues/1904>`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
         = note: `-W clippy::doc-markdown` implied by `-W clippy::pedantic`
         = help: to override `-W clippy::pedantic` add `#[allow(clippy::doc_markdown)]`
2024-08-11 00:08:16 -07:00
David Tolnay e52b7b380f Touch up PR 2567 2024-08-11 00:05:56 -07:00
David Tolnay 84c7419652 Merge pull request #2794 from dtolnay/neverread
Temporarily ignore collection_is_never_read on FlattenSkipDeserializing
2024-08-11 00:05:31 -07:00
David Tolnay 536221b1f9 Temporarily ignore collection_is_never_read on FlattenSkipDeserializing
error: collection is never read
       --> test_suite/tests/test_gen.rs:723:25
        |
    723 |     #[derive(Serialize, Deserialize)]
        |                         ^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collection_is_never_read
    note: the lint level is defined here
       --> test_suite/tests/test_gen.rs:23:9
        |
    23  | #![deny(clippy::collection_is_never_read)]
        |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
2024-08-10 23:59:23 -07:00
David Tolnay fc55ac70d3 Merge pull request #2567 from Mingun/fix-2565
Correctly process flatten fields in enum variants
2024-08-10 23:28:22 -07:00
Mingun 2afe5b4ef9 Add regression test for issue #2792 2024-08-10 21:29:39 +05:00
Mingun b4ec2595c9 Correctly process flatten fields in enum variants
- Fix incorrect deserialization of variants that doesn't contain flatten field when other contains
- Fix a panic when deriving `Deserialize` for an enum with tuple and struct with flatten field

Fixes (2):
    regression::issue2565::simple_variant
    regression::issue1904 (compilation)
2024-08-09 19:59:23 +05:00
Mingun c3ac7b675a Add regression test for issue #1904
Currently panics in derive:

error: proc-macro derive panicked
    --> test_suite\tests\test_annotations.rs:2386:25
     |
2386 |     #[derive(Serialize, Deserialize, PartialEq, Debug)]
     |                         ^^^^^^^^^^^
     |
     = help: message: assertion failed: !cattrs.has_flatten()

error: proc-macro derive panicked
  --> test_suite\tests\regression\issue1904.rs:57:10
   |
57 | #[derive(Deserialize)]
   |          ^^^^^^^^^^^
   |
   = help: message: assertion failed: !cattrs.has_flatten()

error: proc-macro derive panicked
  --> test_suite\tests\regression\issue1904.rs:47:10
   |
47 | #[derive(Deserialize)]
   |          ^^^^^^^^^^^
   |
   = help: message: assertion failed: !cattrs.has_flatten()

error: proc-macro derive panicked
  --> test_suite\tests\regression\issue1904.rs:37:10
   |
37 | #[derive(Deserialize)]
   |          ^^^^^^^^^^^
   |
   = help: message: assertion failed: !cattrs.has_flatten()

error: proc-macro derive panicked
  --> test_suite\tests\regression\issue1904.rs:27:10
   |
27 | #[derive(Deserialize)]
   |          ^^^^^^^^^^^
   |
   = help: message: assertion failed: !cattrs.has_flatten()

error: proc-macro derive panicked
  --> test_suite\tests\regression\issue1904.rs:16:10
   |
16 | #[derive(Deserialize)]
   |          ^^^^^^^^^^^
   |
   = help: message: assertion failed: !cattrs.has_flatten()

error: proc-macro derive panicked
 --> test_suite\tests\regression\issue1904.rs:7:10
  |
7 | #[derive(Deserialize)]
  |          ^^^^^^^^^^^
  |
  = help: message: assertion failed: !cattrs.has_flatten()
2024-08-09 19:55:56 +05:00
Mingun 24614e44bf Add regression test for issue #2565
failures (1):
    regression::issue2565::simple_variant
2024-08-09 19:53:14 +05:00
David Tolnay 9b868ef831 Release 1.0.205 2024-08-07 18:53:21 -07:00
David Tolnay c3eaf76430 Merge pull request #2791 from dtolnay/flatten
Skip collecting unmatched fields in variants that do not use flatten
2024-08-07 18:52:21 -07:00
David Tolnay 32958dec3b Skip collecting unmatched fields in variants that do not use flatten 2024-08-07 18:43:47 -07:00
David Tolnay d64a97ba1e Ignore confusable_idents warning in test
error: found both `σ` and `o` as identifiers, which look alike
       --> test_suite/tests/test_gen.rs:734:13
        |
    292 |         σ: f64,
        |         - other identifier used here
    ...
    734 |             o: T,
        |             ^ this identifier can be confused with `σ`
        |
    note: the lint level is defined here
       --> test_suite/tests/test_gen.rs:5:9
        |
    5   | #![deny(warnings)]
        |         ^^^^^^^^
        = note: `#[deny(confusable_idents)]` implied by `#[deny(warnings)]`
2024-08-07 18:19:51 -07:00
David Tolnay c3df3372a1 Add test of flatten in enum
error: collection is never read
       --> test_suite/tests/test_gen.rs:728:25
        |
    728 |     #[derive(Serialize, Deserialize)]
        |                         ^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collection_is_never_read
        = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
2024-08-07 18:19:17 -07:00
David Tolnay 8764353fe2 Enable collection_is_never_read nursury lint in test
error: collection is never read
       --> test_suite/tests/test_gen.rs:722:25
        |
    722 |     #[derive(Serialize, Deserialize)]
        |                         ^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collection_is_never_read
    note: the lint level is defined here
       --> test_suite/tests/test_gen.rs:22:9
        |
    22  | #![deny(clippy::collection_is_never_read)]
        |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
2024-08-07 18:16:55 -07:00
David Tolnay e08c5de5dd Merge pull request #2785 from Mingun/serialize_entry-in-flatten-newtype-variant
Use serialize_entry instead of serialize_key + serialize_value when serialize flatten newtype enum variant
2024-08-05 00:17:58 -07:00
Mingun 74b538b8ec Produce error about mismatched types of #[serde(with = "...")] and #[serde(default = "...")] attributes on the attribute itself 2024-08-05 00:29:37 +05:00
Mingun 291ec50d98 Add tests that ensures that error reported for a path for with and default attributes 2024-08-05 00:29:37 +05:00
Mingun bc5af506bd Use serialize_entry instead of serialize_key + serialize_value when serialize flatten newtype enum variant
Serializers that reimplements serialize_entry will get benefits from that
2024-08-03 14:49:38 +05:00
Mingun 21c7fd1bd5 Add tests of #[serde(default)] attribute for units and unions 2024-07-23 21:00:11 +05:00
David Tolnay 28a092261b Work around test suite dead code warnings in nightly-2024-07-07
warning: struct `Cows` is never constructed
       --> test_suite/tests/test_borrow.rs:165:12
        |
    165 |     struct Cows<'a, 'b> {
        |            ^^^^

    warning: struct `Wrap` is never constructed
       --> test_suite/tests/test_borrow.rs:181:12
        |
    181 |     struct Wrap<'a, 'b> {
        |            ^^^^

    warning: struct `StructSkipDefaultGeneric` is never constructed
      --> test_suite/tests/test_de.rs:96:8
       |
    96 | struct StructSkipDefaultGeneric<T> {
       |        ^^^^^^^^^^^^^^^^^^^^^^^^

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

    warning: struct `EmptyBraced` is never constructed
       --> test_suite/tests/test_gen.rs:295:12
        |
    295 |     struct EmptyBraced {}
        |            ^^^^^^^^^^^

    warning: struct `EmptyBracedDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:299:12
        |
    299 |     struct EmptyBracedDenyUnknown {}
        |            ^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `BracedSkipAll` is never constructed
       --> test_suite/tests/test_gen.rs:302:12
        |
    302 |     struct BracedSkipAll {
        |            ^^^^^^^^^^^^^

    warning: struct `BracedSkipAllDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:309:12
        |
    309 |     struct BracedSkipAllDenyUnknown {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `EmptyTuple` is never constructed
       --> test_suite/tests/test_gen.rs:315:12
        |
    315 |     struct EmptyTuple();
        |            ^^^^^^^^^^

    warning: struct `EmptyTupleDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:319:12
        |
    319 |     struct EmptyTupleDenyUnknown();
        |            ^^^^^^^^^^^^^^^^^^^^^

    warning: struct `TupleSkipAll` is never constructed
       --> test_suite/tests/test_gen.rs:322:12
        |
    322 |     struct TupleSkipAll(#[serde(skip_deserializing)] u8);
        |            ^^^^^^^^^^^^

    warning: struct `TupleSkipAllDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:326:12
        |
    326 |     struct TupleSkipAllDenyUnknown(#[serde(skip_deserializing)] u8);
        |            ^^^^^^^^^^^^^^^^^^^^^^^

    warning: enum `EmptyEnum` is never used
       --> test_suite/tests/test_gen.rs:329:10
        |
    329 |     enum EmptyEnum {}
        |          ^^^^^^^^^

    warning: enum `EmptyEnumDenyUnknown` is never used
       --> test_suite/tests/test_gen.rs:333:10
        |
    333 |     enum EmptyEnumDenyUnknown {}
        |          ^^^^^^^^^^^^^^^^^^^^

    warning: enum `EnumSkipAll` is never used
       --> test_suite/tests/test_gen.rs:336:10
        |
    336 |     enum EnumSkipAll {
        |          ^^^^^^^^^^^

    warning: enum `EmptyVariants` is never used
       --> test_suite/tests/test_gen.rs:343:10
        |
    343 |     enum EmptyVariants {
        |          ^^^^^^^^^^^^^

    warning: enum `EmptyVariantsDenyUnknown` is never used
       --> test_suite/tests/test_gen.rs:355:10
        |
    355 |     enum EmptyVariantsDenyUnknown {
        |          ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `UnitDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:367:12
        |
    367 |     struct UnitDenyUnknown;
        |            ^^^^^^^^^^^^^^^

    warning: struct `EmptyArray` is never constructed
       --> test_suite/tests/test_gen.rs:370:12
        |
    370 |     struct EmptyArray {
        |            ^^^^^^^^^^

    warning: enum `Or` is never used
       --> test_suite/tests/test_gen.rs:374:10
        |
    374 |     enum Or<A, B> {
        |          ^^

    warning: enum `OrDef` is never used
       --> test_suite/tests/test_gen.rs:381:10
        |
    381 |     enum OrDef<A, B> {
        |          ^^^^^

    warning: struct `Str` is never constructed
       --> test_suite/tests/test_gen.rs:386:12
        |
    386 |     struct Str<'a>(&'a str);
        |            ^^^

    warning: struct `StrDef` is never constructed
       --> test_suite/tests/test_gen.rs:390:12
        |
    390 |     struct StrDef<'a>(&'a str);
        |            ^^^^^^

    warning: struct `Remote` is never constructed
       --> test_suite/tests/test_gen.rs:393:12
        |
    393 |     struct Remote<'a> {
        |            ^^^^^^

    warning: enum `BorrowVariant` is never used
       --> test_suite/tests/test_gen.rs:401:10
        |
    401 |     enum BorrowVariant<'a> {
        |          ^^^^^^^^^^^^^

    warning: struct `RemoteVisibility` is never constructed
       --> test_suite/tests/test_gen.rs:418:12
        |
    418 |     struct RemoteVisibility {
        |            ^^^^^^^^^^^^^^^^

    warning: struct `FlattenDenyUnknown` is never constructed
       --> test_suite/tests/test_gen.rs:551:12
        |
    551 |     struct FlattenDenyUnknown<T> {
        |            ^^^^^^^^^^^^^^^^^^

    warning: struct `StaticStrStruct` is never constructed
       --> test_suite/tests/test_gen.rs:557:12
        |
    557 |     struct StaticStrStruct<'a> {
        |            ^^^^^^^^^^^^^^^

    warning: struct `StaticStrTupleStruct` is never constructed
       --> test_suite/tests/test_gen.rs:563:12
        |
    563 |     struct StaticStrTupleStruct<'a>(&'a str, &'static str);
        |            ^^^^^^^^^^^^^^^^^^^^

    warning: struct `StaticStrNewtypeStruct` is never constructed
       --> test_suite/tests/test_gen.rs:566:12
        |
    566 |     struct StaticStrNewtypeStruct(&'static str);
        |            ^^^^^^^^^^^^^^^^^^^^^^

    warning: enum `StaticStrEnum` is never used
       --> test_suite/tests/test_gen.rs:569:10
        |
    569 |     enum StaticStrEnum<'a> {
        |          ^^^^^^^^^^^^^

    warning: enum `AdjacentlyTaggedVoid` is never used
       --> test_suite/tests/test_gen.rs:652:10
        |
    652 |     enum AdjacentlyTaggedVoid {}
        |          ^^^^^^^^^^^^^^^^^^^^

    warning: struct `ImplicitlyBorrowedOption` is never constructed
       --> test_suite/tests/test_gen.rs:665:12
        |
    665 |     struct ImplicitlyBorrowedOption<'a> {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: enum `UntaggedNewtypeVariantWith` is never used
       --> test_suite/tests/test_gen.rs:672:10
        |
    672 |     enum UntaggedNewtypeVariantWith {
        |          ^^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `TransparentWith` is never constructed
       --> test_suite/tests/test_gen.rs:682:12
        |
    682 |     struct TransparentWith {
        |            ^^^^^^^^^^^^^^^

    warning: struct `FlattenSkipSerializing` is never constructed
       --> test_suite/tests/test_gen.rs:712:12
        |
    712 |     struct FlattenSkipSerializing<T> {
        |            ^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `FlattenSkipSerializingIf` is never constructed
       --> test_suite/tests/test_gen.rs:719:12
        |
    719 |     struct FlattenSkipSerializingIf<T> {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `FlattenSkipDeserializing` is never constructed
       --> test_suite/tests/test_gen.rs:725:12
        |
    725 |     struct FlattenSkipDeserializing<T> {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^

    warning: enum `Message` is never used
       --> test_suite/tests/test_gen.rs:732:10
        |
    732 |     enum Message {
        |          ^^^^^^^

    warning: struct `MacroRules` is never constructed
       --> test_suite/tests/test_gen.rs:751:20
        |
    751 |             struct MacroRules<'a> {
        |                    ^^^^^^^^^^
    ...
    758 |     deriving!(&'a str);
        |     ------------------ in this macro invocation
        |
        = note: this warning originates in the macro `deriving` (in Nightly builds, run with -Z macro-backtrace for more info)

    warning: struct `BorrowLifetimeInsideMacro` is never constructed
       --> test_suite/tests/test_gen.rs:767:12
        |
    767 |     struct BorrowLifetimeInsideMacro<'a> {
        |            ^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: struct `GenericUnitStruct` is never constructed
       --> test_suite/tests/test_gen.rs:782:12
        |
    782 |     struct GenericUnitStruct<const N: usize>;
        |            ^^^^^^^^^^^^^^^^^

    warning: enum `InternallyTagged` is never used
       --> test_suite/tests/test_gen.rs:869:6
        |
    869 | enum InternallyTagged {
        |      ^^^^^^^^^^^^^^^^

    warning: function `deserialize_generic` is never used
       --> test_suite/tests/test_gen.rs:880:4
        |
    880 | fn deserialize_generic<'de, T, D>(deserializer: D) -> StdResult<T, D::Error>
        |    ^^^^^^^^^^^^^^^^^^^

    warning: struct `Restricted` is never constructed
       --> test_suite/tests/test_gen.rs:643:20
        |
    643 |             struct Restricted {
        |                    ^^^^^^^^^^

    warning: struct `Test` is never constructed
      --> test_suite/tests/test_remote.rs:95:8
       |
    95 | struct Test {
       |        ^^^^

    warning: struct `UnitDef` is never constructed
       --> test_suite/tests/test_remote.rs:135:8
        |
    135 | struct UnitDef;
        |        ^^^^^^^

    warning: struct `PrimitivePubDef` is never constructed
       --> test_suite/tests/test_remote.rs:143:8
        |
    143 | struct PrimitivePubDef(u8);
        |        ^^^^^^^^^^^^^^^

    warning: struct `NewtypePubDef` is never constructed
       --> test_suite/tests/test_remote.rs:151:8
        |
    151 | struct NewtypePubDef(#[serde(with = "UnitDef")] remote::Unit);
        |        ^^^^^^^^^^^^^

    warning: struct `TuplePubDef` is never constructed
       --> test_suite/tests/test_remote.rs:162:8
        |
    162 | struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit);
        |        ^^^^^^^^^^^

    warning: struct `StructPubDef` is never constructed
       --> test_suite/tests/test_remote.rs:177:8
        |
    177 | struct StructPubDef {
        |        ^^^^^^^^^^^^

    warning: struct `StructConcrete` is never constructed
       --> test_suite/tests/test_remote.rs:193:8
        |
    193 | struct StructConcrete {
        |        ^^^^^^^^^^^^^^

    warning: enum `EnumConcrete` is never used
       --> test_suite/tests/test_remote.rs:199:6
        |
    199 | enum EnumConcrete {
        |      ^^^^^^^^^^^^

    warning: enum `ErrorKind` is never used
       --> test_suite/tests/test_remote.rs:204:6
        |
    204 | enum ErrorKind {
        |      ^^^^^^^^^

    warning: enum `ErrorKindDef` is never used
       --> test_suite/tests/test_remote.rs:214:6
        |
    214 | enum ErrorKindDef {
        |      ^^^^^^^^^^^^

    warning: struct `PrimitivePub` is never constructed
      --> test_suite/tests/test_remote.rs:10:16
       |
    10 |     pub struct PrimitivePub(pub u8);
       |                ^^^^^^^^^^^^

    warning: struct `NewtypePub` is never constructed
      --> test_suite/tests/test_remote.rs:14:16
       |
    14 |     pub struct NewtypePub(pub Unit);
       |                ^^^^^^^^^^

    warning: struct `TuplePub` is never constructed
      --> test_suite/tests/test_remote.rs:18:16
       |
    18 |     pub struct TuplePub(pub u8, pub Unit);
       |                ^^^^^^^^

    warning: struct `StructPub` is never constructed
      --> test_suite/tests/test_remote.rs:25:16
       |
    25 |     pub struct StructPub {
       |                ^^^^^^^^^

    warning: enum `EnumGeneric` is never used
      --> test_suite/tests/test_remote.rs:89:14
       |
    89 |     pub enum EnumGeneric<T> {
       |              ^^^^^^^^^^^

    warning: struct `Tuple` is never constructed
      --> test_suite/tests/test_self.rs:44:12
       |
    44 |     struct Tuple(
       |            ^^^^^

    warning: associated items `ASSOC` and `assoc` are never used
      --> test_suite/tests/test_self.rs:52:15
       |
    51 |     impl Tuple {
       |     ---------- associated items in this implementation
    52 |         const ASSOC: usize = 1;
       |               ^^^^^
    53 |         const fn assoc() -> usize {
       |                  ^^^^^

    warning: enum `Enum` is never used
      --> test_suite/tests/test_self.rs:63:10
       |
    63 |     enum Enum {
       |          ^^^^

    warning: associated items `ASSOC` and `assoc` are never used
      --> test_suite/tests/test_self.rs:79:15
       |
    78 |     impl Enum {
       |     --------- associated items in this implementation
    79 |         const ASSOC: usize = 1;
       |               ^^^^^
    80 |         const fn assoc() -> usize {
       |                  ^^^^^

    warning: struct `Unit` is never constructed
      --> test_suite/no_std/src/main.rs:26:8
       |
    26 | struct Unit;
       |        ^^^^

    warning: struct `Newtype` is never constructed
      --> test_suite/no_std/src/main.rs:29:8
       |
    29 | struct Newtype(u8);
       |        ^^^^^^^

    warning: struct `Tuple` is never constructed
      --> test_suite/no_std/src/main.rs:32:8
       |
    32 | struct Tuple(u8, u8);
       |        ^^^^^

    warning: struct `Struct` is never constructed
      --> test_suite/no_std/src/main.rs:35:8
       |
    35 | struct Struct {
       |        ^^^^^^

    warning: enum `Enum` is never used
      --> test_suite/no_std/src/main.rs:40:6
       |
    40 | enum Enum {
       |      ^^^^
2024-07-06 19:26:29 -07:00
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
David Tolnay 59892e7b58 Release 1.0.191 2023-11-06 11:30:27 -08:00
David Tolnay 97dd07a7d1 Merge pull request #2647 from dtolnay/doccfg
Render `doc(cfg(...))` on feature gated APIs in docs.rs
2023-11-06 11:29:38 -08:00
David Tolnay c8bc97c81b Document "rc" and "unstable" features on docs.rs 2023-11-06 11:22:25 -08:00
David Tolnay 9dacfbbd69 Fill in more doc(cfg) attributes 2023-11-06 11:20:29 -08:00
David Tolnay 05c2509d07 Relocate cfg attrs into deref_impl 2023-11-06 11:15:27 -08:00
David Tolnay 64f949b37b Relocate cfg attrs into parse_ip_impl and parse_socket_impl 2023-11-06 11:15:08 -08:00
David Tolnay 3f339de36a Relocate cfg attrs into seq_impl and map_impl 2023-11-06 11:15:08 -08:00
David Tolnay 215c2b71ef Relocate cfg attrs into forwarded_impl macro
This will allow adding #[doc(cfg(feature = "..."))] attributes to the
impl in an upcoming commit.
2023-11-06 08:55:14 -08:00
David Tolnay ce8fef7e0b Show that derives are specific to feature="derive" in documentation 2023-11-06 08:55:14 -08:00
David Tolnay 0726b2c479 Enable feature(doc_cfg) during docs.rs documentation build 2023-11-06 08:55:14 -08:00
Robsdedude 589549d7e6 Allow internal tag field in untagged variant 2023-11-06 12:14:49 +01:00
David Tolnay edb1a586d8 Release 1.0.190 2023-10-25 20:05:13 -07:00
David Tolnay 11c2917040 Merge pull request #2637 from dtolnay/nansign
Ensure f32 deserialized from f64 and vice versa preserve NaN sign
2023-10-25 20:03:05 -07:00
David Tolnay 6ba9c12ff6 Float copysign does not exist in libcore yet 2023-10-25 19:55:14 -07:00
David Tolnay d2fcc346b9 Ensure f32 deserialized from f64 and vice versa preserve NaN sign 2023-10-25 19:45:53 -07:00
David Tolnay a091a07aa2 Add float NaN tests 2023-10-25 19:45:53 -07:00
David Tolnay bb4135cae8 Fix unused imports
warning: unused imports: `cmp`, `mem`, `slice`
       --> serde/src/lib.rs:171:26
        |
    171 |     pub use self::core::{cmp, iter, mem, num, ptr, slice, str};
        |                          ^^^        ^^^            ^^^^^
        |
        = note: `#[warn(unused_imports)]` on by default
2023-10-24 22:32:42 -07:00
David Tolnay 8de84b7ca3 Resolve get_first clippy lint
warning: accessing first element with `variant.fields.get(0)`
        --> serde_derive/src/de.rs:1843:27
         |
    1843 |             let default = variant.fields.get(0).map(|field| {
         |                           ^^^^^^^^^^^^^^^^^^^^^ help: try: `variant.fields.first()`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#get_first
         = note: `-W clippy::get-first` implied by `-W clippy::all`
         = help: to override `-W clippy::all` add `#[allow(clippy::get_first)]`

    warning: accessing first element with `variant.fields.get(0)`
        --> serde_derive/src/de.rs:1888:27
         |
    1888 |             let default = variant.fields.get(0).map(|field| {
         |                           ^^^^^^^^^^^^^^^^^^^^^ help: try: `variant.fields.first()`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#get_first
2023-10-21 22:01:10 -07:00
David Tolnay 9cdf332029 Remove 'remember to update' reminder from Cargo.toml 2023-10-17 21:05:31 -07:00
David Tolnay e94fc65f01 Release 1.0.189 2023-10-12 19:20:43 -07:00
David Tolnay b908487476 Remove double nesting of first_attempt
`expr` is of type serde_derive::fragment::Expr, which can be
interpolated directly in any expression position. It does not
need to be nested in another set of braces.
2023-10-12 19:18:42 -07:00
David Tolnay 2a7c7faeb4 Merge pull request #2613 from ahl/fix-untagged-plus-simple
"cannot infer type" from Deserialize derive macro with simple variants and untagged variants
2023-10-12 19:15:32 -07:00
David Tolnay e302e15eea Merge pull request #2625 from marcospb19/add-csv-to-the-list
Add CSV to the formats list
2023-10-09 19:23:12 -07:00
João Marcos P. Bezerra 1cbea892cf Add CSV to the formats list 2023-10-09 22:59:56 -03:00
David Tolnay 37a32857a2 Update ui test suite to nightly-2023-10-06 2023-10-05 23:24:34 -04:00
David Tolnay 8c4aad3a59 Clean up unneeded raw strings in test 2023-09-26 19:09:30 -07:00
David Tolnay 1774794b19 Resolve needless_raw_string_hashes clippy lint in test
warning: unnecessary hashes around raw string literal
        --> test_suite/tests/test_annotations.rs:2722:9
         |
    2722 |         r#"invalid type: unit value, expected variant identifier"#,
         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
         = note: `-W clippy::needless-raw-string-hashes` implied by `-W clippy::all`
         = help: to override `-W clippy::all` add `#[allow(clippy::needless_raw_string_hashes)]`
    help: remove all the hashes around the literal
         |
    2722 -         r#"invalid type: unit value, expected variant identifier"#,
    2722 +         r"invalid type: unit value, expected variant identifier",
         |

    warning: unnecessary hashes around raw string literal
        --> test_suite/tests/test_annotations.rs:2743:9
         |
    2743 |         r#"invalid type: unit value, expected variant identifier"#,
         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the literal
         |
    2743 -         r#"invalid type: unit value, expected variant identifier"#,
    2743 +         r"invalid type: unit value, expected variant identifier",
         |

    warning: unnecessary hashes around raw string literal
        --> test_suite/tests/test_annotations.rs:2769:9
         |
    2769 |         r#"invalid type: unit value, expected variant of enum Enum"#,
         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the literal
         |
    2769 -         r#"invalid type: unit value, expected variant of enum Enum"#,
    2769 +         r"invalid type: unit value, expected variant of enum Enum",
         |

    warning: unnecessary hashes around raw string literal
        --> test_suite/tests/test_annotations.rs:2782:63
         |
    2782 |     assert_de_tokens_error::<Enum>(&[Token::Str("Untagged")], r#"something strange..."#);
         |                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the literal
         |
    2782 -     assert_de_tokens_error::<Enum>(&[Token::Str("Untagged")], r#"something strange..."#);
    2782 +     assert_de_tokens_error::<Enum>(&[Token::Str("Untagged")], r"something strange...");
         |

    warning: unnecessary hashes around raw string literal
        --> test_suite/tests/test_annotations.rs:2803:9
         |
    2803 |         r#"invalid type: unit value, expected something strange..."#,
         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the literal
         |
    2803 -         r#"invalid type: unit value, expected something strange..."#,
    2803 +         r"invalid type: unit value, expected something strange...",
         |

    warning: unnecessary hashes around raw string literal
        --> test_suite/tests/test_annotations.rs:2812:9
         |
    2812 |         r#"invalid type: map, expected something strange..."#,
         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the literal
         |
    2812 -         r#"invalid type: map, expected something strange..."#,
    2812 +         r"invalid type: map, expected something strange...",
         |

    warning: unnecessary hashes around raw string literal
        --> test_suite/tests/test_annotations.rs:2817:9
         |
    2817 |         r#"invalid type: unit value, expected something strange..."#,
         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the literal
         |
    2817 -         r#"invalid type: unit value, expected something strange..."#,
    2817 +         r"invalid type: unit value, expected something strange...",
         |

    warning: unnecessary hashes around raw string literal
        --> test_suite/tests/test_annotations.rs:2828:9
         |
    2828 |         r#"invalid type: map, expected something strange..."#,
         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the literal
         |
    2828 -         r#"invalid type: map, expected something strange..."#,
    2828 +         r"invalid type: map, expected something strange...",
         |
2023-09-26 19:05:18 -07:00
David Tolnay 1af23f1f2d Test docs.rs documentation build in CI 2023-09-24 10:53:44 -07:00
Adam H. Leventhal 94fbc3d388 fix clippy 2023-09-07 22:17:22 -07:00
Adam H. Leventhal 8da2058e2a fix deserialization of untagged variants within internally or adjacently
tagged enums
2023-09-07 17:19:27 -07:00
Adam H. Leventhal 09993a904a Fix for "cannot infer type" from Deserialize derive macro with simple
variants and untagged variants
2023-09-06 15:33:28 -07:00
Adam H. Leventhal 5d1403461c add failing test 2023-09-06 15:31:16 -07:00
David Tolnay ddc1ee564b Release serde_derive_internals 0.29.0 2023-09-06 14:02:05 -07:00
David Tolnay 00a54b848a Update actions/checkout@v3 -> v4 2023-09-04 22:35:02 -07:00
David Tolnay dad15b9fd0 Release 1.0.188 2023-08-25 19:16:10 -07:00
David Tolnay d89c19f903 Revert "Adopt new Cargo feature resolver"
This reverts commit e1c27243b2.

Closes https://github.com/serde-rs/serde/issues/2603.
2023-08-25 19:15:26 -07:00
David Tolnay 146dc0fad5 Release 1.0.187 2023-08-25 10:53:36 -07:00
David Tolnay d26852deef Merge pull request #2602 from dtolnay/resolver
Adopt new Cargo feature resolver
2023-08-25 10:52:42 -07:00
David Tolnay e1c27243b2 Adopt new Cargo feature resolver 2023-08-25 10:35:02 -07:00
David Tolnay dbbfe7abe2 Merge pull request #2600 from dtolnay/oldemscripten
Remove support for emscripten targets on rustc older than 1.40
2023-08-23 22:18:20 -07:00
David Tolnay dc24d12ce0 Clean up all usage of serde_if_integer128 2023-08-23 22:14:23 -07:00
David Tolnay 4e7533e872 Remove support for emscripten targets on rustc older than 1.40 2023-08-23 22:07:21 -07:00
David Tolnay 5d036515ed Release 1.0.186 2023-08-23 17:08:06 -07:00
David Tolnay a741293886 Merge pull request #2599 from dtolnay/encodeutf8
Remove custom encode_utf8 implementation in favor of standard one
2023-08-23 17:06:39 -07:00
David Tolnay f8d0b26d2f Remove custom encode_utf8 implementation in favor of standard one 2023-08-23 17:01:58 -07:00
David Tolnay 7007c1bea5 Merge pull request #2598 from dtolnay/lockstepversion
Duplicate the serde_derive dependency version in one fewer place
2023-08-23 16:34:27 -07:00
David Tolnay 0d8ebac7e1 Duplicate the serde_derive dependency version in one fewer place 2023-08-23 16:29:29 -07:00
David Tolnay 212c42c74f Merge pull request #2597 from dtolnay/lockstepcomment
Reword PR 2588 comment
2023-08-23 16:29:21 -07:00
David Tolnay 919f6be887 Reword PR 2588 comment 2023-08-23 16:24:14 -07:00
David Tolnay c0f70428ba Merge pull request 2588 from soqb:use-impossible-cfg-to-lockstep-serde-derive 2023-08-23 16:17:23 -07:00
David Tolnay e797c90ebd Merge pull request #2594 from Uzaaft/master
Fix: Use `&[T]` instead of `&Vec<T>` wherever possible
2023-08-23 16:09:22 -07:00
David Tolnay fc04d1219a Remove useless discard of function argument that is used 2023-08-23 16:05:07 -07:00
Uzair Aftab df4ad5884d Fix: Use &[T] instead of &Vec<T> 2023-08-21 09:44:03 +02:00
David Tolnay 3c7dd6fc1e Release 1.0.185 2023-08-20 21:41:21 -07:00
David Tolnay 8b196ea1c8 Merge pull request #2592 from dtolnay/remotenonexhaustive
Fix "cannot move out of *self which is behind a shared reference"
2023-08-20 21:40:37 -07:00
David Tolnay 1f8c8ad5a3 Fix "cannot move out of *self which is behind a shared reference" 2023-08-20 21:37:14 -07:00
David Tolnay 870925d503 Add repro of issue 2591
error[E0507]: cannot move out of `*__self` which is behind a shared reference
       --> test_suite/tests/test_remote.rs:210:10
        |
    210 | #[derive(Serialize, Deserialize)]
        |          ^^^^^^^^^
        |          |
        |          data moved here
        |          move occurs because `unrecognized` has type `ErrorKind`, which does not implement the `Copy` trait
        |
        = note: this error originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)
    help: consider borrowing here
        |
    210 | #[derive(&Serialize, Deserialize)]
        |          +
2023-08-20 21:36:30 -07:00
David Tolnay d593215ef7 No need for slow macOS CI if there is no platform-specific code 2023-08-20 21:27:07 -07:00
David Tolnay 110af31b48 Merge pull request #2590 from pinkforest/phase-out-precompiled
Phase out precompiled
2023-08-20 21:00:39 -07:00
pinkforest 360606b9a6 Following consensus on: #2580 (review)
This PR phases out the precompiled per final consensus made in #2580
i#
Fix a cfg
2023-08-21 13:53:48 +10:00
David Tolnay 151b45ae36 Release 1.0.184 2023-08-20 19:49:55 -07:00
soqb 2ea7e1300f guarantee serde is in lockstep with serde_derive 2023-08-21 00:53:22 +01:00
Oli Scherer 4617c957b9 Merge pull request #2587 from wucke13/master
fix shebang in build.sh
2023-08-21 00:22:31 +02:00
wucke13 2547ed83ca fix shebang in build.sh
This fixes #2583.
2023-08-20 23:51:47 +02:00
David Tolnay bfcd44704f Discard the possibility of upx compressing binary
This adds too much decompression overhead per invocation.

It could work if the subprocess were reused across multiple macro
expansions (https://github.com/serde-rs/serde/pull/2523).
2023-08-17 19:07:42 -07:00
David Tolnay 7b548db91e Merge pull request #2572 from serde-rs/cargorm
Adopt `cargo rm` after Cargo bugfix
2023-08-14 04:21:23 -07:00
David Tolnay d39dea85ad Adopt 'cargo rm' after Cargo bugfix 2023-08-14 04:12:55 -07:00
David Tolnay 5e56c9fba8 Merge pull request #2570 from dtolnay/remotenonexhaustive
Treat unmatched non-exhaustive remote variant as serde(skip)
2023-08-13 21:20:42 -07:00
David Tolnay 8d3a03288b Treat unmatched non-exhaustive remote variant as serde(skip) 2023-08-13 21:14:33 -07:00
David Tolnay cb490ec16d Add test of remote enum with non_exhaustive 2023-08-13 21:14:12 -07:00
David Tolnay 45271c3676 Resolve ignored_unit_patterns pedantic clippy lint
warning: matching over `()` is more explicit
       --> serde_derive/src/internals/attr.rs:710:33
        |
    710 |         (Some((untagged_tokens, _)), Some((tag_tokens, _)), None) => {
        |                                 ^ help: use `()` instead of `_`: `()`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns
        = note: `-W clippy::ignored-unit-patterns` implied by `-W clippy::pedantic`

    warning: matching over `()` is more explicit
       --> serde_derive/src/internals/attr.rs:721:33
        |
    721 |         (Some((untagged_tokens, _)), None, Some((content_tokens, _))) => {
        |                                 ^ help: use `()` instead of `_`: `()`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns

    warning: matching over `()` is more explicit
       --> serde_derive/src/internals/attr.rs:728:33
        |
    728 |         (Some((untagged_tokens, _)), Some((tag_tokens, _)), Some((content_tokens, _))) => {
        |                                 ^ help: use `()` instead of `_`: `()`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns

    warning: matching over `()` is more explicit
       --> serde_derive/src/internals/attr.rs:750:44
        |
    750 |         (_, Some((field_identifier_tokens, _)), Some((variant_identifier_tokens, _))) => {
        |                                            ^ help: use `()` instead of `_`: `()`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns

    warning: matching over `()` is more explicit
       --> serde_derive/src/internals/attr.rs:750:82
        |
    750 |         (_, Some((field_identifier_tokens, _)), Some((variant_identifier_tokens, _))) => {
        |                                                                                  ^ help: use `()` instead of `_`: `()`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns
2023-08-11 20:27:21 -07: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
David Tolnay 05a5b7e3c6 Release 1.0.183 2023-08-06 21:00:14 -07:00
David Tolnay 3bff326fb3 Merge pull request #2555 from Mingun/field
Refactor code that generates `__Field` enums
2023-08-06 18:23:52 -07:00
David Tolnay aaadd93878 Merge pull request #2556 from DBLouis/master
Add forward impl for OsStr
2023-08-06 18:02:21 -07:00
Louis Dupré Bertoni 9c864f0b02 Add forward impl for OsStr 2023-08-06 19:41:19 +03:00
Mingun 070cce0d9c Get rid of temporary variable 2023-08-06 19:55:48 +05:00
Mingun b58e8bac12 Replace if let Some(...) = ... to Option::map 2023-08-06 19:53:39 +05:00
Mingun ada50b077e ignore_variant variable is always None, let's take this into account 2023-08-06 19:36:48 +05:00
Mingun 5e313a7330 Move generiс code out-of-function, create more specialized and simple code 2023-08-06 19:35:27 +05:00
Mingun 2a36d11238 Introduce a dedicated function for generating Field enum
(the enum that represents all fields of a struct)
2023-08-06 19:32:53 +05:00
David Tolnay b6685cf9dd Release 1.0.182 2023-08-05 22:16:46 -07:00
David Tolnay fc273c6763 Resolve needless_return clippy lint in PR 2553
warning: unneeded `return` statement
        --> serde_derive/src/de.rs:2986:13
         |
    2986 |             return quote!(#assign_to __default.#member);
         |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
         = note: `-W clippy::needless-return` implied by `-W clippy::all`
    help: remove `return`
         |
    2986 -             return quote!(#assign_to __default.#member);
    2986 +             quote!(#assign_to __default.#member)
         |
2023-08-05 22:16:19 -07:00
David Tolnay bd7b0e257e Touch up PR 2553 2023-08-05 22:13:09 -07:00
David Tolnay 73931692b2 Merge pull request #2553 from Mingun/default-on-tuples
Allow `#[serde(default)]` on tuple structs
2023-08-05 22:12:10 -07:00
David Tolnay 4d93e9f44c Keep deserialize aliases as a sorted set 2023-08-05 17:06:11 -07:00
David Tolnay da55ed7e8d Remove some clones of names of things 2023-08-05 17:01:34 -07:00
David Tolnay e3617e1f28 Update explanation of correct_aliases 2023-08-05 16:39:38 -07:00
David Tolnay 431636af0d Merge pull request #2458 from Mingun/identifier
Keep aliases always sorted and include aliases in expecting message for field/variant_identifier
2023-08-05 16:39:14 -07:00
David Tolnay 891ced598a Update test suite to nightly-2023-08-05
error: the feature `lang_items` is internal to the compiler or standard library
     --> src/main.rs:1:12
      |
    1 | #![feature(lang_items, start)]
      |            ^^^^^^^^^^
      |
      = note: using it is strongly discouraged
      = note: `#[deny(internal_features)]` on by default
2023-08-04 19:09:00 -07:00
David Tolnay 57dc0ee769 Release 1.0.181 2023-08-03 16:58:45 -07:00
David Tolnay 5e102c4da1 Relocate private size_hint module
Let's keep crate::__private for only things that *need* to be accessible
to the macro-generated code. Size_hint can be pub(crate).
2023-08-03 16:53:44 -07:00
Mingun 5c33931422 Allow #[serde(default)] on tuple structs 2023-08-03 22:32:34 +05:00
David Tolnay 4aa54222f4 Delete double reference when setting up adjacently tagged variant seed 2023-08-01 22:54:47 -07:00
David Tolnay ef4f860384 Improve "expecting" message of adjacently tagged enum variant 2023-08-01 22:49:44 -07:00
David Tolnay 9bd52ec5c1 Inline AdjacentlyTaggedEnumVariant::new 2023-08-01 22:38:47 -07:00
David Tolnay 5cdd82d41e Remove Serializer from name of private type that is not a Serializer 2023-08-01 22:26:04 -07:00
David Tolnay 110bf10481 Condense AdjacentlyTaggedEnummVariantVisitor implementation 2023-08-01 22:26:03 -07:00
David Tolnay 43035f6f37 Merge pull request #2505 from Baptistemontan/rework_adjacently_tagged_enum
Revisit of the representation of adjacently tagged enums tag
2023-08-01 22:25:31 -07:00
David Tolnay 83b1a3d5dc Merge pull request #2443 from Mingun/deserialize-in-place
Simplify code in deserialize_in_place_struct and implement #2387 for in-place case
2023-08-01 21:51:22 -07:00
Mingun 878110a4bc Simplify code after dead code elimination 2023-08-01 19:03:21 +05:00
Mingun 59ec8b7db2 Remove dead code - variant_ident and deserializer are always None 2023-08-01 19:03:20 +05:00
Mingun cae1b43829 Inline deserialize_newtype_struct_in_place 2023-08-01 19:03:19 +05:00
Mingun 99fde4ee3e Implement #2387 also for deserialize_in_place method 2023-08-01 19:03:19 +05:00
Mingun afe3872810 Simplify check for missing fields 2023-08-01 19:03:18 +05:00
Mingun 3a3e6bf103 Reorder variables to match order in final quote! 2023-08-01 19:03:18 +05:00
Mingun 935f0bd70f Merge some quote! blocks 2023-08-01 19:03:17 +05:00
Mingun 5c18bfeda6 Inline deserialize_struct_as_struct_in_place_visitor 2023-08-01 19:03:17 +05:00
Baptiste de Montangon 957ef206d1 Revisit of the representation of adjacently tagged enums tag 2023-07-31 20:53:02 +02:00
David Tolnay 0c367838cc Merge pull request #2548 from dtolnay/toolattr
Adopt tool attrs for clippy lint level attributes
2023-07-31 11:48:33 -07:00
David Tolnay 2023cf345f Adopt tool attrs for clippy lint level attributes
Requires rustc 1.31+.
2023-07-31 11:39:31 -07:00
David Tolnay 033d05f70b Release 1.0.180 2023-07-31 11:16:12 -07:00
David Tolnay fe4e3fd3b0 Merge pull request #2547 from dtolnay/tombstone
Delete tombstones of the `__private` module
2023-07-30 22:48:34 -07:00
David Tolnay 8a8a8a70ee Delete tombstones of the __private module
These are previous names of the `__private` module -- first
`serde::export` then `serde::private` then `serde::__private` -- in all
cases marked `doc(hidden)` and documented as not public API. Leaving a
tombstone made rustc give a better diagnostic "module is private" rather
than "unresolved import". But the rename to `__private` was 2.5 years
ago in dd1f4b483e so it's unlikely anyone
is still benefiting from the tombstone at this point.
2023-07-30 22:44:59 -07:00
David Tolnay 339dca828d Merge pull request #2546 from dtolnay/edition
Update to 2018 edition
2023-07-30 22:11:44 -07:00
David Tolnay 0d7349fa4e Resolve ambiguous core import on rustc 1.64 through 1.71
In 1.72+, this is fixed by https://github.com/rust-lang/rust/pull/112086.

    error[E0659]: `core` is ambiguous
       --> serde/src/lib.rs:227:13
        |
    227 |     pub use core::ffi::CStr;
        |             ^^^^ ambiguous name
        |
        = note: ambiguous because of multiple potential import sources
        = note: `core` could refer to a built-in crate
        = help: use `::core` to refer to this crate unambiguously
    note: `core` could also refer to the module defined here
       --> serde/src/lib.rs:166:5
        |
    166 | /     mod core {
    167 | |         #[cfg(not(feature = "std"))]
    168 | |         pub use core::*;
    169 | |         #[cfg(feature = "std")]
    170 | |         pub use std::*;
    171 | |     }
        | |_____^
        = help: use `self::core` to refer to this module unambiguously
2023-07-30 22:06:18 -07:00
David Tolnay 830528d5b1 Update to 2018 edition 2023-07-30 21:45:35 -07:00
David Tolnay ab90fbc7c9 Apply 'cargo fix --edition' 2023-07-30 21:42:57 -07:00
David Tolnay 3eec111e8f Delete support for compilers without crate::-based module system 2023-07-30 21:42:57 -07:00
David Tolnay 9388433642 Rename 'try!' macro to 'tri!' in preparation for 2018 edition
Because 'try' is a keyword in 2018+.
2023-07-30 21:29:53 -07:00
David Tolnay ba12070665 Merge pull request #2545 from dtolnay/up
Delete support for rustc versions 1.19 through 1.27
2023-07-30 21:25:58 -07:00
David Tolnay a57a324d72 Delete support for compilers without NonZero integer types 2023-07-30 21:14:32 -07:00
David Tolnay 92e91b3557 Delete support for compilers without Iterator::try_for_each 2023-07-30 21:14:31 -07:00
David Tolnay 4dcf791706 Delete support for compilers without inclusive range accessors 2023-07-30 21:11:43 -07:00
David Tolnay e77900fb94 Update integer128 case in build script 2023-07-30 21:11:09 -07:00
David Tolnay 1b14cadf20 Delete support for compilers without core::ops::Bound 2023-07-30 21:11:02 -07:00
David Tolnay 4f59cd217a Delete support for compilers without core::time 2023-07-30 21:10:49 -07:00
David Tolnay 27c8b2d66a Delete support for compilers without dynamically sized Rc construction 2023-07-30 20:48:27 -07:00
David Tolnay 89976c2712 Delete support for compilers without PathBuf::into_boxed_path 2023-07-30 20:48:27 -07:00
David Tolnay c91737fef1 Delete support for compilers without CString::into_boxed_c_str 2023-07-30 20:48:27 -07:00
David Tolnay a100719bc6 Delete support for compilers without core::cmp::Reverse 2023-07-30 20:48:27 -07:00
David Tolnay 9a0e149225 Sort version checks in build.rs 2023-07-30 20:48:27 -07:00
David Tolnay 9350927903 Delete support for compilers without std::collections::Bound 2023-07-30 20:48:27 -07:00
David Tolnay 677c13a4ec Merge pull request #2544 from dtolnay/testprecompiled
Add CI job to run test suite against precompiled serde_derive
2023-07-30 18:58:13 -07:00
David Tolnay ee8e1ee7ff Add CI job to run test suite against precompiled serde_derive 2023-07-30 18:50:16 -07:00
David Tolnay f969080b9f Pull in syn fix that makes serde test suite independent of "full" feature
See https://github.com/dtolnay/syn/pull/1491.
2023-07-30 17:39:44 -07:00
David Tolnay c2b16bfbb0 Release 1.0.179 2023-07-30 17:20:10 -07:00
David Tolnay e7df53701c Resolve doc_markdown clippy lint from PR 2448
warning: item in documentation is missing backticks
        --> test_suite/tests/test_annotations.rs:2870:25
         |
    2870 |             /// Reaches crate::private::de::content::VariantDeserializer::tuple_variant
         |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
         = note: `-W clippy::doc-markdown` implied by `-W clippy::pedantic`
    help: try
         |
    2870 |             /// Reaches `crate::private::de::content::VariantDeserializer::tuple_variant`
         |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    warning: item in documentation is missing backticks
        --> test_suite/tests/test_annotations.rs:2871:17
         |
    2871 |             /// Content::Seq case
         |                 ^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
    help: try
         |
    2871 |             /// `Content::Seq` case
         |                 ~~~~~~~~~~~~~~

    warning: item in documentation is missing backticks
        --> test_suite/tests/test_annotations.rs:2872:21
         |
    2872 |             /// via FlatMapDeserializer::deserialize_enum
         |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
    help: try
         |
    2872 |             /// via `FlatMapDeserializer::deserialize_enum`
         |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    warning: item in documentation is missing backticks
        --> test_suite/tests/test_annotations.rs:2894:25
         |
    2894 |             /// Reaches crate::private::de::content::VariantDeserializer::struct_variant
         |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
    help: try
         |
    2894 |             /// Reaches `crate::private::de::content::VariantDeserializer::struct_variant`
         |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    warning: item in documentation is missing backticks
        --> test_suite/tests/test_annotations.rs:2895:17
         |
    2895 |             /// Content::Seq case
         |                 ^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
    help: try
         |
    2895 |             /// `Content::Seq` case
         |                 ~~~~~~~~~~~~~~

    warning: item in documentation is missing backticks
        --> test_suite/tests/test_annotations.rs:2896:21
         |
    2896 |             /// via FlatMapDeserializer::deserialize_enum
         |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
    help: try
         |
    2896 |             /// via `FlatMapDeserializer::deserialize_enum`
         |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    warning: item in documentation is missing backticks
        --> test_suite/tests/test_annotations.rs:2921:25
         |
    2921 |             /// Reaches crate::private::de::content::VariantDeserializer::struct_variant
         |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
    help: try
         |
    2921 |             /// Reaches `crate::private::de::content::VariantDeserializer::struct_variant`
         |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    warning: item in documentation is missing backticks
        --> test_suite/tests/test_annotations.rs:2922:17
         |
    2922 |             /// Content::Map case
         |                 ^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
    help: try
         |
    2922 |             /// `Content::Map` case
         |                 ~~~~~~~~~~~~~~

    warning: item in documentation is missing backticks
        --> test_suite/tests/test_annotations.rs:2923:21
         |
    2923 |             /// via FlatMapDeserializer::deserialize_enum
         |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
    help: try
         |
    2923 |             /// via `FlatMapDeserializer::deserialize_enum`
         |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2023-07-30 16:15:29 -07:00
David Tolnay 02c34e490b Resolve redundant_field_names clippy lint from PR 2448
warning: redundant field names in struct initialization
        --> serde/src/private/ser.rs:1278:13
         |
    1278 |             map: map,
         |             ^^^^^^^^ help: replace it with: `map`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
         = note: `-W clippy::redundant-field-names` implied by `-W clippy::all`
2023-07-30 16:07:27 -07:00
David Tolnay 427c839b3d Merge pull request #2448 from Mingun/ser-flatten-enums
Implement serialization of tuple variants of flatten enums
2023-07-30 16:02:37 -07:00
David Tolnay 48aa054f53 Release 1.0.178 2023-07-28 16:09:39 -07:00
David Tolnay 3616860203 Delete broken symlink from precompiled derive sources 2023-07-28 16:09:22 -07:00
David Tolnay 861b0dfea2 Consistently list StdError under 'Re-exports' heading of rustdoc 2023-07-28 16:06:49 -07:00
David Tolnay 8b3d71ae2d Merge pull request #2541 from dtolnay/de-core-error
Fix `serde::de::StdError` in no-std unstable build
2023-07-28 16:05:14 -07:00
David Tolnay ff5442cd9e Add no-std unstable build in CI 2023-07-28 16:00:07 -07:00
David Tolnay 92d686f9a5 Fix serde::de::StdError in no-std unstable build 2023-07-28 15:58:57 -07:00
David Tolnay 7b09cccd77 Merge pull request #2539 from dtolnay/questionmark
Replace `try!` with `?` in serde_derive
2023-07-27 19:20:15 -07:00
David Tolnay 6f1f38d046 Replace 'try!' with '?' in serde_derive 2023-07-27 19:16:11 -07:00
David Tolnay db8f06467b Eliminate workaround for pre-1.17 rustc in serde_derive
The oldest compiler supported by serde_derive by this point is 1.56.
2023-07-27 19:05:57 -07:00
David Tolnay 91ec1c290f Enforce question mark not used in serde crate yet
Question mark regresses compile time by 6.5–7.5%.
2023-07-27 19:02:11 -07:00
David Tolnay 0676673ca5 Release 1.0.177 2023-07-27 10:51:22 -07:00
David Tolnay 7a4335d664 Merge pull request #2536 from jplatte/jplatte/error-span
Update error span for attribute / data kind mismatches
2023-07-27 10:50:26 -07:00
Jonas Platte 31a0e73489 Update error span for attribute / data kind mismatches 2023-07-27 10:47:45 +02:00
David Tolnay 74fe70855f Ignore return_self_not_must_use pedantic clippy lint
warning: missing `#[must_use]` attribute on a method returning `Self`
       --> serde_derive_internals/src/attr.rs:204:5
        |
    204 | /     pub fn or(self, other_rules: Self) -> Self {
    205 | |         Self {
    206 | |             serialize: self.serialize.or(other_rules.serialize),
    207 | |             deserialize: self.deserialize.or(other_rules.deserialize),
    208 | |         }
    209 | |     }
        | |_____^
        |
        = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use
        = note: `-W clippy::return-self-not-must-use` implied by `-W clippy::pedantic`

    warning: missing `#[must_use]` attribute on a method returning `Self`
       --> serde_derive_internals/src/case.rs:112:5
        |
    112 | /     pub fn or(self, rule_b: Self) -> Self {
    113 | |         match self {
    114 | |             None => rule_b,
    115 | |             _ => self,
    116 | |         }
    117 | |     }
        | |_____^
        |
        = help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use
2023-07-27 00:51:57 -07:00
David Tolnay e74925bc43 Merge pull request #1695 from jplatte/rename_all_fields
Add #[serde(rename_all_fields = "foo")] attribute
2023-07-27 00:45:45 -07:00
Jonas Platte 56be1c203e Pass RenameRule, RenameAllRules by value 2023-07-27 09:19:42 +02:00
Jonas Platte 2f9bf4d3eb Add #[serde(rename_all_fields = "foo")] attribute 2023-07-27 09:19:42 +02:00
David Tolnay ad94aed753 Merge pull request #2535 from dtolnay/baretrait
Restore bare_trait_objects lint within serde_derive code
2023-07-26 14:26:02 -07:00
David Tolnay 30db83fc44 Restore bare_trait_objects lint within serde_derive code 2023-07-26 14:18:25 -07:00
David Tolnay b0f7b00e1f Resolve manual_string_new pedantic clippy lint
warning: empty String is being created manually
        --> test_suite/tests/test_annotations.rs:2280:29
         |
    2280 |     let data = Data::C { t: "".to_string() };
         |                             ^^^^^^^^^^^^^^ help: consider using: `String::new()`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_string_new
         = note: `-W clippy::manual-string-new` implied by `-W clippy::pedantic`
2023-07-26 13:46:28 -07:00
David Tolnay 7255e192d8 Delete unused statement from PR 2266 test 2023-07-26 13:45:49 -07:00
David Tolnay 2102e1aa42 Format PR 2266 tests with rustfmt 2023-07-26 13:41:56 -07:00
David Tolnay 85d5c1fd38 Release 1.0.176 2023-07-26 13:37:44 -07:00
David Tolnay b789286bc3 Merge pull request #2266 from flisky/master
fix: don't check skipped variant with internal tag
2023-07-26 13:36:33 -07:00
David Tolnay a6a8a334f7 Add CI on macOS for the non-precompiled codepath 2023-07-26 01:03:20 -07:00
David Tolnay 78a11a27b6 Skip an extra trip through filesystem on the critical path 2023-07-26 00:58:34 -07:00
David Tolnay d2d7bad04a Improve error message on missing serde_derive exe 2023-07-26 00:52:09 -07:00
David Tolnay b978854258 Eliminate parse_macro_input conflict in precompiled mode 2023-07-26 00:44:55 -07:00
David Tolnay 0fb672a1ef Eliminate #[macro_use] from serde_derive 2023-07-25 23:23:24 -07:00
David Tolnay dd9913675d Ungroup imports 2023-07-25 23:06:34 -07:00
David Tolnay 11677ad926 Merge pull request #2533 from dtolnay/test
Move serde_test out to serde-rs/test
2023-07-25 22:52:36 -07:00
David Tolnay 25a53f10db Move serde_test out to serde-rs/test 2023-07-25 22:48:39 -07:00
David Tolnay 26e2ef001c Delete deprecated AsciiExt extension trait import
This has been superseded by inherent methods since Rust 1.26.
2023-07-25 21:07:33 -07:00
David Tolnay 30f79b3b2e Eliminate 2015-style module system imports from serde_derive 2023-07-25 20:56:19 -07:00
David Tolnay 89f84c2915 Merge pull request #2532 from dtolnay/macrouse
Delete unused serde_derive #[macro_use]
2023-07-25 18:55:14 -07:00
David Tolnay 6882285be0 Move extern crate proc_macro into each possible lib.rs
This makes it slightly more convenient to use the following as a
Reindeer fixup for those that prefer to build from source:

    extra_mapped_srcs = { "src/lib_from_source.rs" = "src/lib.rs" }

    [platform_fixups.'cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))']
    extra_deps = [":proc-macro2", ":quote", ":syn"]

as opposed to checking in a whole new file containing the `extern crate
proc_macro` + `include!("lib_from_source.rs")`.
2023-07-25 18:54:41 -07:00
David Tolnay 3260bc5896 Delete unused serde_derive #[macro_use]
In old versions of rustc (1.15 through 1.29) it would cause a warning if
this #[macro_use] was not present.

    warning: proc macro crates and `#[no_link]` crates have no effect without `#[macro_use]`
       --> serde/src/lib.rs:340:1
        |
    340 | extern crate serde_derive;
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^

These days serde_derive requires a newer compiler than that, so the
bogus warning would never occur.
2023-07-25 18:47:52 -07:00
David Tolnay 6140b6f527 Release 1.0.175 2023-07-23 20:07:32 -07:00
David Tolnay 4cabc9f293 Merge pull request #2527 from ankane/license-files
Include license files in serde_derive crate
2023-07-23 20:04:18 -07:00
Andrew Kane aa7c6345a4 Include license files in serde_derive crate 2023-07-23 19:54:57 -07:00
Mingun f709fc05b0 Do not run the code when results are not used 2023-07-23 15:23:39 +05:00
Mingun 089aae1292 Eliminate even more allocations 2023-07-23 15:23:39 +05:00
Mingun 855acaf112 Eliminate additional allocations for flattening aliases 2023-07-23 15:23:38 +05:00
Mingun 7ca7720262 Slightly reduced number of allocations 2023-07-23 15:23:37 +05:00
Mingun 78fea3aa4a Show possible aliases in the expected message
Fixes tests
2023-07-23 15:23:37 +05:00
Mingun 1efb8b6a53 Add tests for aliases
failures (2):
    field_identifier::unknown
    variant_identifier::unknown
2023-07-23 15:23:36 +05:00
Mingun bc1960b106 Add tests for unknown field / variant 2023-07-23 15:23:33 +05:00
Mingun 967023b755 Group field_identifier and variant_identifier tests in sub-modules
(review this commit with "ignore whitespace changes" option on)
2023-07-23 15:21:22 +05:00
Mingun bb51e68f16 Keep aliases sorted 2023-07-23 15:21:21 +05:00
David Tolnay 27414c90a8 Merge pull request #2522 from serde-rs/leak
Leak all memory allocated during macro expansion
2023-07-22 08:37:52 -07:00
David Tolnay 50e2f4b213 Leak all memory allocated during macro expansion 2023-07-22 08:32:18 -07:00
David Tolnay 22be673beb Release 1.0.174 2023-07-20 22:20:37 -07:00
David Tolnay 166c89fabf Opt in to generate-link-to-definition when building on docs.rs 2023-07-20 22:19:03 -07:00
David Tolnay 6e0b13eedb Release 1.0.173 2023-07-19 16:34:13 -07:00
David Tolnay 7e8f978ca9 Handle $crate special case 2023-07-19 16:32:59 -07:00
David Tolnay 6c0e838a7c Always consider empty output to be unsuccessful 2023-07-19 16:13:02 -07:00
David Tolnay d3da41927a Enable full expression parsing for precompiled serde_derive 2023-07-19 16:01:18 -07:00
David Tolnay 425a4b7a74 Check precompiled subprocess exit status 2023-07-19 16:00:37 -07:00
David Tolnay 63c65ef742 Release 1.0.172 2023-07-19 14:13:56 -07:00
David Tolnay e838b0bd81 Release 1.0.172-alpha.0 2023-07-19 14:00:50 -07:00
David Tolnay 041e99c78a Implement fallback to compiling serde_derive from source 2023-07-19 13:53:49 -07:00
David Tolnay 07dcc4f7fe Remove unneeded 'include' Cargo.toml entries 2023-07-19 13:44:55 -07:00
David Tolnay b88052d875 Rearrange precompiled directory 2023-07-19 13:24:36 -07:00
David Tolnay a28292764c Publish precompiled deserialize_in_place 2023-07-19 12:29:30 -07:00
David Tolnay 2027088741 Support precompiled deserialize_in_place 2023-07-19 12:27:37 -07:00
David Tolnay e2d8589976 Publish span-related fixes 2023-07-19 09:41:11 -07:00
David Tolnay c8a9f99d14 Preserve Group span better on compilers without Span::join 2023-07-19 09:39:11 -07:00
David Tolnay 645d04012d Fix off by one span counter, 0 is used for call_site() 2023-07-19 09:26:56 -07:00
David Tolnay 100ddada2f Suppress dead_code on fields only accessed by deserialize_in_place
error: field `option` is never read
       --> test_suite/tests/test_gen.rs:666:9
        |
    665 |     struct ImplicitlyBorrowedOption<'a> {
        |            ------------------------ field in this struct
    666 |         option: std::option::Option<&'a str>,
        |         ^^^^^^
        |
    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: fields `ty` and `id` are never read
       --> test_suite/tests/test_gen.rs:696:9
        |
    695 |     struct RelObject<'a> {
        |            --------- fields in this struct
    696 |         ty: &'a str,
        |         ^^
    697 |         id: String,
        |         ^^

    error: field `field` is never read
       --> test_suite/tests/test_gen.rs:740:17
        |
    739 |             struct MacroRules<'a> {
        |                    ---------- field in this struct
    740 |                 field: $field,
        |                 ^^^^^
    ...
    745 |     deriving!(&'a str);
        |     ------------------ in this macro invocation
        |
        = note: this error originates in the macro `deriving` (in Nightly builds, run with -Z macro-backtrace for more info)

    error: field `f` is never read
       --> test_suite/tests/test_gen.rs:756:9
        |
    754 |     struct BorrowLifetimeInsideMacro<'a> {
        |            ------------------------- field in this struct
    755 |         #[serde(borrow = "'a")]
    756 |         f: mac!(Cow<'a, str>),
        |         ^

    warning: fields `question` and `answer` are never read
        --> test_suite/tests/test_annotations.rs:2969:9
         |
    2968 |     struct Struct {
         |            ------ fields in this struct
    2969 |         question: String,
         |         ^^^^^^^^
    2970 |         answer: u32,
         |         ^^^^^^
         |
         = note: `#[warn(dead_code)]` on by default
2023-07-19 09:12:35 -07:00
David Tolnay 2ef1cd4b35 Import macros exclusively through serde_derive in test suite
This makes it easier to execute tests against the precompiled serde_derive.
2023-07-19 09:08:05 -07:00
David Tolnay be9c3fd69d Publish raw string fix 2023-07-18 18:42:54 -07:00
David Tolnay ef522e1d16 Add a reminder about trim-paths 2023-07-18 18:39:40 -07:00
David Tolnay 1ddb6c2fdb Fix handling of raw idents in proc-macro2 shim 2023-07-18 18:29:24 -07:00
David Tolnay eb3f2329af Merge pull request #2514 from dtolnay/precompiled
Add experiment to produce precompiled builds of serde_derive
2023-07-18 13:48:17 -07:00
David Tolnay 9e8f14816b Add experiment to produce precompiled builds of serde_derive 2023-07-18 13:37:36 -07:00
Mingun 4e5e55bf1c Remove custom implementations of SeqDeserializer and MapDeserializer for enums
Those deserializers are used to deserialize tuple or struct variants from Content
which is used by internally tagged enums and by flatten

FlatMapDeserializer is reached in the following tests:
    flatten::enum_::externally_tagged::newtype
    flatten::enum_::externally_tagged::struct_from_map
    flatten::enum_::externally_tagged::struct_from_seq
    flatten::enum_::externally_tagged::tuple

ContentDeserializer is reached in the following tests:
    test_enum_in_internally_tagged_enum
    test_internally_tagged_struct_variant_containing_unit_variant
2023-07-11 22:01:48 +05:00
Mingun 4513a9e6a7 Move test_flatten_enum_newtype into new group of flatten tests - flatten::enum_::externally_tagged::newtype 2023-07-11 22:00:38 +05:00
Mingun 4f922e4e5b Implement serialization of flattened tuple variants of externally tagged enums
The Container struct

  struct Container {
    #[serde(flatten)]
    enum_field: Enum,
  }
  enum Enum {
    Tuple(u32, u32),
  }

now can be serialized to JSON as

  { "enum_field": [1, 2] }

Deserialization already works

Fixes (1):
    flatten::enum_::externally_tagged::tuple
2023-07-11 22:00:10 +05:00
Mingun 993966600e Implement tests for crate::private::de::content::VariantDeserializer
failures (1):
    flatten::enum_::externally_tagged::tuple
2023-07-11 21:59:22 +05:00
Mingun 5b96cf1bde Use traditional order for enum variants (Unit, Newtype, Tuple, Struct) and names for tag and content fields 2023-07-11 21:58:43 +05:00
Mingun f3d50e5209 Use FromIterator to fill HashMap 2023-07-11 21:58:14 +05:00
Mingun ab21d4d017 Merge assert_de_tokens and assert_ser_tokens into assert_tokens 2023-07-11 21:57:49 +05:00
Mingun f7c5d93e6a Pull up types from function into module, unify style 2023-07-11 21:57:22 +05:00
Mingun 52a7d40e6e Rename test types so their names reflects, what's tested 2023-07-11 21:56:53 +05:00
Mingun 348bc6b257 Move flatten enum tests to a dedicated module
(review with "ignore whitespace" option on and editor that shows line moves,
for example, TortoiseGitMerge)
2023-07-11 21:56:22 +05:00
David Tolnay 03da66c805 Release 1.0.171 2023-07-09 18:05:02 -07:00
David Tolnay f75426f47e Inline visitor_expr of unit struct deserialize impl 2023-07-09 18:03:58 -07:00
David Tolnay 662fc3861c Add test of const-generic unit struct where-clause edge case
Closes #2501.
2023-07-09 18:01:43 -07:00
David Tolnay 28c10020b9 Merge pull request #2500 from Baptistemontan/derive_generic_unit_struct
Allow `[derive(serde::Deserialize)]` for generic unit structs
2023-07-09 17:52:12 -07:00
Baptiste de Montangon 89c8d85de9 allow Deserialize derive to handle generic unit structs 2023-07-10 01:31:40 +02:00
Yin Jifeng 983347484e fix: don't check skipped variant with internal tag 2022-08-23 20:19:34 +08:00
166 changed files with 11526 additions and 8957 deletions
+1
View File
@@ -0,0 +1 @@
github: dtolnay
+48 -47
View File
@@ -18,16 +18,22 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cd test_suite && cargo test --features unstable
- uses: actions/upload-artifact@v4
if: always()
with:
name: Cargo.lock
path: Cargo.lock
continue-on-error: true
windows:
name: Test suite (windows)
runs-on: windows-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cd test_suite && cargo test --features unstable -- --skip ui --exact
@@ -40,17 +46,16 @@ jobs:
rust: [stable, beta]
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
- run: cd serde && cargo build --features rc
- run: cd serde && cargo build --no-default-features
- run: cd serde_test && cargo build
- run: cd serde_test && cargo test --features serde/derive,serde/rc
- run: cd test_suite/no_std && cargo build
nightly:
name: Rust nightly ${{matrix.os == 'windows' && '(windows)' || ''}}
name: Rust nightly${{matrix.os == 'windows' && ' (windows)' || ''}}
runs-on: ${{matrix.os}}-latest
strategy:
fail-fast: false
@@ -58,13 +63,14 @@ jobs:
os: [ubuntu, windows]
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cd serde && cargo build
- run: cd serde && cargo build --no-default-features
- run: cd serde && cargo build --no-default-features --features alloc
- run: cd serde && cargo build --no-default-features --features rc,alloc
- run: cd serde && cargo test --features derive,rc,unstable
- run: cd serde && cargo build --no-default-features --features unstable
- run: cd serde_core && cargo test --features rc,unstable
- run: cd test_suite/no_std && cargo build
if: matrix.os != 'windows'
- run: cd serde_derive && cargo check --tests
@@ -78,78 +84,70 @@ jobs:
strategy:
fail-fast: false
matrix:
rust: [1.19.0, 1.20.0, 1.21.0, 1.25.0, 1.26.0, 1.34.0]
rust: [1.56.0, 1.60.0]
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- 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
- run: cd serde_test && cargo build
more:
name: Rust ${{matrix.rust}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [1.27.0, 1.28.0]
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
# Work around failing to parse manifest because editions are unstable.
- run: sed -i /test_suite/d Cargo.toml
- run: cd serde && cargo build --no-default-features
- run: cd serde && cargo build --no-default-features --features alloc
- run: cd serde && cargo build
derive:
name: Rust 1.56.0
name: Rust 1.61.0
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.56.0
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.61.0
- run: |
sed -i 's/proc-macro2 = { workspace = true/proc-macro2 = { version = "1"/' serde_derive*/Cargo.toml
sed -i 's/quote = { workspace = true/quote = { version = "1"/' serde_derive*/Cargo.toml
sed -i 's/syn = { workspace = true/syn = { version = "2"/' serde_derive*/Cargo.toml
- run: cd serde && cargo check --no-default-features
- run: cd serde && cargo check
- run: cd serde_derive && cargo check
alloc:
name: Rust 1.36.0
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.36.0
- run: cd serde && cargo build --no-default-features --features alloc
minimal:
name: Minimal versions
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cargo generate-lockfile -Z minimal-versions
- run: cargo check --locked --workspace
doc:
name: Documentation
runs-on: ubuntu-latest
timeout-minutes: 45
env:
RUSTDOCFLAGS: -Dwarnings
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs -p serde
- run: cargo docs-rs -p serde_derive
- run: cargo docs-rs -p serde_derive_internals
clippy:
name: Clippy
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@clippy
- run: cd serde && cargo clippy --features rc,unstable -- -Dclippy::all -Dclippy::pedantic
- run: cd serde_core && cargo clippy --features rc,unstable -- -Dclippy::all -Dclippy::pedantic
- run: cd serde_derive && cargo clippy -- -Dclippy::all -Dclippy::pedantic
- run: cd serde_derive_internals && cargo clippy -- -Dclippy::all -Dclippy::pedantic
- run: cd serde_test && cargo clippy -- -Dclippy::all -Dclippy::pedantic
- run: cd test_suite && cargo clippy --tests --features unstable -- -Dclippy::all -Dclippy::pedantic
- run: cd test_suite/no_std && cargo clippy -- -Dclippy::all -Dclippy::pedantic
@@ -158,10 +156,12 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@miri
with:
toolchain: nightly-2025-05-16 # https://github.com/rust-lang/miri/issues/4323
- run: cargo miri setup
- run: cd serde && cargo miri test --features derive,rc,unstable
- run: cd serde_core && cargo miri test --features rc,unstable
env:
MIRIFLAGS: -Zmiri-strict-provenance
- run: cd test_suite && cargo miri test --features unstable
@@ -174,6 +174,7 @@ jobs:
if: github.event_name != 'pull_request'
timeout-minutes: 45
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/install@cargo-outdated
- run: cargo outdated --workspace --exit-code 1
+2 -4
View File
@@ -1,4 +1,2 @@
target/
**/*.rs.bk
*.sw[po]
Cargo.lock
/target/
/Cargo.lock
+3 -3
View File
@@ -27,11 +27,11 @@ pull request with your changes. If anything does not pass, typically it will be
easier to iterate and fix it locally than waiting for the CI servers to run
tests for you.
##### In the [`serde`] directory
##### In the [`serde_core`] directory
```sh
# Test all the example code in Serde documentation
cargo test --features derive
cargo test
```
##### In the [`test_suite`] directory
@@ -43,7 +43,7 @@ cargo +nightly test --features unstable
Note that this test suite currently only supports running on a nightly compiler.
[`serde`]: https://github.com/serde-rs/serde/tree/master/serde
[`serde_core`]: https://github.com/serde-rs/serde/tree/master/serde_core
[`test_suite`]: https://github.com/serde-rs/serde/tree/master/test_suite
## Conduct
+12 -1
View File
@@ -1,8 +1,19 @@
[workspace]
members = [
"serde",
"serde_core",
"serde_derive",
"serde_derive_internals",
"serde_test",
"test_suite",
]
resolver = "2"
[patch.crates-io]
serde = { path = "serde" }
serde_core = { path = "serde_core" }
serde_derive = { path = "serde_derive" }
[workspace.dependencies]
proc-macro2 = { version = "1.0.74", default-features = false }
quote = { version = "1.0.35", default-features = false }
syn = { version = "2.0.81", default-features = false }
+6 -6
View File
@@ -1,13 +1,13 @@
# Serde &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![serde: rustc 1.19+]][Rust 1.19] [![serde_derive: rustc 1.56+]][Rust 1.56]
# Serde &emsp; [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.56] [![serde_derive msrv]][Rust 1.61]
[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.19+]: https://img.shields.io/badge/serde-rustc_1.19+-lightgray.svg
[serde_derive: rustc 1.56+]: https://img.shields.io/badge/serde_derive-rustc_1.56+-lightgray.svg
[Rust 1.19]: https://blog.rust-lang.org/2017/07/20/Rust-1.19.html
[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.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
[Rust 1.61]: https://blog.rust-lang.org/2022/05/19/Rust-1.61.0.html
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
@@ -15,7 +15,7 @@
You may be looking for:
- [An overview of Serde](https://serde.rs/)
- [An overview of Serde](https://serde.rs)
- [Data formats supported by Serde](https://serde.rs/#data-formats)
- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/derive.html)
- [Examples](https://serde.rs/examples.html)
@@ -27,7 +27,7 @@ You may be looking for:
<details>
<summary>
Click to show Cargo.toml.
<a href="https://play.rust-lang.org/?edition=2018&gist=72755f28f99afc95e01d63174b28c1f5" target="_blank">Run this code in the playground.</a>
<a href="https://play.rust-lang.org/?edition=2021&gist=72755f28f99afc95e01d63174b28c1f5" target="_blank">Run this code in the playground.</a>
</summary>
```toml
+3 -3
View File
@@ -6,7 +6,7 @@
You may be looking for:
- [An overview of Serde](https://serde.rs/)
- [An overview of Serde](https://serde.rs)
- [Data formats supported by Serde](https://serde.rs/#data-formats)
- [Setting up `#[derive(Serialize, Deserialize)]`](https://serde.rs/derive.html)
- [Examples](https://serde.rs/examples.html)
@@ -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
+17 -15
View File
@@ -1,34 +1,36 @@
[package]
name = "serde"
version = "1.0.170" # remember to update html_root_url and serde_derive dependency
version = "1.0.226"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
build = "build.rs"
categories = ["encoding", "no-std", "no-std::no-alloc"]
description = "A generic serialization/deserialization framework"
documentation = "https://docs.rs/serde"
edition = "2021"
homepage = "https://serde.rs"
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
keywords = ["serde", "serialization", "no_std"]
license = "MIT OR Apache-2.0"
readme = "crates-io.md"
repository = "https://github.com/serde-rs/serde"
rust-version = "1.19"
rust-version = "1.56"
[dependencies]
serde_derive = { version = "=1.0.170", optional = true, path = "../serde_derive" }
[dev-dependencies]
serde_derive = { version = "1.0", path = "../serde_derive" }
[lib]
doc-scrape-examples = false
serde_core = { version = "=1.0.226", path = "../serde_core", default-features = false, features = ["result"] }
serde_derive = { version = "1", optional = true, path = "../serde_derive" }
[package.metadata.playground]
features = ["derive", "rc"]
[package.metadata.docs.rs]
features = ["derive"]
features = ["derive", "rc", "unstable"]
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = [
"--generate-link-to-definition",
"--generate-macro-expansion",
"--extern-html-root-url=core=https://doc.rust-lang.org",
"--extern-html-root-url=alloc=https://doc.rust-lang.org",
"--extern-html-root-url=std=https://doc.rust-lang.org",
]
### FEATURES #################################################################
@@ -41,20 +43,20 @@ derive = ["serde_derive"]
# Provide impls for common standard library types like Vec<T> and HashMap<K, V>.
# Requires a dependency on the Rust standard library.
std = []
std = ["serde_core/std"]
# Provide impls for types that require unstable functionality. For tracking and
# discussion of unstable functionality please refer to this issue:
#
# https://github.com/serde-rs/serde/issues/812
unstable = []
unstable = ["serde_core/unstable"]
# Provide impls for types in the Rust core allocation and collections library
# including String, Box<T>, Vec<T>, and Cow<T>. This is a subset of std but may
# be enabled without depending on all of std.
alloc = []
alloc = ["serde_core/alloc"]
# Opt into impls for Rc<T> and Arc<T>. Serializing and deserializing these types
# does not preserve identity and may result in multiple copies of the same data.
# Be sure that this is what you want before enabling this feature.
rc = []
rc = ["serde_core/rc"]
+30 -124
View File
@@ -1,6 +1,17 @@
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use std::str::{self, FromStr};
use std::str;
const PRIVATE: &str = "\
#[doc(hidden)]
pub mod __private$$ {
#[doc(hidden)]
pub use crate::private::*;
}
use serde_core::__private$$ as serde_core_private;
";
// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
@@ -8,145 +19,40 @@ use std::str::{self, FromStr};
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let patch_version = env::var("CARGO_PKG_VERSION_PATCH").unwrap();
let module = PRIVATE.replace("$$", &patch_version);
fs::write(out_dir.join("private.rs"), module).unwrap();
let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
};
let target = env::var("TARGET").unwrap();
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
// std::collections::Bound was stabilized in Rust 1.17
// but it was moved to core::ops later in Rust 1.26:
// https://doc.rust-lang.org/core/ops/enum.Bound.html
if minor < 26 {
println!("cargo:rustc-cfg=no_ops_bound");
if minor < 17 {
println!("cargo:rustc-cfg=no_collections_bound");
}
if minor >= 77 {
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
println!("cargo:rustc-check-cfg=cfg(no_serde_derive)");
}
// core::cmp::Reverse stabilized in Rust 1.19:
// https://doc.rust-lang.org/stable/core/cmp/struct.Reverse.html
if minor < 19 {
println!("cargo:rustc-cfg=no_core_reverse");
}
// CString::into_boxed_c_str and PathBuf::into_boxed_path stabilized in Rust 1.20:
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
// https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.into_boxed_path
if minor < 20 {
println!("cargo:rustc-cfg=no_de_boxed_c_str");
println!("cargo:rustc-cfg=no_de_boxed_path");
}
// From<Box<T>> for Rc<T> / Arc<T> stabilized in Rust 1.21:
// https://doc.rust-lang.org/std/rc/struct.Rc.html#impl-From<Box<T>>
// https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-From<Box<T>>
if minor < 21 {
println!("cargo:rustc-cfg=no_de_rc_dst");
}
// Duration available in core since Rust 1.25:
// https://blog.rust-lang.org/2018/03/29/Rust-1.25.html#library-stabilizations
if minor < 25 {
println!("cargo:rustc-cfg=no_core_duration");
}
// 128-bit integers stabilized in Rust 1.26:
// https://blog.rust-lang.org/2018/05/10/Rust-1.26.html
//
// Disabled on Emscripten targets before Rust 1.40 since
// Emscripten did not support 128-bit integers until Rust 1.40
// (https://github.com/rust-lang/rust/pull/65251)
if minor < 26 || emscripten && minor < 40 {
println!("cargo:rustc-cfg=no_integer128");
}
// Inclusive ranges methods stabilized in Rust 1.27:
// https://github.com/rust-lang/rust/pull/50758
// Also Iterator::try_for_each:
// https://blog.rust-lang.org/2018/06/21/Rust-1.27.html#library-stabilizations
if minor < 27 {
println!("cargo:rustc-cfg=no_range_inclusive");
println!("cargo:rustc-cfg=no_iterator_try_fold");
}
// Non-zero integers stabilized in Rust 1.28:
// https://blog.rust-lang.org/2018/08/02/Rust-1.28.html#library-stabilizations
if minor < 28 {
println!("cargo:rustc-cfg=no_num_nonzero");
}
// TryFrom, Atomic types, non-zero signed integers, and SystemTime::checked_add
// stabilized in Rust 1.34:
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto
// https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#library-stabilizations
if minor < 34 {
println!("cargo:rustc-cfg=no_core_try_from");
println!("cargo:rustc-cfg=no_num_nonzero_signed");
println!("cargo:rustc-cfg=no_systemtime_checked_add");
println!("cargo:rustc-cfg=no_relaxed_trait_bounds");
}
// Current minimum supported version of serde_derive crate is Rust 1.56.
if minor < 56 {
// Current minimum supported version of serde_derive crate is Rust 1.61.
if minor < 61 {
println!("cargo:rustc-cfg=no_serde_derive");
}
// Support for #[cfg(target_has_atomic = "...")] stabilized in Rust 1.60.
if minor < 60 {
println!("cargo:rustc-cfg=no_target_has_atomic");
// Allowlist of archs that support std::sync::atomic module. This is
// based on rustc's compiler/rustc_target/src/spec/*.rs.
let has_atomic64 = target.starts_with("x86_64")
|| target.starts_with("i686")
|| target.starts_with("aarch64")
|| target.starts_with("powerpc64")
|| target.starts_with("sparc64")
|| target.starts_with("mips64el")
|| target.starts_with("riscv64");
let has_atomic32 = has_atomic64 || emscripten;
if minor < 34 || !has_atomic64 {
println!("cargo:rustc-cfg=no_std_atomic64");
}
if minor < 34 || !has_atomic32 {
println!("cargo:rustc-cfg=no_std_atomic");
}
}
// Support for core::ffi::CStr and alloc::ffi::CString stabilized in Rust 1.64.
// https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html#c-compatible-ffi-types-in-core-and-alloc
if minor < 64 {
println!("cargo:rustc-cfg=no_core_cstr");
// 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> {
let rustc = match env::var_os("RUSTC") {
Some(rustc) => rustc,
None => return None,
};
let output = match Command::new(rustc).arg("--version").output() {
Ok(output) => output,
Err(_) => return None,
};
let version = match str::from_utf8(&output.stdout) {
Ok(version) => version,
Err(_) => return None,
};
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
let next = match pieces.next() {
Some(next) => next,
None => return None,
};
u32::from_str(next).ok()
pieces.next()?.parse().ok()
}
-46
View File
@@ -1,46 +0,0 @@
use lib::*;
const TAG_CONT: u8 = 0b1000_0000;
const TAG_TWO_B: u8 = 0b1100_0000;
const TAG_THREE_B: u8 = 0b1110_0000;
const TAG_FOUR_B: u8 = 0b1111_0000;
const MAX_ONE_B: u32 = 0x80;
const MAX_TWO_B: u32 = 0x800;
const MAX_THREE_B: u32 = 0x10000;
#[inline]
pub fn encode(c: char) -> Encode {
let code = c as u32;
let mut buf = [0; 4];
let pos = if code < MAX_ONE_B {
buf[3] = code as u8;
3
} else if code < MAX_TWO_B {
buf[2] = (code >> 6 & 0x1F) as u8 | TAG_TWO_B;
buf[3] = (code & 0x3F) as u8 | TAG_CONT;
2
} else if code < MAX_THREE_B {
buf[1] = (code >> 12 & 0x0F) as u8 | TAG_THREE_B;
buf[2] = (code >> 6 & 0x3F) as u8 | TAG_CONT;
buf[3] = (code & 0x3F) as u8 | TAG_CONT;
1
} else {
buf[0] = (code >> 18 & 0x07) as u8 | TAG_FOUR_B;
buf[1] = (code >> 12 & 0x3F) as u8 | TAG_CONT;
buf[2] = (code >> 6 & 0x3F) as u8 | TAG_CONT;
buf[3] = (code & 0x3F) as u8 | TAG_CONT;
0
};
Encode { buf, pos }
}
pub struct Encode {
buf: [u8; 4],
pos: usize,
}
impl Encode {
pub fn as_str(&self) -> &str {
str::from_utf8(&self.buf[self.pos..]).unwrap()
}
}
+8 -76
View File
@@ -1,82 +1,14 @@
/// Conditional compilation depending on whether Serde is built with support for
/// 128-bit integers.
///
/// Data formats that wish to support Rust compiler versions older than 1.26
/// (or targets that lack 128-bit integers) may place the i128 / u128 methods
/// of their Serializer and Deserializer behind this macro.
///
/// Data formats that require a minimum Rust compiler version of at least 1.26,
/// or do not target platforms that lack 128-bit integers, do not need to
/// bother with this macro and may assume support for 128-bit integers.
///
/// ```edition2021
/// # use serde::__private::doc::Error;
/// #
/// # struct MySerializer;
/// #
/// use serde::{serde_if_integer128, Serializer};
///
/// impl Serializer for MySerializer {
/// type Ok = ();
/// type Error = Error;
///
/// fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> {
/// /* ... */
/// # unimplemented!()
/// }
///
/// /* ... */
///
/// serde_if_integer128! {
/// fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> {
/// /* ... */
/// # unimplemented!()
/// }
///
/// fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> {
/// /* ... */
/// # unimplemented!()
/// }
/// }
/// #
/// # serde::__serialize_unimplemented! {
/// # bool i8 i16 i32 u8 u16 u32 u64 f32 f64 char str bytes none some
/// # unit unit_struct unit_variant newtype_struct newtype_variant seq
/// # tuple tuple_struct tuple_variant map struct struct_variant
/// # }
/// }
/// ```
///
/// When Serde is built with support for 128-bit integers, this macro expands
/// transparently into just the input tokens.
///
/// ```edition2021
/// macro_rules! serde_if_integer128 {
/// ($($tt:tt)*) => {
/// $($tt)*
/// };
/// }
/// ```
///
/// When built without support for 128-bit integers, this macro expands to
/// nothing.
///
/// ```edition2021
/// macro_rules! serde_if_integer128 {
/// ($($tt:tt)*) => {};
/// }
/// ```
#[cfg(not(no_integer128))]
#[macro_export]
#[deprecated = "
This macro has no effect on any version of Serde released in the past 2 years.
It was used long ago in crates that needed to support Rustc older than 1.26.0,
or Emscripten targets older than 1.40.0, which did not yet have 128-bit integer
support. These days Serde requires a Rust compiler newer than that so 128-bit
integers are always supported.
"]
#[doc(hidden)]
macro_rules! serde_if_integer128 {
($($tt:tt)*) => {
$($tt)*
};
}
#[cfg(no_integer128)]
#[macro_export]
#[doc(hidden)]
macro_rules! serde_if_integer128 {
($($tt:tt)*) => {};
}
+83 -169
View File
@@ -9,7 +9,7 @@
//! these two groups interact with each other, allowing any supported data
//! structure to be serialized and deserialized using any supported data format.
//!
//! See the Serde website <https://serde.rs/> for additional documentation and
//! See the Serde website <https://serde.rs> for additional documentation and
//! usage examples.
//!
//! ## Design
@@ -63,6 +63,7 @@
//! and from DynamoDB.
//! - [Hjson], a syntax extension to JSON designed around human reading and
//! editing. *(deserialization only)*
//! - [CSV], Comma-separated values is a tabular text file format.
//!
//! [JSON]: https://github.com/serde-rs/json
//! [Postcard]: https://github.com/jamesmunns/postcard
@@ -89,66 +90,76 @@
//! [DynamoDB Items]: https://docs.rs/serde_dynamo
//! [rusoto_dynamodb]: https://docs.rs/rusoto_dynamodb
//! [Hjson]: https://github.com/Canop/deser-hjson
//! [CSV]: https://docs.rs/csv
////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde/1.0.170")]
#![doc(html_root_url = "https://docs.rs/serde/1.0.226")]
// 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(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))]
#![allow(unknown_lints, bare_trait_objects, deprecated)]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
// Ignored clippy and clippy_pedantic lints
#![cfg_attr(
feature = "cargo-clippy",
allow(
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704
unnested_or_patterns,
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/7768
semicolon_if_nothing_returned,
// not available in our oldest supported compiler
empty_enum,
type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
// integer and float ser/de requires these sorts of casts
cast_possible_truncation,
cast_possible_wrap,
cast_sign_loss,
// things are often more readable this way
cast_lossless,
module_name_repetitions,
option_if_let_else,
single_match_else,
type_complexity,
use_self,
zero_prefixed_literal,
// correctly used
derive_partial_eq_without_eq,
enum_glob_use,
explicit_auto_deref,
let_underscore_untyped,
map_err_ignore,
new_without_default,
result_unit_err,
wildcard_imports,
// not practical
needless_pass_by_value,
similar_names,
too_many_lines,
// preference
doc_markdown,
unseparated_literal_suffix,
// false positive
needless_doctest_main,
// noisy
missing_errors_doc,
must_use_candidate,
)
#![cfg_attr(feature = "unstable", feature(never_type))]
#![allow(
unknown_lints,
bare_trait_objects,
deprecated,
mismatched_lifetime_syntaxes
)]
// Ignored clippy and clippy_pedantic lints
#![allow(
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704
clippy::unnested_or_patterns,
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/7768
clippy::semicolon_if_nothing_returned,
// not available in our oldest supported compiler
clippy::empty_enum,
clippy::type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
// 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::single_match_else,
clippy::type_complexity,
clippy::use_self,
clippy::zero_prefixed_literal,
// correctly used
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,
clippy::result_unit_err,
clippy::wildcard_imports,
// not practical
clippy::needless_pass_by_value,
clippy::similar_names,
clippy::too_many_lines,
// preference
clippy::doc_markdown,
clippy::elidable_lifetime_names,
clippy::needless_lifetimes,
clippy::unseparated_literal_suffix,
// false positive
clippy::needless_doctest_main,
// noisy
clippy::missing_errors_doc,
clippy::must_use_candidate,
)]
// Restrictions
#![deny(clippy::question_mark_used)]
// Rustc lints.
#![deny(missing_docs, unused_imports)]
@@ -168,21 +179,19 @@ mod lib {
pub use std::*;
}
pub use self::core::{cmp, iter, mem, num, ptr, slice, str};
pub use self::core::{f32, f64};
pub use self::core::{i16, i32, i64, i8, isize};
pub use self::core::{u16, u32, u64, u8, usize};
pub use self::core::{ptr, str};
pub use self::core::cell::{Cell, RefCell};
pub use self::core::clone::{self, Clone};
pub use self::core::convert::{self, From, Into};
pub use self::core::default::{self, Default};
pub use self::core::fmt::{self, Debug, Display};
#[cfg(any(feature = "std", feature = "alloc"))]
pub use self::core::slice;
pub use self::core::clone;
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::{Range, RangeFrom, 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;
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::borrow::{Cow, ToOwned};
@@ -203,92 +212,14 @@ mod lib {
pub use alloc::boxed::Box;
#[cfg(feature = "std")]
pub use std::boxed::Box;
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
pub use alloc::rc::{Rc, Weak as RcWeak};
#[cfg(all(feature = "rc", feature = "std"))]
pub use std::rc::{Rc, Weak as RcWeak};
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
pub use alloc::sync::{Arc, Weak as ArcWeak};
#[cfg(all(feature = "rc", feature = "std"))]
pub use std::sync::{Arc, Weak as ArcWeak};
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
#[cfg(feature = "std")]
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
#[cfg(all(not(no_core_cstr), not(feature = "std")))]
pub use core::ffi::CStr;
#[cfg(feature = "std")]
pub use std::ffi::CStr;
#[cfg(all(not(no_core_cstr), feature = "alloc", not(feature = "std")))]
pub use alloc::ffi::CString;
#[cfg(feature = "std")]
pub use std::ffi::CString;
#[cfg(feature = "std")]
pub use std::{error, net};
#[cfg(feature = "std")]
pub use std::collections::{HashMap, HashSet};
#[cfg(feature = "std")]
pub use std::ffi::{OsStr, OsString};
#[cfg(feature = "std")]
pub use std::hash::{BuildHasher, Hash};
#[cfg(feature = "std")]
pub use std::io::Write;
#[cfg(feature = "std")]
pub use std::path::{Path, PathBuf};
#[cfg(feature = "std")]
pub use std::sync::{Mutex, RwLock};
#[cfg(feature = "std")]
pub use std::time::{SystemTime, UNIX_EPOCH};
#[cfg(all(feature = "std", not(no_collections_bound), no_ops_bound))]
pub use std::collections::Bound;
#[cfg(not(no_core_reverse))]
pub use self::core::cmp::Reverse;
#[cfg(not(no_ops_bound))]
pub use self::core::ops::Bound;
#[cfg(not(no_range_inclusive))]
pub use self::core::ops::RangeInclusive;
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
pub use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize, Ordering,
};
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
pub use std::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
pub use std::sync::atomic::Ordering;
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "8"))]
pub use std::sync::atomic::{AtomicBool, AtomicI8, AtomicU8};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "16"))]
pub use std::sync::atomic::{AtomicI16, AtomicU16};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "32"))]
pub use std::sync::atomic::{AtomicI32, AtomicU32};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "64"))]
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(any(feature = "std", not(no_core_duration)))]
pub use self::core::time::Duration;
}
// None of this crate's error handling needs the `From::from` error conversion
// performed implicitly by the `?` operator or the standard library's `try!`
// macro. This simplified macro gives a 5.5% improvement in compile time
// compared to standard `try!`, and 9% improvement compared to `?`.
macro_rules! try {
#[cfg(not(no_serde_derive))]
macro_rules! tri {
($expr:expr) => {
match $expr {
Ok(val) => val,
@@ -299,35 +230,18 @@ macro_rules! try {
////////////////////////////////////////////////////////////////////////////////
#[macro_use]
mod macros;
pub use serde_core::{
de, forward_to_deserialize_any, ser, Deserialize, Deserializer, Serialize, Serializer,
};
#[macro_use]
mod integer128;
pub mod de;
pub mod ser;
#[doc(inline)]
pub use de::{Deserialize, Deserializer};
#[doc(inline)]
pub use ser::{Serialize, Serializer};
// Used by generated code and doc tests. Not public API.
#[doc(hidden)]
#[path = "private/mod.rs"]
pub mod __private;
mod private;
#[allow(unused_imports)]
use self::__private as export;
#[allow(unused_imports)]
use self::__private as private;
#[path = "de/seed.rs"]
mod seed;
#[cfg(not(any(feature = "std", feature = "unstable")))]
mod std_error;
include!(concat!(env!("OUT_DIR"), "/private.rs"));
// Re-export #[derive(Serialize, Deserialize)].
//
@@ -335,15 +249,15 @@ mod std_error;
// be annoying for crates that provide handwritten impls or data formats. They
// would need to disable default features and then explicitly re-enable std.
#[cfg(feature = "serde_derive")]
#[allow(unused_imports)]
#[macro_use]
extern crate serde_derive;
/// Derive macro available if serde is built with `features = ["derive"]`.
#[cfg(feature = "serde_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")))]
mod actually_private {
pub struct T;
#[macro_export]
#[doc(hidden)]
macro_rules! __require_serde_not_serde_core {
() => {};
}
+990 -465
View File
File diff suppressed because it is too large Load Diff
+10 -42
View File
@@ -3,48 +3,16 @@ pub mod de;
#[cfg(not(no_serde_derive))]
pub mod ser;
pub mod size_hint;
pub use crate::lib::clone::Clone;
pub use crate::lib::convert::{From, Into, TryFrom};
pub use crate::lib::default::Default;
pub use crate::lib::fmt::{self, Formatter};
pub use crate::lib::marker::PhantomData;
pub use crate::lib::option::Option::{self, None, Some};
pub use crate::lib::ptr;
pub use crate::lib::result::Result::{self, Err, Ok};
// FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed.
pub mod doc;
pub use lib::clone::Clone;
pub use lib::convert::{From, Into};
pub use lib::default::Default;
pub use lib::fmt::{self, Formatter};
pub use lib::marker::PhantomData;
pub use lib::option::Option::{self, None, Some};
pub use lib::ptr;
pub use lib::result::Result::{self, Err, Ok};
pub use self::string::from_utf8_lossy;
pub use crate::serde_core_private::string::from_utf8_lossy;
#[cfg(any(feature = "alloc", feature = "std"))]
pub use lib::{ToString, Vec};
#[cfg(not(no_core_try_from))]
pub use lib::convert::TryFrom;
mod string {
use lib::*;
#[cfg(any(feature = "std", feature = "alloc"))]
pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<str> {
String::from_utf8_lossy(bytes)
}
// The generated code calls this like:
//
// let value = &_serde::__private::from_utf8_lossy(bytes);
// Err(_serde::de::Error::unknown_variant(value, VARIANTS))
//
// so it is okay for the return type to be different from the std case as long
// as the above works.
#[cfg(not(any(feature = "std", feature = "alloc")))]
pub fn from_utf8_lossy(bytes: &[u8]) -> &str {
// Three unicode replacement characters if it fails. They look like a
// white-on-black question mark. The user will recognize it as invalid
// UTF-8.
str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")
}
}
pub use crate::lib::{ToString, Vec};
+220 -148
View File
@@ -1,6 +1,6 @@
use lib::*;
use crate::lib::*;
use ser::{self, Impossible, Serialize, SerializeMap, SerializeStruct, Serializer};
use crate::ser::{self, Impossible, Serialize, SerializeMap, SerializeStruct, Serializer};
#[cfg(any(feature = "std", feature = "alloc"))]
use self::content::{
@@ -51,14 +51,14 @@ enum Unsupported {
String,
ByteArray,
Optional,
#[cfg(any(feature = "std", feature = "alloc"))]
UnitStruct,
Sequence,
Tuple,
TupleStruct,
#[cfg(not(any(feature = "std", feature = "alloc")))]
Enum,
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl Display for Unsupported {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match *self {
@@ -69,11 +69,10 @@ impl Display for Unsupported {
Unsupported::String => formatter.write_str("a string"),
Unsupported::ByteArray => formatter.write_str("a byte array"),
Unsupported::Optional => formatter.write_str("an optional"),
#[cfg(any(feature = "std", feature = "alloc"))]
Unsupported::UnitStruct => formatter.write_str("unit struct"),
Unsupported::Sequence => formatter.write_str("a sequence"),
Unsupported::Tuple => formatter.write_str("a tuple"),
Unsupported::TupleStruct => formatter.write_str("a tuple struct"),
#[cfg(not(any(feature = "std", feature = "alloc")))]
Unsupported::Enum => formatter.write_str("an enum"),
}
}
@@ -91,6 +90,7 @@ where
}
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<S> Serializer for TaggedSerializer<S>
where
S: Serializer,
@@ -174,22 +174,22 @@ 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))
}
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
let mut map = try!(self.delegate.serialize_map(Some(1)));
try!(map.serialize_entry(self.tag, self.variant_name));
let mut map = tri!(self.delegate.serialize_map(Some(1)));
tri!(map.serialize_entry(self.tag, self.variant_name));
map.end()
}
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
let mut map = try!(self.delegate.serialize_map(Some(1)));
try!(map.serialize_entry(self.tag, self.variant_name));
let mut map = tri!(self.delegate.serialize_map(Some(1)));
tri!(map.serialize_entry(self.tag, self.variant_name));
map.end()
}
@@ -199,24 +199,24 @@ where
_: u32,
inner_variant: &'static str,
) -> Result<Self::Ok, Self::Error> {
let mut map = try!(self.delegate.serialize_map(Some(2)));
try!(map.serialize_entry(self.tag, self.variant_name));
try!(map.serialize_entry(inner_variant, &()));
let mut map = tri!(self.delegate.serialize_map(Some(2)));
tri!(map.serialize_entry(self.tag, self.variant_name));
tri!(map.serialize_entry(inner_variant, &()));
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,11 +224,11 @@ where
inner_value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
let mut map = try!(self.delegate.serialize_map(Some(2)));
try!(map.serialize_entry(self.tag, self.variant_name));
try!(map.serialize_entry(inner_variant, inner_value));
let mut map = tri!(self.delegate.serialize_map(Some(2)));
tri!(map.serialize_entry(self.tag, self.variant_name));
tri!(map.serialize_entry(inner_variant, inner_value));
map.end()
}
@@ -269,9 +269,9 @@ where
inner_variant: &'static str,
len: usize,
) -> Result<Self::SerializeTupleVariant, Self::Error> {
let mut map = try!(self.delegate.serialize_map(Some(2)));
try!(map.serialize_entry(self.tag, self.variant_name));
try!(map.serialize_key(inner_variant));
let mut map = tri!(self.delegate.serialize_map(Some(2)));
tri!(map.serialize_entry(self.tag, self.variant_name));
tri!(map.serialize_key(inner_variant));
Ok(SerializeTupleVariantAsMapValue::new(
map,
inner_variant,
@@ -280,8 +280,8 @@ where
}
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
let mut map = try!(self.delegate.serialize_map(len.map(|len| len + 1)));
try!(map.serialize_entry(self.tag, self.variant_name));
let mut map = tri!(self.delegate.serialize_map(len.map(|len| len + 1)));
tri!(map.serialize_entry(self.tag, self.variant_name));
Ok(map)
}
@@ -290,8 +290,8 @@ where
name: &'static str,
len: usize,
) -> Result<Self::SerializeStruct, Self::Error> {
let mut state = try!(self.delegate.serialize_struct(name, len + 1));
try!(state.serialize_field(self.tag, self.variant_name));
let mut state = tri!(self.delegate.serialize_struct(name, len + 1));
tri!(state.serialize_field(self.tag, self.variant_name));
Ok(state)
}
@@ -316,9 +316,9 @@ where
inner_variant: &'static str,
len: usize,
) -> Result<Self::SerializeStructVariant, Self::Error> {
let mut map = try!(self.delegate.serialize_map(Some(2)));
try!(map.serialize_entry(self.tag, self.variant_name));
try!(map.serialize_key(inner_variant));
let mut map = tri!(self.delegate.serialize_map(Some(2)));
tri!(map.serialize_entry(self.tag, self.variant_name));
tri!(map.serialize_key(inner_variant));
Ok(SerializeStructVariantAsMapValue::new(
map,
inner_variant,
@@ -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))
}
@@ -337,9 +337,9 @@ where
#[cfg(any(feature = "std", feature = "alloc"))]
mod content {
use lib::*;
use crate::lib::*;
use ser::{self, Serialize, Serializer};
use crate::ser::{self, Serialize, Serializer};
pub struct SerializeTupleVariantAsMapValue<M> {
map: M,
@@ -357,6 +357,7 @@ mod content {
}
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<M> ser::SerializeTupleVariant for SerializeTupleVariantAsMapValue<M>
where
M: ser::SerializeMap,
@@ -364,17 +365,17 @@ 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 = try!(value.serialize(ContentSerializer::<M::Error>::new()));
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
self.fields.push(value);
Ok(())
}
fn end(mut self) -> Result<M::Ok, M::Error> {
try!(self
tri!(self
.map
.serialize_value(&Content::TupleStruct(self.name, self.fields)));
self.map.end()
@@ -397,6 +398,7 @@ mod content {
}
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<M> ser::SerializeStructVariant for SerializeStructVariantAsMapValue<M>
where
M: ser::SerializeMap,
@@ -404,21 +406,17 @@ 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 = try!(value.serialize(ContentSerializer::<M::Error>::new()));
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
self.fields.push((key, value));
Ok(())
}
fn end(mut self) -> Result<M::Ok, M::Error> {
try!(self
tri!(self
.map
.serialize_value(&Content::Struct(self.name, self.fields)));
self.map.end()
@@ -468,6 +466,7 @@ mod content {
),
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl Serialize for Content {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -499,50 +498,50 @@ mod content {
}
Content::Seq(ref elements) => elements.serialize(serializer),
Content::Tuple(ref elements) => {
use ser::SerializeTuple;
let mut tuple = try!(serializer.serialize_tuple(elements.len()));
use crate::ser::SerializeTuple;
let mut tuple = tri!(serializer.serialize_tuple(elements.len()));
for e in elements {
try!(tuple.serialize_element(e));
tri!(tuple.serialize_element(e));
}
tuple.end()
}
Content::TupleStruct(n, ref fields) => {
use ser::SerializeTupleStruct;
let mut ts = try!(serializer.serialize_tuple_struct(n, fields.len()));
use crate::ser::SerializeTupleStruct;
let mut ts = tri!(serializer.serialize_tuple_struct(n, fields.len()));
for f in fields {
try!(ts.serialize_field(f));
tri!(ts.serialize_field(f));
}
ts.end()
}
Content::TupleVariant(n, i, v, ref fields) => {
use ser::SerializeTupleVariant;
let mut tv = try!(serializer.serialize_tuple_variant(n, i, v, fields.len()));
use crate::ser::SerializeTupleVariant;
let mut tv = tri!(serializer.serialize_tuple_variant(n, i, v, fields.len()));
for f in fields {
try!(tv.serialize_field(f));
tri!(tv.serialize_field(f));
}
tv.end()
}
Content::Map(ref entries) => {
use ser::SerializeMap;
let mut map = try!(serializer.serialize_map(Some(entries.len())));
use crate::ser::SerializeMap;
let mut map = tri!(serializer.serialize_map(Some(entries.len())));
for (k, v) in entries {
try!(map.serialize_entry(k, v));
tri!(map.serialize_entry(k, v));
}
map.end()
}
Content::Struct(n, ref fields) => {
use ser::SerializeStruct;
let mut s = try!(serializer.serialize_struct(n, fields.len()));
use crate::ser::SerializeStruct;
let mut s = tri!(serializer.serialize_struct(n, fields.len()));
for &(k, ref v) in fields {
try!(s.serialize_field(k, v));
tri!(s.serialize_field(k, v));
}
s.end()
}
Content::StructVariant(n, i, v, ref fields) => {
use ser::SerializeStructVariant;
let mut sv = try!(serializer.serialize_struct_variant(n, i, v, fields.len()));
use crate::ser::SerializeStructVariant;
let mut sv = tri!(serializer.serialize_struct_variant(n, i, v, fields.len()));
for &(k, ref v) in fields {
try!(sv.serialize_field(k, v));
tri!(sv.serialize_field(k, v));
}
sv.end()
}
@@ -560,6 +559,7 @@ mod content {
}
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<E> Serializer for ContentSerializer<E>
where
E: ser::Error,
@@ -635,11 +635,11 @@ 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(try!(value.serialize(self)))))
Ok(Content::Some(Box::new(tri!(value.serialize(self)))))
}
fn serialize_unit(self) -> Result<Content, E> {
@@ -659,21 +659,17 @@ 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,
Box::new(try!(value.serialize(self))),
Box::new(tri!(value.serialize(self))),
))
}
fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
name: &'static str,
variant_index: u32,
@@ -681,13 +677,13 @@ mod content {
value: &T,
) -> Result<Content, E>
where
T: Serialize,
T: ?Sized + Serialize,
{
Ok(Content::NewtypeVariant(
name,
variant_index,
variant,
Box::new(try!(value.serialize(self))),
Box::new(tri!(value.serialize(self))),
))
}
@@ -775,6 +771,7 @@ mod content {
error: PhantomData<E>,
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<E> ser::SerializeSeq for SerializeSeq<E>
where
E: ser::Error,
@@ -782,11 +779,11 @@ 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 = try!(value.serialize(ContentSerializer::<E>::new()));
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.elements.push(value);
Ok(())
}
@@ -801,6 +798,7 @@ mod content {
error: PhantomData<E>,
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<E> ser::SerializeTuple for SerializeTuple<E>
where
E: ser::Error,
@@ -808,11 +806,11 @@ 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 = try!(value.serialize(ContentSerializer::<E>::new()));
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.elements.push(value);
Ok(())
}
@@ -828,6 +826,7 @@ mod content {
error: PhantomData<E>,
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<E> ser::SerializeTupleStruct for SerializeTupleStruct<E>
where
E: ser::Error,
@@ -835,11 +834,11 @@ 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 = try!(value.serialize(ContentSerializer::<E>::new()));
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.fields.push(value);
Ok(())
}
@@ -857,6 +856,7 @@ mod content {
error: PhantomData<E>,
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<E> ser::SerializeTupleVariant for SerializeTupleVariant<E>
where
E: ser::Error,
@@ -864,11 +864,11 @@ 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 = try!(value.serialize(ContentSerializer::<E>::new()));
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.fields.push(value);
Ok(())
}
@@ -889,6 +889,7 @@ mod content {
error: PhantomData<E>,
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<E> ser::SerializeMap for SerializeMap<E>
where
E: ser::Error,
@@ -896,24 +897,24 @@ 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 = try!(key.serialize(ContentSerializer::<E>::new()));
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
.take()
.expect("serialize_value called before serialize_key");
let value = try!(value.serialize(ContentSerializer::<E>::new()));
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.entries.push((key, value));
Ok(())
}
@@ -922,13 +923,13 @@ 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 = try!(key.serialize(ContentSerializer::<E>::new()));
let value = try!(value.serialize(ContentSerializer::<E>::new()));
let key = tri!(key.serialize(ContentSerializer::<E>::new()));
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.entries.push((key, value));
Ok(())
}
@@ -940,6 +941,7 @@ mod content {
error: PhantomData<E>,
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<E> ser::SerializeStruct for SerializeStruct<E>
where
E: ser::Error,
@@ -947,11 +949,11 @@ 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 = try!(value.serialize(ContentSerializer::<E>::new()));
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.fields.push((key, value));
Ok(())
}
@@ -969,6 +971,7 @@ mod content {
error: PhantomData<E>,
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<E> ser::SerializeStructVariant for SerializeStructVariant<E>
where
E: ser::Error,
@@ -976,11 +979,11 @@ 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 = try!(value.serialize(ContentSerializer::<E>::new()));
let value = tri!(value.serialize(ContentSerializer::<E>::new()));
self.fields.push((key, value));
Ok(())
}
@@ -1013,6 +1016,7 @@ where
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<'a, M> Serializer for FlatMapSerializer<'a, M>
where
M: SerializeMap + 'a,
@@ -1025,7 +1029,7 @@ where
type SerializeTupleStruct = Impossible<Self::Ok, M::Error>;
type SerializeMap = FlatMapSerializeMap<'a, M>;
type SerializeStruct = FlatMapSerializeStruct<'a, M>;
type SerializeTupleVariant = Impossible<Self::Ok, M::Error>;
type SerializeTupleVariant = FlatMapSerializeTupleVariantAsMapValue<'a, M>;
type SerializeStructVariant = FlatMapSerializeStructVariantAsMapValue<'a, M>;
fn serialize_bool(self, _: bool) -> Result<Self::Ok, Self::Error> {
@@ -1088,9 +1092,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)
}
@@ -1100,30 +1104,30 @@ where
}
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
Err(Self::bad_type(Unsupported::UnitStruct))
Ok(())
}
fn serialize_unit_variant(
self,
_: &'static str,
_: u32,
_: &'static str,
variant: &'static str,
) -> Result<Self::Ok, Self::Error> {
Err(Self::bad_type(Unsupported::Enum))
self.0.serialize_entry(variant, &())
}
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,10 +1135,9 @@ where
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: Serialize,
T: ?Sized + Serialize,
{
try!(self.0.serialize_key(variant));
self.0.serialize_value(value)
self.0.serialize_entry(variant, value)
}
fn serialize_seq(self, _: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
@@ -1157,10 +1160,11 @@ where
self,
_: &'static str,
_: u32,
_: &'static str,
variant: &'static str,
_: usize,
) -> Result<Self::SerializeTupleVariant, Self::Error> {
Err(Self::bad_type(Unsupported::Enum))
tri!(self.0.serialize_key(variant));
Ok(FlatMapSerializeTupleVariantAsMapValue::new(self.0))
}
fn serialize_map(self, _: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
@@ -1182,7 +1186,7 @@ where
inner_variant: &'static str,
_: usize,
) -> Result<Self::SerializeStructVariant, Self::Error> {
try!(self.0.serialize_key(inner_variant));
tri!(self.0.serialize_key(inner_variant));
Ok(FlatMapSerializeStructVariantAsMapValue::new(
self.0,
inner_variant,
@@ -1194,6 +1198,7 @@ where
pub struct FlatMapSerializeMap<'a, M: 'a>(&'a mut M);
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<'a, M> ser::SerializeMap for FlatMapSerializeMap<'a, M>
where
M: SerializeMap + 'a,
@@ -1201,28 +1206,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)
}
@@ -1236,6 +1237,7 @@ where
pub struct FlatMapSerializeStruct<'a, M: 'a>(&'a mut M);
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<'a, M> ser::SerializeStruct for FlatMapSerializeStruct<'a, M>
where
M: SerializeMap + 'a,
@@ -1243,13 +1245,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)
}
@@ -1259,6 +1257,53 @@ where
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#[cfg(any(feature = "std", feature = "alloc"))]
pub struct FlatMapSerializeTupleVariantAsMapValue<'a, M: 'a> {
map: &'a mut M,
fields: Vec<Content>,
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, M> FlatMapSerializeTupleVariantAsMapValue<'a, M>
where
M: SerializeMap + 'a,
{
fn new(map: &'a mut M) -> Self {
FlatMapSerializeTupleVariantAsMapValue {
map,
fields: Vec::new(),
}
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<'a, M> ser::SerializeTupleVariant for FlatMapSerializeTupleVariantAsMapValue<'a, M>
where
M: SerializeMap + 'a,
{
type Ok = ();
type Error = M::Error;
fn serialize_field<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
self.fields.push(value);
Ok(())
}
fn end(self) -> Result<(), Self::Error> {
tri!(self.map.serialize_value(&Content::Seq(self.fields)));
Ok(())
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#[cfg(any(feature = "std", feature = "alloc"))]
pub struct FlatMapSerializeStructVariantAsMapValue<'a, M: 'a> {
map: &'a mut M,
@@ -1281,6 +1326,7 @@ where
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<'a, M> ser::SerializeStructVariant for FlatMapSerializeStructVariantAsMapValue<'a, M>
where
M: SerializeMap + 'a,
@@ -1288,23 +1334,49 @@ 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 = try!(value.serialize(ContentSerializer::<M::Error>::new()));
let value = tri!(value.serialize(ContentSerializer::<M::Error>::new()));
self.fields.push((key, value));
Ok(())
}
fn end(self) -> Result<(), Self::Error> {
try!(self
tri!(self
.map
.serialize_value(&Content::Struct(self.name, self.fields)));
Ok(())
}
}
pub struct AdjacentlyTaggedEnumVariant {
pub enum_name: &'static str,
pub variant_index: u32,
pub variant_name: &'static str,
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl Serialize for AdjacentlyTaggedEnumVariant {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_unit_variant(self.enum_name, self.variant_index, self.variant_name)
}
}
// Error when Serialize for a non_exhaustive remote enum encounters a variant
// that is not recognized.
pub struct CannotSerializeVariant<T>(pub T);
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<T> Display for CannotSerializeVariant<T>
where
T: Debug,
{
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "enum variant cannot be serialized: {:?}", self.0)
}
}
+70
View File
@@ -0,0 +1,70 @@
[package]
name = "serde_core"
version = "1.0.226"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
build = "build.rs"
categories = ["encoding", "no-std", "no-std::no-alloc"]
description = "Serde traits only, with no support for derive -- use the `serde` crate instead"
documentation = "https://docs.rs/serde_core"
edition = "2021"
homepage = "https://serde.rs"
keywords = ["serde", "serialization", "no_std"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/serde-rs/serde"
rust-version = "1.56"
[dev-dependencies]
serde = { version = "1", path = "../serde" }
serde_derive = { version = "1", path = "../serde_derive" }
[package.metadata.playground]
features = ["rc", "result"]
[package.metadata.docs.rs]
features = ["rc", "result", "unstable"]
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = [
"--generate-link-to-definition",
"--generate-macro-expansion",
"--extern-html-root-url=core=https://doc.rust-lang.org",
"--extern-html-root-url=alloc=https://doc.rust-lang.org",
"--extern-html-root-url=std=https://doc.rust-lang.org",
]
# 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
# separately with serde's "derive" feature disabled. Every serde_derive release
# 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.226", path = "../serde_derive" }
### FEATURES #################################################################
[features]
default = ["std", "result"]
# Provide impls for common standard library types like Vec<T> and HashMap<K, V>.
# Requires a dependency on the Rust standard library.
std = []
# Provide impls for types that require unstable functionality. For tracking and
# discussion of unstable functionality please refer to this issue:
#
# https://github.com/serde-rs/serde/issues/812
unstable = []
# Provide impls for types in the Rust core allocation and collections library
# including String, Box<T>, Vec<T>, and Cow<T>. This is a subset of std but may
# be enabled without depending on all of std.
alloc = []
# Opt into impls for Rc<T> and Arc<T>. Serializing and deserializing these types
# does not preserve identity and may result in multiple copies of the same data.
# Be sure that this is what you want before enabling this feature.
rc = []
# Provide impls for Result<T, E>. Convenient in some contexts but can lead to
# confusion if ? or unwrap are used incautiously.
result = []
+28
View File
@@ -0,0 +1,28 @@
The `serde_core` crate contains Serde's trait definitions with **no support for
#\[derive()\]**.
In crates that derive an implementation of `Serialize` or `Deserialize`, you
must depend on the [`serde`] crate, not `serde_core`.
[`serde`]: https://crates.io/crates/serde
In crates that handwrite implementations of Serde traits, or only use them as
trait bounds, depending on `serde_core` is permitted. But `serde` re-exports all
of these traits and can be used for this use case too. If in doubt, disregard
`serde_core` and always use `serde`.
Crates that depend on `serde_core` instead of `serde` are able to compile in
parallel with `serde_derive` even when `serde`'s "derive" feature is turned on,
as shown in the following build timings.
<br>
| When `serde_json` depends on `serde` |
|---|
| <img src="https://github.com/user-attachments/assets/78dc179c-6ab1-4059-928c-1474b0d9d0bb"> |
<br>
| When `serde_json` depends on `serde_core` |
|---|
| <img src="https://github.com/user-attachments/assets/6b6cff5e-3e45-4ac7-9db1-d99ee8b9f5f7"> |
+112
View File
@@ -0,0 +1,112 @@
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use std::str;
const PRIVATE: &str = "\
#[doc(hidden)]
pub mod __private$$ {
#[doc(hidden)]
pub use crate::private::*;
}
";
// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script.
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let patch_version = env::var("CARGO_PKG_VERSION_PATCH").unwrap();
let module = PRIVATE.replace("$$", &patch_version);
fs::write(out_dir.join("private.rs"), module).unwrap();
let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
};
if minor >= 77 {
println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");
println!("cargo:rustc-check-cfg=cfg(no_core_error)");
println!("cargo:rustc-check-cfg=cfg(no_core_net)");
println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)");
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
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_target_has_atomic)");
}
let target = env::var("TARGET").unwrap();
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
// Support for #[cfg(target_has_atomic = "...")] stabilized in Rust 1.60.
if minor < 60 {
println!("cargo:rustc-cfg=no_target_has_atomic");
// Allowlist of archs that support std::sync::atomic module. This is
// based on rustc's compiler/rustc_target/src/spec/*.rs.
let has_atomic64 = target.starts_with("x86_64")
|| target.starts_with("i686")
|| target.starts_with("aarch64")
|| target.starts_with("powerpc64")
|| target.starts_with("sparc64")
|| target.starts_with("mips64el")
|| target.starts_with("riscv64");
let has_atomic32 = has_atomic64 || emscripten;
if minor < 34 || !has_atomic64 {
println!("cargo:rustc-cfg=no_std_atomic64");
}
if minor < 34 || !has_atomic32 {
println!("cargo:rustc-cfg=no_std_atomic");
}
}
// Current minimum supported version of serde_derive crate is Rust 1.61.
if minor < 61 {
println!("cargo:rustc-cfg=no_serde_derive");
}
// Support for core::ffi::CStr and alloc::ffi::CString stabilized in Rust 1.64.
// https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html#c-compatible-ffi-types-in-core-and-alloc
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 core::net stabilized in Rust 1.77.
// https://blog.rust-lang.org/2024/03/21/Rust-1.77.0.html
if minor < 77 {
println!("cargo:rustc-cfg=no_core_net");
}
// 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");
}
// The Error trait became available in core in 1.81.
// https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#coreerrorerror
if minor < 81 {
println!("cargo:rustc-cfg=no_core_error");
}
}
fn rustc_minor_version() -> Option<u32> {
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
pieces.next()?.parse().ok()
}
@@ -1,6 +1,6 @@
use lib::*;
use crate::lib::*;
use de::{
use crate::de::{
Deserialize, Deserializer, EnumAccess, Error, MapAccess, SeqAccess, VariantAccess, Visitor,
};
@@ -129,12 +129,10 @@ impl<'de> Visitor<'de> for IgnoredAny {
Ok(IgnoredAny)
}
serde_if_integer128! {
#[inline]
fn visit_i128<E>(self, x: i128) -> Result<Self::Value, E> {
let _ = x;
Ok(IgnoredAny)
}
#[inline]
fn visit_i128<E>(self, x: i128) -> Result<Self::Value, E> {
let _ = x;
Ok(IgnoredAny)
}
#[inline]
@@ -143,12 +141,10 @@ impl<'de> Visitor<'de> for IgnoredAny {
Ok(IgnoredAny)
}
serde_if_integer128! {
#[inline]
fn visit_u128<E>(self, x: u128) -> Result<Self::Value, E> {
let _ = x;
Ok(IgnoredAny)
}
#[inline]
fn visit_u128<E>(self, x: u128) -> Result<Self::Value, E> {
let _ = x;
Ok(IgnoredAny)
}
#[inline]
@@ -197,7 +193,7 @@ impl<'de> Visitor<'de> for IgnoredAny {
where
A: SeqAccess<'de>,
{
while let Some(IgnoredAny) = try!(seq.next_element()) {
while let Some(IgnoredAny) = tri!(seq.next_element()) {
// Gobble
}
Ok(IgnoredAny)
@@ -208,7 +204,7 @@ impl<'de> Visitor<'de> for IgnoredAny {
where
A: MapAccess<'de>,
{
while let Some((IgnoredAny, IgnoredAny)) = try!(map.next_entry()) {
while let Some((IgnoredAny, IgnoredAny)) = tri!(map.next_entry()) {
// Gobble
}
Ok(IgnoredAny)
@@ -227,7 +223,7 @@ impl<'de> Visitor<'de> for IgnoredAny {
where
A: EnumAccess<'de>,
{
try!(data.variant::<IgnoredAny>()).1.newtype_variant()
tri!(data.variant::<IgnoredAny>()).1.newtype_variant()
}
}
File diff suppressed because it is too large Load Diff
+197 -99
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\>
@@ -101,8 +101,8 @@
//! - SocketAddrV6
//!
//! [Implementing `Deserialize`]: https://serde.rs/impl-deserialize.html
//! [`Deserialize`]: ../trait.Deserialize.html
//! [`Deserializer`]: ../trait.Deserializer.html
//! [`Deserialize`]: crate::Deserialize
//! [`Deserializer`]: crate::Deserializer
//! [`LinkedHashMap<K, V>`]: https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html
//! [`postcard`]: https://github.com/jamesmunns/postcard
//! [`linked-hash-map`]: https://crates.io/crates/linked-hash-map
@@ -112,26 +112,26 @@
//! [derive section of the manual]: https://serde.rs/derive.html
//! [data formats]: https://serde.rs/#data-formats
use lib::*;
use crate::lib::*;
////////////////////////////////////////////////////////////////////////////////
pub mod value;
#[cfg(not(no_integer128))]
mod format;
mod ignored_any;
mod impls;
mod utf8;
pub use self::ignored_any::IgnoredAny;
pub use crate::private::InPlaceSeed;
#[cfg(all(not(feature = "std"), no_core_error))]
#[doc(no_inline)]
pub use crate::std_error::Error as StdError;
#[cfg(not(any(feature = "std", no_core_error)))]
#[doc(no_inline)]
pub use core::error::Error as StdError;
#[cfg(feature = "std")]
#[doc(no_inline)]
pub use std::error::Error as StdError;
#[cfg(not(feature = "std"))]
#[doc(no_inline)]
pub use std_error::Error as StdError;
////////////////////////////////////////////////////////////////////////////////
@@ -157,6 +157,12 @@ macro_rules! declare_error_trait {
/// type appropriate for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::Error` is not satisfied",
)
)]
pub trait Error: Sized $(+ $($supertrait)::+)* {
/// Raised when there is general error when deserializing a type.
///
@@ -205,7 +211,7 @@ macro_rules! declare_error_trait {
/// containing an integer, the unexpected type is the integer and the
/// expected type is the string.
#[cold]
fn invalid_type(unexp: Unexpected, exp: &Expected) -> Self {
fn invalid_type(unexp: Unexpected, exp: &dyn Expected) -> Self {
Error::custom(format_args!("invalid type: {}, expected {}", unexp, exp))
}
@@ -223,7 +229,7 @@ macro_rules! declare_error_trait {
/// that is not valid UTF-8, the unexpected value is the bytes and the
/// expected value is a string.
#[cold]
fn invalid_value(unexp: Unexpected, exp: &Expected) -> Self {
fn invalid_value(unexp: Unexpected, exp: &dyn Expected) -> Self {
Error::custom(format_args!("invalid value: {}, expected {}", unexp, exp))
}
@@ -237,7 +243,7 @@ macro_rules! declare_error_trait {
/// expected. For example `exp` might say that a tuple of size 6 was
/// expected.
#[cold]
fn invalid_length(len: usize, exp: &Expected) -> Self {
fn invalid_length(len: usize, exp: &dyn Expected) -> Self {
Error::custom(format_args!("invalid length {}, expected {}", len, exp))
}
@@ -400,20 +406,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),
}
}
@@ -470,6 +476,12 @@ impl<'a> fmt::Display for Unexpected<'a> {
/// ));
/// # }
/// ```
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::Expected` is not satisfied",
)
)]
pub trait Expected {
/// Format an explanation of what data was being expected. Same signature as
/// the `Display` and `Debug` traits.
@@ -485,13 +497,13 @@ where
}
}
impl<'a> Expected for &'a str {
impl Expected for &str {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(self)
}
}
impl<'a> Display for Expected + 'a {
impl Display for dyn Expected + '_ {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Expected::fmt(self, formatter)
}
@@ -530,6 +542,16 @@ 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(
// Prevents `serde_core::de::Deserialize` appearing in the error message
// in projects with no direct dependency on serde_core.
message = "the trait bound `{Self}: serde::Deserialize<'de>` is not satisfied",
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.
///
@@ -566,7 +588,7 @@ pub trait Deserialize<'de>: Sized {
D: Deserializer<'de>,
{
// Default implementation just delegates to `deserialize` impl.
*place = try!(Deserialize::deserialize(deserializer));
*place = tri!(Deserialize::deserialize(deserializer));
Ok(())
}
}
@@ -602,6 +624,12 @@ pub trait Deserialize<'de>: Sized {
/// lifetimes].
///
/// [Understanding deserializer lifetimes]: https://serde.rs/lifetimes.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::DeserializeOwned` is not satisfied",
)
)]
pub trait DeserializeOwned: for<'de> Deserialize<'de> {}
impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
@@ -767,6 +795,12 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
/// # Ok(())
/// # }
/// ```
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::DeserializeSeed<'de>` is not satisfied",
)
)]
pub trait DeserializeSeed<'de>: Sized {
/// The type produced by using this seed.
type Value;
@@ -903,6 +937,12 @@ where
/// a basic JSON `Deserializer`.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::Deserializer<'de>` is not satisfied",
)
)]
pub trait Deserializer<'de>: Sized {
/// The error type that can be returned if some error occurs during
/// deserialization.
@@ -946,18 +986,15 @@ pub trait Deserializer<'de>: Sized {
where
V: Visitor<'de>;
serde_if_integer128! {
/// Hint that the `Deserialize` type is expecting an `i128` value.
///
/// This method is available only on Rust compiler versions >=1.26. The
/// default behavior unconditionally returns an error.
fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>
{
let _ = visitor;
Err(Error::custom("i128 is not supported"))
}
/// Hint that the `Deserialize` type is expecting an `i128` value.
///
/// The default behavior unconditionally returns an error.
fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
let _ = visitor;
Err(Error::custom("i128 is not supported"))
}
/// Hint that the `Deserialize` type is expecting a `u8` value.
@@ -980,18 +1017,15 @@ pub trait Deserializer<'de>: Sized {
where
V: Visitor<'de>;
serde_if_integer128! {
/// Hint that the `Deserialize` type is expecting an `u128` value.
///
/// This method is available only on Rust compiler versions >=1.26. The
/// default behavior unconditionally returns an error.
fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>
{
let _ = visitor;
Err(Error::custom("u128 is not supported"))
}
/// Hint that the `Deserialize` type is expecting an `u128` value.
///
/// The default behavior unconditionally returns an error.
fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
let _ = visitor;
Err(Error::custom("u128 is not supported"))
}
/// Hint that the `Deserialize` type is expecting a `f32` value.
@@ -1224,13 +1258,9 @@ pub trait Deserializer<'de>: Sized {
// Not public API.
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
#[doc(hidden)]
fn __deserialize_content<V>(
self,
_: ::actually_private::T,
visitor: V,
) -> Result<::private::de::Content<'de>, Self::Error>
fn __deserialize_content_v1<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de, Value = ::private::de::Content<'de>>,
V: Visitor<'de, Value = crate::private::Content<'de>>,
{
self.deserialize_any(visitor)
}
@@ -1279,6 +1309,12 @@ pub trait Deserializer<'de>: Sized {
/// }
/// }
/// ```
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::Visitor<'de>` is not satisfied",
)
)]
pub trait Visitor<'de>: Sized {
/// The value produced by this visitor.
type Value;
@@ -1363,20 +1399,20 @@ pub trait Visitor<'de>: Sized {
Err(Error::invalid_type(Unexpected::Signed(v), &self))
}
serde_if_integer128! {
/// The input contains a `i128`.
///
/// This method is available only on Rust compiler versions >=1.26. The
/// default implementation fails with a type error.
fn visit_i128<E>(self, v: i128) -> Result<Self::Value, E>
where
E: Error,
{
let mut buf = [0u8; 58];
let mut writer = format::Buf::new(&mut buf);
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as i128", v)).unwrap();
Err(Error::invalid_type(Unexpected::Other(writer.as_str()), &self))
}
/// The input contains a `i128`.
///
/// The default implementation fails with a type error.
fn visit_i128<E>(self, v: i128) -> Result<Self::Value, E>
where
E: Error,
{
let mut buf = [0u8; 58];
let mut writer = crate::format::Buf::new(&mut buf);
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as i128", v)).unwrap();
Err(Error::invalid_type(
Unexpected::Other(writer.as_str()),
&self,
))
}
/// The input contains a `u8`.
@@ -1425,20 +1461,20 @@ pub trait Visitor<'de>: Sized {
Err(Error::invalid_type(Unexpected::Unsigned(v), &self))
}
serde_if_integer128! {
/// The input contains a `u128`.
///
/// This method is available only on Rust compiler versions >=1.26. The
/// default implementation fails with a type error.
fn visit_u128<E>(self, v: u128) -> Result<Self::Value, E>
where
E: Error,
{
let mut buf = [0u8; 57];
let mut writer = format::Buf::new(&mut buf);
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as u128", v)).unwrap();
Err(Error::invalid_type(Unexpected::Other(writer.as_str()), &self))
}
/// The input contains a `u128`.
///
/// The default implementation fails with a type error.
fn visit_u128<E>(self, v: u128) -> Result<Self::Value, E>
where
E: Error,
{
let mut buf = [0u8; 57];
let mut writer = crate::format::Buf::new(&mut buf);
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as u128", v)).unwrap();
Err(Error::invalid_type(
Unexpected::Other(writer.as_str()),
&self,
))
}
/// The input contains an `f32`.
@@ -1474,7 +1510,7 @@ pub trait Visitor<'de>: Sized {
where
E: Error,
{
self.visit_str(utf8::encode(v).as_str())
self.visit_str(v.encode_utf8(&mut [0u8; 4]))
}
/// The input contains a string. The lifetime of the string is ephemeral and
@@ -1529,6 +1565,7 @@ pub trait Visitor<'de>: Sized {
/// `String`.
#[inline]
#[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,
@@ -1551,7 +1588,6 @@ pub trait Visitor<'de>: Sized {
where
E: Error,
{
let _ = v;
Err(Error::invalid_type(Unexpected::Bytes(v), &self))
}
@@ -1588,6 +1624,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(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
where
E: Error,
@@ -1704,6 +1741,12 @@ pub trait Visitor<'de>: Sized {
/// implementation of `SeqAccess` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::SeqAccess<'de>` is not satisfied",
)
)]
pub trait SeqAccess<'de> {
/// The error type that can be returned if some error occurs during
/// deserialization.
@@ -1738,9 +1781,9 @@ pub trait SeqAccess<'de> {
}
}
impl<'de, 'a, A: ?Sized> SeqAccess<'de> for &'a mut A
impl<'de, A> SeqAccess<'de> for &mut A
where
A: SeqAccess<'de>,
A: ?Sized + SeqAccess<'de>,
{
type Error = A::Error;
@@ -1786,6 +1829,12 @@ where
/// implementation of `MapAccess` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::MapAccess<'de>` is not satisfied",
)
)]
pub trait MapAccess<'de> {
/// The error type that can be returned if some error occurs during
/// deserialization.
@@ -1831,9 +1880,9 @@ pub trait MapAccess<'de> {
K: DeserializeSeed<'de>,
V: DeserializeSeed<'de>,
{
match try!(self.next_key_seed(kseed)) {
match tri!(self.next_key_seed(kseed)) {
Some(key) => {
let value = try!(self.next_value_seed(vseed));
let value = tri!(self.next_value_seed(vseed));
Ok(Some((key, value)))
}
None => Ok(None),
@@ -1891,9 +1940,9 @@ pub trait MapAccess<'de> {
}
}
impl<'de, 'a, A: ?Sized> MapAccess<'de> for &'a mut A
impl<'de, A> MapAccess<'de> for &mut A
where
A: MapAccess<'de>,
A: ?Sized + MapAccess<'de>,
{
type Error = A::Error;
@@ -1978,6 +2027,12 @@ where
/// implementation of `EnumAccess` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::EnumAccess<'de>` is not satisfied",
)
)]
pub trait EnumAccess<'de>: Sized {
/// The error type that can be returned if some error occurs during
/// deserialization.
@@ -2025,6 +2080,12 @@ pub trait EnumAccess<'de>: Sized {
/// implementation of `VariantAccess` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::de::VariantAccess<'de>` is not satisfied",
)
)]
pub trait VariantAccess<'de>: Sized {
/// The error type that can be returned if some error occurs during
/// deserialization. Must match the error type of our `EnumAccess`.
@@ -2281,15 +2342,52 @@ impl Display for OneOf {
1 => write!(formatter, "`{}`", self.names[0]),
2 => write!(formatter, "`{}` or `{}`", self.names[0], self.names[1]),
_ => {
try!(write!(formatter, "one of "));
tri!(formatter.write_str("one of "));
for (i, alt) in self.names.iter().enumerate() {
if i > 0 {
try!(write!(formatter, ", "));
tri!(formatter.write_str(", "));
}
try!(write!(formatter, "`{}`", alt));
tri!(write!(formatter, "`{}`", alt));
}
Ok(())
}
}
}
}
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(())
}
}
@@ -21,12 +21,12 @@
//! }
//! ```
use lib::*;
use crate::lib::*;
use self::private::{First, Second};
use __private::size_hint;
use de::{self, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};
use ser;
use crate::de::{self, Deserializer, Expected, IntoDeserializer, SeqAccess, Visitor};
use crate::private::size_hint;
use crate::ser;
////////////////////////////////////////////////////////////////////////////////
@@ -113,6 +113,7 @@ impl Debug for Error {
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl error::Error for Error {
fn description(&self) -> &str {
&self.err
@@ -175,6 +176,17 @@ where
}
}
impl<'de, E> IntoDeserializer<'de, E> for UnitDeserializer<E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<E> Debug for UnitDeserializer<E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.debug_struct("UnitDeserializer").finish()
@@ -185,12 +197,14 @@ impl<E> Debug for UnitDeserializer<E> {
/// A deserializer that cannot be instantiated.
#[cfg(feature = "unstable")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
pub struct NeverDeserializer<E> {
never: !,
marker: PhantomData<E>,
}
#[cfg(feature = "unstable")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
impl<'de, E> IntoDeserializer<'de, E> for !
where
E: de::Error,
@@ -223,6 +237,18 @@ where
}
}
#[cfg(feature = "unstable")]
impl<'de, E> IntoDeserializer<'de, E> for NeverDeserializer<E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
////////////////////////////////////////////////////////////////////////////////
macro_rules! primitive_deserializer {
@@ -277,6 +303,17 @@ macro_rules! primitive_deserializer {
}
}
impl<'de, E> IntoDeserializer<'de, E> for $name<E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<E> Debug for $name<E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
@@ -293,20 +330,17 @@ primitive_deserializer!(i8, "an `i8`.", I8Deserializer, visit_i8);
primitive_deserializer!(i16, "an `i16`.", I16Deserializer, visit_i16);
primitive_deserializer!(i32, "an `i32`.", I32Deserializer, visit_i32);
primitive_deserializer!(i64, "an `i64`.", I64Deserializer, visit_i64);
primitive_deserializer!(i128, "an `i128`.", I128Deserializer, visit_i128);
primitive_deserializer!(isize, "an `isize`.", IsizeDeserializer, visit_i64 as i64);
primitive_deserializer!(u8, "a `u8`.", U8Deserializer, visit_u8);
primitive_deserializer!(u16, "a `u16`.", U16Deserializer, visit_u16);
primitive_deserializer!(u64, "a `u64`.", U64Deserializer, visit_u64);
primitive_deserializer!(u128, "a `u128`.", U128Deserializer, visit_u128);
primitive_deserializer!(usize, "a `usize`.", UsizeDeserializer, visit_u64 as u64);
primitive_deserializer!(f32, "an `f32`.", F32Deserializer, visit_f32);
primitive_deserializer!(f64, "an `f64`.", F64Deserializer, visit_f64);
primitive_deserializer!(char, "a `char`.", CharDeserializer, visit_char);
serde_if_integer128! {
primitive_deserializer!(i128, "an `i128`.", I128Deserializer, visit_i128);
primitive_deserializer!(u128, "a `u128`.", U128Deserializer, visit_u128);
}
/// A deserializer holding a `u32`.
pub struct U32Deserializer<E> {
value: u32,
@@ -370,6 +404,17 @@ where
}
}
impl<'de, E> IntoDeserializer<'de, E> for U32Deserializer<E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<'de, E> de::EnumAccess<'de> for U32Deserializer<E>
where
E: de::Error,
@@ -459,6 +504,17 @@ where
}
}
impl<'de, 'a, E> IntoDeserializer<'de, E> for StrDeserializer<'a, E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<'de, 'a, E> de::EnumAccess<'de> for StrDeserializer<'a, E>
where
E: de::Error,
@@ -538,6 +594,17 @@ where
}
}
impl<'de, E> IntoDeserializer<'de, E> for BorrowedStrDeserializer<'de, E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<'de, E> de::EnumAccess<'de> for BorrowedStrDeserializer<'de, E>
where
E: de::Error,
@@ -566,6 +633,7 @@ impl<'de, E> Debug for BorrowedStrDeserializer<'de, E> {
/// A deserializer holding a `String`.
#[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,6 +650,7 @@ impl<E> Clone for StringDeserializer<E> {
}
#[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,
@@ -639,6 +708,18 @@ where
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'de, E> IntoDeserializer<'de, E> for StringDeserializer<E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'de, E> de::EnumAccess<'de> for StringDeserializer<E>
where
@@ -669,6 +750,7 @@ impl<E> Debug for StringDeserializer<E> {
/// A deserializer holding a `Cow<str>`.
#[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>,
@@ -685,6 +767,7 @@ impl<'a, E> Clone for CowStrDeserializer<'a, E> {
}
#[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,
@@ -745,6 +828,18 @@ where
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'de, 'a, E> IntoDeserializer<'de, E> for CowStrDeserializer<'a, E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl<'de, 'a, E> de::EnumAccess<'de> for CowStrDeserializer<'a, E>
where
@@ -822,6 +917,17 @@ where
}
}
impl<'de, 'a, E> IntoDeserializer<'de, E> for BytesDeserializer<'a, E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<'a, E> Debug for BytesDeserializer<'a, E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
@@ -870,6 +976,17 @@ where
}
}
impl<'de, E> IntoDeserializer<'de, E> for BorrowedBytesDeserializer<'de, E>
where
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<'de, E> Debug for BorrowedBytesDeserializer<'de, E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
@@ -937,8 +1054,8 @@ where
where
V: de::Visitor<'de>,
{
let v = try!(visitor.visit_seq(&mut self));
try!(self.end());
let v = tri!(visitor.visit_seq(&mut self));
tri!(self.end());
Ok(v)
}
@@ -949,6 +1066,19 @@ where
}
}
impl<'de, I, T, E> IntoDeserializer<'de, E> for SeqDeserializer<I, E>
where
I: Iterator<Item = T>,
T: IntoDeserializer<'de, E>,
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<'de, I, T, E> de::SeqAccess<'de> for SeqDeserializer<I, E>
where
I: Iterator<Item = T>,
@@ -980,7 +1110,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)
}
@@ -1003,6 +1133,7 @@ where
////////////////////////////////////////////////////////////////////////////////
#[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>,
@@ -1016,6 +1147,7 @@ where
}
#[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,
@@ -1029,6 +1161,7 @@ where
}
#[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,
@@ -1077,6 +1210,17 @@ where
}
}
impl<'de, A> IntoDeserializer<'de, A::Error> for SeqAccessDeserializer<A>
where
A: de::SeqAccess<'de>,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
////////////////////////////////////////////////////////////////////////////////
/// A deserializer that iterates over a map.
@@ -1162,8 +1306,8 @@ where
where
V: de::Visitor<'de>,
{
let value = try!(visitor.visit_map(&mut self));
try!(self.end());
let value = tri!(visitor.visit_map(&mut self));
tri!(self.end());
Ok(value)
}
@@ -1171,8 +1315,8 @@ where
where
V: de::Visitor<'de>,
{
let value = try!(visitor.visit_seq(&mut self));
try!(self.end());
let value = tri!(visitor.visit_seq(&mut self));
tri!(self.end());
Ok(value)
}
@@ -1191,6 +1335,21 @@ where
}
}
impl<'de, I, E> IntoDeserializer<'de, E> for MapDeserializer<'de, I, E>
where
I: Iterator,
I::Item: private::Pair,
First<I::Item>: IntoDeserializer<'de, E>,
Second<I::Item>: IntoDeserializer<'de, E>,
E: de::Error,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<'de, I, E> de::MapAccess<'de> for MapDeserializer<'de, I, E>
where
I: Iterator,
@@ -1236,8 +1395,8 @@ where
{
match self.next_pair() {
Some((key, value)) => {
let key = try!(kseed.deserialize(key.into_deserializer()));
let value = try!(vseed.deserialize(value.into_deserializer()));
let key = tri!(kseed.deserialize(key.into_deserializer()));
let value = tri!(vseed.deserialize(value.into_deserializer()));
Ok(Some((key, value)))
}
None => Ok(None),
@@ -1341,7 +1500,7 @@ where
V: de::Visitor<'de>,
{
let mut pair_visitor = PairVisitor(Some(self.0), Some(self.1), PhantomData);
let pair = try!(visitor.visit_seq(&mut pair_visitor));
let pair = tri!(visitor.visit_seq(&mut pair_visitor));
if pair_visitor.1.is_none() {
Ok(pair)
} else {
@@ -1405,7 +1564,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)
}
@@ -1415,6 +1574,7 @@ impl Expected for ExpectedInMap {
////////////////////////////////////////////////////////////////////////////////
#[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,
@@ -1429,6 +1589,7 @@ where
}
#[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,
@@ -1490,6 +1651,17 @@ where
}
}
impl<'de, A> IntoDeserializer<'de, A::Error> for MapAccessDeserializer<A>
where
A: de::MapAccess<'de>,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
impl<'de, A> de::EnumAccess<'de> for MapAccessDeserializer<A>
where
A: de::MapAccess<'de>,
@@ -1501,7 +1673,7 @@ where
where
T: de::DeserializeSeed<'de>,
{
match try!(self.map.next_key_seed(seed)) {
match tri!(self.map.next_key_seed(seed)) {
Some(key) => Ok((key, private::map_as_enum(self.map))),
None => Err(de::Error::invalid_type(de::Unexpected::Map, &"enum")),
}
@@ -1543,12 +1715,25 @@ where
}
}
impl<'de, A> IntoDeserializer<'de, A::Error> for EnumAccessDeserializer<A>
where
A: de::EnumAccess<'de>,
{
type Deserializer = Self;
fn into_deserializer(self) -> Self {
self
}
}
////////////////////////////////////////////////////////////////////////////////
mod private {
use lib::*;
use crate::lib::*;
use de::{self, DeserializeSeed, Deserializer, MapAccess, Unexpected, VariantAccess, Visitor};
use crate::de::{
self, DeserializeSeed, Deserializer, MapAccess, Unexpected, VariantAccess, Visitor,
};
pub struct UnitOnly<E> {
marker: PhantomData<E>,
@@ -1,5 +1,5 @@
use lib::fmt::{self, Write};
use lib::str;
use crate::lib::fmt::{self, Write};
use crate::lib::str;
pub(super) struct Buf<'a> {
bytes: &'a mut [u8],
+279
View File
@@ -0,0 +1,279 @@
//! Serde is a framework for ***ser***ializing and ***de***serializing Rust data
//! structures efficiently and generically.
//!
//! The `serde_core` crate contains Serde's trait definitions with **no support
//! for #\[derive()\]**.
//!
//! In crates that derive an implementation of `Serialize` or `Deserialize`, you
//! must depend on the [`serde`] crate, not `serde_core`.
//!
//! [`serde`]: https://crates.io/crates/serde
//!
//! In crates that handwrite implementations of Serde traits, or only use them
//! as trait bounds, depending on `serde_core` is permitted. But `serde`
//! re-exports all of these traits and can be used for this use case too. If in
//! doubt, disregard `serde_core` and always use `serde`.
//!
//! Crates that depend on `serde_core` instead of `serde` are able to compile in
//! parallel with `serde_derive` even when `serde`'s "derive" feature is turned on,
//! as shown in the following build timings.
//!
//! <br>
//!
//! <table>
//! <tr><td align="center">When <code>serde_json</code> depends on <code>serde</code></td></tr>
//! <tr><td><img src="https://github.com/user-attachments/assets/78dc179c-6ab1-4059-928c-1474b0d9d0bb"></td></tr>
//! </table>
//!
//! <br>
//!
//! <table>
//! <tr><td align="center">When <code>serde_json</code> depends on <code>serde_core</code></td></tr>
//! <tr><td><img src="https://github.com/user-attachments/assets/6b6cff5e-3e45-4ac7-9db1-d99ee8b9f5f7"></td></tr>
//! </table>
////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde_core/1.0.226")]
// 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(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(never_type))]
#![allow(unknown_lints, bare_trait_objects, deprecated)]
// Ignored clippy and clippy_pedantic lints
#![allow(
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/5704
clippy::unnested_or_patterns,
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/7768
clippy::semicolon_if_nothing_returned,
// not available in our oldest supported compiler
clippy::empty_enum,
clippy::type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
// 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::single_match_else,
clippy::type_complexity,
clippy::use_self,
clippy::zero_prefixed_literal,
// correctly used
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,
clippy::result_unit_err,
clippy::wildcard_imports,
// not practical
clippy::needless_pass_by_value,
clippy::similar_names,
clippy::too_many_lines,
// preference
clippy::doc_markdown,
clippy::elidable_lifetime_names,
clippy::needless_lifetimes,
clippy::unseparated_literal_suffix,
// false positive
clippy::needless_doctest_main,
// noisy
clippy::missing_errors_doc,
clippy::must_use_candidate,
)]
// Restrictions
#![deny(clippy::question_mark_used)]
// Rustc lints.
#![deny(missing_docs, unused_imports)]
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "alloc")]
extern crate alloc;
/// A facade around all the types we need from the `std`, `core`, and `alloc`
/// crates. This avoids elaborate import wrangling having to happen in every
/// module.
mod lib {
mod core {
#[cfg(not(feature = "std"))]
pub use core::*;
#[cfg(feature = "std")]
pub use std::*;
}
pub use self::core::{f32, f64};
pub use self::core::{iter, num, str};
#[cfg(any(feature = "std", feature = "alloc"))]
pub use self::core::{cmp, mem};
pub use self::core::cell::{Cell, RefCell};
pub use self::core::cmp::Reverse;
pub use self::core::fmt::{self, Debug, Display, Write as FmtWrite};
pub use self::core::marker::PhantomData;
pub use self::core::num::Wrapping;
pub use self::core::ops::{Bound, Range, RangeFrom, RangeInclusive, RangeTo};
pub use self::core::result;
pub use self::core::time::Duration;
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::borrow::{Cow, ToOwned};
#[cfg(feature = "std")]
pub use std::borrow::{Cow, ToOwned};
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::string::{String, ToString};
#[cfg(feature = "std")]
pub use std::string::{String, ToString};
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::vec::Vec;
#[cfg(feature = "std")]
pub use std::vec::Vec;
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::boxed::Box;
#[cfg(feature = "std")]
pub use std::boxed::Box;
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
pub use alloc::rc::{Rc, Weak as RcWeak};
#[cfg(all(feature = "rc", feature = "std"))]
pub use std::rc::{Rc, Weak as RcWeak};
#[cfg(all(feature = "rc", feature = "alloc", not(feature = "std")))]
pub use alloc::sync::{Arc, Weak as ArcWeak};
#[cfg(all(feature = "rc", feature = "std"))]
pub use std::sync::{Arc, Weak as ArcWeak};
#[cfg(all(feature = "alloc", not(feature = "std")))]
pub use alloc::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
#[cfg(feature = "std")]
pub use std::collections::{BTreeMap, BTreeSet, BinaryHeap, LinkedList, VecDeque};
#[cfg(all(not(no_core_cstr), not(feature = "std")))]
pub use self::core::ffi::CStr;
#[cfg(feature = "std")]
pub use std::ffi::CStr;
#[cfg(all(not(no_core_cstr), feature = "alloc", not(feature = "std")))]
pub use alloc::ffi::CString;
#[cfg(feature = "std")]
pub use std::ffi::CString;
#[cfg(all(not(no_core_net), not(feature = "std")))]
pub use self::core::net;
#[cfg(feature = "std")]
pub use std::net;
#[cfg(feature = "std")]
pub use std::error;
#[cfg(feature = "std")]
pub use std::collections::{HashMap, HashSet};
#[cfg(feature = "std")]
pub use std::ffi::{OsStr, OsString};
#[cfg(feature = "std")]
pub use std::hash::{BuildHasher, Hash};
#[cfg(feature = "std")]
pub use std::io::Write;
#[cfg(feature = "std")]
pub use std::path::{Path, PathBuf};
#[cfg(feature = "std")]
pub use std::sync::{Mutex, RwLock};
#[cfg(feature = "std")]
pub use std::time::{SystemTime, UNIX_EPOCH};
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
pub use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize, Ordering,
};
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
pub use std::sync::atomic::{AtomicI64, AtomicU64};
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
pub use std::sync::atomic::Ordering;
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "8"))]
pub use std::sync::atomic::{AtomicBool, AtomicI8, AtomicU8};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "16"))]
pub use std::sync::atomic::{AtomicI16, AtomicU16};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "32"))]
pub use std::sync::atomic::{AtomicI32, AtomicU32};
#[cfg(all(feature = "std", not(no_target_has_atomic), target_has_atomic = "64"))]
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
// performed implicitly by the `?` operator or the standard library's `try!`
// macro. This simplified macro gives a 5.5% improvement in compile time
// compared to standard `try!`, and 9% improvement compared to `?`.
macro_rules! tri {
($expr:expr) => {
match $expr {
Ok(val) => val,
Err(err) => return Err(err),
}
};
}
////////////////////////////////////////////////////////////////////////////////
#[macro_use]
mod macros;
pub mod de;
pub mod ser;
mod format;
#[doc(inline)]
pub use crate::de::{Deserialize, Deserializer};
#[doc(inline)]
pub use crate::ser::{Serialize, Serializer};
// Used by generated code. Not public API.
#[doc(hidden)]
mod private;
// Used by declarative macro generated code. Not public API.
#[doc(hidden)]
pub mod __private {
#[doc(hidden)]
pub use crate::private::doc;
#[doc(hidden)]
pub use core::result::Result;
}
include!(concat!(env!("OUT_DIR"), "/private.rs"));
#[cfg(all(not(feature = "std"), no_core_error))]
mod std_error;
#[macro_export]
#[doc(hidden)]
macro_rules! __require_serde_not_serde_core {
() => {
::core::compile_error!(
"Serde derive requires a dependency on the serde crate, not serde_core"
);
};
}
@@ -1,7 +1,6 @@
// Super explicit first paragraph because this shows up at the top level and
// trips up people who are just looking for basic Serialize / Deserialize
// documentation.
//
/// Helper macro when implementing the `Deserializer` part of a new data format
/// for Serde.
///
@@ -104,9 +103,9 @@
/// # }
/// ```
///
/// [`Deserializer`]: trait.Deserializer.html
/// [`Visitor`]: de/trait.Visitor.html
/// [`Deserializer::deserialize_any`]: trait.Deserializer.html#tymethod.deserialize_any
/// [`Deserializer`]: crate::Deserializer
/// [`Visitor`]: crate::de::Visitor
/// [`Deserializer::deserialize_any`]: crate::Deserializer::deserialize_any
#[macro_export(local_inner_macros)]
macro_rules! forward_to_deserialize_any {
(<$visitor:ident: Visitor<$lifetime:tt>> $($func:ident)*) => {
@@ -123,7 +122,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>,
{
@@ -154,9 +153,7 @@ macro_rules! forward_to_deserialize_any_helper {
forward_to_deserialize_any_method!{deserialize_i64<$l, $v>()}
};
(i128<$l:tt, $v:ident>) => {
serde_if_integer128! {
forward_to_deserialize_any_method!{deserialize_i128<$l, $v>()}
}
forward_to_deserialize_any_method!{deserialize_i128<$l, $v>()}
};
(u8<$l:tt, $v:ident>) => {
forward_to_deserialize_any_method!{deserialize_u8<$l, $v>()}
@@ -171,9 +168,7 @@ macro_rules! forward_to_deserialize_any_helper {
forward_to_deserialize_any_method!{deserialize_u64<$l, $v>()}
};
(u128<$l:tt, $v:ident>) => {
serde_if_integer128! {
forward_to_deserialize_any_method!{deserialize_u128<$l, $v>()}
}
forward_to_deserialize_any_method!{deserialize_u128<$l, $v>()}
};
(f32<$l:tt, $v:ident>) => {
forward_to_deserialize_any_method!{deserialize_f32<$l, $v>()}
+39
View File
@@ -0,0 +1,39 @@
use crate::lib::*;
// Used from generated code to buffer the contents of the Deserializer when
// deserializing untagged enums and internally tagged enums.
//
// Not public API. Use serde-value instead.
//
// Obsoleted by format-specific buffer types (https://github.com/serde-rs/serde/pull/2912).
#[doc(hidden)]
pub enum Content<'de> {
Bool(bool),
U8(u8),
U16(u16),
U32(u32),
U64(u64),
I8(i8),
I16(i16),
I32(i32),
I64(i64),
F32(f32),
F64(f64),
Char(char),
String(String),
Str(&'de str),
ByteBuf(Vec<u8>),
Bytes(&'de [u8]),
None,
Some(Box<Content<'de>>),
Unit,
Newtype(Box<Content<'de>>),
Seq(Vec<Content<'de>>),
Map(Vec<(Content<'de>, Content<'de>)>),
}
@@ -1,13 +1,14 @@
// Used only by Serde doc tests. Not public API.
use lib::*;
use crate::lib::*;
use ser;
use crate::ser;
#[doc(hidden)]
#[derive(Debug)]
pub struct Error;
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl ser::Error for Error {
fn custom<T>(_: T) -> Self
where
@@ -18,12 +19,14 @@ impl ser::Error for Error {
}
#[cfg(feature = "std")]
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl error::Error for Error {
fn description(&self) -> &str {
unimplemented!()
}
}
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl Display for Error {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
@@ -56,7 +59,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!()
}
};
+21
View File
@@ -0,0 +1,21 @@
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
mod content;
mod seed;
// FIXME: #[cfg(doctest)] once https://github.com/rust-lang/rust/issues/67295 is fixed.
#[doc(hidden)]
pub mod doc;
#[doc(hidden)]
pub mod size_hint;
#[doc(hidden)]
pub mod string;
#[cfg(all(not(no_serde_derive), any(feature = "std", feature = "alloc")))]
#[doc(hidden)]
pub use self::content::Content;
#[doc(hidden)]
pub use self::seed::InPlaceSeed;
#[doc(hidden)]
pub use crate::lib::result::Result;
@@ -1,10 +1,11 @@
use de::{Deserialize, DeserializeSeed, Deserializer};
use crate::de::{Deserialize, DeserializeSeed, Deserializer};
/// A DeserializeSeed helper for implementing deserialize_in_place Visitors.
///
/// Wraps a mutable reference and calls deserialize_in_place on it.
pub struct InPlaceSeed<'a, T: 'a>(pub &'a mut T);
#[cfg_attr(not(no_diagnostic_namespace), diagnostic::do_not_recommend)]
impl<'a, 'de, T> DeserializeSeed<'de> for InPlaceSeed<'a, T>
where
T: Deserialize<'de>,
@@ -1,4 +1,5 @@
use lib::*;
#[cfg(any(feature = "std", feature = "alloc"))]
use crate::lib::*;
pub fn from_bounds<I>(iter: &I) -> Option<usize>
where
+23
View File
@@ -0,0 +1,23 @@
use crate::lib::*;
#[cfg(any(feature = "std", feature = "alloc"))]
#[doc(hidden)]
pub fn from_utf8_lossy(bytes: &[u8]) -> Cow<'_, str> {
String::from_utf8_lossy(bytes)
}
// The generated code calls this like:
//
// let value = &_serde::__private::from_utf8_lossy(bytes);
// Err(_serde::de::Error::unknown_variant(value, VARIANTS))
//
// so it is okay for the return type to be different from the std case as long
// as the above works.
#[cfg(not(any(feature = "std", feature = "alloc")))]
#[doc(hidden)]
pub fn from_utf8_lossy(bytes: &[u8]) -> &str {
// Three unicode replacement characters if it fails. They look like a
// white-on-black question mark. The user will recognize it as invalid
// UTF-8.
str::from_utf8(bytes).unwrap_or("\u{fffd}\u{fffd}\u{fffd}")
}
@@ -1,5 +1,5 @@
use lib::*;
use ser::{Error, Impossible, Serialize, Serializer};
use crate::lib::*;
use crate::ser::{Error, Impossible, Serialize, Serializer};
impl Error for fmt::Error {
fn custom<T: Display>(_msg: T) -> Self {
@@ -35,7 +35,7 @@ macro_rules! fmt_primitives {
/// }
/// }
/// ```
impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
impl<'a> Serializer for &mut fmt::Formatter<'a> {
type Ok = ();
type Error = fmt::Error;
type SerializeSeq = Impossible<(), fmt::Error>;
@@ -52,10 +52,12 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
serialize_i16: i16,
serialize_i32: i32,
serialize_i64: i64,
serialize_i128: i128,
serialize_u8: u8,
serialize_u16: u16,
serialize_u32: u32,
serialize_u64: u64,
serialize_u128: u128,
serialize_f32: f32,
serialize_f64: f64,
serialize_char: char,
@@ -63,13 +65,6 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
serialize_unit_struct: &'static str,
}
serde_if_integer128! {
fmt_primitives! {
serialize_i128: i128,
serialize_u128: u128,
}
}
fn serialize_unit_variant(
self,
_name: &'static str,
@@ -79,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)
}
@@ -94,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)
}
@@ -105,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,
@@ -113,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)
}
@@ -166,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)
}
@@ -1,6 +1,6 @@
use lib::*;
use crate::lib::*;
use ser::{Error, Serialize, SerializeTuple, Serializer};
use crate::ser::{Error, Serialize, SerializeTuple, Serializer};
////////////////////////////////////////////////////////////////////////////////
@@ -24,20 +24,17 @@ primitive_impl!(i8, serialize_i8);
primitive_impl!(i16, serialize_i16);
primitive_impl!(i32, serialize_i32);
primitive_impl!(i64, serialize_i64);
primitive_impl!(i128, serialize_i128);
primitive_impl!(usize, serialize_u64 as u64);
primitive_impl!(u8, serialize_u8);
primitive_impl!(u16, serialize_u16);
primitive_impl!(u32, serialize_u32);
primitive_impl!(u64, serialize_u64);
primitive_impl!(u128, serialize_u128);
primitive_impl!(f32, serialize_f32);
primitive_impl!(f64, serialize_f64);
primitive_impl!(char, serialize_char);
serde_if_integer128! {
primitive_impl!(i128, serialize_i128);
primitive_impl!(u128, serialize_u128);
}
////////////////////////////////////////////////////////////////////////////////
impl Serialize for str {
@@ -51,6 +48,7 @@ impl Serialize for str {
}
#[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>
@@ -73,6 +71,7 @@ impl<'a> Serialize for fmt::Arguments<'a> {
////////////////////////////////////////////////////////////////////////////////
#[cfg(any(feature = "std", not(no_core_cstr)))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl Serialize for CStr {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -84,6 +83,7 @@ impl Serialize for CStr {
}
#[cfg(any(feature = "std", all(not(no_core_cstr), 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
@@ -133,7 +136,7 @@ impl<T> Serialize for [T; 0] {
where
S: Serializer,
{
try!(serializer.serialize_tuple(0)).end()
tri!(serializer.serialize_tuple(0)).end()
}
}
@@ -149,9 +152,9 @@ macro_rules! array_impls {
where
S: Serializer,
{
let mut seq = try!(serializer.serialize_tuple($len));
let mut seq = tri!(serializer.serialize_tuple($len));
for e in self {
try!(seq.serialize_element(e));
tri!(seq.serialize_element(e));
}
seq.end()
}
@@ -182,9 +185,12 @@ where
}
}
#[cfg(all(any(feature = "std", feature = "alloc"), not(no_relaxed_trait_bounds)))]
macro_rules! seq_impl {
($ty:ident <T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)*>) => {
(
$(#[$attr:meta])*
$ty:ident <T $(, $typaram:ident : $bound:ident)*>
) => {
$(#[$attr])*
impl<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
where
T: Serialize,
@@ -200,42 +206,41 @@ macro_rules! seq_impl {
}
}
#[cfg(all(any(feature = "std", feature = "alloc"), no_relaxed_trait_bounds))]
macro_rules! seq_impl {
($ty:ident <T $(: $tbound1:ident $(+ $tbound2:ident)*)* $(, $typaram:ident : $bound:ident)*>) => {
impl<T $(, $typaram)*> Serialize for $ty<T $(, $typaram)*>
where
T: Serialize $(+ $tbound1 $(+ $tbound2)*)*,
$($typaram: $bound,)*
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.collect_seq(self)
}
}
}
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BinaryHeap<T>
}
#[cfg(any(feature = "std", feature = "alloc"))]
seq_impl!(BinaryHeap<T: Ord>);
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BTreeSet<T>
}
#[cfg(any(feature = "std", feature = "alloc"))]
seq_impl!(BTreeSet<T: Ord>);
seq_impl! {
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashSet<T, H: BuildHasher>
}
#[cfg(feature = "std")]
seq_impl!(HashSet<T: Eq + Hash, H: BuildHasher>);
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
LinkedList<T>
}
#[cfg(any(feature = "std", feature = "alloc"))]
seq_impl!(LinkedList<T>);
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
Vec<T>
}
#[cfg(any(feature = "std", feature = "alloc"))]
seq_impl!(Vec<T>);
#[cfg(any(feature = "std", feature = "alloc"))]
seq_impl!(VecDeque<T>);
seq_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
VecDeque<T>
}
////////////////////////////////////////////////////////////////////////////////
@@ -248,9 +253,9 @@ where
S: Serializer,
{
use super::SerializeStruct;
let mut state = try!(serializer.serialize_struct("Range", 2));
try!(state.serialize_field("start", &self.start));
try!(state.serialize_field("end", &self.end));
let mut state = tri!(serializer.serialize_struct("Range", 2));
tri!(state.serialize_field("start", &self.start));
tri!(state.serialize_field("end", &self.end));
state.end()
}
}
@@ -266,15 +271,14 @@ where
S: Serializer,
{
use super::SerializeStruct;
let mut state = try!(serializer.serialize_struct("RangeFrom", 1));
try!(state.serialize_field("start", &self.start));
let mut state = tri!(serializer.serialize_struct("RangeFrom", 1));
tri!(state.serialize_field("start", &self.start));
state.end()
}
}
////////////////////////////////////////////////////////////////////////////////
#[cfg(not(no_range_inclusive))]
impl<Idx> Serialize for RangeInclusive<Idx>
where
Idx: Serialize,
@@ -284,9 +288,9 @@ where
S: Serializer,
{
use super::SerializeStruct;
let mut state = try!(serializer.serialize_struct("RangeInclusive", 2));
try!(state.serialize_field("start", &self.start()));
try!(state.serialize_field("end", &self.end()));
let mut state = tri!(serializer.serialize_struct("RangeInclusive", 2));
tri!(state.serialize_field("start", &self.start()));
tri!(state.serialize_field("end", &self.end()));
state.end()
}
}
@@ -302,15 +306,14 @@ where
S: Serializer,
{
use super::SerializeStruct;
let mut state = try!(serializer.serialize_struct("RangeTo", 1));
try!(state.serialize_field("end", &self.end));
let mut state = tri!(serializer.serialize_struct("RangeTo", 1));
tri!(state.serialize_field("end", &self.end));
state.end()
}
}
////////////////////////////////////////////////////////////////////////////////
#[cfg(any(not(no_ops_bound), all(feature = "std", not(no_collections_bound))))]
impl<T> Serialize for Bound<T>
where
T: Serialize,
@@ -344,6 +347,7 @@ impl Serialize for () {
}
#[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
@@ -358,28 +362,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 = try!(serializer.serialize_tuple($len));
$(
try!(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)
@@ -399,9 +421,12 @@ tuple_impls! {
////////////////////////////////////////////////////////////////////////////////
#[cfg(all(any(feature = "std", feature = "alloc"), not(no_relaxed_trait_bounds)))]
macro_rules! map_impl {
($ty:ident <K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)*>) => {
(
$(#[$attr:meta])*
$ty:ident <K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)*>
) => {
$(#[$attr])*
impl<K, V $(, $typaram)*> Serialize for $ty<K, V $(, $typaram)*>
where
K: Serialize,
@@ -418,40 +443,26 @@ macro_rules! map_impl {
}
}
#[cfg(all(any(feature = "std", feature = "alloc"), no_relaxed_trait_bounds))]
macro_rules! map_impl {
($ty:ident <K $(: $kbound1:ident $(+ $kbound2:ident)*)*, V $(, $typaram:ident : $bound:ident)*>) => {
impl<K, V $(, $typaram)*> Serialize for $ty<K, V $(, $typaram)*>
where
K: Serialize $(+ $kbound1 $(+ $kbound2)*)*,
V: Serialize,
$($typaram: $bound,)*
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.collect_map(self)
}
}
}
map_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
BTreeMap<K: Ord, V>
}
#[cfg(any(feature = "std", feature = "alloc"))]
map_impl!(BTreeMap<K: Ord, V>);
#[cfg(feature = "std")]
map_impl!(HashMap<K: Eq + Hash, V, H: BuildHasher>);
map_impl! {
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
HashMap<K: Eq + Hash, V, H: BuildHasher>
}
////////////////////////////////////////////////////////////////////////////////
macro_rules! deref_impl {
(
$(#[doc = $doc:tt])*
$(#[$attr:meta])*
<$($desc:tt)+
) => {
$(#[doc = $doc])*
$(#[$attr])*
impl <$($desc)+ {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -464,13 +475,20 @@ macro_rules! deref_impl {
};
}
deref_impl!(<'a, T: ?Sized> Serialize for &'a T where T: Serialize);
deref_impl!(<'a, T: ?Sized> Serialize for &'a mut T where T: Serialize);
deref_impl! {
<'a, T> Serialize for &'a T where T: ?Sized + Serialize
}
#[cfg(any(feature = "std", feature = "alloc"))]
deref_impl!(<T: ?Sized> Serialize for Box<T> where T: Serialize);
deref_impl! {
<'a, T> Serialize for &'a mut T where T: ?Sized + Serialize
}
deref_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
<T> Serialize for Box<T> where T: ?Sized + Serialize
}
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
deref_impl! {
/// This impl requires the [`"rc"`] Cargo feature of Serde.
///
@@ -480,10 +498,11 @@ deref_impl! {
/// repeated data.
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
<T: ?Sized> Serialize for Rc<T> where T: Serialize
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
<T> Serialize for Rc<T> where T: ?Sized + Serialize
}
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
deref_impl! {
/// This impl requires the [`"rc"`] Cargo feature of Serde.
///
@@ -493,11 +512,16 @@ deref_impl! {
/// repeated data.
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
<T: ?Sized> Serialize for Arc<T> where T: Serialize
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))))]
<T> Serialize for Arc<T> where T: ?Sized + Serialize
}
#[cfg(any(feature = "std", feature = "alloc"))]
deref_impl!(<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwned);
deref_impl! {
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
<'a, T> Serialize for Cow<'a, T> where T: ?Sized + Serialize + ToOwned
}
////////////////////////////////////////////////////////////////////////////////
@@ -505,9 +529,13 @@ deref_impl!(<'a, T: ?Sized> Serialize for Cow<'a, T> where T: Serialize + ToOwne
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
impl<T: ?Sized> Serialize for RcWeak<T>
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
)]
impl<T> Serialize for RcWeak<T>
where
T: Serialize,
T: ?Sized + Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -521,9 +549,13 @@ where
///
/// [`"rc"`]: https://serde.rs/feature-flags.html#-features-rc
#[cfg(all(feature = "rc", any(feature = "std", feature = "alloc")))]
impl<T: ?Sized> Serialize for ArcWeak<T>
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "rc", any(feature = "std", feature = "alloc"))))
)]
impl<T> Serialize for ArcWeak<T>
where
T: Serialize,
T: ?Sized + Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -538,7 +570,6 @@ where
macro_rules! nonzero_integers {
($($T:ident,)+) => {
$(
#[cfg(not(no_num_nonzero))]
impl Serialize for num::$T {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -551,34 +582,19 @@ macro_rules! nonzero_integers {
}
}
nonzero_integers! {
NonZeroU8,
NonZeroU16,
NonZeroU32,
NonZeroU64,
NonZeroUsize,
}
#[cfg(not(no_num_nonzero_signed))]
nonzero_integers! {
NonZeroI8,
NonZeroI16,
NonZeroI32,
NonZeroI64,
NonZeroI128,
NonZeroIsize,
}
// Currently 128-bit integers do not work on Emscripten targets so we need an
// additional `#[cfg]`
serde_if_integer128! {
nonzero_integers! {
NonZeroU128,
}
#[cfg(not(no_num_nonzero_signed))]
nonzero_integers! {
NonZeroI128,
}
NonZeroU8,
NonZeroU16,
NonZeroU32,
NonZeroU64,
NonZeroU128,
NonZeroUsize,
}
impl<T> Serialize for Cell<T>
@@ -593,9 +609,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
@@ -609,9 +625,10 @@ where
}
#[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
@@ -625,9 +642,10 @@ where
}
#[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
@@ -642,6 +660,8 @@ where
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "result")]
#[cfg_attr(docsrs, doc(cfg(feature = "result")))]
impl<T, E> Serialize for Result<T, E>
where
T: Serialize,
@@ -662,16 +682,15 @@ where
////////////////////////////////////////////////////////////////////////////////
#[cfg(any(feature = "std", not(no_core_duration)))]
impl Serialize for Duration {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
use super::SerializeStruct;
let mut state = try!(serializer.serialize_struct("Duration", 2));
try!(state.serialize_field("secs", &self.as_secs()));
try!(state.serialize_field("nanos", &self.subsec_nanos()));
let mut state = tri!(serializer.serialize_struct("Duration", 2));
tri!(state.serialize_field("secs", &self.as_secs()));
tri!(state.serialize_field("nanos", &self.subsec_nanos()));
state.end()
}
}
@@ -679,6 +698,7 @@ impl Serialize for Duration {
////////////////////////////////////////////////////////////////////////////////
#[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
@@ -689,9 +709,9 @@ impl Serialize for SystemTime {
Ok(duration_since_epoch) => duration_since_epoch,
Err(_) => return Err(S::Error::custom("SystemTime must be later than UNIX_EPOCH")),
};
let mut state = try!(serializer.serialize_struct("SystemTime", 2));
try!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
try!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
let mut state = tri!(serializer.serialize_struct("SystemTime", 2));
tri!(state.serialize_field("secs_since_epoch", &duration_since_epoch.as_secs()));
tri!(state.serialize_field("nanos_since_epoch", &duration_since_epoch.subsec_nanos()));
state.end()
}
}
@@ -702,27 +722,17 @@ impl Serialize for SystemTime {
/// statically known to never have more than a constant `MAX_LEN` bytes.
///
/// Panics if the `Display` impl tries to write more than `MAX_LEN` bytes.
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
macro_rules! serialize_display_bounded_length {
($value:expr, $max:expr, $serializer:expr) => {{
let mut buffer = [0u8; $max];
let remaining_len = {
let mut remaining = &mut buffer[..];
write!(remaining, "{}", $value).unwrap();
remaining.len()
};
let written_len = buffer.len() - remaining_len;
let written = &buffer[..written_len];
// write! only provides fmt::Formatter to Display implementations, which
// has methods write_str and write_char but no method to write arbitrary
// bytes. Therefore `written` must be valid UTF-8.
let written_str = str::from_utf8(written).expect("must be valid UTF-8");
$serializer.serialize_str(written_str)
let mut writer = crate::format::Buf::new(&mut buffer);
write!(&mut writer, "{}", $value).unwrap();
$serializer.serialize_str(writer.as_str())
}};
}
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
impl Serialize for net::IpAddr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -746,7 +756,7 @@ impl Serialize for net::IpAddr {
}
}
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
const DEC_DIGITS_LUT: &[u8] = b"\
0001020304050607080910111213141516171819\
2021222324252627282930313233343536373839\
@@ -754,7 +764,7 @@ const DEC_DIGITS_LUT: &[u8] = b"\
6061626364656667686970717273747576777879\
8081828384858687888990919293949596979899";
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
#[inline]
fn format_u8(mut n: u8, out: &mut [u8]) -> usize {
if n >= 100 {
@@ -775,7 +785,7 @@ fn format_u8(mut n: u8, out: &mut [u8]) -> usize {
}
}
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
#[test]
fn test_format_u8() {
let mut i = 0u8;
@@ -792,7 +802,7 @@ fn test_format_u8() {
}
}
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
impl Serialize for net::Ipv4Addr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -816,7 +826,7 @@ impl Serialize for net::Ipv4Addr {
}
}
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
impl Serialize for net::Ipv6Addr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -832,7 +842,7 @@ impl Serialize for net::Ipv6Addr {
}
}
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
impl Serialize for net::SocketAddr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -856,7 +866,7 @@ impl Serialize for net::SocketAddr {
}
}
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
impl Serialize for net::SocketAddrV4 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -872,7 +882,7 @@ impl Serialize for net::SocketAddrV4 {
}
}
#[cfg(feature = "std")]
#[cfg(any(feature = "std", not(no_core_net)))]
impl Serialize for net::SocketAddrV6 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -894,6 +904,7 @@ impl Serialize for net::SocketAddrV6 {
////////////////////////////////////////////////////////////////////////////////
#[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
@@ -907,6 +918,7 @@ impl Serialize for Path {
}
#[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
@@ -917,6 +929,7 @@ impl Serialize for PathBuf {
}
#[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>
@@ -939,6 +952,7 @@ impl Serialize for OsStr {
}
#[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
@@ -963,7 +977,20 @@ where
}
}
#[cfg(not(no_core_reverse))]
#[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,
@@ -984,6 +1011,7 @@ macro_rules! atomic_impl {
($($ty:ident $size:expr)*) => {
$(
#[cfg(any(no_target_has_atomic, 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
@@ -1,8 +1,8 @@
//! This module contains `Impossible` serializer and its implementations.
use lib::*;
use crate::lib::*;
use ser::{
use crate::ser::{
self, Serialize, SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant,
SerializeTuple, SerializeTupleStruct, SerializeTupleVariant,
};
@@ -17,7 +17,7 @@ use ser::{
///
/// ```edition2021
/// # use serde::ser::{Serializer, Impossible};
/// # use serde::__private::doc::Error;
/// # use serde_core::__private::doc::Error;
/// #
/// # struct MySerializer;
/// #
@@ -41,7 +41,7 @@ use ser::{
/// }
///
/// /* other Serializer methods */
/// # serde::__serialize_unimplemented! {
/// # serde_core::__serialize_unimplemented! {
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str bytes none some
/// # unit unit_struct unit_variant newtype_struct newtype_variant
/// # tuple tuple_struct tuple_variant map struct struct_variant
@@ -49,14 +49,14 @@ use ser::{
/// }
/// ```
///
/// [`Serializer`]: trait.Serializer.html
/// [`SerializeSeq`]: trait.SerializeSeq.html
/// [`SerializeTuple`]: trait.SerializeTuple.html
/// [`SerializeTupleStruct`]: trait.SerializeTupleStruct.html
/// [`SerializeTupleVariant`]: trait.SerializeTupleVariant.html
/// [`SerializeMap`]: trait.SerializeMap.html
/// [`SerializeStruct`]: trait.SerializeStruct.html
/// [`SerializeStructVariant`]: trait.SerializeStructVariant.html
/// [`Serializer`]: crate::Serializer
/// [`SerializeSeq`]: crate::ser::SerializeSeq
/// [`SerializeTuple`]: crate::ser::SerializeTuple
/// [`SerializeTupleStruct`]: crate::ser::SerializeTupleStruct
/// [`SerializeTupleVariant`]: crate::ser::SerializeTupleVariant
/// [`SerializeMap`]: crate::ser::SerializeMap
/// [`SerializeStruct`]: crate::ser::SerializeStruct
/// [`SerializeStructVariant`]: crate::ser::SerializeStructVariant
pub struct Impossible<Ok, Error> {
void: Void,
ok: PhantomData<Ok>,
@@ -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;
+185 -159
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\>
@@ -97,8 +97,8 @@
//!
//! [Implementing `Serialize`]: https://serde.rs/impl-serialize.html
//! [`LinkedHashMap<K, V>`]: https://docs.rs/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap.html
//! [`Serialize`]: ../trait.Serialize.html
//! [`Serializer`]: ../trait.Serializer.html
//! [`Serialize`]: crate::Serialize
//! [`Serializer`]: crate::Serializer
//! [`postcard`]: https://github.com/jamesmunns/postcard
//! [`linked-hash-map`]: https://crates.io/crates/linked-hash-map
//! [`serde_derive`]: https://crates.io/crates/serde_derive
@@ -107,7 +107,7 @@
//! [derive section of the manual]: https://serde.rs/derive.html
//! [data formats]: https://serde.rs/#data-formats
use lib::*;
use crate::lib::*;
mod fmt;
mod impls;
@@ -115,15 +115,15 @@ mod impossible;
pub use self::impossible::Impossible;
#[cfg(all(feature = "unstable", not(feature = "std")))]
#[doc(inline)]
#[cfg(all(not(feature = "std"), no_core_error))]
#[doc(no_inline)]
pub use crate::std_error::Error as StdError;
#[cfg(not(any(feature = "std", no_core_error)))]
#[doc(no_inline)]
pub use core::error::Error as StdError;
#[cfg(feature = "std")]
#[doc(no_inline)]
pub use std::error::Error as StdError;
#[cfg(not(any(feature = "std", feature = "unstable")))]
#[doc(no_inline)]
pub use std_error::Error as StdError;
////////////////////////////////////////////////////////////////////////////////
@@ -139,6 +139,12 @@ macro_rules! declare_error_trait {
/// type appropriate for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::ser::Error` is not satisfied",
)
)]
pub trait Error: Sized $(+ $($supertrait)::+)* {
/// Used when a [`Serialize`] implementation encounters any error
/// while serializing a type.
@@ -173,8 +179,8 @@ macro_rules! declare_error_trait {
/// }
/// ```
///
/// [`Path`]: https://doc.rust-lang.org/std/path/struct.Path.html
/// [`Serialize`]: ../trait.Serialize.html
/// [`Path`]: std::path::Path
/// [`Serialize`]: crate::Serialize
fn custom<T>(msg: T) -> Self
where
T: Display;
@@ -215,6 +221,16 @@ 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(
// Prevents `serde_core::ser::Serialize` appearing in the error message
// in projects with no direct dependency on serde_core.
message = "the trait bound `{Self}: serde::Serialize` is not satisfied",
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.
///
@@ -330,6 +346,12 @@ pub trait Serialize {
/// a basic JSON `Serializer`.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::Serializer` is not satisfied",
)
)]
pub trait Serializer: Sized {
/// The output type produced by this `Serializer` during successful
/// serialization. Most serializers that produce text or binary output
@@ -338,7 +360,7 @@ pub trait Serializer: Sized {
/// in-memory data structures may be simplified by using `Ok` to propagate
/// the data structure around.
///
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
/// [`io::Write`]: std::io::Write
type Ok;
/// The error type when some error occurs during serialization.
@@ -391,7 +413,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for bool {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -413,7 +435,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for i8 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -435,7 +457,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for i16 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -457,7 +479,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for i32 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -475,7 +497,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for i64 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -488,30 +510,27 @@ pub trait Serializer: Sized {
/// ```
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error>;
serde_if_integer128! {
/// Serialize an `i128` value.
///
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// #
/// impl Serialize for i128 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// where
/// S: Serializer,
/// {
/// serializer.serialize_i128(*self)
/// }
/// }
/// ```
///
/// This method is available only on Rust compiler versions >=1.26. The
/// default behavior unconditionally returns an error.
fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> {
let _ = v;
Err(Error::custom("i128 is not supported"))
}
/// Serialize an `i128` value.
///
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for i128 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// where
/// S: Serializer,
/// {
/// serializer.serialize_i128(*self)
/// }
/// }
/// ```
///
/// The default behavior unconditionally returns an error.
fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> {
let _ = v;
Err(Error::custom("i128 is not supported"))
}
/// Serialize a `u8` value.
@@ -523,7 +542,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for u8 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -545,7 +564,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for u16 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -567,7 +586,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for u32 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -585,7 +604,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for u64 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -598,30 +617,27 @@ pub trait Serializer: Sized {
/// ```
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error>;
serde_if_integer128! {
/// Serialize a `u128` value.
///
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// #
/// impl Serialize for u128 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// where
/// S: Serializer,
/// {
/// serializer.serialize_u128(*self)
/// }
/// }
/// ```
///
/// This method is available only on Rust compiler versions >=1.26. The
/// default behavior unconditionally returns an error.
fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> {
let _ = v;
Err(Error::custom("u128 is not supported"))
}
/// Serialize a `u128` value.
///
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for u128 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// where
/// S: Serializer,
/// {
/// serializer.serialize_u128(*self)
/// }
/// }
/// ```
///
/// The default behavior unconditionally returns an error.
fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> {
let _ = v;
Err(Error::custom("u128 is not supported"))
}
/// Serialize an `f32` value.
@@ -633,7 +649,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for f32 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -651,7 +667,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for f64 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -672,7 +688,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for char {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -690,7 +706,7 @@ pub trait Serializer: Sized {
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for str {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -713,7 +729,7 @@ pub trait Serializer: Sized {
///
/// ```edition2021
/// # use serde::ser::{Serializer, SerializeSeq};
/// # use serde::__private::doc::Error;
/// # use serde_core::__private::doc::Error;
/// #
/// # struct MySerializer;
/// #
@@ -729,7 +745,7 @@ pub trait Serializer: Sized {
/// seq.end()
/// }
/// #
/// # serde::__serialize_unimplemented! {
/// # serde_core::__serialize_unimplemented! {
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str none some
/// # unit unit_struct unit_variant newtype_struct newtype_variant
/// # seq tuple tuple_struct tuple_variant map struct struct_variant
@@ -768,7 +784,7 @@ pub trait Serializer: Sized {
/// # fn main() {}
/// ```
///
/// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
/// [`None`]: core::option::Option::None
fn serialize_none(self) -> Result<Self::Ok, Self::Error>;
/// Serialize a [`Some(T)`] value.
@@ -801,17 +817,17 @@ pub trait Serializer: Sized {
/// # fn main() {}
/// ```
///
/// [`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>
/// [`Some(T)`]: core::option::Option::Some
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: Serialize;
T: ?Sized + Serialize;
/// Serialize a `()` value.
///
/// ```edition2021
/// # use serde::Serializer;
/// #
/// # serde::__private_serialize!();
/// # serde_core::__private_serialize!();
/// #
/// impl Serialize for () {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -897,13 +913,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) }`.
///
@@ -931,7 +947,7 @@ pub trait Serializer: Sized {
/// }
/// }
/// ```
fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
name: &'static str,
variant_index: u32,
@@ -939,7 +955,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
@@ -1176,7 +1192,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};
@@ -1213,6 +1230,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};
@@ -1279,22 +1298,9 @@ pub trait Serializer: Sized {
I: IntoIterator,
<I as IntoIterator>::Item: Serialize,
{
let iter = iter.into_iter();
let mut serializer = try!(self.serialize_seq(iterator_len_hint(&iter)));
#[cfg(not(no_iterator_try_fold))]
{
let mut iter = iter;
try!(iter.try_for_each(|item| serializer.serialize_element(&item)));
}
#[cfg(no_iterator_try_fold)]
{
for item in iter {
try!(serializer.serialize_element(&item));
}
}
let mut iter = iter.into_iter();
let mut serializer = tri!(self.serialize_seq(iterator_len_hint(&iter)));
tri!(iter.try_for_each(|item| serializer.serialize_element(&item)));
serializer.end()
}
@@ -1330,22 +1336,9 @@ pub trait Serializer: Sized {
V: Serialize,
I: IntoIterator<Item = (K, V)>,
{
let iter = iter.into_iter();
let mut serializer = try!(self.serialize_map(iterator_len_hint(&iter)));
#[cfg(not(no_iterator_try_fold))]
{
let mut iter = iter;
try!(iter.try_for_each(|(key, value)| serializer.serialize_entry(&key, &value)));
}
#[cfg(no_iterator_try_fold)]
{
for (key, value) in iter {
try!(serializer.serialize_entry(&key, &value));
}
}
let mut iter = iter.into_iter();
let mut serializer = tri!(self.serialize_map(iterator_len_hint(&iter)));
tri!(iter.try_for_each(|(key, value)| serializer.serialize_entry(&key, &value)));
serializer.end()
}
@@ -1375,12 +1368,11 @@ pub trait Serializer: Sized {
/// }
/// ```
///
/// [`String`]: https://doc.rust-lang.org/std/string/struct.String.html
/// [`serialize_str`]: #tymethod.serialize_str
/// [`serialize_str`]: Self::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())
}
@@ -1411,9 +1403,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.
@@ -1517,6 +1509,12 @@ pub trait Serializer: Sized {
/// implementation of `SerializeSeq` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::ser::SerializeSeq` is not satisfied",
)
)]
pub trait SerializeSeq {
/// Must match the `Ok` type of our `Serializer`.
type Ok;
@@ -1525,9 +1523,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>;
@@ -1617,6 +1615,12 @@ pub trait SerializeSeq {
/// implementation of `SerializeTuple` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::ser::SerializeTuple` is not satisfied",
)
)]
pub trait SerializeTuple {
/// Must match the `Ok` type of our `Serializer`.
type Ok;
@@ -1625,9 +1629,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>;
@@ -1662,6 +1666,12 @@ pub trait SerializeTuple {
/// implementation of `SerializeTupleStruct` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::ser::SerializeTupleStruct` is not satisfied",
)
)]
pub trait SerializeTupleStruct {
/// Must match the `Ok` type of our `Serializer`.
type Ok;
@@ -1670,9 +1680,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>;
@@ -1720,6 +1730,12 @@ pub trait SerializeTupleStruct {
/// implementation of `SerializeTupleVariant` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::ser::SerializeTupleVariant` is not satisfied",
)
)]
pub trait SerializeTupleVariant {
/// Must match the `Ok` type of our `Serializer`.
type Ok;
@@ -1728,9 +1744,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>;
@@ -1786,6 +1802,12 @@ pub trait SerializeTupleVariant {
/// implementation of `SerializeMap` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::ser::SerializeMap` is not satisfied",
)
)]
pub trait SerializeMap {
/// Must match the `Ok` type of our `Serializer`.
type Ok;
@@ -1799,9 +1821,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.
///
@@ -1809,9 +1831,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.
///
@@ -1827,19 +1849,15 @@ pub trait SerializeMap {
/// care about performance or are not able to optimize `serialize_entry` any
/// better than this.
///
/// [`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>
/// [`Serialize`]: crate::Serialize
/// [`serialize_key`]: Self::serialize_key
/// [`serialize_value`]: Self::serialize_value
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,
{
try!(self.serialize_key(key));
tri!(self.serialize_key(key));
self.serialize_value(value)
}
@@ -1880,6 +1898,12 @@ pub trait SerializeMap {
/// implementation of `SerializeStruct` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::ser::SerializeStruct` is not satisfied",
)
)]
pub trait SerializeStruct {
/// Must match the `Ok` type of our `Serializer`.
type Ok;
@@ -1888,15 +1912,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;
@@ -1946,6 +1968,12 @@ pub trait SerializeStruct {
/// implementation of `SerializeStructVariant` for a basic JSON data format.
///
/// [example data format]: https://serde.rs/data-format.html
#[cfg_attr(
not(no_diagnostic_namespace),
diagnostic::on_unimplemented(
message = "the trait bound `{Self}: serde::ser::SerializeStructVariant` is not satisfied",
)
)]
pub trait SerializeStructVariant {
/// Must match the `Ok` type of our `Serializer`.
type Ok;
@@ -1954,15 +1982,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;
@@ -1,4 +1,4 @@
use lib::{Debug, Display};
use crate::lib::{Debug, Display};
/// Either a re-export of std::error::Error or a new identical trait, depending
/// on whether Serde's "std" feature is enabled.
@@ -42,7 +42,7 @@ use lib::{Debug, Display};
/// ```
pub trait Error: Debug + Display {
/// The underlying cause of this error, if any.
fn source(&self) -> Option<&(Error + 'static)> {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}
+16 -7
View File
@@ -1,17 +1,18 @@
[package]
name = "serde_derive"
version = "1.0.170" # remember to update html_root_url
version = "1.0.226"
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 = "2021"
exclude = ["build.rs"]
homepage = "https://serde.rs"
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
keywords = ["serde", "serialization", "no_std", "derive"]
license = "MIT OR Apache-2.0"
readme = "crates-io.md"
repository = "https://github.com/serde-rs/serde"
rust-version = "1.56"
rust-version = "1.61"
[features]
default = []
@@ -22,12 +23,20 @@ name = "serde_derive"
proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0.25"
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.0", path = "../serde" }
serde = { version = "1", path = "../serde" }
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = [
"--generate-link-to-definition",
"--generate-macro-expansion",
"--extern-html-root-url=core=https://doc.rust-lang.org",
"--extern-html-root-url=alloc=https://doc.rust-lang.org",
"--extern-html-root-url=std=https://doc.rust-lang.org",
"--extern-html-root-url=proc_macro=https://doc.rust-lang.org",
]
+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)");
}
+11 -15
View File
@@ -1,12 +1,9 @@
use std::collections::HashSet;
use syn;
use syn::punctuated::{Pair, Punctuated};
use internals::ast::{Container, Data};
use internals::{attr, ungroup};
use crate::internals::ast::{Container, Data};
use crate::internals::{attr, ungroup};
use proc_macro2::Span;
use std::collections::HashSet;
use syn::punctuated::{Pair, Punctuated};
use syn::Token;
// Remove the default from every type parameter because in the generated impls
// they look like associated types: "error: associated type bindings are not
@@ -147,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 {
@@ -184,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))]
_ => {}
}
}
@@ -199,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)
)]
_ => {}
}
}
@@ -231,9 +225,11 @@ 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))]
syn::TypeParamBound::Lifetime(_)
| syn::TypeParamBound::PreciseCapture(_)
| syn::TypeParamBound::Verbatim(_) => {}
_ => {}
}
}
+670 -593
View File
File diff suppressed because it is too large Load Diff
+56
View File
@@ -0,0 +1,56 @@
use proc_macro2::TokenStream;
use quote::quote;
pub fn allow_deprecated(input: &syn::DeriveInput) -> Option<TokenStream> {
if should_allow_deprecated(input) {
Some(quote! { #[allow(deprecated)] })
} else {
None
}
}
/// Determine if an `#[allow(deprecated)]` should be added to the derived impl.
///
/// This should happen if the derive input or an enum variant it contains has
/// one of:
/// - `#[deprecated]`
/// - `#[allow(deprecated)]`
fn should_allow_deprecated(input: &syn::DeriveInput) -> bool {
if contains_deprecated(&input.attrs) {
return true;
}
if let syn::Data::Enum(data_enum) = &input.data {
for variant in &data_enum.variants {
if contains_deprecated(&variant.attrs) {
return true;
}
}
}
false
}
/// Check whether the given attributes contains one of:
/// - `#[deprecated]`
/// - `#[allow(deprecated)]`
fn contains_deprecated(attrs: &[syn::Attribute]) -> bool {
for attr in attrs {
if attr.path().is_ident("deprecated") {
return true;
}
if let syn::Meta::List(meta_list) = &attr.meta {
if meta_list.path.is_ident("allow") {
let mut allow_deprecated = false;
let _ = meta_list.parse_nested_meta(|meta| {
if meta.path.is_ident("deprecated") {
allow_deprecated = true;
}
Ok(())
});
if allow_deprecated {
return true;
}
}
}
}
false
}
+10 -7
View File
@@ -1,11 +1,7 @@
use proc_macro2::TokenStream;
use syn;
use try;
use quote::quote;
pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> TokenStream {
let try_replacement = try::replacement();
let use_serde = match serde_path {
Some(path) => quote! {
use #path as _serde;
@@ -18,10 +14,17 @@ pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> Token
quote! {
#[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
#[allow(
non_upper_case_globals,
unused_attributes,
unused_qualifications,
clippy::absolute_paths,
)]
const _: () = {
#use_serde
#try_replacement
_serde::__require_serde_not_serde_core!();
#code
};
}
+1 -1
View File
@@ -1,6 +1,6 @@
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::token;
use syn::{token, Token};
pub enum Fragment {
/// Tokens that can be used as an expression.
+31 -28
View File
@@ -1,10 +1,9 @@
//! A Serde ast, parsed from the Syn ast and ready to generate Rust code.
use internals::attr;
use internals::check;
use internals::{Ctxt, Derive};
use syn;
use crate::internals::{attr, check, Ctxt, Derive};
use proc_macro2::Ident;
use syn::punctuated::Punctuated;
use syn::Token;
/// A source data structure annotated with `#[derive(Serialize)]` and/or `#[derive(Deserialize)]`,
/// parsed into an internal representation.
@@ -64,13 +63,17 @@ impl<'a> Container<'a> {
cx: &Ctxt,
item: &'a syn::DeriveInput,
derive: Derive,
private: &Ident,
) -> Option<Container<'a>> {
let mut attrs = attr::Container::from_ast(cx, item);
let attrs = attr::Container::from_ast(cx, item);
let mut data = match &item.data {
syn::Data::Enum(data) => Data::Enum(enum_from_ast(cx, &data.variants, attrs.default())),
syn::Data::Enum(data) => {
Data::Enum(enum_from_ast(cx, &data.variants, attrs.default(), private))
}
syn::Data::Struct(data) => {
let (style, fields) = struct_from_ast(cx, &data.fields, None, attrs.default());
let (style, fields) =
struct_from_ast(cx, &data.fields, None, attrs.default(), private);
Data::Struct(style, fields)
}
syn::Data::Union(_) => {
@@ -79,35 +82,27 @@ impl<'a> Container<'a> {
}
};
let mut has_flatten = false;
match &mut data {
Data::Enum(variants) => {
for variant in variants {
variant.attrs.rename_by_rules(attrs.rename_all_rules());
for field in &mut variant.fields {
if field.attrs.flatten() {
has_flatten = true;
}
field
.attrs
.rename_by_rules(variant.attrs.rename_all_rules());
field.attrs.rename_by_rules(
variant
.attrs
.rename_all_rules()
.or(attrs.rename_all_fields_rules()),
);
}
}
}
Data::Struct(_, fields) => {
for field in fields {
if field.attrs.flatten() {
has_flatten = true;
}
field.attrs.rename_by_rules(attrs.rename_all_rules());
}
}
}
if has_flatten {
attrs.mark_has_flatten();
}
let mut item = Container {
ident: item.ident.clone(),
attrs,
@@ -121,7 +116,7 @@ impl<'a> Container<'a> {
}
impl<'a> Data<'a> {
pub fn all_fields(&'a self) -> Box<Iterator<Item = &'a Field<'a>> + 'a> {
pub fn all_fields(&'a self) -> Box<dyn Iterator<Item = &'a Field<'a>> + 'a> {
match self {
Data::Enum(variants) => {
Box::new(variants.iter().flat_map(|variant| variant.fields.iter()))
@@ -139,13 +134,19 @@ fn enum_from_ast<'a>(
cx: &Ctxt,
variants: &'a Punctuated<syn::Variant, Token![,]>,
container_default: &attr::Default,
private: &Ident,
) -> Vec<Variant<'a>> {
let variants: Vec<Variant> = variants
.iter()
.map(|variant| {
let attrs = attr::Variant::from_ast(cx, variant);
let (style, fields) =
struct_from_ast(cx, &variant.fields, Some(&attrs), container_default);
let (style, fields) = struct_from_ast(
cx,
&variant.fields,
Some(&attrs),
container_default,
private,
);
Variant {
ident: variant.ident.clone(),
attrs,
@@ -175,19 +176,20 @@ fn struct_from_ast<'a>(
fields: &'a syn::Fields,
attrs: Option<&attr::Variant>,
container_default: &attr::Default,
private: &Ident,
) -> (Style, Vec<Field<'a>>) {
match fields {
syn::Fields::Named(fields) => (
Style::Struct,
fields_from_ast(cx, &fields.named, attrs, container_default),
fields_from_ast(cx, &fields.named, attrs, container_default, private),
),
syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => (
Style::Newtype,
fields_from_ast(cx, &fields.unnamed, attrs, container_default),
fields_from_ast(cx, &fields.unnamed, attrs, container_default, private),
),
syn::Fields::Unnamed(fields) => (
Style::Tuple,
fields_from_ast(cx, &fields.unnamed, attrs, container_default),
fields_from_ast(cx, &fields.unnamed, attrs, container_default, private),
),
syn::Fields::Unit => (Style::Unit, Vec::new()),
}
@@ -198,6 +200,7 @@ fn fields_from_ast<'a>(
fields: &'a Punctuated<syn::Field, Token![,]>,
attrs: Option<&attr::Variant>,
container_default: &attr::Default,
private: &Ident,
) -> Vec<Field<'a>> {
fields
.iter()
@@ -207,7 +210,7 @@ fn fields_from_ast<'a>(
Some(ident) => syn::Member::Named(ident.clone()),
None => syn::Member::Unnamed(i.into()),
},
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default, private),
ty: &field.ty,
original: field,
})
+183 -164
View File
@@ -1,15 +1,15 @@
use internals::symbol::*;
use internals::{ungroup, Ctxt};
use crate::internals::name::{MultiName, Name};
use crate::internals::symbol::*;
use crate::internals::{ungroup, Ctxt};
use proc_macro2::{Spacing, Span, TokenStream, TokenTree};
use quote::ToTokens;
use std::borrow::Cow;
use std::collections::BTreeSet;
use std::iter::FromIterator;
use syn;
use syn::meta::ParseNestedMeta;
use syn::parse::ParseStream;
use syn::punctuated::Punctuated;
use syn::{token, Ident, Lifetime};
use syn::spanned::Spanned;
use syn::{token, Ident, Lifetime, Token};
// This module handles parsing of `#[serde(...)]` attributes. The entrypoints
// are `attr::Container::from_ast`, `attr::Variant::from_ast`, and
@@ -19,9 +19,9 @@ use syn::{token, Ident, Lifetime};
// user will see errors simultaneously for all bad attributes in the crate
// rather than just the first.
pub use internals::case::RenameRule;
pub use crate::internals::case::RenameRule;
struct Attr<'c, T> {
pub(crate) struct Attr<'c, T> {
cx: &'c Ctxt,
name: Symbol,
tokens: TokenStream,
@@ -62,7 +62,7 @@ impl<'c, T> Attr<'c, T> {
}
}
fn get(self) -> Option<T> {
pub(crate) fn get(self) -> Option<T> {
self.value
}
@@ -90,7 +90,7 @@ impl<'c> BoolAttr<'c> {
}
}
struct VecAttr<'c, T> {
pub(crate) struct VecAttr<'c, T> {
cx: &'c Ctxt,
name: Symbol,
first_dup_tokens: TokenStream,
@@ -125,86 +125,40 @@ impl<'c, T> VecAttr<'c, T> {
}
}
fn get(self) -> Vec<T> {
pub(crate) fn get(self) -> Vec<T> {
self.values
}
}
pub struct Name {
serialize: String,
serialize_renamed: bool,
deserialize: String,
deserialize_renamed: bool,
deserialize_aliases: Vec<String>,
}
fn unraw(ident: &Ident) -> String {
ident.to_string().trim_start_matches("r#").to_owned()
}
impl Name {
fn from_attrs(
source_name: String,
ser_name: Attr<String>,
de_name: Attr<String>,
de_aliases: Option<VecAttr<String>>,
) -> Name {
let deserialize_aliases = match de_aliases {
Some(de_aliases) => {
let mut alias_list = BTreeSet::new();
for alias_name in de_aliases.get() {
alias_list.insert(alias_name);
}
alias_list.into_iter().collect()
}
None => Vec::new(),
};
let ser_name = ser_name.get();
let ser_renamed = ser_name.is_some();
let de_name = de_name.get();
let de_renamed = de_name.is_some();
Name {
serialize: ser_name.unwrap_or_else(|| source_name.clone()),
serialize_renamed: ser_renamed,
deserialize: de_name.unwrap_or(source_name),
deserialize_renamed: de_renamed,
deserialize_aliases,
}
}
/// Return the container name for the container when serializing.
pub fn serialize_name(&self) -> String {
self.serialize.clone()
}
/// Return the container name for the container when deserializing.
pub fn deserialize_name(&self) -> String {
self.deserialize.clone()
}
fn deserialize_aliases(&self) -> Vec<String> {
let mut aliases = self.deserialize_aliases.clone();
let main_name = self.deserialize_name();
if !aliases.contains(&main_name) {
aliases.push(main_name);
}
aliases
}
fn unraw(ident: &Ident) -> Ident {
Ident::new(ident.to_string().trim_start_matches("r#"), ident.span())
}
#[derive(Copy, Clone)]
pub struct RenameAllRules {
serialize: RenameRule,
deserialize: RenameRule,
pub serialize: RenameRule,
pub deserialize: RenameRule,
}
impl RenameAllRules {
/// Returns a new `RenameAllRules` with the individual rules of `self` and
/// `other_rules` joined by `RenameRules::or`.
pub fn or(self, other_rules: Self) -> Self {
Self {
serialize: self.serialize.or(other_rules.serialize),
deserialize: self.deserialize.or(other_rules.deserialize),
}
}
}
/// Represents struct or enum attribute information.
pub struct Container {
name: Name,
name: MultiName,
transparent: bool,
deny_unknown_fields: bool,
default: Default,
rename_all_rules: RenameAllRules,
rename_all_fields_rules: RenameAllRules,
ser_bound: Option<Vec<syn::WherePredicate>>,
de_bound: Option<Vec<syn::WherePredicate>>,
tag: TagType,
@@ -213,11 +167,11 @@ pub struct Container {
type_into: Option<syn::Type>,
remote: Option<syn::Path>,
identifier: Identifier,
has_flatten: bool,
serde_path: Option<syn::Path>,
is_packed: bool,
/// Error message generated when type can't be deserialized
expecting: Option<String>,
non_exhaustive: bool,
}
/// Styles of representing an enum.
@@ -288,6 +242,8 @@ impl Container {
let mut default = Attr::none(cx, DEFAULT);
let mut rename_all_ser_rule = Attr::none(cx, RENAME_ALL);
let mut rename_all_de_rule = Attr::none(cx, RENAME_ALL);
let mut rename_all_fields_ser_rule = Attr::none(cx, RENAME_ALL_FIELDS);
let mut rename_all_fields_de_rule = Attr::none(cx, RENAME_ALL_FIELDS);
let mut ser_bound = Attr::none(cx, BOUND);
let mut de_bound = Attr::none(cx, BOUND);
let mut untagged = BoolAttr::none(cx, UNTAGGED);
@@ -301,9 +257,12 @@ impl Container {
let mut variant_identifier = BoolAttr::none(cx, VARIANT_IDENTIFIER);
let mut serde_path = Attr::none(cx, CRATE);
let mut expecting = Attr::none(cx, EXPECTING);
let mut non_exhaustive = false;
for attr in &item.attrs {
if attr.path() != SERDE {
non_exhaustive |=
matches!(&attr.meta, syn::Meta::Path(path) if path == NON_EXHAUSTIVE);
continue;
}
@@ -318,8 +277,8 @@ impl Container {
// #[serde(rename = "foo")]
// #[serde(rename(serialize = "foo", deserialize = "bar"))]
let (ser, de) = get_renames(cx, RENAME, &meta)?;
ser_name.set_opt(&meta.path, ser.as_ref().map(syn::LitStr::value));
de_name.set_opt(&meta.path, de.as_ref().map(syn::LitStr::value));
ser_name.set_opt(&meta.path, ser.as_ref().map(Name::from));
de_name.set_opt(&meta.path, de.as_ref().map(Name::from));
} else if meta.path == RENAME_ALL {
// #[serde(rename_all = "foo")]
// #[serde(rename_all(serialize = "foo", deserialize = "bar"))]
@@ -341,6 +300,44 @@ impl Container {
}
}
}
} else if meta.path == RENAME_ALL_FIELDS {
// #[serde(rename_all_fields = "foo")]
// #[serde(rename_all_fields(serialize = "foo", deserialize = "bar"))]
let one_name = meta.input.peek(Token![=]);
let (ser, de) = get_renames(cx, RENAME_ALL_FIELDS, &meta)?;
match item.data {
syn::Data::Enum(_) => {
if let Some(ser) = ser {
match RenameRule::from_str(&ser.value()) {
Ok(rename_rule) => {
rename_all_fields_ser_rule.set(&meta.path, rename_rule);
}
Err(err) => cx.error_spanned_by(ser, err),
}
}
if let Some(de) = de {
match RenameRule::from_str(&de.value()) {
Ok(rename_rule) => {
rename_all_fields_de_rule.set(&meta.path, rename_rule);
}
Err(err) => {
if !one_name {
cx.error_spanned_by(de, err);
}
}
}
}
}
syn::Data::Struct(_) => {
let msg = "#[serde(rename_all_fields)] can only be used on enums";
cx.syn_error(meta.error(msg));
}
syn::Data::Union(_) => {
let msg = "#[serde(rename_all_fields)] can only be used on enums";
cx.syn_error(meta.error(msg));
}
}
} else if meta.path == TRANSPARENT {
// #[serde(transparent)]
transparent.set_true(meta.path);
@@ -353,21 +350,21 @@ impl Container {
if let Some(path) = parse_lit_into_expr_path(cx, DEFAULT, &meta)? {
match &item.data {
syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields {
syn::Fields::Named(_) => {
syn::Fields::Named(_) | syn::Fields::Unnamed(_) => {
default.set(&meta.path, Default::Path(path));
}
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
let msg = "#[serde(default = \"...\")] can only be used on structs with named fields";
cx.error_spanned_by(fields, msg);
syn::Fields::Unit => {
let msg = "#[serde(default = \"...\")] can only be used on structs that have fields";
cx.syn_error(meta.error(msg));
}
},
syn::Data::Enum(syn::DataEnum { enum_token, .. }) => {
let msg = "#[serde(default = \"...\")] can only be used on structs with named fields";
cx.error_spanned_by(enum_token, msg);
syn::Data::Enum(_) => {
let msg = "#[serde(default = \"...\")] can only be used on structs";
cx.syn_error(meta.error(msg));
}
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
let msg = "#[serde(default = \"...\")] can only be used on structs with named fields";
cx.error_spanned_by(union_token, msg);
syn::Data::Union(_) => {
let msg = "#[serde(default = \"...\")] can only be used on structs";
cx.syn_error(meta.error(msg));
}
}
}
@@ -375,21 +372,21 @@ impl Container {
// #[serde(default)]
match &item.data {
syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields {
syn::Fields::Named(_) => {
syn::Fields::Named(_) | syn::Fields::Unnamed(_) => {
default.set(meta.path, Default::Default);
}
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
let msg = "#[serde(default)] can only be used on structs with named fields";
syn::Fields::Unit => {
let msg = "#[serde(default)] can only be used on structs that have fields";
cx.error_spanned_by(fields, msg);
}
},
syn::Data::Enum(syn::DataEnum { enum_token, .. }) => {
let msg = "#[serde(default)] can only be used on structs with named fields";
cx.error_spanned_by(enum_token, msg);
syn::Data::Enum(_) => {
let msg = "#[serde(default)] can only be used on structs";
cx.syn_error(meta.error(msg));
}
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
let msg = "#[serde(default)] can only be used on structs with named fields";
cx.error_spanned_by(union_token, msg);
syn::Data::Union(_) => {
let msg = "#[serde(default)] can only be used on structs";
cx.syn_error(meta.error(msg));
}
}
}
@@ -405,13 +402,13 @@ impl Container {
syn::Data::Enum(_) => {
untagged.set_true(&meta.path);
}
syn::Data::Struct(syn::DataStruct { struct_token, .. }) => {
syn::Data::Struct(_) => {
let msg = "#[serde(untagged)] can only be used on enums";
cx.error_spanned_by(struct_token, msg);
cx.syn_error(meta.error(msg));
}
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
syn::Data::Union(_) => {
let msg = "#[serde(untagged)] can only be used on enums";
cx.error_spanned_by(union_token, msg);
cx.syn_error(meta.error(msg));
}
}
} else if meta.path == TAG {
@@ -427,12 +424,12 @@ impl Container {
}
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
let msg = "#[serde(tag = \"...\")] can only be used on enums and structs with named fields";
cx.error_spanned_by(fields, msg);
cx.syn_error(meta.error(msg));
}
},
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
syn::Data::Union(_) => {
let msg = "#[serde(tag = \"...\")] can only be used on enums and structs with named fields";
cx.error_spanned_by(union_token, msg);
cx.syn_error(meta.error(msg));
}
}
}
@@ -443,13 +440,13 @@ impl Container {
syn::Data::Enum(_) => {
content.set(&meta.path, s.value());
}
syn::Data::Struct(syn::DataStruct { struct_token, .. }) => {
syn::Data::Struct(_) => {
let msg = "#[serde(content = \"...\")] can only be used on enums";
cx.error_spanned_by(struct_token, msg);
cx.syn_error(meta.error(msg));
}
syn::Data::Union(syn::DataUnion { union_token, .. }) => {
syn::Data::Union(_) => {
let msg = "#[serde(content = \"...\")] can only be used on enums";
cx.error_spanned_by(union_token, msg);
cx.syn_error(meta.error(msg));
}
}
}
@@ -520,7 +517,7 @@ impl Container {
}
Container {
name: Name::from_attrs(unraw(&item.ident), ser_name, de_name, None),
name: MultiName::from_attrs(Name::from(&unraw(&item.ident)), ser_name, de_name, None),
transparent: transparent.get(),
deny_unknown_fields: deny_unknown_fields.get(),
default: default.get().unwrap_or(Default::None),
@@ -528,6 +525,10 @@ impl Container {
serialize: rename_all_ser_rule.get().unwrap_or(RenameRule::None),
deserialize: rename_all_de_rule.get().unwrap_or(RenameRule::None),
},
rename_all_fields_rules: RenameAllRules {
serialize: rename_all_fields_ser_rule.get().unwrap_or(RenameRule::None),
deserialize: rename_all_fields_de_rule.get().unwrap_or(RenameRule::None),
},
ser_bound: ser_bound.get(),
de_bound: de_bound.get(),
tag: decide_tag(cx, item, untagged, internal_tag, content),
@@ -536,19 +537,23 @@ impl Container {
type_into: type_into.get(),
remote: remote.get(),
identifier: decide_identifier(cx, item, field_identifier, variant_identifier),
has_flatten: false,
serde_path: serde_path.get(),
is_packed,
expecting: expecting.get(),
non_exhaustive,
}
}
pub fn name(&self) -> &Name {
pub fn name(&self) -> &MultiName {
&self.name
}
pub fn rename_all_rules(&self) -> &RenameAllRules {
&self.rename_all_rules
pub fn rename_all_rules(&self) -> RenameAllRules {
self.rename_all_rules
}
pub fn rename_all_fields_rules(&self) -> RenameAllRules {
self.rename_all_fields_rules
}
pub fn transparent(&self) -> bool {
@@ -599,28 +604,19 @@ impl Container {
self.identifier
}
pub fn has_flatten(&self) -> bool {
self.has_flatten
}
pub fn mark_has_flatten(&mut self) {
self.has_flatten = true;
}
pub fn custom_serde_path(&self) -> Option<&syn::Path> {
self.serde_path.as_ref()
}
pub fn serde_path(&self) -> Cow<syn::Path> {
self.custom_serde_path()
.map_or_else(|| Cow::Owned(parse_quote!(_serde)), Cow::Borrowed)
}
/// Error message generated when type can't be deserialized.
/// If `None`, default message will be used
pub fn expecting(&self) -> Option<&str> {
self.expecting.as_ref().map(String::as_ref)
}
pub fn non_exhaustive(&self) -> bool {
self.non_exhaustive
}
}
fn decide_tag(
@@ -656,7 +652,7 @@ fn decide_tag(
}
TagType::Internal { tag }
}
(Some((untagged_tokens, _)), Some((tag_tokens, _)), None) => {
(Some((untagged_tokens, ())), Some((tag_tokens, _)), None) => {
let msg = "enum cannot be both untagged and internally tagged";
cx.error_spanned_by(untagged_tokens, msg);
cx.error_spanned_by(tag_tokens, msg);
@@ -667,14 +663,14 @@ fn decide_tag(
cx.error_spanned_by(content_tokens, msg);
TagType::External
}
(Some((untagged_tokens, _)), None, Some((content_tokens, _))) => {
(Some((untagged_tokens, ())), None, Some((content_tokens, _))) => {
let msg = "untagged enum cannot have #[serde(content = \"...\")]";
cx.error_spanned_by(untagged_tokens, msg);
cx.error_spanned_by(content_tokens, msg);
TagType::External
}
(None, Some((_, tag)), Some((_, content))) => TagType::Adjacent { tag, content },
(Some((untagged_tokens, _)), Some((tag_tokens, _)), Some((content_tokens, _))) => {
(Some((untagged_tokens, ())), Some((tag_tokens, _)), Some((content_tokens, _))) => {
let msg = "untagged enum cannot have #[serde(tag = \"...\", content = \"...\")]";
cx.error_spanned_by(untagged_tokens, msg);
cx.error_spanned_by(tag_tokens, msg);
@@ -696,7 +692,7 @@ fn decide_identifier(
variant_identifier.0.get_with_tokens(),
) {
(_, None, None) => Identifier::No,
(_, Some((field_identifier_tokens, _)), Some((variant_identifier_tokens, _))) => {
(_, Some((field_identifier_tokens, ())), Some((variant_identifier_tokens, ()))) => {
let msg =
"#[serde(field_identifier)] and #[serde(variant_identifier)] cannot both be set";
cx.error_spanned_by(field_identifier_tokens, msg);
@@ -730,7 +726,7 @@ fn decide_identifier(
/// Represents variant attribute information
pub struct Variant {
name: Name,
name: MultiName,
rename_all_rules: RenameAllRules,
ser_bound: Option<Vec<syn::WherePredicate>>,
de_bound: Option<Vec<syn::WherePredicate>>,
@@ -781,15 +777,15 @@ impl Variant {
// #[serde(rename = "foo")]
// #[serde(rename(serialize = "foo", deserialize = "bar"))]
let (ser, de) = get_multiple_renames(cx, &meta)?;
ser_name.set_opt(&meta.path, ser.as_ref().map(syn::LitStr::value));
ser_name.set_opt(&meta.path, ser.as_ref().map(Name::from));
for de_value in de {
de_name.set_if_none(de_value.value());
de_aliases.insert(&meta.path, de_value.value());
de_name.set_if_none(Name::from(&de_value));
de_aliases.insert(&meta.path, Name::from(&de_value));
}
} else if meta.path == ALIAS {
// #[serde(alias = "foo")]
if let Some(s) = get_lit_str(cx, ALIAS, &meta)? {
de_aliases.insert(&meta.path, s.value());
de_aliases.insert(&meta.path, Name::from(&s));
}
} else if meta.path == RENAME_ALL {
// #[serde(rename_all = "foo")]
@@ -838,13 +834,13 @@ impl Variant {
ser_path
.path
.segments
.push(Ident::new("serialize", Span::call_site()).into());
.push(Ident::new("serialize", ser_path.span()).into());
serialize_with.set(&meta.path, ser_path);
let mut de_path = path;
de_path
.path
.segments
.push(Ident::new("deserialize", Span::call_site()).into());
.push(Ident::new("deserialize", de_path.span()).into());
deserialize_with.set(&meta.path, de_path);
}
} else if meta.path == SERIALIZE_WITH {
@@ -896,7 +892,12 @@ impl Variant {
}
Variant {
name: Name::from_attrs(unraw(&variant.ident), ser_name, de_name, Some(de_aliases)),
name: MultiName::from_attrs(
Name::from(&unraw(&variant.ident)),
ser_name,
de_name,
Some(de_aliases),
),
rename_all_rules: RenameAllRules {
serialize: rename_all_ser_rule.get().unwrap_or(RenameRule::None),
deserialize: rename_all_de_rule.get().unwrap_or(RenameRule::None),
@@ -913,25 +914,31 @@ impl Variant {
}
}
pub fn name(&self) -> &Name {
pub fn name(&self) -> &MultiName {
&self.name
}
pub fn aliases(&self) -> Vec<String> {
pub fn aliases(&self) -> &BTreeSet<Name> {
self.name.deserialize_aliases()
}
pub fn rename_by_rules(&mut self, rules: &RenameAllRules) {
pub fn rename_by_rules(&mut self, rules: RenameAllRules) {
if !self.name.serialize_renamed {
self.name.serialize = rules.serialize.apply_to_variant(&self.name.serialize);
self.name.serialize.value =
rules.serialize.apply_to_variant(&self.name.serialize.value);
}
if !self.name.deserialize_renamed {
self.name.deserialize = rules.deserialize.apply_to_variant(&self.name.deserialize);
self.name.deserialize.value = rules
.deserialize
.apply_to_variant(&self.name.deserialize.value);
}
self.name
.deserialize_aliases
.insert(self.name.deserialize.clone());
}
pub fn rename_all_rules(&self) -> &RenameAllRules {
&self.rename_all_rules
pub fn rename_all_rules(&self) -> RenameAllRules {
self.rename_all_rules
}
pub fn ser_bound(&self) -> Option<&[syn::WherePredicate]> {
@@ -969,7 +976,7 @@ impl Variant {
/// Represents field attribute information
pub struct Field {
name: Name,
name: MultiName,
skip_serializing: bool,
skip_deserializing: bool,
skip_serializing_if: Option<syn::ExprPath>,
@@ -1011,6 +1018,7 @@ impl Field {
field: &syn::Field,
attrs: Option<&Variant>,
container_default: &Default,
private: &Ident,
) -> Self {
let mut ser_name = Attr::none(cx, RENAME);
let mut de_name = Attr::none(cx, RENAME);
@@ -1028,8 +1036,11 @@ impl Field {
let mut flatten = BoolAttr::none(cx, FLATTEN);
let ident = match &field.ident {
Some(ident) => unraw(ident),
None => index.to_string(),
Some(ident) => Name::from(&unraw(ident)),
None => Name {
value: index.to_string(),
span: Span::call_site(),
},
};
if let Some(borrow_attribute) = attrs.and_then(|variant| variant.borrow.as_ref()) {
@@ -1065,15 +1076,15 @@ impl Field {
// #[serde(rename = "foo")]
// #[serde(rename(serialize = "foo", deserialize = "bar"))]
let (ser, de) = get_multiple_renames(cx, &meta)?;
ser_name.set_opt(&meta.path, ser.as_ref().map(syn::LitStr::value));
ser_name.set_opt(&meta.path, ser.as_ref().map(Name::from));
for de_value in de {
de_name.set_if_none(de_value.value());
de_aliases.insert(&meta.path, de_value.value());
de_name.set_if_none(Name::from(&de_value));
de_aliases.insert(&meta.path, Name::from(&de_value));
}
} else if meta.path == ALIAS {
// #[serde(alias = "foo")]
if let Some(s) = get_lit_str(cx, ALIAS, &meta)? {
de_aliases.insert(&meta.path, s.value());
de_aliases.insert(&meta.path, Name::from(&s));
}
} else if meta.path == DEFAULT {
if meta.input.peek(Token![=]) {
@@ -1117,13 +1128,13 @@ impl Field {
ser_path
.path
.segments
.push(Ident::new("serialize", Span::call_site()).into());
.push(Ident::new("serialize", ser_path.span()).into());
serialize_with.set(&meta.path, ser_path);
let mut de_path = path;
de_path
.path
.segments
.push(Ident::new("deserialize", Span::call_site()).into());
.push(Ident::new("deserialize", de_path.span()).into());
deserialize_with.set(&meta.path, de_path);
}
} else if meta.path == BOUND {
@@ -1201,7 +1212,7 @@ impl Field {
};
let span = Span::call_site();
path.segments.push(Ident::new("_serde", span).into());
path.segments.push(Ident::new("__private", span).into());
path.segments.push(private.clone().into());
path.segments.push(Ident::new("de", span).into());
path.segments
.push(Ident::new("borrow_cow_str", span).into());
@@ -1218,7 +1229,7 @@ impl Field {
};
let span = Span::call_site();
path.segments.push(Ident::new("_serde", span).into());
path.segments.push(Ident::new("__private", span).into());
path.segments.push(private.clone().into());
path.segments.push(Ident::new("de", span).into());
path.segments
.push(Ident::new("borrow_cow_bytes", span).into());
@@ -1236,7 +1247,7 @@ impl Field {
}
Field {
name: Name::from_attrs(ident, ser_name, de_name, Some(de_aliases)),
name: MultiName::from_attrs(ident, ser_name, de_name, Some(de_aliases)),
skip_serializing: skip_serializing.get(),
skip_deserializing: skip_deserializing.get(),
skip_serializing_if: skip_serializing_if.get(),
@@ -1252,21 +1263,26 @@ impl Field {
}
}
pub fn name(&self) -> &Name {
pub fn name(&self) -> &MultiName {
&self.name
}
pub fn aliases(&self) -> Vec<String> {
pub fn aliases(&self) -> &BTreeSet<Name> {
self.name.deserialize_aliases()
}
pub fn rename_by_rules(&mut self, rules: &RenameAllRules) {
pub fn rename_by_rules(&mut self, rules: RenameAllRules) {
if !self.name.serialize_renamed {
self.name.serialize = rules.serialize.apply_to_field(&self.name.serialize);
self.name.serialize.value = rules.serialize.apply_to_field(&self.name.serialize.value);
}
if !self.name.deserialize_renamed {
self.name.deserialize = rules.deserialize.apply_to_field(&self.name.deserialize);
self.name.deserialize.value = rules
.deserialize
.apply_to_field(&self.name.deserialize.value);
}
self.name
.deserialize_aliases
.insert(self.name.deserialize.clone());
}
pub fn skip_serializing(&self) -> bool {
@@ -1712,7 +1728,7 @@ fn is_primitive_path(path: &syn::Path, primitive: &str) -> bool {
// attribute on the field so there must be at least one borrowable lifetime.
fn borrowable_lifetimes(
cx: &Ctxt,
name: &str,
name: &Name,
field: &syn::Field,
) -> Result<BTreeSet<syn::Lifetime>, ()> {
let mut lifetimes = BTreeSet::new();
@@ -1728,6 +1744,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);
}
@@ -1763,7 +1780,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(_)
| _ => {}
}
}
}
@@ -1785,7 +1805,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))]
_ => {}
}
}
+13 -10
View File
@@ -1,13 +1,8 @@
//! Code to convert the Rust-styled field/variant (e.g. `my_field`, `MyType`) to the
//! case of the source (e.g. `my-field`, `MY_FIELD`).
// See https://users.rust-lang.org/t/psa-dealing-with-warning-unused-import-std-ascii-asciiext-in-today-s-nightly/13726
#[allow(deprecated, unused_imports)]
use std::ascii::AsciiExt;
use std::fmt::{self, Debug, Display};
use self::RenameRule::*;
use std::fmt::{self, Debug, Display};
/// The different possible ways to change case of fields in a struct, or variants in an enum.
#[derive(Copy, Clone, PartialEq)]
@@ -59,8 +54,8 @@ impl RenameRule {
}
/// Apply a renaming rule to an enum variant, returning the version expected in the source.
pub fn apply_to_variant(&self, variant: &str) -> String {
match *self {
pub fn apply_to_variant(self, variant: &str) -> String {
match self {
None | PascalCase => variant.to_owned(),
LowerCase => variant.to_ascii_lowercase(),
UpperCase => variant.to_ascii_uppercase(),
@@ -84,8 +79,8 @@ impl RenameRule {
}
/// Apply a renaming rule to a struct field, returning the version expected in the source.
pub fn apply_to_field(&self, field: &str) -> String {
match *self {
pub fn apply_to_field(self, field: &str) -> String {
match self {
None | LowerCase | SnakeCase => field.to_owned(),
UpperCase => field.to_ascii_uppercase(),
PascalCase => {
@@ -112,6 +107,14 @@ impl RenameRule {
ScreamingKebabCase => ScreamingSnakeCase.apply_to_field(field).replace('_', "-"),
}
}
/// Returns the `RenameRule` if it is not `None`, `rule_b` otherwise.
pub fn or(self, rule_b: Self) -> Self {
match self {
None => rule_b,
_ => self,
}
}
}
pub struct ParseError<'a> {
+46 -7
View File
@@ -1,11 +1,12 @@
use internals::ast::{Container, Data, Field, Style};
use internals::attr::{Identifier, TagType};
use internals::{ungroup, Ctxt, Derive};
use crate::internals::ast::{Container, Data, Field, Style};
use crate::internals::attr::{Default, Identifier, TagType};
use crate::internals::{ungroup, Ctxt, Derive};
use syn::{Member, Type};
// Cross-cutting checks that require looking at more than a single attrs object.
// Simpler checks should happen when parsing and building the attrs.
pub fn check(cx: &Ctxt, cont: &mut Container, derive: Derive) {
check_default_on_tuple(cx, cont);
check_remote_generic(cx, cont);
check_getter(cx, cont);
check_flatten(cx, cont);
@@ -17,6 +18,39 @@ pub fn check(cx: &Ctxt, cont: &mut Container, derive: Derive) {
check_from_and_try_from(cx, cont);
}
// If some field of a tuple struct is marked #[serde(default)] then all fields
// after it must also be marked with that attribute, or the struct must have a
// container-level serde(default) attribute. A field's default value is only
// used for tuple fields if the sequence is exhausted at that point; that means
// all subsequent fields will fail to deserialize if they don't have their own
// default.
fn check_default_on_tuple(cx: &Ctxt, cont: &Container) {
if let Default::None = cont.attrs.default() {
if let Data::Struct(Style::Tuple, fields) = &cont.data {
let mut first_default_index = None;
for (i, field) in fields.iter().enumerate() {
// Skipped fields automatically get the #[serde(default)]
// attribute. We are interested only on non-skipped fields here.
if field.attrs.skip_deserializing() {
continue;
}
if let Default::None = field.attrs.default() {
if let Some(first) = first_default_index {
cx.error_spanned_by(
field.ty,
format!("field must have #[serde(default)] because previous field {} has #[serde(default)]", first),
);
}
continue;
}
if first_default_index.is_none() {
first_default_index = Some(i);
}
}
}
}
}
// Remote derive definition type must have either all of the generics of the
// remote type:
//
@@ -284,19 +318,24 @@ 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();
let check_de = !field.attrs.skip_deserializing();
let check_ser =
!(field.attrs.skip_serializing() || variant.attrs.skip_serializing());
let check_de =
!(field.attrs.skip_deserializing() || variant.attrs.skip_deserializing());
let name = field.attrs.name();
let ser_name = name.serialize_name();
if check_ser && ser_name == tag {
if check_ser && ser_name.value == tag {
diagnose_conflict();
return;
}
for de_name in field.attrs.aliases() {
if check_de && de_name == tag {
if check_de && de_name.value == tag {
diagnose_conflict();
return;
}
-1
View File
@@ -2,7 +2,6 @@ use quote::ToTokens;
use std::cell::RefCell;
use std::fmt::Display;
use std::thread;
use syn;
/// A type to collect errors together and format them.
///
+6 -6
View File
@@ -1,19 +1,19 @@
pub mod ast;
pub mod attr;
mod ctxt;
pub use self::ctxt::Ctxt;
mod receiver;
pub use self::receiver::replace_receiver;
pub mod name;
mod case;
mod check;
mod ctxt;
mod receiver;
mod respan;
mod symbol;
use syn::Type;
pub use self::ctxt::Ctxt;
pub use self::receiver::replace_receiver;
#[derive(Copy, Clone)]
pub enum Derive {
Serialize,
+113
View File
@@ -0,0 +1,113 @@
use crate::internals::attr::{Attr, VecAttr};
use proc_macro2::{Ident, Span, TokenStream};
use quote::ToTokens;
use std::cmp::Ordering;
use std::collections::BTreeSet;
use std::fmt::{self, Display};
use syn::LitStr;
pub struct MultiName {
pub(crate) serialize: Name,
pub(crate) serialize_renamed: bool,
pub(crate) deserialize: Name,
pub(crate) deserialize_renamed: bool,
pub(crate) deserialize_aliases: BTreeSet<Name>,
}
impl MultiName {
pub(crate) fn from_attrs(
source_name: Name,
ser_name: Attr<Name>,
de_name: Attr<Name>,
de_aliases: Option<VecAttr<Name>>,
) -> Self {
let mut alias_set = BTreeSet::new();
if let Some(de_aliases) = de_aliases {
for alias_name in de_aliases.get() {
alias_set.insert(alias_name);
}
}
let ser_name = ser_name.get();
let ser_renamed = ser_name.is_some();
let de_name = de_name.get();
let de_renamed = de_name.is_some();
MultiName {
serialize: ser_name.unwrap_or_else(|| source_name.clone()),
serialize_renamed: ser_renamed,
deserialize: de_name.unwrap_or(source_name),
deserialize_renamed: de_renamed,
deserialize_aliases: alias_set,
}
}
/// Return the container name for the container when serializing.
pub fn serialize_name(&self) -> &Name {
&self.serialize
}
/// Return the container name for the container when deserializing.
pub fn deserialize_name(&self) -> &Name {
&self.deserialize
}
pub(crate) fn deserialize_aliases(&self) -> &BTreeSet<Name> {
&self.deserialize_aliases
}
}
#[derive(Clone)]
pub struct Name {
pub value: String,
pub span: Span,
}
impl ToTokens for Name {
fn to_tokens(&self, tokens: &mut TokenStream) {
LitStr::new(&self.value, self.span).to_tokens(tokens);
}
}
impl Ord for Name {
fn cmp(&self, other: &Self) -> Ordering {
Ord::cmp(&self.value, &other.value)
}
}
impl PartialOrd for Name {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(Ord::cmp(self, other))
}
}
impl Eq for Name {}
impl PartialEq for Name {
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}
impl From<&Ident> for Name {
fn from(ident: &Ident) -> Self {
Name {
value: ident.to_string(),
span: ident.span(),
}
}
}
impl From<&LitStr> for Name {
fn from(lit: &LitStr) -> Self {
Name {
value: lit.value(),
span: lit.span(),
}
}
}
impl Display for Name {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Display::fmt(&self.value, formatter)
}
}
+11 -10
View File
@@ -1,11 +1,10 @@
use internals::respan::respan;
use crate::internals::respan::respan;
use proc_macro2::Span;
use quote::ToTokens;
use std::mem;
use syn::punctuated::Punctuated;
use syn::{
parse_quote, Data, DeriveInput, Expr, ExprPath, GenericArgument, GenericParam, Generics, Macro,
Path, PathArguments, QSelf, ReturnType, Type, TypeParamBound, TypePath, WherePredicate,
Path, PathArguments, QSelf, ReturnType, Token, Type, TypeParamBound, TypePath, WherePredicate,
};
pub fn replace_receiver(input: &mut DeriveInput) {
@@ -49,7 +48,7 @@ impl ReplaceReceiver<'_> {
path.leading_colon = Some(**path.segments.pairs().next().unwrap().punct().unwrap());
let segments = mem::replace(&mut path.segments, Punctuated::new());
let segments = mem::take(&mut path.segments);
path.segments = segments.into_pairs().skip(1).collect();
}
@@ -84,7 +83,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 +106,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 +147,6 @@ impl ReplaceReceiver<'_> {
Type::Infer(_) | Type::Never(_) | Type::Verbatim(_) => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => {}
}
}
@@ -178,13 +177,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 +206,11 @@ 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))]
TypeParamBound::Lifetime(_)
| TypeParamBound::PreciseCapture(_)
| TypeParamBound::Verbatim(_) => {}
_ => {}
}
}
@@ -228,6 +229,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 +237,6 @@ impl ReplaceReceiver<'_> {
}
}
WherePredicate::Lifetime(_) => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => {}
}
}
+4 -2
View File
@@ -19,10 +19,12 @@ pub const FLATTEN: Symbol = Symbol("flatten");
pub const FROM: Symbol = Symbol("from");
pub const GETTER: Symbol = Symbol("getter");
pub const INTO: Symbol = Symbol("into");
pub const NON_EXHAUSTIVE: Symbol = Symbol("non_exhaustive");
pub const OTHER: Symbol = Symbol("other");
pub const REMOTE: Symbol = Symbol("remote");
pub const RENAME: Symbol = Symbol("rename");
pub const RENAME_ALL: Symbol = Symbol("rename_all");
pub const RENAME_ALL_FIELDS: Symbol = Symbol("rename_all_fields");
pub const REPR: Symbol = Symbol("repr");
pub const SERDE: Symbol = Symbol("serde");
pub const SERIALIZE: Symbol = Symbol("serialize");
@@ -44,7 +46,7 @@ impl PartialEq<Symbol> for Ident {
}
}
impl<'a> PartialEq<Symbol> for &'a Ident {
impl PartialEq<Symbol> for &Ident {
fn eq(&self, word: &Symbol) -> bool {
*self == word.0
}
@@ -56,7 +58,7 @@ impl PartialEq<Symbol> for Path {
}
}
impl<'a> PartialEq<Symbol> for &'a Path {
impl PartialEq<Symbol> for &Path {
fn eq(&self, word: &Symbol) -> bool {
self.is_ident(word.0)
}
+29 -7
View File
@@ -13,8 +13,8 @@
//!
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.170")]
#![allow(unknown_lints, bare_trait_objects)]
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.226")]
#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
// Ignored clippy lints
#![allow(
// clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7054
@@ -27,6 +27,7 @@
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6797
clippy::manual_map,
clippy::match_like_matches_macro,
clippy::needless_lifetimes,
clippy::needless_pass_by_value,
clippy::too_many_arguments,
clippy::trivially_copy_pass_by_ref,
@@ -40,6 +41,7 @@
clippy::cast_possible_truncation,
clippy::checked_conversions,
clippy::doc_markdown,
clippy::elidable_lifetime_names,
clippy::enum_glob_use,
clippy::indexing_slicing,
clippy::items_after_statements,
@@ -51,29 +53,31 @@
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,
clippy::too_many_lines,
clippy::uninlined_format_args,
clippy::unseparated_literal_suffix,
clippy::unused_self,
clippy::use_self,
clippy::wildcard_imports
)]
#![cfg_attr(all(test, exhaustive), feature(non_exhaustive_omitted_patterns_lint))]
#![allow(unknown_lints, mismatched_lifetime_syntaxes)]
#[macro_use]
extern crate proc_macro2;
extern crate quote;
#[macro_use]
extern crate syn;
extern crate proc_macro;
extern crate proc_macro2;
mod internals;
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span};
use quote::{ToTokens, TokenStreamExt as _};
use syn::parse_macro_input;
use syn::DeriveInput;
#[macro_use]
@@ -82,11 +86,29 @@ mod bound;
mod fragment;
mod de;
mod deprecated;
mod dummy;
mod pretend;
mod ser;
mod this;
mod try;
#[allow(non_camel_case_types)]
struct private;
impl private {
fn ident(&self) -> Ident {
Ident::new(
concat!("__private", env!("CARGO_PKG_VERSION_PATCH")),
Span::call_site(),
)
}
}
impl ToTokens for private {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
tokens.append(self.ident());
}
}
#[proc_macro_derive(Serialize, attributes(serde))]
pub fn derive_serialize(input: TokenStream) -> TokenStream {
+18 -16
View File
@@ -1,7 +1,7 @@
use crate::internals::ast::{Container, Data, Field, Style, Variant};
use crate::private;
use proc_macro2::TokenStream;
use quote::format_ident;
use internals::ast::{Container, Data, Field, Style, Variant};
use quote::{format_ident, quote};
// Suppress dead_code warnings that would otherwise appear when using a remote
// derive. Other than this pretend code, a struct annotated with remote derive
@@ -65,14 +65,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!(),
}
}
@@ -84,8 +84,8 @@ fn pretend_fields_used_struct(cont: &Container, fields: &[Field]) -> TokenStream
let placeholders = (0usize..).map(|i| format_ident!("__v{}", i));
quote! {
match _serde::__private::None::<&#type_ident #ty_generics> {
_serde::__private::Some(#type_ident { #(#members: #placeholders),* }) => {}
match _serde::#private::None::<&#type_ident #ty_generics> {
_serde::#private::Some(#type_ident { #(#members: #placeholders),* }) => {}
_ => {}
}
}
@@ -97,11 +97,12 @@ fn pretend_fields_used_struct_packed(cont: &Container, fields: &[Field]) -> Toke
let members = fields.iter().map(|field| &field.member).collect::<Vec<_>>();
let private2 = private;
quote! {
match _serde::__private::None::<&#type_ident #ty_generics> {
_serde::__private::Some(__v @ #type_ident { #(#members: _),* }) => {
match _serde::#private::None::<&#type_ident #ty_generics> {
_serde::#private::Some(__v @ #type_ident { #(#members: _),* }) => {
#(
let _ = _serde::__private::ptr::addr_of!(__v.#members);
let _ = _serde::#private2::ptr::addr_of!(__v.#members);
)*
}
_ => {}
@@ -116,20 +117,21 @@ 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<_>>();
let private2 = private;
quote! {
match _serde::__private::None::<&#type_ident #ty_generics> {
match _serde::#private::None::<&#type_ident #ty_generics> {
#(
_serde::__private::Some(#patterns) => {}
_serde::#private2::Some(#patterns) => {}
)*
_ => {}
}
@@ -173,8 +175,8 @@ fn pretend_variants_used(cont: &Container) -> TokenStream {
};
quote! {
match _serde::__private::None {
_serde::__private::Some((#(#placeholders,)*)) => {
match _serde::#private::None {
_serde::#private::Some((#(#placeholders,)*)) => {
let _ = #type_ident::#variant_ident #turbofish #pat;
}
_ => {}
+147 -119
View File
@@ -1,20 +1,19 @@
use crate::deprecated::allow_deprecated;
use crate::fragment::{Fragment, Match, Stmts};
use crate::internals::ast::{Container, Data, Field, Style, Variant};
use crate::internals::name::Name;
use crate::internals::{attr, replace_receiver, Ctxt, Derive};
use crate::{bound, dummy, pretend, private, this};
use proc_macro2::{Span, TokenStream};
use quote::{quote, quote_spanned};
use syn::spanned::Spanned;
use syn::{self, Ident, Index, Member};
use bound;
use dummy;
use fragment::{Fragment, Match, Stmts};
use internals::ast::{Container, Data, Field, Style, Variant};
use internals::{attr, replace_receiver, Ctxt, Derive};
use pretend;
use this;
use syn::{parse_quote, Ident, Index, Member};
pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
replace_receiver(input);
let ctxt = Ctxt::new();
let cont = match Container::from_ast(&ctxt, input, Derive::Serialize) {
let cont = match Container::from_ast(&ctxt, input, Derive::Serialize, &private.ident()) {
Some(cont) => cont,
None => return Err(ctxt.check().unwrap_err()),
};
@@ -25,16 +24,18 @@ pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<Toke
let params = Parameters::new(&cont);
let (impl_generics, ty_generics, where_clause) = params.generics.split_for_impl();
let body = Stmts(serialize_body(&cont, &params));
let serde = cont.attrs.serde_path();
let allow_deprecated = allow_deprecated(input);
let impl_block = if let Some(remote) = cont.attrs.remote() {
let vis = &input.vis;
let used = pretend::pretend_used(&cont, params.is_packed);
quote! {
#[automatically_derived]
#allow_deprecated
impl #impl_generics #ident #ty_generics #where_clause {
#vis fn serialize<__S>(__self: &#remote #ty_generics, __serializer: __S) -> #serde::__private::Result<__S::Ok, __S::Error>
#vis fn serialize<__S>(__self: &#remote #ty_generics, __serializer: __S) -> _serde::#private::Result<__S::Ok, __S::Error>
where
__S: #serde::Serializer,
__S: _serde::Serializer,
{
#used
#body
@@ -44,10 +45,11 @@ pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<Toke
} else {
quote! {
#[automatically_derived]
impl #impl_generics #serde::Serialize for #ident #ty_generics #where_clause {
fn serialize<__S>(&self, __serializer: __S) -> #serde::__private::Result<__S::Ok, __S::Error>
#allow_deprecated
impl #impl_generics _serde::Serialize for #ident #ty_generics #where_clause {
fn serialize<__S>(&self, __serializer: __S) -> _serde::#private::Result<__S::Ok, __S::Error>
where
__S: #serde::Serializer,
__S: _serde::Serializer,
{
#body
}
@@ -151,7 +153,7 @@ fn build_generics(cont: &Container) -> syn::Generics {
}
// Fields with a `skip_serializing` or `serialize_with` attribute, or which
// belong to a variant with a 'skip_serializing` or `serialize_with` attribute,
// belong to a variant with a `skip_serializing` or `serialize_with` attribute,
// are not serialized by us so we do not generate a bound. Fields with a `bound`
// attribute specify their own bound so we do not generate one. All other fields
// may need a `T: Serialize` bound where T is the type of the field.
@@ -213,7 +215,7 @@ fn serialize_into(params: &Parameters, type_into: &syn::Type) -> Fragment {
let self_var = &params.self_var;
quote_block! {
_serde::Serialize::serialize(
&_serde::__private::Into::<#type_into>::into(_serde::__private::Clone::clone(#self_var)),
&_serde::#private::Into::<#type_into>::into(_serde::#private::Clone::clone(#self_var)),
__serializer)
}
}
@@ -285,16 +287,25 @@ fn serialize_tuple_struct(
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_tuple_struct(__serializer, #type_name, #len));
let #let_mut __serde_state = _serde::Serializer::serialize_tuple_struct(__serializer, #type_name, #len)?;
#(#serialize_stmts)*
_serde::ser::SerializeTupleStruct::end(__serde_state)
}
}
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),
"too many fields in {}: {}, maximum supported count is {}",
cattrs.name().serialize_name(),
fields.len(),
u32::MAX,
);
if cattrs.has_flatten() {
let has_non_skipped_flatten = fields
.iter()
.any(|field| field.attrs.flatten() && !field.attrs.skip_serializing());
if has_non_skipped_flatten {
serialize_struct_as_map(params, fields, cattrs)
} else {
serialize_struct_as_struct(params, fields, cattrs)
@@ -307,7 +318,7 @@ fn serialize_struct_tag_field(cattrs: &attr::Container, struct_trait: &StructTra
let type_name = cattrs.name().serialize_name();
let func = struct_trait.serialize_field(Span::call_site());
quote! {
try!(#func(&mut __serde_state, #tag, #type_name));
#func(&mut __serde_state, #tag, #type_name)?;
}
}
_ => quote! {},
@@ -348,7 +359,7 @@ fn serialize_struct_as_struct(
);
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len));
let #let_mut __serde_state = _serde::Serializer::serialize_struct(__serializer, #type_name, #len)?;
#tag_field
#(#serialize_fields)*
_serde::ser::SerializeStruct::end(__serde_state)
@@ -373,26 +384,8 @@ fn serialize_struct_as_map(
let let_mut = mut_if(serialized_fields.peek().is_some() || tag_field_exists);
let len = if cattrs.has_flatten() {
quote!(_serde::__private::None)
} else {
let len = serialized_fields
.map(|field| match field.attrs.skip_serializing_if() {
None => quote!(1),
Some(path) => {
let field_expr = get_member(params, field, &field.member);
quote!(if #path(#field_expr) { 0 } else { 1 })
}
})
.fold(
quote!(#tag_field_exists as usize),
|sum, expr| quote!(#sum + #expr),
);
quote!(_serde::__private::Some(#len))
};
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_map(__serializer, #len));
let #let_mut __serde_state = _serde::Serializer::serialize_map(__serializer, _serde::#private::None)?;
#tag_field
#(#serialize_fields)*
_serde::ser::SerializeMap::end(__serde_state)
@@ -400,11 +393,11 @@ 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;
let arms: Vec<_> = variants
let mut arms: Vec<_> = variants
.iter()
.enumerate()
.map(|(variant_index, variant)| {
@@ -412,6 +405,12 @@ fn serialize_enum(params: &Parameters, variants: &[Variant], cattrs: &attr::Cont
})
.collect();
if cattrs.remote().is_some() && cattrs.non_exhaustive() {
arms.push(quote! {
ref unrecognized => _serde::#private::Err(_serde::ser::Error::custom(_serde::#private::ser::CannotSerializeVariant(unrecognized))),
});
}
quote_expr! {
match *#self_var {
#(#arms)*
@@ -435,7 +434,7 @@ fn serialize_variant(
variant_ident
);
let skipped_err = quote! {
_serde::__private::Err(_serde::ser::Error::custom(#skipped_msg))
_serde::#private::Err(_serde::ser::Error::custom(#skipped_msg))
};
let fields_pat = match variant.style {
Style::Unit => quote!(),
@@ -481,7 +480,14 @@ fn serialize_variant(
serialize_internally_tagged_variant(params, variant, cattrs, tag)
}
(attr::TagType::Adjacent { tag, content }, false) => {
serialize_adjacently_tagged_variant(params, variant, cattrs, tag, content)
serialize_adjacently_tagged_variant(
params,
variant,
cattrs,
variant_index,
tag,
content,
)
}
(attr::TagType::None, _) | (_, true) => {
serialize_untagged_variant(params, variant, cattrs)
@@ -562,7 +568,7 @@ fn serialize_externally_tagged_variant(
},
params,
&variant.fields,
&type_name,
type_name,
),
}
}
@@ -582,7 +588,7 @@ fn serialize_internally_tagged_variant(
if let Some(path) = variant.attrs.serialize_with() {
let ser = wrap_serialize_variant_with(params, path, variant);
return quote_expr! {
_serde::__private::ser::serialize_tagged_newtype(
_serde::#private::ser::serialize_tagged_newtype(
__serializer,
#enum_ident_str,
#variant_ident_str,
@@ -596,10 +602,10 @@ fn serialize_internally_tagged_variant(
match effective_style(variant) {
Style::Unit => {
quote_block! {
let mut __struct = try!(_serde::Serializer::serialize_struct(
__serializer, #type_name, 1));
try!(_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #variant_name));
let mut __struct = _serde::Serializer::serialize_struct(
__serializer, #type_name, 1)?;
_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #variant_name)?;
_serde::ser::SerializeStruct::end(__struct)
}
}
@@ -611,7 +617,7 @@ fn serialize_internally_tagged_variant(
}
let span = field.original.span();
let func = quote_spanned!(span=> _serde::__private::ser::serialize_tagged_newtype);
let func = quote_spanned!(span=> _serde::#private::ser::serialize_tagged_newtype);
quote_expr! {
#func(
__serializer,
@@ -627,7 +633,7 @@ fn serialize_internally_tagged_variant(
StructVariant::InternallyTagged { tag, variant_name },
params,
&variant.fields,
&type_name,
type_name,
),
Style::Tuple => unreachable!("checked in serde_derive_internals"),
}
@@ -637,12 +643,20 @@ fn serialize_adjacently_tagged_variant(
params: &Parameters,
variant: &Variant,
cattrs: &attr::Container,
variant_index: u32,
tag: &str,
content: &str,
) -> Fragment {
let this_type = &params.this_type;
let type_name = cattrs.name().serialize_name();
let variant_name = variant.attrs.name().serialize_name();
let serialize_variant = quote! {
&_serde::#private::ser::AdjacentlyTaggedEnumVariant {
enum_name: #type_name,
variant_index: #variant_index,
variant_name: #variant_name,
}
};
let inner = Stmts(if let Some(path) = variant.attrs.serialize_with() {
let ser = wrap_serialize_variant_with(params, path, variant);
@@ -653,10 +667,10 @@ fn serialize_adjacently_tagged_variant(
match effective_style(variant) {
Style::Unit => {
return quote_block! {
let mut __struct = try!(_serde::Serializer::serialize_struct(
__serializer, #type_name, 1));
try!(_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #variant_name));
let mut __struct = _serde::Serializer::serialize_struct(
__serializer, #type_name, 1)?;
_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #serialize_variant)?;
_serde::ser::SerializeStruct::end(__struct)
};
}
@@ -670,12 +684,12 @@ fn serialize_adjacently_tagged_variant(
let span = field.original.span();
let func = quote_spanned!(span=> _serde::ser::SerializeStruct::serialize_field);
return quote_block! {
let mut __struct = try!(_serde::Serializer::serialize_struct(
__serializer, #type_name, 2));
try!(_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #variant_name));
try!(#func(
&mut __struct, #content, #field_expr));
let mut __struct = _serde::Serializer::serialize_struct(
__serializer, #type_name, 2)?;
_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #serialize_variant)?;
#func(
&mut __struct, #content, #field_expr)?;
_serde::ser::SerializeStruct::end(__struct)
};
}
@@ -686,13 +700,13 @@ fn serialize_adjacently_tagged_variant(
StructVariant::Untagged,
params,
&variant.fields,
&variant_name,
variant_name,
),
}
});
let fields_ty = variant.fields.iter().map(|f| &f.ty);
let fields_ident: &Vec<_> = &match variant.style {
let fields_ident: &[_] = &match variant.style {
Style::Unit => {
if variant.attrs.serialize_with().is_some() {
vec![]
@@ -720,11 +734,12 @@ fn serialize_adjacently_tagged_variant(
#[doc(hidden)]
struct __AdjacentlyTagged #wrapper_generics #where_clause {
data: (#(&'__a #fields_ty,)*),
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
phantom: _serde::#private::PhantomData<#this_type #ty_generics>,
}
#[automatically_derived]
impl #wrapper_impl_generics _serde::Serialize for __AdjacentlyTagged #wrapper_ty_generics #where_clause {
fn serialize<__S>(&self, __serializer: __S) -> _serde::__private::Result<__S::Ok, __S::Error>
fn serialize<__S>(&self, __serializer: __S) -> _serde::#private::Result<__S::Ok, __S::Error>
where
__S: _serde::Serializer,
{
@@ -735,15 +750,15 @@ fn serialize_adjacently_tagged_variant(
}
}
let mut __struct = try!(_serde::Serializer::serialize_struct(
__serializer, #type_name, 2));
try!(_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #variant_name));
try!(_serde::ser::SerializeStruct::serialize_field(
let mut __struct = _serde::Serializer::serialize_struct(
__serializer, #type_name, 2)?;
_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #tag, #serialize_variant)?;
_serde::ser::SerializeStruct::serialize_field(
&mut __struct, #content, &__AdjacentlyTagged {
data: (#(#fields_ident,)*),
phantom: _serde::__private::PhantomData::<#this_type #ty_generics>,
}));
phantom: _serde::#private::PhantomData::<#this_type #ty_generics>,
})?;
_serde::ser::SerializeStruct::end(__struct)
}
}
@@ -782,16 +797,16 @@ fn serialize_untagged_variant(
Style::Tuple => serialize_tuple_variant(TupleVariant::Untagged, params, &variant.fields),
Style::Struct => {
let type_name = cattrs.name().serialize_name();
serialize_struct_variant(StructVariant::Untagged, params, &variant.fields, &type_name)
serialize_struct_variant(StructVariant::Untagged, params, &variant.fields, type_name)
}
}
}
enum TupleVariant {
enum TupleVariant<'a> {
ExternallyTagged {
type_name: String,
type_name: &'a Name,
variant_index: u32,
variant_name: String,
variant_name: &'a Name,
},
Untagged,
}
@@ -833,21 +848,21 @@ fn serialize_tuple_variant(
variant_name,
} => {
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_tuple_variant(
let #let_mut __serde_state = _serde::Serializer::serialize_tuple_variant(
__serializer,
#type_name,
#variant_index,
#variant_name,
#len));
#len)?;
#(#serialize_stmts)*
_serde::ser::SerializeTupleVariant::end(__serde_state)
}
}
TupleVariant::Untagged => {
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_tuple(
let #let_mut __serde_state = _serde::Serializer::serialize_tuple(
__serializer,
#len));
#len)?;
#(#serialize_stmts)*
_serde::ser::SerializeTuple::end(__serde_state)
}
@@ -858,11 +873,11 @@ fn serialize_tuple_variant(
enum StructVariant<'a> {
ExternallyTagged {
variant_index: u32,
variant_name: String,
variant_name: &'a Name,
},
InternallyTagged {
tag: &'a str,
variant_name: String,
variant_name: &'a Name,
},
Untagged,
}
@@ -871,7 +886,7 @@ fn serialize_struct_variant(
context: StructVariant,
params: &Parameters,
fields: &[Field],
name: &str,
name: &Name,
) -> Fragment {
if fields.iter().any(|field| field.attrs.flatten()) {
return serialize_struct_variant_with_flatten(context, params, fields, name);
@@ -910,40 +925,40 @@ fn serialize_struct_variant(
variant_name,
} => {
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct_variant(
let #let_mut __serde_state = _serde::Serializer::serialize_struct_variant(
__serializer,
#name,
#variant_index,
#variant_name,
#len,
));
)?;
#(#serialize_fields)*
_serde::ser::SerializeStructVariant::end(__serde_state)
}
}
StructVariant::InternallyTagged { tag, variant_name } => {
quote_block! {
let mut __serde_state = try!(_serde::Serializer::serialize_struct(
let mut __serde_state = _serde::Serializer::serialize_struct(
__serializer,
#name,
#len + 1,
));
try!(_serde::ser::SerializeStruct::serialize_field(
)?;
_serde::ser::SerializeStruct::serialize_field(
&mut __serde_state,
#tag,
#variant_name,
));
)?;
#(#serialize_fields)*
_serde::ser::SerializeStruct::end(__serde_state)
}
}
StructVariant::Untagged => {
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(
let #let_mut __serde_state = _serde::Serializer::serialize_struct(
__serializer,
#name,
#len,
));
)?;
#(#serialize_fields)*
_serde::ser::SerializeStruct::end(__serde_state)
}
@@ -955,7 +970,7 @@ fn serialize_struct_variant_with_flatten(
context: StructVariant,
params: &Parameters,
fields: &[Field],
name: &str,
name: &Name,
) -> Fragment {
let struct_trait = StructTrait::SerializeMap;
let serialize_fields = serialize_struct_visitor(fields, params, true, &struct_trait);
@@ -984,18 +999,19 @@ fn serialize_struct_variant_with_flatten(
#[doc(hidden)]
struct __EnumFlatten #wrapper_generics #where_clause {
data: (#(&'__a #fields_ty,)*),
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
phantom: _serde::#private::PhantomData<#this_type #ty_generics>,
}
#[automatically_derived]
impl #wrapper_impl_generics _serde::Serialize for __EnumFlatten #wrapper_ty_generics #where_clause {
fn serialize<__S>(&self, __serializer: __S) -> _serde::__private::Result<__S::Ok, __S::Error>
fn serialize<__S>(&self, __serializer: __S) -> _serde::#private::Result<__S::Ok, __S::Error>
where
__S: _serde::Serializer,
{
let (#(#members,)*) = self.data;
let #let_mut __serde_state = try!(_serde::Serializer::serialize_map(
let #let_mut __serde_state = _serde::Serializer::serialize_map(
__serializer,
_serde::__private::None));
_serde::#private::None)?;
#(#serialize_fields)*
_serde::ser::SerializeMap::end(__serde_state)
}
@@ -1008,29 +1024,29 @@ fn serialize_struct_variant_with_flatten(
#variant_name,
&__EnumFlatten {
data: (#(#members,)*),
phantom: _serde::__private::PhantomData::<#this_type #ty_generics>,
phantom: _serde::#private::PhantomData::<#this_type #ty_generics>,
})
}
}
StructVariant::InternallyTagged { tag, variant_name } => {
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_map(
let #let_mut __serde_state = _serde::Serializer::serialize_map(
__serializer,
_serde::__private::None));
try!(_serde::ser::SerializeMap::serialize_entry(
_serde::#private::None)?;
_serde::ser::SerializeMap::serialize_entry(
&mut __serde_state,
#tag,
#variant_name,
));
)?;
#(#serialize_fields)*
_serde::ser::SerializeMap::end(__serde_state)
}
}
StructVariant::Untagged => {
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_map(
let #let_mut __serde_state = _serde::Serializer::serialize_map(
__serializer,
_serde::__private::None));
_serde::#private::None)?;
#(#serialize_fields)*
_serde::ser::SerializeMap::end(__serde_state)
}
@@ -1075,7 +1091,7 @@ fn serialize_tuple_struct_visitor(
let span = field.original.span();
let func = tuple_trait.serialize_element(span);
let ser = quote! {
try!(#func(&mut __serde_state, #field_expr));
#func(&mut __serde_state, #field_expr)?;
};
match skip {
@@ -1119,12 +1135,12 @@ fn serialize_struct_visitor(
let ser = if field.attrs.flatten() {
let func = quote_spanned!(span=> _serde::Serialize::serialize);
quote! {
try!(#func(&#field_expr, _serde::__private::ser::FlatMapSerializer(&mut __serde_state)));
#func(&#field_expr, _serde::#private::ser::FlatMapSerializer(&mut __serde_state))?;
}
} else {
let func = struct_trait.serialize_field(span);
quote! {
try!(#func(&mut __serde_state, #key_expr, #field_expr));
#func(&mut __serde_state, #key_expr, #field_expr)?;
}
};
@@ -1136,7 +1152,7 @@ fn serialize_struct_visitor(
if !#skip {
#ser
} else {
try!(#skip_func(&mut __serde_state, #key_expr));
#skip_func(&mut __serde_state, #key_expr)?;
}
}
} else {
@@ -1211,32 +1227,44 @@ fn wrap_serialize_with(
})
});
quote!({
let self_var = quote!(self);
let serializer_var = quote!(__s);
// If #serialize_with returns wrong type, error will be reported on here.
// We attach span of the path to this piece so error will be reported
// on the #[serde(with = "...")]
// ^^^^^
let wrapper_serialize = quote_spanned! {serialize_with.span()=>
#serialize_with(#(#self_var.values.#field_access, )* #serializer_var)
};
quote!(&{
#[doc(hidden)]
struct __SerializeWith #wrapper_impl_generics #where_clause {
values: (#(&'__a #field_tys, )*),
phantom: _serde::__private::PhantomData<#this_type #ty_generics>,
phantom: _serde::#private::PhantomData<#this_type #ty_generics>,
}
#[automatically_derived]
impl #wrapper_impl_generics _serde::Serialize for __SerializeWith #wrapper_ty_generics #where_clause {
fn serialize<__S>(&self, __s: __S) -> _serde::__private::Result<__S::Ok, __S::Error>
fn serialize<__S>(&#self_var, #serializer_var: __S) -> _serde::#private::Result<__S::Ok, __S::Error>
where
__S: _serde::Serializer,
{
#serialize_with(#(self.values.#field_access, )* __s)
#wrapper_serialize
}
}
&__SerializeWith {
__SerializeWith {
values: (#(#field_exprs, )*),
phantom: _serde::__private::PhantomData::<#this_type #ty_generics>,
phantom: _serde::#private::PhantomData::<#this_type #ty_generics>,
}
})
}
// Serialization of an empty struct results in code like:
//
// let mut __serde_state = try!(serializer.serialize_struct("S", 0));
// let mut __serde_state = serializer.serialize_struct("S", 0)?;
// _serde::ser::SerializeStruct::end(__serde_state)
//
// where we want to omit the `mut` to avoid a warning.
@@ -1265,11 +1293,11 @@ fn get_member(params: &Parameters, field: &Field, member: &Member) -> TokenStrea
quote!(&#self_var.#member)
};
let ty = field.ty;
quote!(_serde::__private::ser::constrain::<#ty>(#inner))
quote!(_serde::#private::ser::constrain::<#ty>(#inner))
}
(true, Some(getter)) => {
let ty = field.ty;
quote!(_serde::__private::ser::constrain::<#ty>(&#getter(#self_var)))
quote!(_serde::#private::ser::constrain::<#ty>(&#getter(#self_var)))
}
(false, Some(_)) => {
unreachable!("getter is only allowed for remote impls");
+1 -1
View File
@@ -1,4 +1,4 @@
use internals::ast::Container;
use crate::internals::ast::Container;
use syn::{Path, PathArguments, Token};
pub fn this_type(cont: &Container) -> Path {
-24
View File
@@ -1,24 +0,0 @@
use proc_macro2::{Punct, Spacing, TokenStream};
// None of our generated code requires the `From::from` error conversion
// performed by the standard library's `try!` macro. With this simplified macro
// we see a significant improvement in type checking and borrow checking time of
// the generated code and a slight improvement in binary size.
pub fn replacement() -> TokenStream {
// Cannot pass `$expr` to `quote!` prior to Rust 1.17.0 so interpolate it.
let dollar = Punct::new('$', Spacing::Alone);
quote! {
#[allow(unused_macros)]
macro_rules! try {
(#dollar __expr:expr) => {
match #dollar __expr {
_serde::__private::Ok(__val) => __val,
_serde::__private::Err(__err) => {
return _serde::__private::Err(__err);
}
}
}
}
}
}
+15 -6
View File
@@ -1,23 +1,32 @@
[package]
name = "serde_derive_internals"
version = "0.28.0" # remember to update html_root_url
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 = "2021"
exclude = ["build.rs"]
homepage = "https://serde.rs"
include = ["lib.rs", "src/**/*.rs", "LICENSE-APACHE", "LICENSE-MIT"]
keywords = ["serde", "serialization"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/serde-rs/serde"
rust-version = "1.56"
rust-version = "1.61"
[lib]
path = "lib.rs"
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "2.0.25", 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"]
rustdoc-args = [
"--generate-link-to-definition",
"--generate-macro-expansion",
"--extern-html-root-url=core=https://doc.rust-lang.org",
"--extern-html-root-url=alloc=https://doc.rust-lang.org",
"--extern-html-root-url=std=https://doc.rust-lang.org",
"--extern-html-root-url=proc_macro=https://doc.rust-lang.org",
]
+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
+8 -5
View File
@@ -1,5 +1,5 @@
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.28.0")]
#![allow(unknown_lints, bare_trait_objects)]
#![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,
@@ -9,6 +9,7 @@
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6797
clippy::manual_map,
clippy::missing_panics_doc,
clippy::needless_lifetimes,
clippy::redundant_field_names,
clippy::result_unit_err,
clippy::should_implement_trait,
@@ -20,6 +21,7 @@
// Ignored clippy_pedantic lints
#![allow(
clippy::doc_markdown,
clippy::elidable_lifetime_names,
clippy::enum_glob_use,
clippy::items_after_statements,
clippy::let_underscore_untyped,
@@ -30,19 +32,20 @@
clippy::missing_errors_doc,
clippy::module_name_repetitions,
clippy::must_use_candidate,
clippy::return_self_not_must_use,
clippy::similar_names,
clippy::single_match_else,
clippy::struct_excessive_bools,
clippy::too_many_lines,
clippy::uninlined_format_args,
clippy::unused_self,
clippy::wildcard_imports
)]
#[macro_use]
extern crate syn;
#![allow(unknown_lints, mismatched_lifetime_syntaxes)]
extern crate proc_macro2;
extern crate quote;
extern crate syn;
#[cfg_attr(serde_build_from_git, path = "../serde_derive/src/internals/mod.rs")]
#[cfg_attr(not(serde_build_from_git), path = "src/mod.rs")]
-28
View File
@@ -1,28 +0,0 @@
[package]
name = "serde_test"
version = "1.0.170" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
build = "build.rs"
categories = ["development-tools::testing"]
description = "Token De/Serializer for testing De/Serialize implementations"
documentation = "https://docs.rs/serde_test"
homepage = "https://serde.rs"
include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
keywords = ["serde", "serialization", "testing", "dev-dependencies"]
license = "MIT OR Apache-2.0"
readme = "crates-io.md"
repository = "https://github.com/serde-rs/serde"
rust-version = "1.19"
[dependencies]
serde = { version = "1.0.60", path = "../serde" }
[dev-dependencies]
serde = { version = "1.0", path = "../serde", features = ["rc"] }
serde_derive = { version = "1.0", path = "../serde_derive" }
[lib]
doc-scrape-examples = false
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
-1
View File
@@ -1 +0,0 @@
../README.md
-50
View File
@@ -1,50 +0,0 @@
use std::env;
use std::process::Command;
use std::str::{self, FromStr};
// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
// these cfgs other than by executing our build script.
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
};
// #[track_caller] stabilized in Rust 1.46:
// https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html#track_caller
if minor < 46 {
println!("cargo:rustc-cfg=no_track_caller");
}
}
fn rustc_minor_version() -> Option<u32> {
let rustc = match env::var_os("RUSTC") {
Some(rustc) => rustc,
None => return None,
};
let output = match Command::new(rustc).arg("--version").output() {
Ok(output) => output,
Err(_) => return None,
};
let version = match str::from_utf8(&output.stdout) {
Ok(version) => version,
Err(_) => return None,
};
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
let next = match pieces.next() {
Some(next) => next,
None => return None,
};
u32::from_str(next).ok()
}
-1
View File
@@ -1 +0,0 @@
../crates-io.md
-237
View File
@@ -1,237 +0,0 @@
use serde::{Deserialize, Serialize};
use de::Deserializer;
use ser::Serializer;
use token::Token;
use std::fmt::Debug;
/// Runs both `assert_ser_tokens` and `assert_de_tokens`.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// struct S {
/// a: u8,
/// b: u8,
/// }
///
/// let s = S { a: 0, b: 0 };
/// assert_tokens(
/// &s,
/// &[
/// Token::Struct { name: "S", len: 2 },
/// Token::Str("a"),
/// Token::U8(0),
/// Token::Str("b"),
/// Token::U8(0),
/// Token::StructEnd,
/// ],
/// );
/// ```
#[cfg_attr(not(no_track_caller), track_caller)]
pub fn assert_tokens<'de, T>(value: &T, tokens: &'de [Token])
where
T: Serialize + Deserialize<'de> + PartialEq + Debug,
{
assert_ser_tokens(value, tokens);
assert_de_tokens(value, tokens);
}
/// Asserts that `value` serializes to the given `tokens`.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_ser_tokens, Token};
/// #
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// struct S {
/// a: u8,
/// b: u8,
/// }
///
/// let s = S { a: 0, b: 0 };
/// assert_ser_tokens(
/// &s,
/// &[
/// Token::Struct { name: "S", len: 2 },
/// Token::Str("a"),
/// Token::U8(0),
/// Token::Str("b"),
/// Token::U8(0),
/// Token::StructEnd,
/// ],
/// );
/// ```
#[cfg_attr(not(no_track_caller), track_caller)]
pub fn assert_ser_tokens<T: ?Sized>(value: &T, tokens: &[Token])
where
T: Serialize,
{
let mut ser = Serializer::new(tokens);
match value.serialize(&mut ser) {
Ok(_) => {}
Err(err) => panic!("value failed to serialize: {}", err),
}
if ser.remaining() > 0 {
panic!("{} remaining tokens", ser.remaining());
}
}
/// Asserts that `value` serializes to the given `tokens`, and then yields
/// `error`.
///
/// ```edition2021
/// use serde_derive::Serialize;
/// use serde_test::{assert_ser_tokens_error, Token};
/// use std::sync::{Arc, Mutex};
/// use std::thread;
///
/// #[derive(Serialize)]
/// struct Example {
/// lock: Arc<Mutex<u32>>,
/// }
///
/// fn main() {
/// let example = Example {
/// lock: Arc::new(Mutex::new(0)),
/// };
/// let lock = example.lock.clone();
///
/// let thread = thread::spawn(move || {
/// // This thread will acquire the mutex first, unwrapping the result
/// // of `lock` because the lock has not been poisoned.
/// let _guard = lock.lock().unwrap();
///
/// // This panic while holding the lock (`_guard` is in scope) will
/// // poison the mutex.
/// panic!()
/// });
/// thread.join();
///
/// let expected = &[
/// Token::Struct {
/// name: "Example",
/// len: 1,
/// },
/// Token::Str("lock"),
/// ];
/// let error = "lock poison error while serializing";
/// assert_ser_tokens_error(&example, expected, error);
/// }
/// ```
#[cfg_attr(not(no_track_caller), track_caller)]
pub fn assert_ser_tokens_error<T: ?Sized>(value: &T, tokens: &[Token], error: &str)
where
T: Serialize,
{
let mut ser = Serializer::new(tokens);
match value.serialize(&mut ser) {
Ok(_) => panic!("value serialized successfully"),
Err(e) => assert_eq!(e, *error),
}
if ser.remaining() > 0 {
panic!("{} remaining tokens", ser.remaining());
}
}
/// Asserts that the given `tokens` deserialize into `value`.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_de_tokens, Token};
/// #
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// struct S {
/// a: u8,
/// b: u8,
/// }
///
/// let s = S { a: 0, b: 0 };
/// assert_de_tokens(
/// &s,
/// &[
/// Token::Struct { name: "S", len: 2 },
/// Token::Str("a"),
/// Token::U8(0),
/// Token::Str("b"),
/// Token::U8(0),
/// Token::StructEnd,
/// ],
/// );
/// ```
#[cfg_attr(not(no_track_caller), track_caller)]
pub fn assert_de_tokens<'de, T>(value: &T, tokens: &'de [Token])
where
T: Deserialize<'de> + PartialEq + Debug,
{
let mut de = Deserializer::new(tokens);
let mut deserialized_val = match T::deserialize(&mut de) {
Ok(v) => {
assert_eq!(v, *value);
v
}
Err(e) => panic!("tokens failed to deserialize: {}", e),
};
if de.remaining() > 0 {
panic!("{} remaining tokens", de.remaining());
}
// Do the same thing for deserialize_in_place. This isn't *great* because a
// no-op impl of deserialize_in_place can technically succeed here. Still,
// this should catch a lot of junk.
let mut de = Deserializer::new(tokens);
match T::deserialize_in_place(&mut de, &mut deserialized_val) {
Ok(()) => {
assert_eq!(deserialized_val, *value);
}
Err(e) => panic!("tokens failed to deserialize_in_place: {}", e),
}
if de.remaining() > 0 {
panic!("{} remaining tokens", de.remaining());
}
}
/// Asserts that the given `tokens` yield `error` when deserializing.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_de_tokens_error, Token};
/// #
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// #[serde(deny_unknown_fields)]
/// struct S {
/// a: u8,
/// b: u8,
/// }
///
/// assert_de_tokens_error::<S>(
/// &[
/// Token::Struct { name: "S", len: 2 },
/// Token::Str("x"),
/// ],
/// "unknown field `x`, expected `a` or `b`",
/// );
/// ```
#[cfg_attr(not(no_track_caller), track_caller)]
pub fn assert_de_tokens_error<'de, T>(tokens: &'de [Token], error: &str)
where
T: Deserialize<'de>,
{
let mut de = Deserializer::new(tokens);
match T::deserialize(&mut de) {
Ok(_) => panic!("tokens deserialized successfully"),
Err(e) => assert_eq!(e, *error),
}
// There may be one token left if a peek caused the error
de.next_token_opt();
if de.remaining() > 0 {
panic!("{} remaining tokens", de.remaining());
}
}
-847
View File
@@ -1,847 +0,0 @@
use std::fmt;
use serde::ser::{
SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant, SerializeTuple,
SerializeTupleStruct, SerializeTupleVariant,
};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Readable<T: ?Sized>(T);
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Compact<T: ?Sized>(T);
/// Trait to determine whether a value is represented in human-readable or
/// compact form.
///
/// ```edition2021
/// use serde::{Deserialize, Deserializer, Serialize, Serializer};
/// use serde_test::{assert_tokens, Configure, Token};
///
/// #[derive(Debug, PartialEq)]
/// struct Example(u8, u8);
///
/// impl Serialize for Example {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// where
/// S: Serializer,
/// {
/// if serializer.is_human_readable() {
/// format!("{}.{}", self.0, self.1).serialize(serializer)
/// } else {
/// (self.0, self.1).serialize(serializer)
/// }
/// }
/// }
///
/// impl<'de> Deserialize<'de> for Example {
/// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
/// where
/// D: Deserializer<'de>,
/// {
/// use serde::de::Error;
/// if deserializer.is_human_readable() {
/// let s = String::deserialize(deserializer)?;
/// let parts: Vec<_> = s.split('.').collect();
/// Ok(Example(
/// parts[0].parse().map_err(D::Error::custom)?,
/// parts[1].parse().map_err(D::Error::custom)?,
/// ))
/// } else {
/// let (x, y) = Deserialize::deserialize(deserializer)?;
/// Ok(Example(x, y))
/// }
/// }
/// }
///
/// fn main() {
/// assert_tokens(
/// &Example(1, 0).compact(),
/// &[
/// Token::Tuple { len: 2 },
/// Token::U8(1),
/// Token::U8(0),
/// Token::TupleEnd,
/// ],
/// );
/// assert_tokens(&Example(1, 0).readable(), &[Token::Str("1.0")]);
/// }
/// ```
pub trait Configure {
/// Marks `self` as using `is_human_readable == true`
fn readable(self) -> Readable<Self>
where
Self: Sized,
{
Readable(self)
}
/// Marks `self` as using `is_human_readable == false`
fn compact(self) -> Compact<Self>
where
Self: Sized,
{
Compact(self)
}
}
impl<T: ?Sized> Configure for T {}
impl<T: ?Sized> Serialize for Readable<T>
where
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(Readable(serializer))
}
}
impl<T: ?Sized> Serialize for Compact<T>
where
T: Serialize,
{
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(Compact(serializer))
}
}
impl<'de, T> Deserialize<'de> for Readable<T>
where
T: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
T::deserialize(Readable(deserializer)).map(Readable)
}
}
impl<'de, T> Deserialize<'de> for Compact<T>
where
T: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
T::deserialize(Compact(deserializer)).map(Compact)
}
}
impl<'de, T> DeserializeSeed<'de> for Readable<T>
where
T: DeserializeSeed<'de>,
{
type Value = T::Value;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: Deserializer<'de>,
{
self.0.deserialize(Readable(deserializer))
}
}
impl<'de, T> DeserializeSeed<'de> for Compact<T>
where
T: DeserializeSeed<'de>,
{
type Value = T::Value;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: Deserializer<'de>,
{
self.0.deserialize(Compact(deserializer))
}
}
macro_rules! forward_method {
($name: ident (self $(, $arg: ident : $arg_type: ty)* ) -> $return_type: ty) => {
fn $name (self $(, $arg : $arg_type)* ) -> $return_type {
(self.0).$name( $($arg),* )
}
};
}
macro_rules! forward_serialize_methods {
( $( $name: ident $arg_type: ty ),* ) => {
$(
forward_method!($name(self, v : $arg_type) -> Result<Self::Ok, Self::Error>);
)*
};
}
macro_rules! impl_serializer {
($wrapper:ident, $is_human_readable:expr) => {
impl<S> Serializer for $wrapper<S>
where
S: Serializer,
{
type Ok = S::Ok;
type Error = S::Error;
type SerializeSeq = $wrapper<S::SerializeSeq>;
type SerializeTuple = $wrapper<S::SerializeTuple>;
type SerializeTupleStruct = $wrapper<S::SerializeTupleStruct>;
type SerializeTupleVariant = $wrapper<S::SerializeTupleVariant>;
type SerializeMap = $wrapper<S::SerializeMap>;
type SerializeStruct = $wrapper<S::SerializeStruct>;
type SerializeStructVariant = $wrapper<S::SerializeStructVariant>;
fn is_human_readable(&self) -> bool {
$is_human_readable
}
forward_serialize_methods! {
serialize_bool bool,
serialize_i8 i8,
serialize_i16 i16,
serialize_i32 i32,
serialize_i64 i64,
serialize_u8 u8,
serialize_u16 u16,
serialize_u32 u32,
serialize_u64 u64,
serialize_f32 f32,
serialize_f64 f64,
serialize_char char,
serialize_str &str,
serialize_bytes &[u8],
serialize_unit_struct &'static str
}
fn serialize_unit(self) -> Result<S::Ok, S::Error> {
self.0.serialize_unit()
}
fn serialize_unit_variant(
self,
name: &'static str,
variant_index: u32,
variant: &'static str,
) -> Result<S::Ok, S::Error> {
self.0.serialize_unit_variant(name, variant_index, variant)
}
fn serialize_newtype_struct<T: ?Sized>(
self,
name: &'static str,
value: &T,
) -> Result<S::Ok, S::Error>
where
T: Serialize,
{
self.0.serialize_newtype_struct(name, &$wrapper(value))
}
fn serialize_newtype_variant<T: ?Sized>(
self,
name: &'static str,
variant_index: u32,
variant: &'static str,
value: &T,
) -> Result<S::Ok, S::Error>
where
T: Serialize,
{
self.0
.serialize_newtype_variant(name, variant_index, variant, &$wrapper(value))
}
fn serialize_none(self) -> Result<S::Ok, Self::Error> {
self.0.serialize_none()
}
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<S::Ok, Self::Error>
where
T: Serialize,
{
self.0.serialize_some(&$wrapper(value))
}
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
self.0.serialize_seq(len).map($wrapper)
}
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> {
self.0.serialize_tuple(len).map($wrapper)
}
fn serialize_tuple_struct(
self,
name: &'static str,
len: usize,
) -> Result<Self::SerializeTupleStruct, Self::Error> {
self.0.serialize_tuple_struct(name, len).map($wrapper)
}
fn serialize_tuple_variant(
self,
name: &'static str,
variant_index: u32,
variant: &'static str,
len: usize,
) -> Result<Self::SerializeTupleVariant, Self::Error> {
self.0
.serialize_tuple_variant(name, variant_index, variant, len)
.map($wrapper)
}
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
self.0.serialize_map(len).map($wrapper)
}
fn serialize_struct(
self,
name: &'static str,
len: usize,
) -> Result<Self::SerializeStruct, Self::Error> {
self.0.serialize_struct(name, len).map($wrapper)
}
fn serialize_struct_variant(
self,
name: &'static str,
variant_index: u32,
variant: &'static str,
len: usize,
) -> Result<Self::SerializeStructVariant, Self::Error> {
self.0
.serialize_struct_variant(name, variant_index, variant, len)
.map($wrapper)
}
}
impl<S> SerializeSeq for $wrapper<S>
where
S: SerializeSeq,
{
type Ok = S::Ok;
type Error = S::Error;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), S::Error>
where
T: Serialize,
{
self.0.serialize_element(&$wrapper(value))
}
fn end(self) -> Result<S::Ok, S::Error> {
self.0.end()
}
}
impl<S> SerializeTuple for $wrapper<S>
where
S: SerializeTuple,
{
type Ok = S::Ok;
type Error = S::Error;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), S::Error>
where
T: Serialize,
{
self.0.serialize_element(&$wrapper(value))
}
fn end(self) -> Result<S::Ok, S::Error> {
self.0.end()
}
}
impl<S> SerializeTupleStruct for $wrapper<S>
where
S: SerializeTupleStruct,
{
type Ok = S::Ok;
type Error = S::Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), S::Error>
where
T: Serialize,
{
self.0.serialize_field(&$wrapper(value))
}
fn end(self) -> Result<S::Ok, S::Error> {
self.0.end()
}
}
impl<S> SerializeTupleVariant for $wrapper<S>
where
S: SerializeTupleVariant,
{
type Ok = S::Ok;
type Error = S::Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), S::Error>
where
T: Serialize,
{
self.0.serialize_field(&$wrapper(value))
}
fn end(self) -> Result<S::Ok, S::Error> {
self.0.end()
}
}
impl<S> SerializeMap for $wrapper<S>
where
S: SerializeMap,
{
type Ok = S::Ok;
type Error = S::Error;
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), S::Error>
where
T: Serialize,
{
self.0.serialize_key(&$wrapper(key))
}
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), S::Error>
where
T: Serialize,
{
self.0.serialize_value(&$wrapper(value))
}
fn serialize_entry<K: ?Sized, V: ?Sized>(
&mut self,
key: &K,
value: &V,
) -> Result<(), S::Error>
where
K: Serialize,
V: Serialize,
{
self.0.serialize_entry(key, &$wrapper(value))
}
fn end(self) -> Result<S::Ok, S::Error> {
self.0.end()
}
}
impl<S> SerializeStruct for $wrapper<S>
where
S: SerializeStruct,
{
type Ok = S::Ok;
type Error = S::Error;
fn serialize_field<T: ?Sized>(
&mut self,
name: &'static str,
field: &T,
) -> Result<(), S::Error>
where
T: Serialize,
{
self.0.serialize_field(name, &$wrapper(field))
}
fn end(self) -> Result<S::Ok, S::Error> {
self.0.end()
}
}
impl<S> SerializeStructVariant for $wrapper<S>
where
S: SerializeStructVariant,
{
type Ok = S::Ok;
type Error = S::Error;
fn serialize_field<T: ?Sized>(
&mut self,
name: &'static str,
field: &T,
) -> Result<(), S::Error>
where
T: Serialize,
{
self.0.serialize_field(name, &$wrapper(field))
}
fn end(self) -> Result<S::Ok, S::Error> {
self.0.end()
}
}
};
}
impl_serializer!(Readable, true);
impl_serializer!(Compact, false);
use serde::de::{DeserializeSeed, EnumAccess, Error, MapAccess, SeqAccess, VariantAccess, Visitor};
macro_rules! forward_deserialize_methods {
( $wrapper : ident ( $( $name: ident ),* ) ) => {
$(
fn $name<V>(self, visitor: V) -> Result<V::Value, D::Error>
where
V: Visitor<'de>,
{
(self.0).$name($wrapper(visitor))
}
)*
};
}
macro_rules! impl_deserializer {
($wrapper:ident, $is_human_readable:expr) => {
impl<'de, D> Deserializer<'de> for $wrapper<D>
where
D: Deserializer<'de>,
{
type Error = D::Error;
forward_deserialize_methods! {
$wrapper (
deserialize_any,
deserialize_bool,
deserialize_u8,
deserialize_u16,
deserialize_u32,
deserialize_u64,
deserialize_i8,
deserialize_i16,
deserialize_i32,
deserialize_i64,
deserialize_f32,
deserialize_f64,
deserialize_char,
deserialize_str,
deserialize_string,
deserialize_bytes,
deserialize_byte_buf,
deserialize_option,
deserialize_unit,
deserialize_seq,
deserialize_map,
deserialize_identifier,
deserialize_ignored_any
)
}
fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, D::Error>
where
V: Visitor<'de>,
{
self.0.deserialize_unit_struct(name, $wrapper(visitor))
}
fn deserialize_newtype_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, D::Error>
where
V: Visitor<'de>,
{
self.0.deserialize_newtype_struct(name, $wrapper(visitor))
}
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, D::Error>
where
V: Visitor<'de>,
{
self.0.deserialize_tuple(len, $wrapper(visitor))
}
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value, D::Error>
where
V: Visitor<'de>,
{
self.0
.deserialize_tuple_struct(name, len, $wrapper(visitor))
}
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, D::Error>
where
V: Visitor<'de>,
{
self.0.deserialize_struct(name, fields, $wrapper(visitor))
}
fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, D::Error>
where
V: Visitor<'de>,
{
self.0.deserialize_enum(name, variants, $wrapper(visitor))
}
fn is_human_readable(&self) -> bool {
$is_human_readable
}
}
impl<'de, D> Visitor<'de> for $wrapper<D>
where
D: Visitor<'de>,
{
type Value = D::Value;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.0.expecting(formatter)
}
fn visit_bool<E>(self, v: bool) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_bool(v)
}
fn visit_i8<E>(self, v: i8) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_i8(v)
}
fn visit_i16<E>(self, v: i16) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_i16(v)
}
fn visit_i32<E>(self, v: i32) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_i32(v)
}
fn visit_i64<E>(self, v: i64) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_i64(v)
}
fn visit_u8<E>(self, v: u8) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_u8(v)
}
fn visit_u16<E>(self, v: u16) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_u16(v)
}
fn visit_u32<E>(self, v: u32) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_u32(v)
}
fn visit_u64<E>(self, v: u64) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_u64(v)
}
fn visit_f32<E>(self, v: f32) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_f32(v)
}
fn visit_f64<E>(self, v: f64) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_f64(v)
}
fn visit_char<E>(self, v: char) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_char(v)
}
fn visit_str<E>(self, v: &str) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_str(v)
}
fn visit_borrowed_str<E>(self, v: &'de str) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_borrowed_str(v)
}
fn visit_string<E>(self, v: String) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_string(v)
}
fn visit_bytes<E>(self, v: &[u8]) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_bytes(v)
}
fn visit_borrowed_bytes<E>(self, v: &'de [u8]) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_borrowed_bytes(v)
}
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_byte_buf(v)
}
fn visit_none<E>(self) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_none()
}
fn visit_some<D2>(self, deserializer: D2) -> Result<Self::Value, D2::Error>
where
D2: Deserializer<'de>,
{
self.0.visit_some($wrapper(deserializer))
}
fn visit_unit<E>(self) -> Result<D::Value, E>
where
E: Error,
{
self.0.visit_unit()
}
fn visit_newtype_struct<D2>(self, deserializer: D2) -> Result<Self::Value, D2::Error>
where
D2: Deserializer<'de>,
{
self.0.visit_newtype_struct($wrapper(deserializer))
}
fn visit_seq<V>(self, seq: V) -> Result<D::Value, V::Error>
where
V: SeqAccess<'de>,
{
self.0.visit_seq($wrapper(seq))
}
fn visit_map<V>(self, map: V) -> Result<D::Value, V::Error>
where
V: MapAccess<'de>,
{
self.0.visit_map($wrapper(map))
}
fn visit_enum<V>(self, data: V) -> Result<D::Value, V::Error>
where
V: EnumAccess<'de>,
{
self.0.visit_enum($wrapper(data))
}
}
impl<'de, D> SeqAccess<'de> for $wrapper<D>
where
D: SeqAccess<'de>,
{
type Error = D::Error;
fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, D::Error>
where
T: DeserializeSeed<'de>,
{
self.0.next_element_seed($wrapper(seed))
}
fn size_hint(&self) -> Option<usize> {
self.0.size_hint()
}
}
impl<'de, D> MapAccess<'de> for $wrapper<D>
where
D: MapAccess<'de>,
{
type Error = D::Error;
fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, D::Error>
where
K: DeserializeSeed<'de>,
{
self.0.next_key_seed($wrapper(seed))
}
fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, D::Error>
where
V: DeserializeSeed<'de>,
{
self.0.next_value_seed($wrapper(seed))
}
fn next_entry_seed<K, V>(
&mut self,
kseed: K,
vseed: V,
) -> Result<Option<(K::Value, V::Value)>, D::Error>
where
K: DeserializeSeed<'de>,
V: DeserializeSeed<'de>,
{
self.0.next_entry_seed($wrapper(kseed), $wrapper(vseed))
}
fn size_hint(&self) -> Option<usize> {
self.0.size_hint()
}
}
impl<'de, D> EnumAccess<'de> for $wrapper<D>
where
D: EnumAccess<'de>,
{
type Error = D::Error;
type Variant = $wrapper<D::Variant>;
fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant), Self::Error>
where
V: DeserializeSeed<'de>,
{
self.0
.variant_seed($wrapper(seed))
.map(|(value, variant)| (value, $wrapper(variant)))
}
}
impl<'de, D> VariantAccess<'de> for $wrapper<D>
where
D: VariantAccess<'de>,
{
type Error = D::Error;
fn unit_variant(self) -> Result<(), D::Error> {
self.0.unit_variant()
}
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, D::Error>
where
T: DeserializeSeed<'de>,
{
self.0.newtype_variant_seed($wrapper(seed))
}
fn tuple_variant<V>(self, len: usize, visitor: V) -> Result<V::Value, D::Error>
where
V: Visitor<'de>,
{
self.0.tuple_variant(len, $wrapper(visitor))
}
fn struct_variant<V>(
self,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, D::Error>
where
V: Visitor<'de>,
{
self.0.struct_variant(fields, $wrapper(visitor))
}
}
};
}
impl_deserializer!(Readable, true);
impl_deserializer!(Compact, false);
-671
View File
@@ -1,671 +0,0 @@
use serde::de::value::{MapAccessDeserializer, SeqAccessDeserializer};
use serde::de::{
self, Deserialize, DeserializeSeed, EnumAccess, IntoDeserializer, MapAccess, SeqAccess,
VariantAccess, Visitor,
};
use error::Error;
use token::Token;
#[derive(Debug)]
pub struct Deserializer<'de> {
tokens: &'de [Token],
}
fn assert_next_token(de: &mut Deserializer, expected: Token) -> Result<(), Error> {
match de.next_token_opt() {
Some(token) if token == expected => Ok(()),
Some(other) => Err(de::Error::custom(format!(
"expected Token::{} but deserialization wants Token::{}",
other, expected,
))),
None => Err(de::Error::custom(format!(
"end of tokens but deserialization wants Token::{}",
expected,
))),
}
}
fn unexpected(token: Token) -> Error {
de::Error::custom(format!(
"deserialization did not expect this token: {}",
token,
))
}
fn end_of_tokens() -> Error {
de::Error::custom("ran out of tokens to deserialize")
}
impl<'de> Deserializer<'de> {
pub fn new(tokens: &'de [Token]) -> Self {
Deserializer { tokens: tokens }
}
fn peek_token_opt(&self) -> Option<Token> {
self.tokens.first().cloned()
}
fn peek_token(&self) -> Result<Token, Error> {
self.peek_token_opt().ok_or_else(end_of_tokens)
}
pub fn next_token_opt(&mut self) -> Option<Token> {
match self.tokens.split_first() {
Some((&first, rest)) => {
self.tokens = rest;
Some(first)
}
None => None,
}
}
fn next_token(&mut self) -> Result<Token, Error> {
let (&first, rest) = self.tokens.split_first().ok_or_else(end_of_tokens)?;
self.tokens = rest;
Ok(first)
}
pub fn remaining(&self) -> usize {
self.tokens.len()
}
fn visit_seq<V>(
&mut self,
len: Option<usize>,
end: Token,
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
let value = visitor.visit_seq(DeserializerSeqVisitor {
de: self,
len: len,
end: end,
})?;
assert_next_token(self, end)?;
Ok(value)
}
fn visit_map<V>(
&mut self,
len: Option<usize>,
end: Token,
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
let value = visitor.visit_map(DeserializerMapVisitor {
de: self,
len: len,
end: end,
})?;
assert_next_token(self, end)?;
Ok(value)
}
}
impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
type Error = Error;
forward_to_deserialize_any! {
bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
bytes byte_buf unit seq map identifier ignored_any
}
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
let token = self.next_token()?;
match token {
Token::Bool(v) => visitor.visit_bool(v),
Token::I8(v) => visitor.visit_i8(v),
Token::I16(v) => visitor.visit_i16(v),
Token::I32(v) => visitor.visit_i32(v),
Token::I64(v) => visitor.visit_i64(v),
Token::U8(v) => visitor.visit_u8(v),
Token::U16(v) => visitor.visit_u16(v),
Token::U32(v) => visitor.visit_u32(v),
Token::U64(v) => visitor.visit_u64(v),
Token::F32(v) => visitor.visit_f32(v),
Token::F64(v) => visitor.visit_f64(v),
Token::Char(v) => visitor.visit_char(v),
Token::Str(v) => visitor.visit_str(v),
Token::BorrowedStr(v) => visitor.visit_borrowed_str(v),
Token::String(v) => visitor.visit_string(v.to_owned()),
Token::Bytes(v) => visitor.visit_bytes(v),
Token::BorrowedBytes(v) => visitor.visit_borrowed_bytes(v),
Token::ByteBuf(v) => visitor.visit_byte_buf(v.to_vec()),
Token::None => visitor.visit_none(),
Token::Some => visitor.visit_some(self),
Token::Unit | Token::UnitStruct { .. } => visitor.visit_unit(),
Token::NewtypeStruct { .. } => visitor.visit_newtype_struct(self),
Token::Seq { len } => self.visit_seq(len, Token::SeqEnd, visitor),
Token::Tuple { len } => self.visit_seq(Some(len), Token::TupleEnd, visitor),
Token::TupleStruct { len, .. } => {
self.visit_seq(Some(len), Token::TupleStructEnd, visitor)
}
Token::Map { len } => self.visit_map(len, Token::MapEnd, visitor),
Token::Struct { len, .. } => self.visit_map(Some(len), Token::StructEnd, visitor),
Token::Enum { .. } => {
let variant = self.next_token()?;
let next = self.peek_token()?;
match (variant, next) {
(Token::Str(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_str(variant)
}
(Token::BorrowedStr(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_borrowed_str(variant)
}
(Token::String(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_string(variant.to_string())
}
(Token::Bytes(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_bytes(variant)
}
(Token::BorrowedBytes(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_borrowed_bytes(variant)
}
(Token::ByteBuf(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_byte_buf(variant.to_vec())
}
(Token::U8(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_u8(variant)
}
(Token::U16(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_u16(variant)
}
(Token::U32(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_u32(variant)
}
(Token::U64(variant), Token::Unit) => {
self.next_token()?;
visitor.visit_u64(variant)
}
(variant, Token::Unit) => Err(unexpected(variant)),
(variant, _) => {
visitor.visit_map(EnumMapVisitor::new(self, variant, EnumFormat::Any))
}
}
}
Token::UnitVariant { variant, .. } => visitor.visit_str(variant),
Token::NewtypeVariant { variant, .. } => visitor.visit_map(EnumMapVisitor::new(
self,
Token::Str(variant),
EnumFormat::Any,
)),
Token::TupleVariant { variant, .. } => visitor.visit_map(EnumMapVisitor::new(
self,
Token::Str(variant),
EnumFormat::Seq,
)),
Token::StructVariant { variant, .. } => visitor.visit_map(EnumMapVisitor::new(
self,
Token::Str(variant),
EnumFormat::Map,
)),
Token::SeqEnd
| Token::TupleEnd
| Token::TupleStructEnd
| Token::MapEnd
| Token::StructEnd
| Token::TupleVariantEnd
| Token::StructVariantEnd => Err(unexpected(token)),
}
}
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self.peek_token()? {
Token::Unit | Token::None => {
self.next_token()?;
visitor.visit_none()
}
Token::Some => {
self.next_token()?;
visitor.visit_some(self)
}
_ => self.deserialize_any(visitor),
}
}
fn deserialize_enum<V>(
self,
name: &'static str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self.peek_token()? {
Token::Enum { name: n } if name == n => {
self.next_token()?;
visitor.visit_enum(DeserializerEnumVisitor { de: self })
}
Token::UnitVariant { name: n, .. }
| Token::NewtypeVariant { name: n, .. }
| Token::TupleVariant { name: n, .. }
| Token::StructVariant { name: n, .. }
if name == n =>
{
visitor.visit_enum(DeserializerEnumVisitor { de: self })
}
_ => self.deserialize_any(visitor),
}
}
fn deserialize_unit_struct<V>(self, name: &'static str, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self.peek_token()? {
Token::UnitStruct { .. } => {
assert_next_token(self, Token::UnitStruct { name: name })?;
visitor.visit_unit()
}
_ => self.deserialize_any(visitor),
}
}
fn deserialize_newtype_struct<V>(
self,
name: &'static str,
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self.peek_token()? {
Token::NewtypeStruct { .. } => {
assert_next_token(self, Token::NewtypeStruct { name: name })?;
visitor.visit_newtype_struct(self)
}
_ => self.deserialize_any(visitor),
}
}
fn deserialize_tuple<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self.peek_token()? {
Token::Unit | Token::UnitStruct { .. } => {
self.next_token()?;
visitor.visit_unit()
}
Token::Seq { .. } => {
self.next_token()?;
self.visit_seq(Some(len), Token::SeqEnd, visitor)
}
Token::Tuple { .. } => {
self.next_token()?;
self.visit_seq(Some(len), Token::TupleEnd, visitor)
}
Token::TupleStruct { .. } => {
self.next_token()?;
self.visit_seq(Some(len), Token::TupleStructEnd, visitor)
}
_ => self.deserialize_any(visitor),
}
}
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self.peek_token()? {
Token::Unit => {
self.next_token()?;
visitor.visit_unit()
}
Token::UnitStruct { .. } => {
assert_next_token(self, Token::UnitStruct { name: name })?;
visitor.visit_unit()
}
Token::Seq { .. } => {
self.next_token()?;
self.visit_seq(Some(len), Token::SeqEnd, visitor)
}
Token::Tuple { .. } => {
self.next_token()?;
self.visit_seq(Some(len), Token::TupleEnd, visitor)
}
Token::TupleStruct { len: n, .. } => {
assert_next_token(self, Token::TupleStruct { name: name, len: n })?;
self.visit_seq(Some(len), Token::TupleStructEnd, visitor)
}
_ => self.deserialize_any(visitor),
}
}
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self.peek_token()? {
Token::Struct { len: n, .. } => {
assert_next_token(self, Token::Struct { name: name, len: n })?;
self.visit_map(Some(fields.len()), Token::StructEnd, visitor)
}
Token::Map { .. } => {
self.next_token()?;
self.visit_map(Some(fields.len()), Token::MapEnd, visitor)
}
_ => self.deserialize_any(visitor),
}
}
fn is_human_readable(&self) -> bool {
panic!(
"Types which have different human-readable and compact representations \
must explicitly mark their test cases with `serde_test::Configure`"
);
}
}
//////////////////////////////////////////////////////////////////////////
struct DeserializerSeqVisitor<'a, 'de: 'a> {
de: &'a mut Deserializer<'de>,
len: Option<usize>,
end: Token,
}
impl<'de, 'a> SeqAccess<'de> for DeserializerSeqVisitor<'a, 'de> {
type Error = Error;
fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Error>
where
T: DeserializeSeed<'de>,
{
if self.de.peek_token_opt() == Some(self.end) {
return Ok(None);
}
self.len = self.len.map(|len| len.saturating_sub(1));
seed.deserialize(&mut *self.de).map(Some)
}
fn size_hint(&self) -> Option<usize> {
self.len
}
}
//////////////////////////////////////////////////////////////////////////
struct DeserializerMapVisitor<'a, 'de: 'a> {
de: &'a mut Deserializer<'de>,
len: Option<usize>,
end: Token,
}
impl<'de, 'a> MapAccess<'de> for DeserializerMapVisitor<'a, 'de> {
type Error = Error;
fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error>
where
K: DeserializeSeed<'de>,
{
if self.de.peek_token_opt() == Some(self.end) {
return Ok(None);
}
self.len = self.len.map(|len| len.saturating_sub(1));
seed.deserialize(&mut *self.de).map(Some)
}
fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error>
where
V: DeserializeSeed<'de>,
{
seed.deserialize(&mut *self.de)
}
fn size_hint(&self) -> Option<usize> {
self.len
}
}
//////////////////////////////////////////////////////////////////////////
struct DeserializerEnumVisitor<'a, 'de: 'a> {
de: &'a mut Deserializer<'de>,
}
impl<'de, 'a> EnumAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
type Error = Error;
type Variant = Self;
fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self), Error>
where
V: DeserializeSeed<'de>,
{
match self.de.peek_token()? {
Token::UnitVariant { variant: v, .. }
| Token::NewtypeVariant { variant: v, .. }
| Token::TupleVariant { variant: v, .. }
| Token::StructVariant { variant: v, .. } => {
let de = v.into_deserializer();
let value = seed.deserialize(de)?;
Ok((value, self))
}
_ => {
let value = seed.deserialize(&mut *self.de)?;
Ok((value, self))
}
}
}
}
impl<'de, 'a> VariantAccess<'de> for DeserializerEnumVisitor<'a, 'de> {
type Error = Error;
fn unit_variant(self) -> Result<(), Error> {
match self.de.peek_token()? {
Token::UnitVariant { .. } => {
self.de.next_token()?;
Ok(())
}
_ => Deserialize::deserialize(self.de),
}
}
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
where
T: DeserializeSeed<'de>,
{
match self.de.peek_token()? {
Token::NewtypeVariant { .. } => {
self.de.next_token()?;
seed.deserialize(self.de)
}
_ => seed.deserialize(self.de),
}
}
fn tuple_variant<V>(self, len: usize, visitor: V) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self.de.peek_token()? {
Token::TupleVariant { len: enum_len, .. } => {
let token = self.de.next_token()?;
if len == enum_len {
self.de
.visit_seq(Some(len), Token::TupleVariantEnd, visitor)
} else {
Err(unexpected(token))
}
}
Token::Seq {
len: Some(enum_len),
} => {
let token = self.de.next_token()?;
if len == enum_len {
self.de.visit_seq(Some(len), Token::SeqEnd, visitor)
} else {
Err(unexpected(token))
}
}
_ => de::Deserializer::deserialize_any(self.de, visitor),
}
}
fn struct_variant<V>(
self,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
match self.de.peek_token()? {
Token::StructVariant { len: enum_len, .. } => {
let token = self.de.next_token()?;
if fields.len() == enum_len {
self.de
.visit_map(Some(fields.len()), Token::StructVariantEnd, visitor)
} else {
Err(unexpected(token))
}
}
Token::Map {
len: Some(enum_len),
} => {
let token = self.de.next_token()?;
if fields.len() == enum_len {
self.de
.visit_map(Some(fields.len()), Token::MapEnd, visitor)
} else {
Err(unexpected(token))
}
}
_ => de::Deserializer::deserialize_any(self.de, visitor),
}
}
}
//////////////////////////////////////////////////////////////////////////
struct EnumMapVisitor<'a, 'de: 'a> {
de: &'a mut Deserializer<'de>,
variant: Option<Token>,
format: EnumFormat,
}
enum EnumFormat {
Seq,
Map,
Any,
}
impl<'a, 'de> EnumMapVisitor<'a, 'de> {
fn new(de: &'a mut Deserializer<'de>, variant: Token, format: EnumFormat) -> Self {
EnumMapVisitor {
de: de,
variant: Some(variant),
format: format,
}
}
}
impl<'de, 'a> MapAccess<'de> for EnumMapVisitor<'a, 'de> {
type Error = Error;
fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Error>
where
K: DeserializeSeed<'de>,
{
match self.variant.take() {
Some(Token::Str(variant)) => seed.deserialize(variant.into_deserializer()).map(Some),
Some(Token::Bytes(variant)) => seed
.deserialize(BytesDeserializer { value: variant })
.map(Some),
Some(Token::U32(variant)) => seed.deserialize(variant.into_deserializer()).map(Some),
Some(other) => Err(unexpected(other)),
None => Ok(None),
}
}
fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Error>
where
V: DeserializeSeed<'de>,
{
match self.format {
EnumFormat::Seq => {
let value = {
let visitor = DeserializerSeqVisitor {
de: self.de,
len: None,
end: Token::TupleVariantEnd,
};
seed.deserialize(SeqAccessDeserializer::new(visitor))?
};
assert_next_token(self.de, Token::TupleVariantEnd)?;
Ok(value)
}
EnumFormat::Map => {
let value = {
let visitor = DeserializerMapVisitor {
de: self.de,
len: None,
end: Token::StructVariantEnd,
};
seed.deserialize(MapAccessDeserializer::new(visitor))?
};
assert_next_token(self.de, Token::StructVariantEnd)?;
Ok(value)
}
EnumFormat::Any => seed.deserialize(&mut *self.de),
}
}
}
struct BytesDeserializer {
value: &'static [u8],
}
impl<'de> de::Deserializer<'de> for BytesDeserializer {
type Error = Error;
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
visitor.visit_bytes(self.value)
}
forward_to_deserialize_any! {
bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
bytes byte_buf option unit unit_struct newtype_struct seq tuple
tuple_struct map struct enum identifier ignored_any
}
}
-43
View File
@@ -1,43 +0,0 @@
use std::error;
use std::fmt::{self, Display};
use serde::{de, ser};
#[derive(Clone, Debug)]
pub struct Error {
msg: String,
}
impl ser::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error {
msg: msg.to_string(),
}
}
}
impl de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error {
msg: msg.to_string(),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(&self.msg)
}
}
impl error::Error for Error {
fn description(&self) -> &str {
&self.msg
}
}
impl PartialEq<str> for Error {
fn eq(&self, other: &str) -> bool {
self.msg == other
}
}
-188
View File
@@ -1,188 +0,0 @@
//! This crate provides a convenient concise way to write unit tests for
//! implementations of [`Serialize`] and [`Deserialize`].
//!
//! [`Serialize`]: serde::ser::Serialize
//! [`Deserialize`]: serde::de::Deserialize
//!
//! The `Serialize` impl for a value can be characterized by the sequence of
//! [`Serializer`] calls that are made in the course of serializing the value,
//! so `serde_test` provides a [`Token`] abstraction which corresponds roughly
//! to `Serializer` method calls. There is an [`assert_ser_tokens`] function to
//! test that a value serializes to a particular sequence of method calls, an
//! [`assert_de_tokens`] function to test that a value can be deserialized from
//! a particular sequence of method calls, and an [`assert_tokens`] function to
//! test both directions. There are also functions to test expected failure
//! conditions.
//!
//! [`Serializer`]: serde::ser::Serializer
//!
//! Here is an example from the [`linked-hash-map`] crate.
//!
//! [`linked-hash-map`]: https://github.com/contain-rs/linked-hash-map
//!
//! ```edition2021
//! # const IGNORE: &str = stringify! {
//! use linked_hash_map::LinkedHashMap;
//! # };
//! use serde_test::{assert_tokens, Token};
//!
//! # use std::fmt;
//! # use std::marker::PhantomData;
//! #
//! # use serde::ser::{Serialize, Serializer, SerializeMap};
//! # use serde::de::{Deserialize, Deserializer, Visitor, MapAccess};
//! #
//! # // Dumb imitation of LinkedHashMap.
//! # #[derive(PartialEq, Debug)]
//! # struct LinkedHashMap<K, V>(Vec<(K, V)>);
//! #
//! # impl<K, V> LinkedHashMap<K, V> {
//! # fn new() -> Self {
//! # LinkedHashMap(Vec::new())
//! # }
//! #
//! # fn insert(&mut self, k: K, v: V) {
//! # self.0.push((k, v));
//! # }
//! # }
//! #
//! # impl<K, V> Serialize for LinkedHashMap<K, V>
//! # where
//! # K: Serialize,
//! # V: Serialize,
//! # {
//! # fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
//! # where
//! # S: Serializer,
//! # {
//! # let mut map = serializer.serialize_map(Some(self.0.len()))?;
//! # for &(ref k, ref v) in &self.0 {
//! # map.serialize_entry(k, v)?;
//! # }
//! # map.end()
//! # }
//! # }
//! #
//! # struct LinkedHashMapVisitor<K, V>(PhantomData<(K, V)>);
//! #
//! # impl<'de, K, V> Visitor<'de> for LinkedHashMapVisitor<K, V>
//! # where
//! # K: Deserialize<'de>,
//! # V: Deserialize<'de>,
//! # {
//! # type Value = LinkedHashMap<K, V>;
//! #
//! # fn expecting(&self, _: &mut fmt::Formatter) -> fmt::Result {
//! # unimplemented!()
//! # }
//! #
//! # fn visit_map<M>(self, mut access: M) -> Result<Self::Value, M::Error>
//! # where
//! # M: MapAccess<'de>,
//! # {
//! # let mut map = LinkedHashMap::new();
//! # while let Some((key, value)) = access.next_entry()? {
//! # map.insert(key, value);
//! # }
//! # Ok(map)
//! # }
//! # }
//! #
//! # impl<'de, K, V> Deserialize<'de> for LinkedHashMap<K, V>
//! # where
//! # K: Deserialize<'de>,
//! # V: Deserialize<'de>,
//! # {
//! # fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
//! # where
//! # D: Deserializer<'de>,
//! # {
//! # deserializer.deserialize_map(LinkedHashMapVisitor(PhantomData))
//! # }
//! # }
//! #
//! #[test]
//! # fn not_a_test_ser_de_empty() {}
//! fn test_ser_de_empty() {
//! let map = LinkedHashMap::<char, u32>::new();
//!
//! assert_tokens(
//! &map,
//! &[
//! Token::Map { len: Some(0) },
//! Token::MapEnd,
//! ],
//! );
//! }
//!
//! #[test]
//! # fn not_a_test_ser_de() {}
//! fn test_ser_de() {
//! let mut map = LinkedHashMap::new();
//! map.insert('b', 20);
//! map.insert('a', 10);
//! map.insert('c', 30);
//!
//! assert_tokens(
//! &map,
//! &[
//! Token::Map { len: Some(3) },
//! Token::Char('b'),
//! Token::I32(20),
//! Token::Char('a'),
//! Token::I32(10),
//! Token::Char('c'),
//! Token::I32(30),
//! Token::MapEnd,
//! ],
//! );
//! }
//! #
//! # fn main() {
//! # test_ser_de_empty();
//! # test_ser_de();
//! # }
//! ```
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.170")]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
// Ignored clippy lints
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp, needless_doctest_main))]
// Ignored clippy_pedantic lints
#![cfg_attr(
feature = "cargo-clippy",
allow(
cloned_instead_of_copied,
doc_link_with_quotes, // https://github.com/rust-lang/rust-clippy/issues/8961
empty_line_after_outer_attr,
manual_assert,
missing_docs_in_private_items,
missing_panics_doc,
module_name_repetitions,
must_use_candidate,
redundant_field_names,
too_many_lines,
type_repetition_in_bounds, // https://github.com/rust-lang/rust-clippy/issues/8772
use_debug,
use_self
)
)]
#[macro_use]
extern crate serde;
mod de;
mod error;
mod ser;
mod assert;
mod configure;
mod token;
pub use assert::{
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_ser_tokens_error,
assert_tokens,
};
pub use token::Token;
pub use configure::{Compact, Configure, Readable};
-462
View File
@@ -1,462 +0,0 @@
use serde::{ser, Serialize};
use error::Error;
use token::Token;
/// A `Serializer` that ensures that a value serializes to a given list of
/// tokens.
#[derive(Debug)]
pub struct Serializer<'a> {
tokens: &'a [Token],
}
impl<'a> Serializer<'a> {
/// Creates the serializer.
pub fn new(tokens: &'a [Token]) -> Self {
Serializer { tokens: tokens }
}
/// Pulls the next token off of the serializer, ignoring it.
fn next_token(&mut self) -> Option<Token> {
if let Some((&first, rest)) = self.tokens.split_first() {
self.tokens = rest;
Some(first)
} else {
None
}
}
pub fn remaining(&self) -> usize {
self.tokens.len()
}
}
macro_rules! assert_next_token {
($ser:expr, $actual:ident) => {{
assert_next_token!($ser, stringify!($actual), Token::$actual, true);
}};
($ser:expr, $actual:ident($v:expr)) => {{
assert_next_token!(
$ser,
format_args!(concat!(stringify!($actual), "({:?})"), $v),
Token::$actual(v),
v == $v
);
}};
($ser:expr, $actual:ident { $($k:ident),* }) => {{
let compare = ($($k,)*);
let field_format = || {
use std::fmt::Write;
let mut buffer = String::new();
$(
write!(&mut buffer, concat!(stringify!($k), ": {:?}, "), $k).unwrap();
)*
buffer
};
assert_next_token!(
$ser,
format_args!(concat!(stringify!($actual), " {{ {}}}"), field_format()),
Token::$actual { $($k),* },
($($k,)*) == compare
);
}};
($ser:expr, $actual:expr, $pat:pat, $guard:expr) => {
match $ser.next_token() {
Some($pat) if $guard => {}
Some(expected) => return Err(ser::Error::custom(
format!("expected Token::{} but serialized as {}", expected, $actual)
)),
None => return Err(ser::Error::custom(
format!("expected end of tokens, but {} was serialized", $actual)
)),
}
};
}
impl<'s, 'a> ser::Serializer for &'s mut Serializer<'a> {
type Ok = ();
type Error = Error;
type SerializeSeq = Self;
type SerializeTuple = Self;
type SerializeTupleStruct = Self;
type SerializeTupleVariant = Variant<'s, 'a>;
type SerializeMap = Self;
type SerializeStruct = Self;
type SerializeStructVariant = Variant<'s, 'a>;
fn serialize_bool(self, v: bool) -> Result<(), Error> {
assert_next_token!(self, Bool(v));
Ok(())
}
fn serialize_i8(self, v: i8) -> Result<(), Error> {
assert_next_token!(self, I8(v));
Ok(())
}
fn serialize_i16(self, v: i16) -> Result<(), Error> {
assert_next_token!(self, I16(v));
Ok(())
}
fn serialize_i32(self, v: i32) -> Result<(), Error> {
assert_next_token!(self, I32(v));
Ok(())
}
fn serialize_i64(self, v: i64) -> Result<(), Error> {
assert_next_token!(self, I64(v));
Ok(())
}
fn serialize_u8(self, v: u8) -> Result<(), Error> {
assert_next_token!(self, U8(v));
Ok(())
}
fn serialize_u16(self, v: u16) -> Result<(), Error> {
assert_next_token!(self, U16(v));
Ok(())
}
fn serialize_u32(self, v: u32) -> Result<(), Error> {
assert_next_token!(self, U32(v));
Ok(())
}
fn serialize_u64(self, v: u64) -> Result<(), Error> {
assert_next_token!(self, U64(v));
Ok(())
}
fn serialize_f32(self, v: f32) -> Result<(), Error> {
assert_next_token!(self, F32(v));
Ok(())
}
fn serialize_f64(self, v: f64) -> Result<(), Error> {
assert_next_token!(self, F64(v));
Ok(())
}
fn serialize_char(self, v: char) -> Result<(), Error> {
assert_next_token!(self, Char(v));
Ok(())
}
fn serialize_str(self, v: &str) -> Result<(), Error> {
match self.tokens.first() {
Some(&Token::BorrowedStr(_)) => assert_next_token!(self, BorrowedStr(v)),
Some(&Token::String(_)) => assert_next_token!(self, String(v)),
_ => assert_next_token!(self, Str(v)),
}
Ok(())
}
fn serialize_bytes(self, v: &[u8]) -> Result<(), Self::Error> {
match self.tokens.first() {
Some(&Token::BorrowedBytes(_)) => assert_next_token!(self, BorrowedBytes(v)),
Some(&Token::ByteBuf(_)) => assert_next_token!(self, ByteBuf(v)),
_ => assert_next_token!(self, Bytes(v)),
}
Ok(())
}
fn serialize_unit(self) -> Result<(), Error> {
assert_next_token!(self, Unit);
Ok(())
}
fn serialize_unit_struct(self, name: &'static str) -> Result<(), Error> {
assert_next_token!(self, UnitStruct { name });
Ok(())
}
fn serialize_unit_variant(
self,
name: &'static str,
_variant_index: u32,
variant: &'static str,
) -> Result<(), Error> {
if self.tokens.first() == Some(&Token::Enum { name: name }) {
self.next_token();
assert_next_token!(self, Str(variant));
assert_next_token!(self, Unit);
} else {
assert_next_token!(self, UnitVariant { name, variant });
}
Ok(())
}
fn serialize_newtype_struct<T: ?Sized>(self, name: &'static str, value: &T) -> Result<(), Error>
where
T: Serialize,
{
assert_next_token!(self, NewtypeStruct { name });
value.serialize(self)
}
fn serialize_newtype_variant<T: ?Sized>(
self,
name: &'static str,
_variant_index: u32,
variant: &'static str,
value: &T,
) -> Result<(), Error>
where
T: Serialize,
{
if self.tokens.first() == Some(&Token::Enum { name: name }) {
self.next_token();
assert_next_token!(self, Str(variant));
} else {
assert_next_token!(self, NewtypeVariant { name, variant });
}
value.serialize(self)
}
fn serialize_none(self) -> Result<(), Error> {
assert_next_token!(self, None);
Ok(())
}
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<(), Error>
where
T: Serialize,
{
assert_next_token!(self, Some);
value.serialize(self)
}
fn serialize_seq(self, len: Option<usize>) -> Result<Self, Error> {
assert_next_token!(self, Seq { len });
Ok(self)
}
fn serialize_tuple(self, len: usize) -> Result<Self, Error> {
assert_next_token!(self, Tuple { len });
Ok(self)
}
fn serialize_tuple_struct(self, name: &'static str, len: usize) -> Result<Self, Error> {
assert_next_token!(self, TupleStruct { name, len });
Ok(self)
}
fn serialize_tuple_variant(
self,
name: &'static str,
_variant_index: u32,
variant: &'static str,
len: usize,
) -> Result<Self::SerializeTupleVariant, Error> {
if self.tokens.first() == Some(&Token::Enum { name: name }) {
self.next_token();
assert_next_token!(self, Str(variant));
let len = Some(len);
assert_next_token!(self, Seq { len });
Ok(Variant {
ser: self,
end: Token::SeqEnd,
})
} else {
assert_next_token!(self, TupleVariant { name, variant, len });
Ok(Variant {
ser: self,
end: Token::TupleVariantEnd,
})
}
}
fn serialize_map(self, len: Option<usize>) -> Result<Self, Error> {
assert_next_token!(self, Map { len });
Ok(self)
}
fn serialize_struct(self, name: &'static str, len: usize) -> Result<Self, Error> {
assert_next_token!(self, Struct { name, len });
Ok(self)
}
fn serialize_struct_variant(
self,
name: &'static str,
_variant_index: u32,
variant: &'static str,
len: usize,
) -> Result<Self::SerializeStructVariant, Error> {
if self.tokens.first() == Some(&Token::Enum { name: name }) {
self.next_token();
assert_next_token!(self, Str(variant));
let len = Some(len);
assert_next_token!(self, Map { len });
Ok(Variant {
ser: self,
end: Token::MapEnd,
})
} else {
assert_next_token!(self, StructVariant { name, variant, len });
Ok(Variant {
ser: self,
end: Token::StructVariantEnd,
})
}
}
fn is_human_readable(&self) -> bool {
panic!(
"Types which have different human-readable and compact representations \
must explicitly mark their test cases with `serde_test::Configure`"
);
}
}
pub struct Variant<'s, 'a: 's> {
ser: &'s mut Serializer<'a>,
end: Token,
}
impl<'s, 'a> ser::SerializeSeq for &'s mut Serializer<'a> {
type Ok = ();
type Error = Error;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
where
T: Serialize,
{
value.serialize(&mut **self)
}
fn end(self) -> Result<(), Error> {
assert_next_token!(self, SeqEnd);
Ok(())
}
}
impl<'s, 'a> ser::SerializeTuple for &'s mut Serializer<'a> {
type Ok = ();
type Error = Error;
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
where
T: Serialize,
{
value.serialize(&mut **self)
}
fn end(self) -> Result<(), Error> {
assert_next_token!(self, TupleEnd);
Ok(())
}
}
impl<'s, 'a> ser::SerializeTupleStruct for &'s mut Serializer<'a> {
type Ok = ();
type Error = Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
where
T: Serialize,
{
value.serialize(&mut **self)
}
fn end(self) -> Result<(), Error> {
assert_next_token!(self, TupleStructEnd);
Ok(())
}
}
impl<'s, 'a> ser::SerializeTupleVariant for Variant<'s, 'a> {
type Ok = ();
type Error = Error;
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
where
T: Serialize,
{
value.serialize(&mut *self.ser)
}
fn end(self) -> Result<(), Error> {
match self.end {
Token::TupleVariantEnd => assert_next_token!(self.ser, TupleVariantEnd),
Token::SeqEnd => assert_next_token!(self.ser, SeqEnd),
_ => unreachable!(),
}
Ok(())
}
}
impl<'s, 'a> ser::SerializeMap for &'s mut Serializer<'a> {
type Ok = ();
type Error = Error;
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
where
T: Serialize,
{
key.serialize(&mut **self)
}
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: Serialize,
{
value.serialize(&mut **self)
}
fn end(self) -> Result<(), Self::Error> {
assert_next_token!(self, MapEnd);
Ok(())
}
}
impl<'s, 'a> ser::SerializeStruct for &'s mut Serializer<'a> {
type Ok = ();
type Error = Error;
fn serialize_field<T: ?Sized>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
where
T: Serialize,
{
key.serialize(&mut **self)?;
value.serialize(&mut **self)
}
fn end(self) -> Result<(), Self::Error> {
assert_next_token!(self, StructEnd);
Ok(())
}
}
impl<'s, 'a> ser::SerializeStructVariant for Variant<'s, 'a> {
type Ok = ();
type Error = Error;
fn serialize_field<T: ?Sized>(
&mut self,
key: &'static str,
value: &T,
) -> Result<(), Self::Error>
where
T: Serialize,
{
key.serialize(&mut *self.ser)?;
value.serialize(&mut *self.ser)
}
fn end(self) -> Result<(), Self::Error> {
match self.end {
Token::StructVariantEnd => assert_next_token!(self.ser, StructVariantEnd),
Token::MapEnd => assert_next_token!(self.ser, MapEnd),
_ => unreachable!(),
}
Ok(())
}
}
-561
View File
@@ -1,561 +0,0 @@
use std::fmt::{self, Debug, Display};
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Token {
/// A serialized `bool`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&true, &[Token::Bool(true)]);
/// ```
Bool(bool),
/// A serialized `i8`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0i8, &[Token::I8(0)]);
/// ```
I8(i8),
/// A serialized `i16`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0i16, &[Token::I16(0)]);
/// ```
I16(i16),
/// A serialized `i32`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0i32, &[Token::I32(0)]);
/// ```
I32(i32),
/// A serialized `i64`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0i64, &[Token::I64(0)]);
/// ```
I64(i64),
/// A serialized `u8`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0u8, &[Token::U8(0)]);
/// ```
U8(u8),
/// A serialized `u16`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0u16, &[Token::U16(0)]);
/// ```
U16(u16),
/// A serialized `u32`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0u32, &[Token::U32(0)]);
/// ```
U32(u32),
/// A serialized `u64`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0u64, &[Token::U64(0)]);
/// ```
U64(u64),
/// A serialized `f32`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0f32, &[Token::F32(0.0)]);
/// ```
F32(f32),
/// A serialized `f64`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0f64, &[Token::F64(0.0)]);
/// ```
F64(f64),
/// A serialized `char`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&'\n', &[Token::Char('\n')]);
/// ```
Char(char),
/// A serialized `str`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// let s = String::from("transient");
/// assert_tokens(&s, &[Token::Str("transient")]);
/// ```
Str(&'static str),
/// A borrowed `str`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// let s: &str = "borrowed";
/// assert_tokens(&s, &[Token::BorrowedStr("borrowed")]);
/// ```
BorrowedStr(&'static str),
/// A serialized `String`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// let s = String::from("owned");
/// assert_tokens(&s, &[Token::String("owned")]);
/// ```
String(&'static str),
/// A serialized `[u8]`
Bytes(&'static [u8]),
/// A borrowed `[u8]`.
BorrowedBytes(&'static [u8]),
/// A serialized `ByteBuf`
ByteBuf(&'static [u8]),
/// A serialized `Option<T>` containing none.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// let opt = None::<char>;
/// assert_tokens(&opt, &[Token::None]);
/// ```
None,
/// The header to a serialized `Option<T>` containing some value.
///
/// The tokens of the value follow after this header.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// let opt = Some('c');
/// assert_tokens(&opt, &[Token::Some, Token::Char('c')]);
/// ```
Some,
/// A serialized `()`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&(), &[Token::Unit]);
/// ```
Unit,
/// A serialized unit struct of the given name.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// struct X;
///
/// assert_tokens(&X, &[Token::UnitStruct { name: "X" }]);
/// # }
/// ```
UnitStruct { name: &'static str },
/// A unit variant of an enum.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// enum E {
/// A,
/// }
///
/// let a = E::A;
/// assert_tokens(
/// &a,
/// &[Token::UnitVariant {
/// name: "E",
/// variant: "A",
/// }],
/// );
/// # }
/// ```
UnitVariant {
name: &'static str,
variant: &'static str,
},
/// The header to a serialized newtype struct of the given name.
///
/// After this header is the value contained in the newtype struct.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// struct N(String);
///
/// let n = N("newtype".to_owned());
/// assert_tokens(
/// &n,
/// &[Token::NewtypeStruct { name: "N" }, Token::String("newtype")],
/// );
/// # }
/// ```
NewtypeStruct { name: &'static str },
/// The header to a newtype variant of an enum.
///
/// After this header is the value contained in the newtype variant.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// enum E {
/// B(u8),
/// }
///
/// let b = E::B(0);
/// assert_tokens(
/// &b,
/// &[
/// Token::NewtypeVariant {
/// name: "E",
/// variant: "B",
/// },
/// Token::U8(0),
/// ],
/// );
/// # }
/// ```
NewtypeVariant {
name: &'static str,
variant: &'static str,
},
/// The header to a sequence.
///
/// After this header are the elements of the sequence, followed by
/// `SeqEnd`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// let vec = vec!['a', 'b', 'c'];
/// assert_tokens(
/// &vec,
/// &[
/// Token::Seq { len: Some(3) },
/// Token::Char('a'),
/// Token::Char('b'),
/// Token::Char('c'),
/// Token::SeqEnd,
/// ],
/// );
/// ```
Seq { len: Option<usize> },
/// An indicator of the end of a sequence.
SeqEnd,
/// The header to a tuple.
///
/// After this header are the elements of the tuple, followed by `TupleEnd`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// let tuple = ('a', 100);
/// assert_tokens(
/// &tuple,
/// &[
/// Token::Tuple { len: 2 },
/// Token::Char('a'),
/// Token::I32(100),
/// Token::TupleEnd,
/// ],
/// );
/// ```
Tuple { len: usize },
/// An indicator of the end of a tuple.
TupleEnd,
/// The header to a tuple struct.
///
/// After this header are the fields of the tuple struct, followed by
/// `TupleStructEnd`.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// struct T(u8, u8);
///
/// let t = T(0, 0);
/// assert_tokens(
/// &t,
/// &[
/// Token::TupleStruct { name: "T", len: 2 },
/// Token::U8(0),
/// Token::U8(0),
/// Token::TupleStructEnd,
/// ],
/// );
/// # }
/// ```
TupleStruct { name: &'static str, len: usize },
/// An indicator of the end of a tuple struct.
TupleStructEnd,
/// The header to a tuple variant of an enum.
///
/// After this header are the fields of the tuple variant, followed by
/// `TupleVariantEnd`.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// enum E {
/// C(u8, u8),
/// }
///
/// let c = E::C(0, 0);
/// assert_tokens(
/// &c,
/// &[
/// Token::TupleVariant {
/// name: "E",
/// variant: "C",
/// len: 2,
/// },
/// Token::U8(0),
/// Token::U8(0),
/// Token::TupleVariantEnd,
/// ],
/// );
/// # }
/// ```
TupleVariant {
name: &'static str,
variant: &'static str,
len: usize,
},
/// An indicator of the end of a tuple variant.
TupleVariantEnd,
/// The header to a map.
///
/// After this header are the entries of the map, followed by `MapEnd`.
///
/// ```edition2021
/// # use serde_test::{assert_tokens, Token};
/// #
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert('A', 65);
/// map.insert('Z', 90);
///
/// assert_tokens(
/// &map,
/// &[
/// Token::Map { len: Some(2) },
/// Token::Char('A'),
/// Token::I32(65),
/// Token::Char('Z'),
/// Token::I32(90),
/// Token::MapEnd,
/// ],
/// );
/// ```
Map { len: Option<usize> },
/// An indicator of the end of a map.
MapEnd,
/// The header of a struct.
///
/// After this header are the fields of the struct, followed by `StructEnd`.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// struct S {
/// a: u8,
/// b: u8,
/// }
///
/// let s = S { a: 0, b: 0 };
/// assert_tokens(
/// &s,
/// &[
/// Token::Struct { name: "S", len: 2 },
/// Token::Str("a"),
/// Token::U8(0),
/// Token::Str("b"),
/// Token::U8(0),
/// Token::StructEnd,
/// ],
/// );
/// # }
/// ```
Struct { name: &'static str, len: usize },
/// An indicator of the end of a struct.
StructEnd,
/// The header of a struct variant of an enum.
///
/// After this header are the fields of the struct variant, followed by
/// `StructVariantEnd`.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// enum E {
/// D { d: u8 },
/// }
///
/// let d = E::D { d: 0 };
/// assert_tokens(
/// &d,
/// &[
/// Token::StructVariant {
/// name: "E",
/// variant: "D",
/// len: 1,
/// },
/// Token::Str("d"),
/// Token::U8(0),
/// Token::StructVariantEnd,
/// ],
/// );
/// # }
/// ```
StructVariant {
name: &'static str,
variant: &'static str,
len: usize,
},
/// An indicator of the end of a struct variant.
StructVariantEnd,
/// The header to an enum of the given name.
///
/// ```edition2021
/// # use serde_derive::{Deserialize, Serialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
/// #[derive(Serialize, Deserialize, PartialEq, Debug)]
/// enum E {
/// A,
/// B(u8),
/// C(u8, u8),
/// D { d: u8 },
/// }
///
/// let a = E::A;
/// assert_tokens(
/// &a,
/// &[Token::Enum { name: "E" }, Token::Str("A"), Token::Unit],
/// );
///
/// let b = E::B(0);
/// assert_tokens(
/// &b,
/// &[Token::Enum { name: "E" }, Token::Str("B"), Token::U8(0)],
/// );
///
/// let c = E::C(0, 0);
/// assert_tokens(
/// &c,
/// &[
/// Token::Enum { name: "E" },
/// Token::Str("C"),
/// Token::Seq { len: Some(2) },
/// Token::U8(0),
/// Token::U8(0),
/// Token::SeqEnd,
/// ],
/// );
///
/// let d = E::D { d: 0 };
/// assert_tokens(
/// &d,
/// &[
/// Token::Enum { name: "E" },
/// Token::Str("D"),
/// Token::Map { len: Some(1) },
/// Token::Str("d"),
/// Token::U8(0),
/// Token::MapEnd,
/// ],
/// );
/// # }
/// ```
Enum { name: &'static str },
}
impl Display for Token {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(self, formatter)
}
}
+5 -5
View File
@@ -2,7 +2,7 @@
name = "serde_test_suite"
version = "0.0.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
edition = "2018"
edition = "2021"
publish = false
[features]
@@ -13,9 +13,9 @@ serde = { path = "../serde" }
[dev-dependencies]
automod = "1.0.1"
fnv = "1.0"
foldhash = "0.2"
rustversion = "1.0"
serde = { path = "../serde", features = ["rc", "derive"] }
serde = { path = "../serde", features = ["rc"] }
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
serde_test = { path = "../serde_test" }
trybuild = { version = "1.0.66", features = ["diff"] }
serde_test = "1.0.176"
trybuild = { version = "1.0.108", features = ["diff"] }
+2
View File
@@ -0,0 +1,2 @@
/target/
/Cargo.lock
+9 -2
View File
@@ -2,11 +2,18 @@
name = "serde_derive_tests_no_std"
version = "0.0.0"
authors = ["David Tolnay <dtolnay@gmail.com>"]
edition = "2018"
edition = "2021"
publish = false
[dependencies]
libc = { version = "0.2", default-features = false }
serde = { path = "../../serde", default-features = false, features = ["derive"] }
serde = { path = "../../serde", default-features = false }
serde_derive = { path = "../../serde_derive" }
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
[workspace]
+11 -13
View File
@@ -1,15 +1,13 @@
#![feature(lang_items, start)]
#![no_std]
#![no_main]
#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
use core::ffi::c_int;
#[no_mangle]
extern "C" fn main(_argc: c_int, _argv: *const *const u8) -> c_int {
0
}
#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe {
@@ -19,24 +17,24 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
//////////////////////////////////////////////////////////////////////////////
use serde::{Deserialize, Serialize};
use serde_derive::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct Unit;
pub struct Unit;
#[derive(Serialize, Deserialize)]
struct Newtype(u8);
pub struct Newtype(u8);
#[derive(Serialize, Deserialize)]
struct Tuple(u8, u8);
pub struct Tuple(u8, u8);
#[derive(Serialize, Deserialize)]
struct Struct {
pub struct Struct {
f: u8,
}
#[derive(Serialize, Deserialize)]
enum Enum {
pub enum Enum {
Unit,
Newtype(u8),
Tuple(u8, u8),
+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() {
+4 -6
View File
@@ -34,9 +34,8 @@ macro_rules! hashset {
$(set.insert($value);)+
set
}};
($hasher:ident @ $($value:expr),+) => {{
use std::hash::BuildHasherDefault;
let mut set = HashSet::with_hasher(BuildHasherDefault::<$hasher>::default());
($hasher:ty; $($value:expr),+) => {{
let mut set = HashSet::<_, $hasher>::default();
$(set.insert($value);)+
set
}};
@@ -51,9 +50,8 @@ macro_rules! hashmap {
$(map.insert($key, $value);)+
map
}};
($hasher:ident @ $($key:expr => $value:expr),+) => {{
use std::hash::BuildHasherDefault;
let mut map = HashMap::with_hasher(BuildHasherDefault::<$hasher>::default());
($hasher:ty; $($key:expr => $value:expr),+) => {{
let mut map = HashMap::<_, _, $hasher>::default();
$(map.insert($key, $value);)+
map
}};
+66
View File
@@ -0,0 +1,66 @@
#![allow(dead_code)] // we do not read enum fields
use serde_derive::Deserialize;
#[derive(Deserialize)]
pub struct Nested;
#[derive(Deserialize)]
pub enum ExternallyTagged1 {
Tuple(f64, String),
Flatten {
#[serde(flatten)]
nested: Nested,
},
}
#[derive(Deserialize)]
pub enum ExternallyTagged2 {
Flatten {
#[serde(flatten)]
nested: Nested,
},
Tuple(f64, String),
}
// Internally tagged enums cannot contain tuple variants so not tested here
#[derive(Deserialize)]
#[serde(tag = "tag", content = "content")]
pub enum AdjacentlyTagged1 {
Tuple(f64, String),
Flatten {
#[serde(flatten)]
nested: Nested,
},
}
#[derive(Deserialize)]
#[serde(tag = "tag", content = "content")]
pub enum AdjacentlyTagged2 {
Flatten {
#[serde(flatten)]
nested: Nested,
},
Tuple(f64, String),
}
#[derive(Deserialize)]
#[serde(untagged)]
pub enum Untagged1 {
Tuple(f64, String),
Flatten {
#[serde(flatten)]
nested: Nested,
},
}
#[derive(Deserialize)]
#[serde(untagged)]
pub enum Untagged2 {
Flatten {
#[serde(flatten)]
nested: Nested,
},
Tuple(f64, String),
}
+11 -1
View File
@@ -1,4 +1,6 @@
use serde::Deserialize;
#![allow(dead_code)]
use serde_derive::Deserialize;
#[derive(Deserialize)]
pub struct Nested;
@@ -7,7 +9,9 @@ pub struct Nested;
pub enum ExternallyTagged {
Flatten {
#[serde(flatten)]
#[allow(dead_code)]
nested: Nested,
#[allow(dead_code)]
string: &'static str,
},
}
@@ -17,7 +21,9 @@ pub enum ExternallyTagged {
pub enum InternallyTagged {
Flatten {
#[serde(flatten)]
#[allow(dead_code)]
nested: Nested,
#[allow(dead_code)]
string: &'static str,
},
}
@@ -27,7 +33,9 @@ pub enum InternallyTagged {
pub enum AdjacentlyTagged {
Flatten {
#[serde(flatten)]
#[allow(dead_code)]
nested: Nested,
#[allow(dead_code)]
string: &'static str,
},
}
@@ -37,7 +45,9 @@ pub enum AdjacentlyTagged {
pub enum UntaggedWorkaround {
Flatten {
#[serde(flatten)]
#[allow(dead_code)]
nested: Nested,
#[allow(dead_code)]
string: &'static str,
},
}
+3 -1
View File
@@ -1,4 +1,6 @@
use serde::Deserialize;
#![allow(dead_code)]
use serde_derive::Deserialize;
macro_rules! bug {
($serde_path:literal) => {
+1
View File
@@ -2,4 +2,5 @@ use serde_derive::Serialize;
#[derive(Serialize)]
#[serde()]
#[allow(dead_code)]
pub struct S;
+48
View File
@@ -0,0 +1,48 @@
use serde_derive::{Deserialize, Serialize};
use serde_test::{assert_tokens, Token};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
enum Enum {
Simple {
a: i32,
},
Flatten {
#[serde(flatten)]
flatten: (),
a: i32,
},
}
#[test]
fn simple_variant() {
assert_tokens(
&Enum::Simple { a: 42 },
&[
Token::StructVariant {
name: "Enum",
variant: "Simple",
len: 1,
},
Token::Str("a"),
Token::I32(42),
Token::StructVariantEnd,
],
);
}
#[test]
fn flatten_variant() {
assert_tokens(
&Enum::Flatten { flatten: (), a: 42 },
&[
Token::NewtypeVariant {
name: "Enum",
variant: "Flatten",
},
Token::Map { len: None },
Token::Str("a"),
Token::I32(42),
Token::MapEnd,
],
);
}
+18
View File
@@ -0,0 +1,18 @@
#![allow(dead_code)] // we do not read enum fields
use serde_derive::Deserialize;
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub enum A {
B {
c: String,
},
D {
#[serde(flatten)]
e: E,
},
}
#[derive(Deserialize)]
pub struct E {}
+33
View File
@@ -0,0 +1,33 @@
#![allow(clippy::trivially_copy_pass_by_ref, dead_code)]
use serde_derive::{Deserialize, Serialize};
macro_rules! declare_in_macro {
($with:literal) => {
#[derive(Serialize, Deserialize)]
pub struct S {
#[serde(with = $with)]
f: i32,
}
};
}
declare_in_macro!("with");
mod with {
use serde::{Deserializer, Serializer};
pub fn serialize<S>(_: &i32, _: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
unimplemented!()
}
pub fn deserialize<'de, D>(_: D) -> Result<i32, D::Error>
where
D: Deserializer<'de>,
{
unimplemented!()
}
}
+27
View File
@@ -0,0 +1,27 @@
#![allow(clippy::trivially_copy_pass_by_ref, dead_code)]
use serde_derive::Deserialize;
macro_rules! declare_in_macro {
($with:literal) => {
#[derive(Deserialize)]
pub struct S(
#[serde(with = $with)]
#[allow(dead_code)]
i32,
);
};
}
declare_in_macro!("with");
mod with {
use serde::Deserializer;
pub fn deserialize<'de, D>(_: D) -> Result<i32, D::Error>
where
D: Deserializer<'de>,
{
unimplemented!()
}
}
File diff suppressed because it is too large Load Diff
+8 -6
View File
@@ -1,14 +1,16 @@
#![allow(
clippy::derive_partial_eq_without_eq,
clippy::items_after_statements,
clippy::used_underscore_binding
clippy::used_underscore_binding,
// We use lots of declarations inside function bodies to avoid conflicts,
// but they aren't used. We just want to make sure they compile.
dead_code,
)]
use serde::de::value::{BorrowedStrDeserializer, MapDeserializer};
use serde::de::IntoDeserializer;
use serde::{Deserialize, Deserializer};
use serde::de::{Deserialize, Deserializer, IntoDeserializer};
use serde_derive::Deserialize;
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
use std::borrow::Cow;
#[test]
@@ -163,7 +165,7 @@ fn test_cow() {
#[test]
fn test_lifetimes() {
#[derive(Deserialize)]
struct Cows<'a, 'b> {
pub struct Cows<'a, 'b> {
_copied: Cow<'a, str>,
#[serde(borrow)]
@@ -179,7 +181,7 @@ fn test_lifetimes() {
}
#[derive(Deserialize)]
struct Wrap<'a, 'b> {
pub struct Wrap<'a, 'b> {
#[serde(borrow = "'b")]
_cows: Cows<'a, 'b>,
}
+121 -12
View File
@@ -10,6 +10,10 @@
)]
#![cfg_attr(feature = "unstable", feature(never_type))]
use serde::de::value::{F32Deserializer, F64Deserializer};
use serde::de::{Deserialize, DeserializeOwned, Deserializer, IntoDeserializer};
use serde_derive::Deserialize;
use serde_test::{assert_de_tokens, Configure, Token};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::ffi::{CStr, CString, OsString};
@@ -18,7 +22,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};
@@ -27,16 +31,10 @@ use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize, Ordering,
};
use std::sync::{Arc, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};
#[cfg(target_arch = "x86_64")]
use std::sync::atomic::{AtomicI64, AtomicU64};
use fnv::FnvHasher;
use serde::de::{DeserializeOwned, IntoDeserializer};
use serde::{Deserialize, Deserializer};
use serde_test::{assert_de_tokens, Configure, Token};
use std::sync::{Arc, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};
#[macro_use]
mod macros;
@@ -46,6 +44,9 @@ mod macros;
#[derive(Copy, Clone, PartialEq, Debug, Deserialize)]
struct UnitStruct;
#[derive(Copy, Clone, PartialEq, Debug, Deserialize)]
struct GenericUnitStruct<const N: u8>;
#[derive(PartialEq, Debug, Deserialize)]
struct NewtypeStruct(i32);
@@ -91,7 +92,7 @@ struct StructSkipDefault {
#[derive(PartialEq, Debug, Deserialize)]
#[serde(default)]
struct StructSkipDefaultGeneric<T> {
pub struct StructSkipDefaultGeneric<T> {
#[serde(skip_deserializing)]
t: T,
}
@@ -831,6 +832,26 @@ fn test_f64() {
test(1.11, &[Token::F64(1.11)]);
}
#[test]
fn test_nan() {
let f32_deserializer = F32Deserializer::<serde::de::value::Error>::new;
let f64_deserializer = F64Deserializer::<serde::de::value::Error>::new;
let pos_f32_nan = f32_deserializer(f32::NAN.copysign(1.0));
let pos_f64_nan = f64_deserializer(f64::NAN.copysign(1.0));
assert!(f32::deserialize(pos_f32_nan).unwrap().is_sign_positive());
assert!(f32::deserialize(pos_f64_nan).unwrap().is_sign_positive());
assert!(f64::deserialize(pos_f32_nan).unwrap().is_sign_positive());
assert!(f64::deserialize(pos_f64_nan).unwrap().is_sign_positive());
let neg_f32_nan = f32_deserializer(f32::NAN.copysign(-1.0));
let neg_f64_nan = f64_deserializer(f64::NAN.copysign(-1.0));
assert!(f32::deserialize(neg_f32_nan).unwrap().is_sign_negative());
assert!(f32::deserialize(neg_f64_nan).unwrap().is_sign_negative());
assert!(f64::deserialize(neg_f32_nan).unwrap().is_sign_negative());
assert!(f64::deserialize(neg_f64_nan).unwrap().is_sign_negative());
}
#[test]
fn test_char() {
test('a', &[Token::Char('a')]);
@@ -883,6 +904,17 @@ fn test_unit_struct() {
test(UnitStruct, &[Token::UnitStruct { name: "UnitStruct" }]);
}
#[test]
fn test_generic_unit_struct() {
test(GenericUnitStruct::<8>, &[Token::Unit]);
test(
GenericUnitStruct::<8>,
&[Token::UnitStruct {
name: "GenericUnitStruct",
}],
);
}
#[test]
fn test_newtype_struct() {
test(
@@ -1007,7 +1039,7 @@ fn test_hashset() {
],
);
test(
hashset![FnvHasher @ 1, 2, 3],
hashset![foldhash::fast::FixedState; 1, 2, 3],
&[
Token::Seq { len: Some(3) },
Token::I32(1),
@@ -1242,7 +1274,7 @@ fn test_hashmap() {
],
);
test(
hashmap![FnvHasher @ 1 => 2, 3 => 4],
hashmap![foldhash::fast::FixedState; 1 => 2, 3 => 4],
&[
Token::Map { len: Some(2) },
Token::I32(1),
@@ -1865,6 +1897,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(
@@ -1992,6 +2064,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")]);
+16 -9
View File
@@ -5,8 +5,8 @@
)]
#![cfg_attr(feature = "unstable", feature(never_type))]
use serde::de::IntoDeserializer;
use serde::Deserialize;
use serde::de::{Deserialize, IntoDeserializer};
use serde_derive::Deserialize;
use serde_test::{assert_de_tokens_error, Token};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::ffi::{CStr, CString};
@@ -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,
],
+30
View File
@@ -0,0 +1,30 @@
#![deny(deprecated)]
#![allow(dead_code)]
use serde_derive::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[deprecated]
enum DeprecatedEnum {
A,
B,
}
#[derive(Serialize, Deserialize)]
#[deprecated]
struct DeprecatedStruct {
a: bool,
}
#[derive(Serialize, Deserialize)]
enum DeprecatedVariant {
A,
#[deprecated]
B,
}
#[derive(Serialize, Deserialize)]
struct DeprecatedField {
#[deprecated]
a: bool,
}
@@ -0,0 +1,799 @@
#![deny(trivial_numeric_casts)]
#![allow(
clippy::derive_partial_eq_without_eq,
clippy::enum_variant_names,
clippy::redundant_field_names,
clippy::too_many_lines
)]
use serde_derive::{Deserialize, Serialize};
use serde_test::{assert_de_tokens, assert_de_tokens_error, assert_tokens, Token};
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
enum AdjacentlyTagged<T> {
Unit,
Newtype(T),
Tuple(u8, u8),
Struct { f: u8 },
}
mod unit {
use super::*;
#[test]
fn map_str_tag_only() {
// Map: tag only
assert_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 1,
},
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
// Map: tag only and incorrect hint for number of elements
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
}
#[test]
fn map_int_tag_only() {
// Map: tag (as number) only
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 1,
},
Token::U16(0),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
}
#[test]
fn map_bytes_tag_only() {
// Map: tag only
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 1,
},
Token::Bytes(b"t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
// Map: tag only
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 1,
},
Token::BorrowedBytes(b"t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
}
#[test]
fn map_str_tag_content() {
// Map: tag + content
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::Str("c"),
Token::Unit,
Token::StructEnd,
],
);
// Map: content + tag
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("c"),
Token::Unit,
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
// Map: tag + content + excess fields (f, g, h)
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("f"),
Token::Unit,
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::Str("g"),
Token::Unit,
Token::Str("c"),
Token::Unit,
Token::Str("h"),
Token::Unit,
Token::StructEnd,
],
);
}
#[test]
fn map_int_tag_content() {
// Map: tag (as number) + content (as number)
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::U8(0),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::U8(1),
Token::Unit,
Token::StructEnd,
],
);
// Map: content (as number) + tag (as number)
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::U64(1),
Token::Unit,
Token::U64(0),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
}
#[test]
fn map_bytes_tag_content() {
// Map: tag + content
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::BorrowedBytes(b"t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::BorrowedBytes(b"c"),
Token::Unit,
Token::StructEnd,
],
);
// Map: content + tag
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Bytes(b"c"),
Token::Unit,
Token::Bytes(b"t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::StructEnd,
],
);
}
#[test]
fn seq_tag_content() {
// Seq: tag and content
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Seq { len: Some(2) },
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::Unit,
Token::SeqEnd,
],
);
// Seq: tag (as string) and content
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Seq { len: None },
Token::Str("Unit"), // tag
Token::Unit, // content
Token::SeqEnd,
],
);
// Seq: tag (as borrowed string) and content
assert_de_tokens(
&AdjacentlyTagged::Unit::<u8>,
&[
Token::Seq { len: None },
Token::BorrowedStr("Unit"), // tag
Token::Unit, // content
Token::SeqEnd,
],
);
}
}
mod newtype {
use super::*;
#[test]
fn map_tag_only() {
// optional newtype with no content field
assert_de_tokens(
&AdjacentlyTagged::Newtype::<Option<u8>>(None),
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 1,
},
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Newtype",
},
Token::StructEnd,
],
);
}
#[test]
fn map_tag_content() {
let value = AdjacentlyTagged::Newtype::<u8>(1);
// Map: tag + content
assert_tokens(
&value,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Newtype",
},
Token::Str("c"),
Token::U8(1),
Token::StructEnd,
],
);
// Map: content + tag
assert_de_tokens(
&value,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("c"),
Token::U8(1),
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Newtype",
},
Token::StructEnd,
],
);
}
#[test]
fn seq() {
let value = AdjacentlyTagged::Newtype::<u8>(1);
// Seq: tag and content
assert_de_tokens(
&value,
&[
Token::Seq { len: Some(2) },
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Newtype",
},
Token::U8(1),
Token::SeqEnd,
],
);
// Seq: tag (as string) and content
assert_de_tokens(
&value,
&[
Token::Seq { len: None },
Token::Str("Newtype"), // tag
Token::U8(1), // content
Token::SeqEnd,
],
);
// Seq: tag (as borrowed string) and content
assert_de_tokens(
&value,
&[
Token::Seq { len: None },
Token::BorrowedStr("Newtype"), // tag
Token::U8(1), // content
Token::SeqEnd,
],
);
}
}
#[test]
fn newtype_with_newtype() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct NewtypeStruct(u32);
assert_de_tokens(
&AdjacentlyTagged::Newtype(NewtypeStruct(5)),
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("c"),
Token::NewtypeStruct {
name: "NewtypeStruct",
},
Token::U32(5),
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Newtype",
},
Token::StructEnd,
],
);
}
mod tuple {
use super::*;
#[test]
fn map() {
let value = AdjacentlyTagged::Tuple::<u8>(1, 1);
// Map: tag + content
assert_tokens(
&value,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Tuple",
},
Token::Str("c"),
Token::Tuple { len: 2 },
Token::U8(1),
Token::U8(1),
Token::TupleEnd,
Token::StructEnd,
],
);
// Map: content + tag
assert_de_tokens(
&value,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("c"),
Token::Tuple { len: 2 },
Token::U8(1),
Token::U8(1),
Token::TupleEnd,
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Tuple",
},
Token::StructEnd,
],
);
}
#[test]
fn seq() {
let value = AdjacentlyTagged::Tuple::<u8>(1, 1);
// Seq: tag + content
assert_de_tokens(
&value,
&[
Token::Seq { len: Some(2) },
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Tuple",
},
Token::Tuple { len: 2 },
Token::U8(1),
Token::U8(1),
Token::TupleEnd,
Token::SeqEnd,
],
);
}
}
mod struct_ {
use super::*;
#[test]
fn map() {
let value = AdjacentlyTagged::Struct::<u8> { f: 1 };
// Map: tag + content
assert_tokens(
&value,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Struct",
},
Token::Str("c"),
Token::Struct {
name: "Struct",
len: 1,
},
Token::Str("f"),
Token::U8(1),
Token::StructEnd,
Token::StructEnd,
],
);
// Map: content + tag
assert_de_tokens(
&value,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("c"),
Token::Struct {
name: "Struct",
len: 1,
},
Token::Str("f"),
Token::U8(1),
Token::StructEnd,
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Struct",
},
Token::StructEnd,
],
);
}
#[test]
fn seq() {
let value = AdjacentlyTagged::Struct::<u8> { f: 1 };
// Seq: tag + content
assert_de_tokens(
&value,
&[
Token::Seq { len: Some(2) },
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Struct",
},
Token::Struct {
name: "Struct",
len: 1,
},
Token::Str("f"),
Token::U8(1),
Token::StructEnd,
Token::SeqEnd,
],
);
}
}
#[test]
fn struct_with_flatten() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(tag = "t", content = "c")]
enum Data {
A {
a: i32,
#[serde(flatten)]
flat: Flat,
},
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Flat {
b: i32,
}
let data = Data::A {
a: 0,
flat: Flat { b: 0 },
};
assert_tokens(
&data,
&[
Token::Struct {
name: "Data",
len: 2,
},
Token::Str("t"),
Token::UnitVariant {
name: "Data",
variant: "A",
},
Token::Str("c"),
Token::Map { len: None },
Token::Str("a"),
Token::I32(0),
Token::Str("b"),
Token::I32(0),
Token::MapEnd,
Token::StructEnd,
],
);
}
#[test]
fn expecting_message() {
#[derive(Deserialize)]
#[serde(tag = "tag", content = "content")]
#[serde(expecting = "something strange...")]
enum Enum {
AdjacentlyTagged,
}
assert_de_tokens_error::<Enum>(
&[Token::Str("AdjacentlyTagged")],
r#"invalid type: string "AdjacentlyTagged", expected something strange..."#,
);
assert_de_tokens_error::<Enum>(
&[Token::Map { len: None }, Token::Unit],
r#"invalid type: unit value, expected "tag", "content", or other ignored fields"#,
);
// Check that #[serde(expecting = "...")] doesn't affect variant identifier error message
assert_de_tokens_error::<Enum>(
&[Token::Map { len: None }, Token::Str("tag"), Token::Unit],
"invalid type: unit value, expected variant of enum Enum",
);
}
#[test]
fn partially_untagged() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(tag = "t", content = "c")]
enum Data {
A(u32),
B,
#[serde(untagged)]
Var(u32),
}
let data = Data::A(7);
assert_de_tokens(
&data,
&[
Token::Map { len: None },
Token::Str("t"),
Token::Str("A"),
Token::Str("c"),
Token::U32(7),
Token::MapEnd,
],
);
let data = Data::Var(42);
assert_de_tokens(&data, &[Token::U32(42)]);
// TODO test error output
}
#[test]
fn deny_unknown_fields() {
#[derive(Debug, PartialEq, Deserialize)]
#[serde(tag = "t", content = "c", deny_unknown_fields)]
enum AdjacentlyTagged {
Unit,
}
assert_de_tokens(
&AdjacentlyTagged::Unit,
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::Str("c"),
Token::Unit,
Token::StructEnd,
],
);
assert_de_tokens_error::<AdjacentlyTagged>(
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("t"),
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::Str("c"),
Token::Unit,
Token::Str("h"),
],
r#"invalid value: string "h", expected "t" or "c""#,
);
assert_de_tokens_error::<AdjacentlyTagged>(
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("h"),
],
r#"invalid value: string "h", expected "t" or "c""#,
);
assert_de_tokens_error::<AdjacentlyTagged>(
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Str("c"),
Token::Unit,
Token::Str("h"),
],
r#"invalid value: string "h", expected "t" or "c""#,
);
assert_de_tokens_error::<AdjacentlyTagged>(
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::U64(0), // tag field
Token::UnitVariant {
name: "AdjacentlyTagged",
variant: "Unit",
},
Token::U64(3),
],
r#"invalid value: integer `3`, expected "t" or "c""#,
);
assert_de_tokens_error::<AdjacentlyTagged>(
&[
Token::Struct {
name: "AdjacentlyTagged",
len: 2,
},
Token::Bytes(b"c"),
Token::Unit,
Token::Bytes(b"h"),
],
r#"invalid value: byte array, expected "t" or "c""#,
);
}
File diff suppressed because it is too large Load Diff
+583
View File
@@ -0,0 +1,583 @@
#![deny(trivial_numeric_casts)]
#![allow(
clippy::derive_partial_eq_without_eq,
clippy::enum_variant_names,
clippy::redundant_field_names,
clippy::too_many_lines
)]
mod bytes;
use serde_derive::{Deserialize, Serialize};
use serde_test::{assert_de_tokens, assert_de_tokens_error, assert_tokens, Token};
use std::collections::BTreeMap;
#[test]
fn complex() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
enum Untagged {
A { a: u8 },
B { b: u8 },
C,
D(u8),
E(String),
F(u8, u8),
}
assert_tokens(
&Untagged::A { a: 1 },
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("a"),
Token::U8(1),
Token::StructEnd,
],
);
assert_tokens(
&Untagged::B { b: 2 },
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("b"),
Token::U8(2),
Token::StructEnd,
],
);
// Serializes to unit, deserializes from either depending on format's
// preference.
assert_tokens(&Untagged::C, &[Token::Unit]);
assert_de_tokens(&Untagged::C, &[Token::None]);
assert_tokens(&Untagged::D(4), &[Token::U8(4)]);
assert_tokens(&Untagged::E("e".to_owned()), &[Token::Str("e")]);
assert_tokens(
&Untagged::F(1, 2),
&[
Token::Tuple { len: 2 },
Token::U8(1),
Token::U8(2),
Token::TupleEnd,
],
);
assert_de_tokens_error::<Untagged>(
&[Token::Tuple { len: 1 }, Token::U8(1), Token::TupleEnd],
"data did not match any variant of untagged enum Untagged",
);
assert_de_tokens_error::<Untagged>(
&[
Token::Tuple { len: 3 },
Token::U8(1),
Token::U8(2),
Token::U8(3),
Token::TupleEnd,
],
"data did not match any variant of untagged enum Untagged",
);
}
#[test]
fn newtype_unit_and_empty_map() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Unit;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
enum Message {
Unit(Unit),
Map(BTreeMap<String, String>),
}
assert_tokens(
&Message::Map(BTreeMap::new()),
&[Token::Map { len: Some(0) }, Token::MapEnd],
);
}
// Reaches crate::private::de::content::ContentRefDeserializer::deserialize_newtype_struct
#[test]
fn newtype_struct() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct NewtypeStruct(u32);
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
enum E {
Newtype(NewtypeStruct),
Null,
}
let value = E::Newtype(NewtypeStruct(5));
// Content::Newtype case
assert_tokens(
&value,
&[
Token::NewtypeStruct {
name: "NewtypeStruct",
},
Token::U32(5),
],
);
// _ case
assert_de_tokens(&value, &[Token::U32(5)]);
}
mod newtype_enum {
use super::*;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
enum Outer {
Inner(Inner),
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
enum Inner {
Unit,
Newtype(u8),
Tuple0(),
Tuple2(u8, u8),
Struct { f: u8 },
EmptyStruct {},
}
// Reaches crate::private::de::content::VariantRefDeserializer::unit_variant
#[test]
fn unit() {
assert_tokens(
&Outer::Inner(Inner::Unit),
&[Token::UnitVariant {
name: "Inner",
variant: "Unit",
}],
);
}
// Reaches crate::private::de::content::VariantRefDeserializer::newtype_variant_seed
#[test]
fn newtype() {
assert_tokens(
&Outer::Inner(Inner::Newtype(1)),
&[
Token::NewtypeVariant {
name: "Inner",
variant: "Newtype",
},
Token::U8(1),
],
);
}
// Reaches crate::private::de::content::VariantRefDeserializer::tuple_variant
#[test]
fn tuple0() {
assert_tokens(
&Outer::Inner(Inner::Tuple0()),
&[
Token::TupleVariant {
name: "Inner",
variant: "Tuple0",
len: 0,
},
Token::TupleVariantEnd,
],
);
}
// Reaches crate::private::de::content::VariantRefDeserializer::tuple_variant
#[test]
fn tuple2() {
assert_tokens(
&Outer::Inner(Inner::Tuple2(1, 1)),
&[
Token::TupleVariant {
name: "Inner",
variant: "Tuple2",
len: 2,
},
Token::U8(1),
Token::U8(1),
Token::TupleVariantEnd,
],
);
}
// Reaches crate::private::de::content::VariantRefDeserializer::struct_variant
// Content::Map case
#[test]
fn struct_from_map() {
assert_tokens(
&Outer::Inner(Inner::Struct { f: 1 }),
&[
Token::StructVariant {
name: "Inner",
variant: "Struct",
len: 1,
},
Token::Str("f"),
Token::U8(1),
Token::StructVariantEnd,
],
);
}
// Reaches crate::private::de::content::VariantRefDeserializer::struct_variant
// Content::Seq case
#[test]
fn struct_from_seq() {
assert_de_tokens(
&Outer::Inner(Inner::Struct { f: 1 }),
&[
Token::Map { len: Some(1) },
// tag
Token::Str("Struct"),
// content
Token::Seq { len: Some(1) },
Token::U8(1),
Token::SeqEnd,
Token::MapEnd,
],
);
}
// Reaches crate::private::de::content::VariantRefDeserializer::struct_variant
// Content::Map case
// Special case - empty map
#[test]
fn empty_struct_from_map() {
assert_de_tokens(
&Outer::Inner(Inner::EmptyStruct {}),
&[
Token::Map { len: Some(1) },
// tag
Token::Str("EmptyStruct"),
// content
Token::Map { len: Some(0) },
Token::MapEnd,
Token::MapEnd,
],
);
}
// Reaches crate::private::de::content::VariantRefDeserializer::struct_variant
// Content::Seq case
// Special case - empty seq
#[test]
fn empty_struct_from_seq() {
assert_de_tokens(
&Outer::Inner(Inner::EmptyStruct {}),
&[
Token::Map { len: Some(1) },
// tag
Token::Str("EmptyStruct"),
// content
Token::Seq { len: Some(0) },
Token::SeqEnd,
Token::MapEnd,
],
);
}
}
// Reaches crate::private::de::content::ContentRefDeserializer::deserialize_option
mod with_optional_field {
use super::*;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
enum Enum {
Struct { optional: Option<u32> },
Null,
}
#[test]
fn some() {
assert_tokens(
&Enum::Struct { optional: Some(42) },
&[
Token::Struct {
name: "Enum",
len: 1,
},
Token::Str("optional"),
Token::Some,
Token::U32(42),
Token::StructEnd,
],
);
}
#[test]
fn some_without_marker() {
assert_de_tokens(
&Enum::Struct { optional: Some(42) },
&[
Token::Struct {
name: "Enum",
len: 1,
},
Token::Str("optional"),
Token::U32(42),
Token::StructEnd,
],
);
}
#[test]
fn none() {
assert_tokens(
&Enum::Struct { optional: None },
&[
Token::Struct {
name: "Enum",
len: 1,
},
Token::Str("optional"),
Token::None,
Token::StructEnd,
],
);
}
#[test]
fn unit() {
assert_de_tokens(
&Enum::Struct { optional: None },
&[
Token::Map { len: None },
Token::Str("optional"),
Token::Unit,
Token::MapEnd,
],
);
}
}
#[test]
fn string_and_bytes() {
#[derive(Debug, PartialEq, Deserialize)]
#[serde(untagged)]
enum Untagged {
String {
string: String,
},
Bytes {
#[serde(with = "bytes")]
bytes: Vec<u8>,
},
}
assert_de_tokens(
&Untagged::String {
string: "\0".to_owned(),
},
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("string"),
Token::Str("\0"),
Token::StructEnd,
],
);
assert_de_tokens(
&Untagged::String {
string: "\0".to_owned(),
},
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("string"),
Token::String("\0"),
Token::StructEnd,
],
);
assert_de_tokens(
&Untagged::String {
string: "\0".to_owned(),
},
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("string"),
Token::Bytes(b"\0"),
Token::StructEnd,
],
);
assert_de_tokens(
&Untagged::String {
string: "\0".to_owned(),
},
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("string"),
Token::ByteBuf(b"\0"),
Token::StructEnd,
],
);
assert_de_tokens(
&Untagged::Bytes { bytes: vec![0] },
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("bytes"),
Token::Str("\0"),
Token::StructEnd,
],
);
assert_de_tokens(
&Untagged::Bytes { bytes: vec![0] },
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("bytes"),
Token::String("\0"),
Token::StructEnd,
],
);
assert_de_tokens(
&Untagged::Bytes { bytes: vec![0] },
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("bytes"),
Token::Bytes(b"\0"),
Token::StructEnd,
],
);
assert_de_tokens(
&Untagged::Bytes { bytes: vec![0] },
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("bytes"),
Token::ByteBuf(b"\0"),
Token::StructEnd,
],
);
assert_de_tokens(
&Untagged::Bytes { bytes: vec![0] },
&[
Token::Struct {
name: "Untagged",
len: 1,
},
Token::Str("bytes"),
Token::Seq { len: Some(1) },
Token::U8(0),
Token::SeqEnd,
Token::StructEnd,
],
);
}
#[test]
fn contains_flatten() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(untagged)]
enum Data {
A {
a: i32,
#[serde(flatten)]
flat: Flat,
},
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Flat {
b: i32,
}
let data = Data::A {
a: 0,
flat: Flat { b: 0 },
};
assert_tokens(
&data,
&[
Token::Map { len: None },
Token::Str("a"),
Token::I32(0),
Token::Str("b"),
Token::I32(0),
Token::MapEnd,
],
);
}
#[test]
fn contains_flatten_with_integer_key() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Untagged {
Variant {
#[serde(flatten)]
map: BTreeMap<u64, String>,
},
}
assert_tokens(
&Untagged::Variant {
map: {
let mut map = BTreeMap::new();
map.insert(100, "BTreeMap".to_owned());
map
},
},
&[
Token::Map { len: None },
Token::U64(100),
Token::Str("BTreeMap"),
Token::MapEnd,
],
);
}
#[test]
fn expecting_message() {
#[derive(Deserialize)]
#[serde(untagged)]
#[serde(expecting = "something strange...")]
enum Enum {
Untagged,
}
assert_de_tokens_error::<Enum>(&[Token::Str("Untagged")], "something strange...");
}
+114 -58
View File
@@ -4,6 +4,7 @@
#![deny(warnings)]
#![allow(
confusable_idents,
unknown_lints,
mixed_script_confusables,
clippy::derive_partial_eq_without_eq,
@@ -17,12 +18,16 @@
clippy::ptr_arg,
clippy::too_many_lines,
clippy::trivially_copy_pass_by_ref,
clippy::type_repetition_in_bounds
clippy::type_repetition_in_bounds,
// We use lots of declarations inside function bodies to avoid conflicts,
// but they aren't used. We just want to make sure they compile.
dead_code,
)]
#![deny(clippy::collection_is_never_read)]
use serde::de::DeserializeOwned;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
use serde::ser::{Serialize, Serializer};
use serde_derive::{Deserialize, Serialize};
use std::borrow::Cow;
use std::marker::PhantomData;
use std::option::Option as StdOption;
@@ -287,60 +292,60 @@ fn test_gen() {
assert::<EmptyEnumVariant>();
#[derive(Serialize, Deserialize)]
struct NonAsciiIdents {
pub struct NonAsciiIdents {
σ: f64,
}
#[derive(Serialize, Deserialize)]
struct EmptyBraced {}
pub struct EmptyBraced {}
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct EmptyBracedDenyUnknown {}
pub struct EmptyBracedDenyUnknown {}
#[derive(Serialize, Deserialize)]
struct BracedSkipAll {
pub struct BracedSkipAll {
#[serde(skip_deserializing)]
f: u8,
}
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct BracedSkipAllDenyUnknown {
pub struct BracedSkipAllDenyUnknown {
#[serde(skip_deserializing)]
f: u8,
}
#[derive(Serialize, Deserialize)]
struct EmptyTuple();
pub struct EmptyTuple();
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct EmptyTupleDenyUnknown();
pub struct EmptyTupleDenyUnknown();
#[derive(Serialize, Deserialize)]
struct TupleSkipAll(#[serde(skip_deserializing)] u8);
pub struct TupleSkipAll(#[serde(skip_deserializing)] u8);
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct TupleSkipAllDenyUnknown(#[serde(skip_deserializing)] u8);
pub struct TupleSkipAllDenyUnknown(#[serde(skip_deserializing)] u8);
#[derive(Serialize, Deserialize)]
enum EmptyEnum {}
pub enum EmptyEnum {}
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
enum EmptyEnumDenyUnknown {}
pub enum EmptyEnumDenyUnknown {}
#[derive(Serialize, Deserialize)]
enum EnumSkipAll {
pub enum EnumSkipAll {
#[serde(skip_deserializing)]
#[allow(dead_code)]
Variant,
}
#[derive(Serialize, Deserialize)]
enum EmptyVariants {
pub enum EmptyVariants {
Braced {},
Tuple(),
BracedSkip {
@@ -352,7 +357,7 @@ fn test_gen() {
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
enum EmptyVariantsDenyUnknown {
pub enum EmptyVariantsDenyUnknown {
Braced {},
Tuple(),
BracedSkip {
@@ -364,21 +369,21 @@ fn test_gen() {
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct UnitDenyUnknown;
pub struct UnitDenyUnknown;
#[derive(Serialize, Deserialize)]
struct EmptyArray {
pub struct EmptyArray {
empty: [X; 0],
}
enum Or<A, B> {
pub enum Or<A, B> {
A(A),
B(B),
}
#[derive(Serialize, Deserialize)]
#[serde(untagged, remote = "Or")]
enum OrDef<A, B> {
pub enum OrDef<A, B> {
A(A),
B(B),
}
@@ -390,7 +395,7 @@ fn test_gen() {
struct StrDef<'a>(&'a str);
#[derive(Serialize, Deserialize)]
struct Remote<'a> {
pub struct Remote<'a> {
#[serde(with = "OrDef")]
or: Or<u8, bool>,
#[serde(borrow, with = "StrDef")]
@@ -398,13 +403,13 @@ fn test_gen() {
}
#[derive(Serialize, Deserialize)]
enum BorrowVariant<'a> {
pub enum BorrowVariant<'a> {
#[serde(borrow, with = "StrDef")]
S(Str<'a>),
}
mod vis {
use serde::{Deserialize, Serialize};
use serde_derive::{Deserialize, Serialize};
pub struct S;
@@ -415,14 +420,14 @@ fn test_gen() {
// This would not work if SDef::serialize / deserialize are private.
#[derive(Serialize, Deserialize)]
struct RemoteVisibility {
pub struct RemoteVisibility {
#[serde(with = "vis::SDef")]
s: vis::S,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "Self")]
struct RemoteSelf;
pub struct RemoteSelf;
#[derive(Serialize, Deserialize)]
enum ExternallyTaggedVariantWith {
@@ -546,26 +551,45 @@ fn test_gen() {
assert::<FlattenWith>();
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct FlattenDenyUnknown<T> {
pub struct Flatten<T> {
#[serde(flatten)]
t: T,
}
#[derive(Serialize, Deserialize)]
struct StaticStrStruct<'a> {
#[serde(deny_unknown_fields)]
pub struct FlattenDenyUnknown<T> {
#[serde(flatten)]
t: T,
}
#[derive(Serialize, Deserialize)]
pub struct SkipDeserializing<T> {
#[serde(skip_deserializing)]
flat: T,
}
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SkipDeserializingDenyUnknown<T> {
#[serde(skip_deserializing)]
flat: T,
}
#[derive(Serialize, Deserialize)]
pub struct StaticStrStruct<'a> {
a: &'a str,
b: &'static str,
}
#[derive(Serialize, Deserialize)]
struct StaticStrTupleStruct<'a>(&'a str, &'static str);
pub struct StaticStrTupleStruct<'a>(&'a str, &'static str);
#[derive(Serialize, Deserialize)]
struct StaticStrNewtypeStruct(&'static str);
pub struct StaticStrNewtypeStruct(&'static str);
#[derive(Serialize, Deserialize)]
enum StaticStrEnum<'a> {
pub enum StaticStrEnum<'a> {
Struct { a: &'a str, b: &'static str },
Tuple(&'a str, &'static str),
Newtype(&'static str),
@@ -636,9 +660,10 @@ fn test_gen() {
mod restricted {
mod inner {
use serde::{Deserialize, Serialize};
use serde_derive::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[allow(dead_code)]
struct Restricted {
pub(super) a: usize,
pub(in super::inner) b: usize,
@@ -648,7 +673,7 @@ fn test_gen() {
#[derive(Deserialize)]
#[serde(tag = "t", content = "c")]
enum AdjacentlyTaggedVoid {}
pub enum AdjacentlyTaggedVoid {}
#[derive(Serialize, Deserialize)]
enum SkippedVariant<T> {
@@ -661,13 +686,14 @@ fn test_gen() {
assert::<SkippedVariant<X>>();
#[derive(Deserialize)]
struct ImplicitlyBorrowedOption<'a> {
pub struct ImplicitlyBorrowedOption<'a> {
option: std::option::Option<&'a str>,
}
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
enum UntaggedNewtypeVariantWith {
#[allow(dead_code)]
pub enum UntaggedNewtypeVariantWith {
Newtype(
#[serde(serialize_with = "ser_x")]
#[serde(deserialize_with = "de_x")]
@@ -677,7 +703,8 @@ fn test_gen() {
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
struct TransparentWith {
#[allow(dead_code)]
pub struct TransparentWith {
#[serde(serialize_with = "ser_x")]
#[serde(deserialize_with = "de_x")]
x: X,
@@ -685,39 +712,61 @@ fn test_gen() {
#[derive(Deserialize)]
#[serde(untagged)]
enum UntaggedWithBorrow<'a> {
Single(#[serde(borrow)] RelObject<'a>),
Many(#[serde(borrow)] Vec<RelObject<'a>>),
#[allow(dead_code)]
pub enum UntaggedWithBorrow<'a> {
Single(
#[serde(borrow)]
#[allow(dead_code)]
RelObject<'a>,
),
Many(
#[serde(borrow)]
#[allow(dead_code)]
Vec<RelObject<'a>>,
),
}
#[derive(Deserialize)]
struct RelObject<'a> {
pub struct RelObject<'a> {
ty: &'a str,
id: String,
}
#[derive(Serialize, Deserialize)]
struct FlattenSkipSerializing<T> {
pub struct FlattenSkipSerializing<T> {
#[serde(flatten, skip_serializing)]
#[allow(dead_code)]
flat: T,
}
#[derive(Serialize, Deserialize)]
struct FlattenSkipSerializingIf<T> {
pub struct FlattenSkipSerializingIf<T> {
#[serde(flatten, skip_serializing_if = "StdOption::is_none")]
flat: StdOption<T>,
}
#[derive(Serialize, Deserialize)]
struct FlattenSkipDeserializing<T> {
pub struct FlattenSkipDeserializing<T> {
#[serde(flatten, skip_deserializing)]
flat: T,
}
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum Inner<T> {
Builder {
s: T,
#[serde(flatten)]
o: T,
},
Default {
s: T,
},
}
// https://github.com/serde-rs/serde/issues/1804
#[derive(Serialize, Deserialize)]
enum Message {
pub enum Message {
#[serde(skip)]
#[allow(dead_code)]
String(String),
@@ -726,7 +775,8 @@ fn test_gen() {
}
#[derive(Serialize)]
#[repr(packed)]
#[repr(C, packed)]
#[allow(dead_code)]
struct Packed {
x: u8,
y: u16,
@@ -735,7 +785,7 @@ fn test_gen() {
macro_rules! deriving {
($field:ty) => {
#[derive(Deserialize)]
struct MacroRules<'a> {
pub struct MacroRules<'a> {
field: $field,
}
};
@@ -750,16 +800,22 @@ fn test_gen() {
}
#[derive(Deserialize)]
struct BorrowLifetimeInsideMacro<'a> {
pub struct BorrowLifetimeInsideMacro<'a> {
#[serde(borrow = "'a")]
f: mac!(Cow<'a, str>),
pub f: mac!(Cow<'a, str>),
}
#[derive(Serialize)]
struct Struct {
pub struct Struct {
#[serde(serialize_with = "vec_first_element")]
vec: Vec<Self>,
pub vec: Vec<Self>,
}
assert_ser::<Struct>();
#[derive(Deserialize)]
#[serde(bound(deserialize = "[&'de str; N]: Copy"))]
pub struct GenericUnitStruct<const N: usize>;
}
//////////////////////////////////////////////////////////////////////////
@@ -834,7 +890,7 @@ pub fn is_zero(n: &u8) -> bool {
*n == 0
}
fn vec_first_element<T, S>(vec: &Vec<T>, serializer: S) -> StdResult<S::Ok, S::Error>
fn vec_first_element<T, S>(vec: &[T], serializer: S) -> StdResult<S::Ok, S::Error>
where
T: Serialize,
S: Serializer,
@@ -846,7 +902,7 @@ where
#[derive(Debug, PartialEq, Deserialize)]
#[serde(tag = "tag")]
enum InternallyTagged {
pub enum InternallyTagged {
#[serde(deserialize_with = "deserialize_generic")]
Unit,
@@ -867,14 +923,14 @@ where
//////////////////////////////////////////////////////////////////////////
#[repr(packed)]
#[repr(C, packed)]
pub struct RemotePacked {
pub a: u16,
pub b: u32,
}
#[derive(Serialize)]
#[repr(packed)]
#[repr(C, packed)]
#[serde(remote = "RemotePacked")]
pub struct RemotePackedDef {
a: u16,
@@ -885,14 +941,14 @@ impl Drop for RemotePackedDef {
fn drop(&mut self) {}
}
#[repr(packed)]
#[repr(C, packed)]
pub struct RemotePackedNonCopy {
pub a: u16,
pub b: String,
}
#[derive(Deserialize)]
#[repr(packed)]
#[repr(C, packed)]
#[serde(remote = "RemotePackedNonCopy")]
pub struct RemotePackedNonCopyDef {
a: u16,
+159 -59
View File
@@ -2,87 +2,187 @@
#![allow(clippy::derive_partial_eq_without_eq)]
use serde::Deserialize;
use serde_test::{assert_de_tokens, Token};
use serde_derive::Deserialize;
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
mod variant_identifier {
use super::*;
#[test]
fn test_variant_identifier() {
#[derive(Deserialize, Debug, PartialEq)]
#[serde(variant_identifier)]
enum V {
Aaa,
#[serde(alias = "Ccc", alias = "Ddd")]
Bbb,
}
assert_de_tokens(&V::Aaa, &[Token::U8(0)]);
assert_de_tokens(&V::Aaa, &[Token::U16(0)]);
assert_de_tokens(&V::Aaa, &[Token::U32(0)]);
assert_de_tokens(&V::Aaa, &[Token::U64(0)]);
assert_de_tokens(&V::Aaa, &[Token::Str("Aaa")]);
assert_de_tokens(&V::Aaa, &[Token::Bytes(b"Aaa")]);
#[test]
fn variant1() {
assert_de_tokens(&V::Aaa, &[Token::U8(0)]);
assert_de_tokens(&V::Aaa, &[Token::U16(0)]);
assert_de_tokens(&V::Aaa, &[Token::U32(0)]);
assert_de_tokens(&V::Aaa, &[Token::U64(0)]);
assert_de_tokens(&V::Aaa, &[Token::Str("Aaa")]);
assert_de_tokens(&V::Aaa, &[Token::Bytes(b"Aaa")]);
}
#[test]
fn aliases() {
assert_de_tokens(&V::Bbb, &[Token::U8(1)]);
assert_de_tokens(&V::Bbb, &[Token::U16(1)]);
assert_de_tokens(&V::Bbb, &[Token::U32(1)]);
assert_de_tokens(&V::Bbb, &[Token::U64(1)]);
assert_de_tokens(&V::Bbb, &[Token::Str("Bbb")]);
assert_de_tokens(&V::Bbb, &[Token::Bytes(b"Bbb")]);
assert_de_tokens(&V::Bbb, &[Token::Str("Ccc")]);
assert_de_tokens(&V::Bbb, &[Token::Bytes(b"Ccc")]);
assert_de_tokens(&V::Bbb, &[Token::Str("Ddd")]);
assert_de_tokens(&V::Bbb, &[Token::Bytes(b"Ddd")]);
}
#[test]
fn unknown() {
assert_de_tokens_error::<V>(
&[Token::U8(42)],
"invalid value: integer `42`, expected variant index 0 <= i < 2",
);
assert_de_tokens_error::<V>(
&[Token::U16(42)],
"invalid value: integer `42`, expected variant index 0 <= i < 2",
);
assert_de_tokens_error::<V>(
&[Token::U32(42)],
"invalid value: integer `42`, expected variant index 0 <= i < 2",
);
assert_de_tokens_error::<V>(
&[Token::U64(42)],
"invalid value: integer `42`, expected variant index 0 <= i < 2",
);
assert_de_tokens_error::<V>(
&[Token::Str("Unknown")],
"unknown variant `Unknown`, expected one of `Aaa`, `Bbb`, `Ccc`, `Ddd`",
);
assert_de_tokens_error::<V>(
&[Token::Bytes(b"Unknown")],
"unknown variant `Unknown`, expected one of `Aaa`, `Bbb`, `Ccc`, `Ddd`",
);
}
}
#[test]
fn test_field_identifier() {
mod field_identifier {
use super::*;
#[derive(Deserialize, Debug, PartialEq)]
#[serde(field_identifier, rename_all = "snake_case")]
enum F {
Aaa,
#[serde(alias = "ccc", alias = "ddd")]
Bbb,
}
assert_de_tokens(&F::Aaa, &[Token::U8(0)]);
assert_de_tokens(&F::Aaa, &[Token::U16(0)]);
assert_de_tokens(&F::Aaa, &[Token::U32(0)]);
assert_de_tokens(&F::Aaa, &[Token::U64(0)]);
assert_de_tokens(&F::Aaa, &[Token::Str("aaa")]);
assert_de_tokens(&F::Aaa, &[Token::Bytes(b"aaa")]);
}
#[test]
fn test_unit_fallthrough() {
#[derive(Deserialize, Debug, PartialEq)]
#[serde(field_identifier, rename_all = "snake_case")]
enum F {
Aaa,
Bbb,
#[serde(other)]
Other,
#[test]
fn field1() {
assert_de_tokens(&F::Aaa, &[Token::U8(0)]);
assert_de_tokens(&F::Aaa, &[Token::U16(0)]);
assert_de_tokens(&F::Aaa, &[Token::U32(0)]);
assert_de_tokens(&F::Aaa, &[Token::U64(0)]);
assert_de_tokens(&F::Aaa, &[Token::Str("aaa")]);
assert_de_tokens(&F::Aaa, &[Token::Bytes(b"aaa")]);
}
assert_de_tokens(&F::Other, &[Token::U8(42)]);
assert_de_tokens(&F::Other, &[Token::U16(42)]);
assert_de_tokens(&F::Other, &[Token::U32(42)]);
assert_de_tokens(&F::Other, &[Token::U64(42)]);
assert_de_tokens(&F::Other, &[Token::Str("x")]);
}
#[test]
fn aliases() {
assert_de_tokens(&F::Bbb, &[Token::U8(1)]);
assert_de_tokens(&F::Bbb, &[Token::U16(1)]);
assert_de_tokens(&F::Bbb, &[Token::U32(1)]);
assert_de_tokens(&F::Bbb, &[Token::U64(1)]);
#[test]
fn test_newtype_fallthrough() {
#[derive(Deserialize, Debug, PartialEq)]
#[serde(field_identifier, rename_all = "snake_case")]
enum F {
Aaa,
Bbb,
Other(String),
assert_de_tokens(&F::Bbb, &[Token::Str("bbb")]);
assert_de_tokens(&F::Bbb, &[Token::Bytes(b"bbb")]);
assert_de_tokens(&F::Bbb, &[Token::Str("ccc")]);
assert_de_tokens(&F::Bbb, &[Token::Bytes(b"ccc")]);
assert_de_tokens(&F::Bbb, &[Token::Str("ddd")]);
assert_de_tokens(&F::Bbb, &[Token::Bytes(b"ddd")]);
}
assert_de_tokens(&F::Other("x".to_owned()), &[Token::Str("x")]);
}
#[test]
fn test_newtype_fallthrough_generic() {
#[derive(Deserialize, Debug, PartialEq)]
#[serde(field_identifier, rename_all = "snake_case")]
enum F<T> {
Aaa,
Bbb,
Other(T),
#[test]
fn unknown() {
assert_de_tokens_error::<F>(
&[Token::U8(42)],
"invalid value: integer `42`, expected field index 0 <= i < 2",
);
assert_de_tokens_error::<F>(
&[Token::U16(42)],
"invalid value: integer `42`, expected field index 0 <= i < 2",
);
assert_de_tokens_error::<F>(
&[Token::U32(42)],
"invalid value: integer `42`, expected field index 0 <= i < 2",
);
assert_de_tokens_error::<F>(
&[Token::U64(42)],
"invalid value: integer `42`, expected field index 0 <= i < 2",
);
assert_de_tokens_error::<F>(
&[Token::Str("unknown")],
"unknown field `unknown`, expected one of `aaa`, `bbb`, `ccc`, `ddd`",
);
assert_de_tokens_error::<F>(
&[Token::Bytes(b"unknown")],
"unknown field `unknown`, expected one of `aaa`, `bbb`, `ccc`, `ddd`",
);
}
assert_de_tokens(&F::Other(42u8), &[Token::U8(42)]);
assert_de_tokens(&F::Other(42u16), &[Token::U16(42)]);
assert_de_tokens(&F::Other(42u32), &[Token::U32(42)]);
assert_de_tokens(&F::Other(42u64), &[Token::U64(42)]);
assert_de_tokens(&F::Other("x".to_owned()), &[Token::Str("x")]);
#[test]
fn unit_fallthrough() {
#[derive(Deserialize, Debug, PartialEq)]
#[serde(field_identifier, rename_all = "snake_case")]
enum F {
Aaa,
Bbb,
#[serde(other)]
Other,
}
assert_de_tokens(&F::Other, &[Token::U8(42)]);
assert_de_tokens(&F::Other, &[Token::U16(42)]);
assert_de_tokens(&F::Other, &[Token::U32(42)]);
assert_de_tokens(&F::Other, &[Token::U64(42)]);
assert_de_tokens(&F::Other, &[Token::Str("x")]);
}
#[test]
fn newtype_fallthrough() {
#[derive(Deserialize, Debug, PartialEq)]
#[serde(field_identifier, rename_all = "snake_case")]
enum F {
Aaa,
Bbb,
Other(String),
}
assert_de_tokens(&F::Other("x".to_owned()), &[Token::Str("x")]);
}
#[test]
fn newtype_fallthrough_generic() {
#[derive(Deserialize, Debug, PartialEq)]
#[serde(field_identifier, rename_all = "snake_case")]
enum F<T> {
Aaa,
Bbb,
Other(T),
}
assert_de_tokens(&F::Other(42u8), &[Token::U8(42)]);
assert_de_tokens(&F::Other(42u16), &[Token::U16(42)]);
assert_de_tokens(&F::Other(42u32), &[Token::U32(42)]);
assert_de_tokens(&F::Other(42u64), &[Token::U64(42)]);
assert_de_tokens(&F::Other("x".to_owned()), &[Token::Str("x")]);
}
}
+4 -2
View File
@@ -2,9 +2,11 @@
use serde::de::value::{Error, MapDeserializer, SeqDeserializer};
use serde::de::{
DeserializeSeed, EnumAccess, IgnoredAny, IntoDeserializer, VariantAccess, Visitor,
Deserialize, DeserializeSeed, Deserializer, EnumAccess, IgnoredAny, IntoDeserializer,
VariantAccess, Visitor,
};
use serde::{forward_to_deserialize_any, Deserialize, Deserializer};
use serde::forward_to_deserialize_any;
use serde_derive::Deserialize;
#[derive(PartialEq, Debug, Deserialize)]
enum Target {
File diff suppressed because it is too large Load Diff
+37 -2
View File
@@ -1,20 +1,23 @@
#![allow(clippy::redundant_field_names)]
#![allow(clippy::redundant_field_names, dead_code)]
use serde::{Deserialize, Serialize};
use serde_derive::{Deserialize, Serialize};
mod remote {
pub struct Unit;
pub struct PrimitivePriv(u8);
#[allow(dead_code)]
pub struct PrimitivePub(pub u8);
pub struct NewtypePriv(Unit);
#[allow(dead_code)]
pub struct NewtypePub(pub Unit);
pub struct TuplePriv(u8, Unit);
#[allow(dead_code)]
pub struct TuplePub(pub u8, pub Unit);
pub struct StructPriv {
@@ -22,6 +25,7 @@ mod remote {
b: Unit,
}
#[allow(dead_code)]
pub struct StructPub {
pub a: u8,
pub b: Unit,
@@ -86,12 +90,14 @@ mod remote {
}
}
#[allow(dead_code)]
pub enum EnumGeneric<T> {
Variant(T),
}
}
#[derive(Serialize, Deserialize)]
#[allow(dead_code)]
struct Test {
#[serde(with = "UnitDef")]
unit: remote::Unit,
@@ -125,10 +131,14 @@ struct Test {
#[serde(with = "EnumConcrete")]
enum_concrete: remote::EnumGeneric<u8>,
#[serde(with = "ErrorKindDef")]
io_error_kind: ErrorKind,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::Unit")]
#[allow(dead_code)]
struct UnitDef;
#[derive(Serialize, Deserialize)]
@@ -137,6 +147,7 @@ struct PrimitivePrivDef(#[serde(getter = "remote::PrimitivePriv::get")] u8);
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::PrimitivePub")]
#[allow(dead_code)]
struct PrimitivePubDef(u8);
#[derive(Serialize, Deserialize)]
@@ -145,6 +156,7 @@ struct NewtypePrivDef(#[serde(getter = "remote::NewtypePriv::get", with = "UnitD
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::NewtypePub")]
#[allow(dead_code)]
struct NewtypePubDef(#[serde(with = "UnitDef")] remote::Unit);
#[derive(Serialize, Deserialize)]
@@ -156,6 +168,7 @@ struct TuplePrivDef(
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::TuplePub")]
#[allow(dead_code)]
struct TuplePubDef(u8, #[serde(with = "UnitDef")] remote::Unit);
#[derive(Serialize, Deserialize)]
@@ -171,6 +184,7 @@ struct StructPrivDef {
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructPub")]
#[allow(dead_code)]
struct StructPubDef {
a: u8,
@@ -187,16 +201,37 @@ struct StructGenericWithGetterDef<T> {
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructGeneric<u8>")]
#[allow(dead_code)]
struct StructConcrete {
value: u8,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::EnumGeneric<u8>")]
#[allow(dead_code)]
enum EnumConcrete {
Variant(u8),
}
#[derive(Debug)]
#[allow(dead_code)]
enum ErrorKind {
NotFound,
PermissionDenied,
#[allow(dead_code)]
ConnectionRefused,
}
#[derive(Serialize, Deserialize)]
#[serde(remote = "ErrorKind")]
#[non_exhaustive]
#[allow(dead_code)]
enum ErrorKindDef {
NotFound,
PermissionDenied,
// ...
}
impl From<PrimitivePrivDef> for remote::PrimitivePriv {
fn from(def: PrimitivePrivDef) -> Self {
remote::PrimitivePriv::new(def.0)

Some files were not shown because too many files have changed in this diff Show More