4278 Commits

Author SHA1 Message Date
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:🇩🇪: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