Commit Graph

812 Commits

Author SHA1 Message Date
Baptiste de Montangon
957ef206d1
Revisit of the representation of adjacently tagged enums tag 2023-07-31 20:53:02 +02:00
David Tolnay
033d05f70b
Release 1.0.180 2023-07-31 11:16:12 -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
48aa054f53
Release 1.0.178 2023-07-28 16:09:39 -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
0676673ca5
Release 1.0.177 2023-07-27 10:51:22 -07:00
Jonas Platte
31a0e73489
Update error span for attribute / data kind mismatches 2023-07-27 10:47:45 +02: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
30db83fc44
Restore bare_trait_objects lint within serde_derive code 2023-07-26 14:18:25 -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
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
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
6140b6f527
Release 1.0.175 2023-07-23 20:07:32 -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
bb51e68f16 Keep aliases sorted 2023-07-23 15:21:21 +05: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
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
07dcc4f7fe
Remove unneeded 'include' Cargo.toml entries 2023-07-19 13:44:55 -07:00
David Tolnay
2027088741
Support precompiled deserialize_in_place 2023-07-19 12:27:37 -07:00
David Tolnay
9e8f14816b
Add experiment to produce precompiled builds of serde_derive 2023-07-18 13:37:36 -07: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
Baptiste de Montangon
89c8d85de9 allow Deserialize derive to handle generic unit structs 2023-07-10 01:31:40 +02:00
David Tolnay
6502838f27
Release 1.0.170 2023-07-09 11:17:30 -07:00
David Tolnay
8264e002a7
Reject suffixed string literals inside serde attrs 2023-07-09 11:13:24 -07:00
David Tolnay
3fb5e71c33
Release 1.0.169 2023-07-08 21:09:08 -07:00
David Tolnay
296db177e2
Pull in syn fix for issue 2414 2023-07-08 21:08:22 -07:00
David Tolnay
09b78b24e9
Release 1.0.168 2023-07-08 17:52:06 -07:00
David Tolnay
807bd20a64
Release 1.0.167 2023-07-06 16:25:48 -07:00
David Tolnay
ed9a140348
Merge pull request #2444 from Mingun/dedup
Simplify code for generation of struct deserializers
2023-07-06 16:25:15 -07:00
David Tolnay
92bfc8d3af
Merge pull request #2290 from Mingun/enum-tests-and-cleanup
Remove unused `impl` and unnecessary struct-wrapper around tuple
2023-07-06 16:02:27 -07:00
David Tolnay
fa0312ac45
More formatting of doc tests and example code 2023-07-06 15:56:47 -07:00
David Tolnay
0666fbfa20
Update documentation example code to 2021 edition 2023-07-06 15:17:05 -07:00
David Tolnay
d640b5624f
Add no-alloc category to the macro crate also 2023-07-03 14:05:32 -07:00
David Tolnay
48479e4bae
Release 1.0.166 2023-07-03 11:33:19 -07:00
David Tolnay
dcbc3e0162
Release 1.0.165 2023-07-03 04:21:59 -07:00
David Tolnay
0289d31724
Fix -Zminimal-versions build 2023-07-03 04:21:14 -07:00
David Tolnay
6b4e75520a
Resolve explicit_iter_loop pedantic clippy lint
error: it is more concise to loop over references to containers instead of using explicit iteration methods
        --> serde/src/private/de.rs:2761:22
         |
    2761 |         for entry in self.0.iter_mut() {
         |                      ^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *self.0`
         |
         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop
         = note: `-D clippy::explicit-iter-loop` implied by `-D clippy::pedantic`

    error: it is more concise to loop over references to containers instead of using explicit iteration methods
       --> serde_derive/src/internals/check.rs:202:20
        |
    202 |     for variant in variants.iter() {
        |                    ^^^^^^^^^^^^^^^ help: to write this more concisely, try: `variants`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop
        = note: `-D clippy::explicit-iter-loop` implied by `-D clippy::pedantic`

    error: it is more concise to loop over references to containers instead of using explicit iteration methods
       --> serde_derive/src/bound.rs:262:28
        |
    262 |             for variant in variants.iter() {
        |                            ^^^^^^^^^^^^^^^ help: to write this more concisely, try: `variants`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_iter_loop
2023-07-02 21:08:44 -07:00
David Tolnay
b053b4f492
Touch up early return in Enum checks 2023-07-02 21:08:44 -07:00
Mingun
4cf1fec575 Replace several linked variables with enumeration for tuples 2023-06-26 20:55:52 +05:00
Mingun
ee7d77defa Replace several linked variables with enumeration for structs 2023-06-26 20:55:52 +05:00
Mingun
d0dfc4577e Replace enum with boolean parameter 2023-06-26 20:55:52 +05:00
Mingun
bbbd1d24c9 Move deserialize_generated_identifier out from if because the call is same in both arms 2023-06-26 20:55:51 +05:00
Mingun
fb3a9e0d7c Simplify check for missing fields 2023-06-26 20:55:51 +05:00
Mingun
5ffebeb6ef Actually, field_names_idents can be calculated using the same code in both cases
When !cattrs.has_flatten() all fields is !field.attrs.flatten()

Co-authored-by: Oliver Schneider <oli-obk@users.noreply.github.com>
2023-06-26 20:55:51 +05:00
Mingun
75db73066b Inline deserialize_struct_as_map_visitor and deserialize_struct_as_struct_visitor 2023-06-26 20:55:51 +05:00
Mingun
2796833c82 Pull up call to deserialize_map because it's identical 2023-06-26 20:55:50 +05:00
Mingun
95730dc7f7 Reorder variables to match order in final quote! 2023-06-26 20:55:50 +05:00
Mingun
795261919f Generate visit_seq only when needed 2023-06-26 20:55:50 +05:00
Mingun
3783a30ae7 Remove TaggedContent, replace it by a tuple
That type does not give any benefits so we can avoid that hidden public but no-API struct
2023-06-24 20:49:49 +05:00
Mingun
780a461d92 Generate one deserializer rather than in each arm 2023-06-24 20:48:08 +05:00
David Tolnay
20a48c9580
Remove .clippy.toml in favor of respecting rust-version from Cargo.toml 2023-06-15 18:31:38 -07:00
David Tolnay
8a4dfa7231
Merge pull request #2466 from Mingun/fix-de-count-of-field
Fix incorrect count of fields passed to tuple deserialization methods
2023-06-07 22:13:08 -07:00
David Tolnay
107018c628
Release 1.0.164 2023-06-07 22:05:07 -07:00
David Tolnay
a398237930
Point out serde(untagged) variants which are out of order
Previously if someone wrote an enum containing:

- `A` (untagged)
- `B` (tagged)
- `C` (tagged)
- `D` (untagged)
- `E` (tagged)
- `F` (untagged)

serde_derive would produce errors referring to B and E only, saying
you're supposed to put untagged variants at the end. The choice of B and
E for this error doesn't make a lot of sense because in order to resolve
the issue, the user must either:

- move A and D down

or:

- move B, C, and E up.

This commit changes the error to appear on A and D instead.
2023-06-07 21:49:30 -07:00
David Tolnay
f60324e883
Reuse a single ContentRefDeserializer throughout untagged enum deserialization 2023-06-07 21:33:14 -07:00
David Tolnay
361c23a09a
Simplify enumerate().find(...) -> Iterator::position 2023-06-07 21:23:31 -07:00
David Tolnay
43b23c7ea0
Format PR 2403 with rustfmt 2023-06-07 21:18:30 -07:00
David Tolnay
6081497506
Resolve semicolon_if_nothing_returned pedantic clippy lint
error: consider adding a `;` to the last statement for consistent formatting
       --> serde_derive/src/internals/ast.rs:161:13
        |
    161 |             seen_untagged = variant.attrs.untagged()
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `seen_untagged = variant.attrs.untagged();`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
        = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D clippy::pedantic`

    error: consider adding a `;` to the last statement for consistent formatting
       --> serde_derive/src/internals/ast.rs:159:17
        |
    159 | ...   cx.error_spanned_by(&variant.ident, "all variants with the #[serde(untagged)] attribute must be placed at the end of the enum")
        |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `cx.error_spanned_by(&variant.ident, "all variants with the #[serde(untagged)] attribute must be placed at the end of the enum");`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
2023-06-07 21:17:24 -07:00
David Ewert
48e5753e76
Allowed Enum variants to be individually marked as untagged (#2403) 2023-06-07 20:58:59 -07:00
Mingun
2c1f62d4b4 Fix incorrect count of fields passed to tuple deserialization methods
This count should mean the number of fields expected in the serialized form,
so if some fields are skipped, they shouldn't be counted

Methods affected:
- Deserializer::deserialize_tuple
- Deserializer::deserialize_tuple_struct
- VariantAccess::tuple_variant
2023-05-28 23:17:05 +05:00
David Tolnay
7c2c12aa43
Use syn::Error's combine() API instead of Vec<syn::Error> 2023-05-25 08:10:14 -07:00
David Tolnay
fccb9499bc
Release 1.0.163 2023-05-10 00:47:53 -07:00
David Tolnay
a139ab2572
Adjust PR 2446 with less overgeneralized name 2023-05-10 00:45:52 -07:00
Mingun
ab6588ef74 Extract duplicated code into a function 2023-05-08 10:39:30 +05:00
Taiki Endo
ef2a7c753f Remove build script from serde_derive
The current serde_derive's MSRV is 1.56, and both underscore consts and
ptr::addr_of! are always available.
2023-05-06 05:34:38 +09:00
David Tolnay
99f165b45a
Release 1.0.162 2023-05-04 18:46:55 -07:00
David Tolnay
3e4a23cbd0
Release 1.0.161 2023-05-04 16:45:18 -07:00
David Tolnay
0c6a2bbf79
Release 1.0.160 2023-04-10 22:15:49 -07:00
Michael Goulet
5f3fd9994e Make serializer/deserializer internals doc(hidden) 2023-04-10 21:41:50 -07:00
David Tolnay
d6de911855
Release 1.0.159 2023-03-27 22:05:58 -07:00
David Tolnay
4cb8d079f8
Accept empty #[serde()] attribute 2023-03-27 22:00:46 -07:00
David Tolnay
e3058105f0
Release 1.0.158 2023-03-20 04:24:27 -07:00
David Tolnay
dc200a6450
Reformat comments of non-public serde_derive internals
Fixes these being treated as "tests" by `cargo test` in serde_derive:

    running 3 tests
    test src/internals/check.rs - internals::check::check_remote_generic (line 23) ... FAILED
    test src/internals/check.rs - internals::check::check_remote_generic (line 29) ... FAILED
    test src/lib.rs - (line 3) ... ok

    failures:

    ---- src/internals/check.rs - internals::check::check_remote_generic (line 23) stdout ----
    error: unknown start of token: \u{2026}
     --> src/internals/check.rs:25:20
      |
    4 | struct Generic<T> {…}
      |                    ^

    error: cannot find attribute `serde` in this scope
     --> src/internals/check.rs:24:3
      |
    3 | #[serde(remote = "Generic")]
      |   ^^^^^
      |
      = note: `serde` is in scope, but it is a crate, not an attribute

    error[E0392]: parameter `T` is never used
     --> src/internals/check.rs:25:16
      |
    4 | struct Generic<T> {…}
      |                ^ unused parameter
      |
      = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
      = help: if you intended `T` to be a const parameter, use `const T: usize` instead

    ---- src/internals/check.rs - internals::check::check_remote_generic (line 29) stdout ----
    error: unknown start of token: \u{2026}
     --> src/internals/check.rs:31:21
      |
    4 | struct ConcreteDef {…}
      |                     ^

    error: cannot find attribute `serde` in this scope
     --> src/internals/check.rs:30:3
      |
    3 | #[serde(remote = "Generic<T>")]
      |   ^^^^^
      |
      = note: `serde` is in scope, but it is a crate, not an attribute
2023-03-20 04:23:46 -07:00
David Tolnay
dd460f82a1
Check for None-delimited group in attribute value 2023-03-20 04:16:52 -07:00
David Tolnay
479a00a215
Release 1.0.157 2023-03-17 17:35:09 -07:00
David Tolnay
c42e7c8012
Reflect serde_derive required compiler in build script and rust-version metadata 2023-03-17 17:34:46 -07:00
David Tolnay
bc22641359
Rewrite attribute parser using parse_nested_meta 2023-03-17 17:23:56 -07:00
David Tolnay
32f0d00ff9
Update to syn 2 2023-03-17 17:17:40 -07:00
David Tolnay
54671259aa
Release 1.0.156 2023-03-14 01:02:18 -07:00
David Tolnay
2ba406726f
Release 1.0.155 2023-03-11 12:57:53 -08:00
David Tolnay
8b1887c440
Remove unneeded attr_name argument when parsing borrow attr 2023-03-11 11:35:03 -08:00
David Tolnay
e106feb5ec
Eagerly parse variant-level borrow attribute instead of deferring entire Meta 2023-03-11 11:25:00 -08:00
David Tolnay
b7b636a23f
Treat field-level borrow attr as duplicate of variant-level borrow attr 2023-03-11 11:17:40 -08:00
David Tolnay
183b91775e
Fix some comments in parsing of from/try_from/into attributes 2023-03-10 14:16:11 -08:00