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.
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.
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...
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<'_>,
|