mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-22 20:41:07 +00:00
Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 58a8d22931 | |||
| ef0ed22593 | |||
| 79925ac394 | |||
| b60e4092ec | |||
| fdc36e5c06 | |||
| 49e11ce1ba | |||
| 7ae1b5f8f3 | |||
| 1ac054b34a | |||
| 1e36ef551d | |||
| 0058c7226e | |||
| 29d4f3e887 | |||
| 1b8310d98a | |||
| af4c388dff | |||
| 09f6d9361d | |||
| 1f9eb8300f | |||
| c6a5be7f6a | |||
| 0a06af8d21 | |||
| 3393ad6760 | |||
| 830309fcb5 | |||
| ab4f3f3111 | |||
| 00460b8dee | |||
| d4486be2b9 | |||
| 991e344804 | |||
| 6a7de26e5a | |||
| 5382ef3b0b | |||
| a8cbc9184e | |||
| 966e9ccf0c | |||
| 53ade10137 | |||
| 422c719352 | |||
| 3415619bfd | |||
| 04bb76bc00 | |||
| 8b0f482666 | |||
| 4b3178b053 | |||
| 8e1ae68569 | |||
| 31000e1874 | |||
| 4487cb26c7 | |||
| aba4e18553 | |||
| c82f2580b4 | |||
| 1d7b009aec | |||
| 8b769fcc20 | |||
| 9c954264f4 | |||
| 74b538b8ec | |||
| 291ec50d98 | |||
| 21c7fd1bd5 |
@@ -0,0 +1 @@
|
|||||||
|
github: dtolnay
|
||||||
@@ -95,13 +95,16 @@ jobs:
|
|||||||
- run: cd serde && cargo build
|
- run: cd serde && cargo build
|
||||||
|
|
||||||
derive:
|
derive:
|
||||||
name: Rust 1.56.0
|
name: Rust 1.61.0
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 45
|
timeout-minutes: 45
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: dtolnay/rust-toolchain@1.56.0
|
- uses: dtolnay/rust-toolchain@1.61.0
|
||||||
- run: sed -i '/"test_suite"/d' Cargo.toml
|
- 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 --no-default-features
|
||||||
- run: cd serde && cargo check
|
- run: cd serde && cargo check
|
||||||
- run: cd serde_derive && cargo check
|
- run: cd serde_derive && cargo check
|
||||||
|
|||||||
+1
-1
@@ -12,4 +12,4 @@ serde = { path = "serde" }
|
|||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
proc-macro2 = { version = "1.0.74", default-features = false }
|
proc-macro2 = { version = "1.0.74", default-features = false }
|
||||||
quote = { version = "1.0.35", default-features = false }
|
quote = { version = "1.0.35", default-features = false }
|
||||||
syn = { version = "2.0.46", default-features = false }
|
syn = { version = "2.0.81", default-features = false }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.31] [![serde_derive msrv]][Rust 1.56]
|
# Serde   [![Build Status]][actions] [![Latest Version]][crates.io] [![serde msrv]][Rust 1.31] [![serde_derive msrv]][Rust 1.61]
|
||||||
|
|
||||||
[Build Status]: https://img.shields.io/github/actions/workflow/status/serde-rs/serde/ci.yml?branch=master
|
[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
|
[actions]: https://github.com/serde-rs/serde/actions?query=branch%3Amaster
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
[serde msrv]: https://img.shields.io/crates/msrv/serde.svg?label=serde%20msrv&color=lightgray
|
[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
|
[serde_derive msrv]: https://img.shields.io/crates/msrv/serde_derive.svg?label=serde_derive%20msrv&color=lightgray
|
||||||
[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
|
[Rust 1.31]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
|
||||||
[Rust 1.56]: https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
|
[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.**
|
**Serde is a framework for *ser*ializing and *de*serializing Rust data structures efficiently and generically.**
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.210"
|
version = "1.0.213"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
categories = ["encoding", "no-std", "no-std::no-alloc"]
|
categories = ["encoding", "no-std", "no-std::no-alloc"]
|
||||||
@@ -37,7 +37,7 @@ rustdoc-args = ["--generate-link-to-definition"]
|
|||||||
# is compatible with exactly one serde release because the generated code
|
# is compatible with exactly one serde release because the generated code
|
||||||
# involves nonpublic APIs which are not bound by semver.
|
# involves nonpublic APIs which are not bound by semver.
|
||||||
[target.'cfg(any())'.dependencies]
|
[target.'cfg(any())'.dependencies]
|
||||||
serde_derive = { version = "=1.0.210", path = "../serde_derive" }
|
serde_derive = { version = "=1.0.213", path = "../serde_derive" }
|
||||||
|
|
||||||
|
|
||||||
### FEATURES #################################################################
|
### FEATURES #################################################################
|
||||||
|
|||||||
+5
-5
@@ -50,11 +50,6 @@ fn main() {
|
|||||||
println!("cargo:rustc-cfg=no_float_copysign");
|
println!("cargo:rustc-cfg=no_float_copysign");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current minimum supported version of serde_derive crate is Rust 1.56.
|
|
||||||
if minor < 56 {
|
|
||||||
println!("cargo:rustc-cfg=no_serde_derive");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Support for #[cfg(target_has_atomic = "...")] stabilized in Rust 1.60.
|
// Support for #[cfg(target_has_atomic = "...")] stabilized in Rust 1.60.
|
||||||
if minor < 60 {
|
if minor < 60 {
|
||||||
println!("cargo:rustc-cfg=no_target_has_atomic");
|
println!("cargo:rustc-cfg=no_target_has_atomic");
|
||||||
@@ -76,6 +71,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
// 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
|
// https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html#c-compatible-ffi-types-in-core-and-alloc
|
||||||
if minor < 64 {
|
if minor < 64 {
|
||||||
|
|||||||
+4
-4
@@ -486,13 +486,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Expected for &'a str {
|
impl Expected for &str {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
formatter.write_str(self)
|
formatter.write_str(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Display for Expected + 'a {
|
impl Display for Expected + '_ {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
Expected::fmt(self, formatter)
|
Expected::fmt(self, formatter)
|
||||||
}
|
}
|
||||||
@@ -1741,7 +1741,7 @@ pub trait SeqAccess<'de> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de, 'a, A> SeqAccess<'de> for &'a mut A
|
impl<'de, A> SeqAccess<'de> for &mut A
|
||||||
where
|
where
|
||||||
A: ?Sized + SeqAccess<'de>,
|
A: ?Sized + SeqAccess<'de>,
|
||||||
{
|
{
|
||||||
@@ -1894,7 +1894,7 @@ pub trait MapAccess<'de> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de, 'a, A> MapAccess<'de> for &'a mut A
|
impl<'de, A> MapAccess<'de> for &mut A
|
||||||
where
|
where
|
||||||
A: ?Sized + MapAccess<'de>,
|
A: ?Sized + MapAccess<'de>,
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-1
@@ -95,7 +95,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Serde types in rustdoc of other crates get linked to here.
|
// Serde types in rustdoc of other crates get linked to here.
|
||||||
#![doc(html_root_url = "https://docs.rs/serde/1.0.210")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.213")]
|
||||||
// Support using Serde without the standard library!
|
// Support using Serde without the standard library!
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
// Show which crate feature enables conditionally compiled APIs in documentation.
|
// Show which crate feature enables conditionally compiled APIs in documentation.
|
||||||
@@ -144,6 +144,7 @@
|
|||||||
clippy::too_many_lines,
|
clippy::too_many_lines,
|
||||||
// preference
|
// preference
|
||||||
clippy::doc_markdown,
|
clippy::doc_markdown,
|
||||||
|
clippy::needless_lifetimes,
|
||||||
clippy::unseparated_literal_suffix,
|
clippy::unseparated_literal_suffix,
|
||||||
// false positive
|
// false positive
|
||||||
clippy::needless_doctest_main,
|
clippy::needless_doctest_main,
|
||||||
|
|||||||
+25
-16
@@ -313,6 +313,17 @@ mod content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'de, E> de::IntoDeserializer<'de, E> for &'a Content<'de>
|
||||||
|
where
|
||||||
|
E: de::Error,
|
||||||
|
{
|
||||||
|
type Deserializer = ContentRefDeserializer<'a, 'de, E>;
|
||||||
|
|
||||||
|
fn into_deserializer(self) -> Self::Deserializer {
|
||||||
|
ContentRefDeserializer::new(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Used to capture data in [`Content`] from other deserializers.
|
/// Used to capture data in [`Content`] from other deserializers.
|
||||||
/// Cannot capture externally tagged enums, `i128` and `u128`.
|
/// Cannot capture externally tagged enums, `i128` and `u128`.
|
||||||
struct ContentVisitor<'de> {
|
struct ContentVisitor<'de> {
|
||||||
@@ -476,14 +487,16 @@ mod content {
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
Deserialize::deserialize(deserializer).map(|v| Content::Some(Box::new(v)))
|
let v = tri!(Deserialize::deserialize(deserializer));
|
||||||
|
Ok(Content::Some(Box::new(v)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
Deserialize::deserialize(deserializer).map(|v| Content::Newtype(Box::new(v)))
|
let v = tri!(Deserialize::deserialize(deserializer));
|
||||||
|
Ok(Content::Newtype(Box::new(v)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||||
@@ -1098,8 +1111,7 @@ mod content {
|
|||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
{
|
{
|
||||||
let seq = content.into_iter().map(ContentDeserializer::new);
|
let mut seq_visitor = SeqDeserializer::new(content.into_iter());
|
||||||
let mut seq_visitor = SeqDeserializer::new(seq);
|
|
||||||
let value = tri!(visitor.visit_seq(&mut seq_visitor));
|
let value = tri!(visitor.visit_seq(&mut seq_visitor));
|
||||||
tri!(seq_visitor.end());
|
tri!(seq_visitor.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
@@ -1113,10 +1125,7 @@ mod content {
|
|||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
{
|
{
|
||||||
let map = content
|
let mut map_visitor = MapDeserializer::new(content.into_iter());
|
||||||
.into_iter()
|
|
||||||
.map(|(k, v)| (ContentDeserializer::new(k), ContentDeserializer::new(v)));
|
|
||||||
let mut map_visitor = MapDeserializer::new(map);
|
|
||||||
let value = tri!(visitor.visit_map(&mut map_visitor));
|
let value = tri!(visitor.visit_map(&mut map_visitor));
|
||||||
tri!(map_visitor.end());
|
tri!(map_visitor.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
@@ -1694,8 +1703,7 @@ mod content {
|
|||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
{
|
{
|
||||||
let seq = content.iter().map(ContentRefDeserializer::new);
|
let mut seq_visitor = SeqDeserializer::new(content.iter());
|
||||||
let mut seq_visitor = SeqDeserializer::new(seq);
|
|
||||||
let value = tri!(visitor.visit_seq(&mut seq_visitor));
|
let value = tri!(visitor.visit_seq(&mut seq_visitor));
|
||||||
tri!(seq_visitor.end());
|
tri!(seq_visitor.end());
|
||||||
Ok(value)
|
Ok(value)
|
||||||
@@ -1709,12 +1717,13 @@ mod content {
|
|||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
{
|
{
|
||||||
let map = content.iter().map(|(k, v)| {
|
fn content_ref_deserializer_pair<'a, 'de>(
|
||||||
(
|
(k, v): &'a (Content<'de>, Content<'de>),
|
||||||
ContentRefDeserializer::new(k),
|
) -> (&'a Content<'de>, &'a Content<'de>) {
|
||||||
ContentRefDeserializer::new(v),
|
(k, v)
|
||||||
)
|
}
|
||||||
});
|
|
||||||
|
let map = content.iter().map(content_ref_deserializer_pair);
|
||||||
let mut map_visitor = MapDeserializer::new(map);
|
let mut map_visitor = MapDeserializer::new(map);
|
||||||
let value = tri!(visitor.visit_map(&mut map_visitor));
|
let value = tri!(visitor.visit_map(&mut map_visitor));
|
||||||
tri!(map_visitor.end());
|
tri!(map_visitor.end());
|
||||||
|
|||||||
@@ -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 Ok = ();
|
||||||
type Error = fmt::Error;
|
type Error = fmt::Error;
|
||||||
type SerializeSeq = Impossible<(), fmt::Error>;
|
type SerializeSeq = Impossible<(), fmt::Error>;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.210"
|
version = "1.0.213"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
categories = ["no-std", "no-std::no-alloc"]
|
categories = ["no-std", "no-std::no-alloc"]
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
@@ -12,7 +12,7 @@ keywords = ["serde", "serialization", "no_std", "derive"]
|
|||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
readme = "crates-io.md"
|
readme = "crates-io.md"
|
||||||
repository = "https://github.com/serde-rs/serde"
|
repository = "https://github.com/serde-rs/serde"
|
||||||
rust-version = "1.56"
|
rust-version = "1.61"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|||||||
@@ -227,7 +227,9 @@ pub fn with_bound(
|
|||||||
match bound {
|
match bound {
|
||||||
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
||||||
syn::TypeParamBound::Trait(bound) => self.visit_path(&bound.path),
|
syn::TypeParamBound::Trait(bound) => self.visit_path(&bound.path),
|
||||||
syn::TypeParamBound::Lifetime(_) | syn::TypeParamBound::Verbatim(_) => {}
|
syn::TypeParamBound::Lifetime(_)
|
||||||
|
| syn::TypeParamBound::PreciseCapture(_)
|
||||||
|
| syn::TypeParamBound::Verbatim(_) => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+118
-74
@@ -371,7 +371,11 @@ fn deserialize_transparent(cont: &Container, params: &Parameters) -> Fragment {
|
|||||||
} else {
|
} else {
|
||||||
let value = match field.attrs.default() {
|
let value = match field.attrs.default() {
|
||||||
attr::Default::Default => quote!(_serde::__private::Default::default()),
|
attr::Default::Default => quote!(_serde::__private::Default::default()),
|
||||||
attr::Default::Path(path) => quote!(#path()),
|
// If #path returns wrong type, error will be reported here (^^^^^).
|
||||||
|
// We attach span of the path to the function so it will be reported
|
||||||
|
// on the #[serde(default = "...")]
|
||||||
|
// ^^^^^
|
||||||
|
attr::Default::Path(path) => quote_spanned!(path.span()=> #path()),
|
||||||
attr::Default::None => quote!(_serde::__private::PhantomData),
|
attr::Default::None => quote!(_serde::__private::PhantomData),
|
||||||
};
|
};
|
||||||
quote!(#member: #value)
|
quote!(#member: #value)
|
||||||
@@ -757,7 +761,11 @@ fn deserialize_seq(
|
|||||||
attr::Default::Default => Some(quote!(
|
attr::Default::Default => Some(quote!(
|
||||||
let __default: Self::Value = _serde::__private::Default::default();
|
let __default: Self::Value = _serde::__private::Default::default();
|
||||||
)),
|
)),
|
||||||
attr::Default::Path(path) => Some(quote!(
|
// If #path returns wrong type, error will be reported here (^^^^^).
|
||||||
|
// We attach span of the path to the function so it will be reported
|
||||||
|
// on the #[serde(default = "...")]
|
||||||
|
// ^^^^^
|
||||||
|
attr::Default::Path(path) => Some(quote_spanned!(path.span()=>
|
||||||
let __default: Self::Value = #path();
|
let __default: Self::Value = #path();
|
||||||
)),
|
)),
|
||||||
attr::Default::None => {
|
attr::Default::None => {
|
||||||
@@ -839,7 +847,11 @@ fn deserialize_seq_in_place(
|
|||||||
attr::Default::Default => Some(quote!(
|
attr::Default::Default => Some(quote!(
|
||||||
let __default: #this_type #ty_generics = _serde::__private::Default::default();
|
let __default: #this_type #ty_generics = _serde::__private::Default::default();
|
||||||
)),
|
)),
|
||||||
attr::Default::Path(path) => Some(quote!(
|
// If #path returns wrong type, error will be reported here (^^^^^).
|
||||||
|
// We attach span of the path to the function so it will be reported
|
||||||
|
// on the #[serde(default = "...")]
|
||||||
|
// ^^^^^
|
||||||
|
attr::Default::Path(path) => Some(quote_spanned!(path.span()=>
|
||||||
let __default: #this_type #ty_generics = #path();
|
let __default: #this_type #ty_generics = #path();
|
||||||
)),
|
)),
|
||||||
attr::Default::None => {
|
attr::Default::None => {
|
||||||
@@ -863,18 +875,23 @@ fn deserialize_newtype_struct(
|
|||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
let delife = params.borrowed.de_lifetime();
|
let delife = params.borrowed.de_lifetime();
|
||||||
let field_ty = field.ty;
|
let field_ty = field.ty;
|
||||||
|
let deserializer_var = quote!(__e);
|
||||||
|
|
||||||
let value = match field.attrs.deserialize_with() {
|
let value = match field.attrs.deserialize_with() {
|
||||||
None => {
|
None => {
|
||||||
let span = field.original.span();
|
let span = field.original.span();
|
||||||
let func = quote_spanned!(span=> <#field_ty as _serde::Deserialize>::deserialize);
|
let func = quote_spanned!(span=> <#field_ty as _serde::Deserialize>::deserialize);
|
||||||
quote! {
|
quote! {
|
||||||
#func(__e)?
|
#func(#deserializer_var)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
quote! {
|
// If #path returns wrong type, error will be reported here (^^^^^).
|
||||||
#path(__e)?
|
// We attach span of the path to the function so it will be reported
|
||||||
|
// on the #[serde(with = "...")]
|
||||||
|
// ^^^^^
|
||||||
|
quote_spanned! {path.span()=>
|
||||||
|
#path(#deserializer_var)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -890,7 +907,7 @@ fn deserialize_newtype_struct(
|
|||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_newtype_struct<__E>(self, __e: __E) -> _serde::__private::Result<Self::Value, __E::Error>
|
fn visit_newtype_struct<__E>(self, #deserializer_var: __E) -> _serde::__private::Result<Self::Value, __E::Error>
|
||||||
where
|
where
|
||||||
__E: _serde::Deserializer<#delife>,
|
__E: _serde::Deserializer<#delife>,
|
||||||
{
|
{
|
||||||
@@ -950,23 +967,20 @@ fn deserialize_struct(
|
|||||||
};
|
};
|
||||||
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
||||||
|
|
||||||
let field_names_idents: Vec<_> = fields
|
let deserialized_fields: Vec<_> = fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
// Skip fields that shouldn't be deserialized or that were flattened,
|
// Skip fields that shouldn't be deserialized or that were flattened,
|
||||||
// so they don't appear in the storage in their literal form
|
// so they don't appear in the storage in their literal form
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
.filter(|&(_, field)| !field.attrs.skip_deserializing() && !field.attrs.flatten())
|
||||||
.map(|(i, field)| {
|
.map(|(i, field)| FieldWithAliases {
|
||||||
(
|
ident: field_i(i),
|
||||||
field.attrs.name().deserialize_name(),
|
aliases: field.attrs.aliases(),
|
||||||
field_i(i),
|
|
||||||
field.attrs.aliases(),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let has_flatten = has_flatten(fields);
|
let has_flatten = has_flatten(fields);
|
||||||
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs, has_flatten);
|
let field_visitor = deserialize_field_identifier(&deserialized_fields, cattrs, has_flatten);
|
||||||
|
|
||||||
// untagged struct variants do not get a visit_seq method. The same applies to
|
// untagged struct variants do not get a visit_seq method. The same applies to
|
||||||
// structs that only have a map representation.
|
// structs that only have a map representation.
|
||||||
@@ -974,7 +988,7 @@ fn deserialize_struct(
|
|||||||
StructForm::Untagged(..) => None,
|
StructForm::Untagged(..) => None,
|
||||||
_ if has_flatten => None,
|
_ if has_flatten => None,
|
||||||
_ => {
|
_ => {
|
||||||
let mut_seq = if field_names_idents.is_empty() {
|
let mut_seq = if deserialized_fields.is_empty() {
|
||||||
quote!(_)
|
quote!(_)
|
||||||
} else {
|
} else {
|
||||||
quote!(mut __seq)
|
quote!(mut __seq)
|
||||||
@@ -1022,9 +1036,7 @@ fn deserialize_struct(
|
|||||||
let fields_stmt = if has_flatten {
|
let fields_stmt = if has_flatten {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let field_names = field_names_idents
|
let field_names = deserialized_fields.iter().flat_map(|field| field.aliases);
|
||||||
.iter()
|
|
||||||
.flat_map(|&(_, _, aliases)| aliases);
|
|
||||||
|
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
@@ -1117,31 +1129,26 @@ fn deserialize_struct_in_place(
|
|||||||
let expecting = format!("struct {}", params.type_name());
|
let expecting = format!("struct {}", params.type_name());
|
||||||
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
let expecting = cattrs.expecting().unwrap_or(&expecting);
|
||||||
|
|
||||||
let field_names_idents: Vec<_> = fields
|
let deserialized_fields: Vec<_> = fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
.filter(|&(_, field)| !field.attrs.skip_deserializing())
|
||||||
.map(|(i, field)| {
|
.map(|(i, field)| FieldWithAliases {
|
||||||
(
|
ident: field_i(i),
|
||||||
field.attrs.name().deserialize_name(),
|
aliases: field.attrs.aliases(),
|
||||||
field_i(i),
|
|
||||||
field.attrs.aliases(),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs, false);
|
let field_visitor = deserialize_field_identifier(&deserialized_fields, cattrs, false);
|
||||||
|
|
||||||
let mut_seq = if field_names_idents.is_empty() {
|
let mut_seq = if deserialized_fields.is_empty() {
|
||||||
quote!(_)
|
quote!(_)
|
||||||
} else {
|
} else {
|
||||||
quote!(mut __seq)
|
quote!(mut __seq)
|
||||||
};
|
};
|
||||||
let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, expecting));
|
let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, expecting));
|
||||||
let visit_map = Stmts(deserialize_map_in_place(params, fields, cattrs));
|
let visit_map = Stmts(deserialize_map_in_place(params, fields, cattrs));
|
||||||
let field_names = field_names_idents
|
let field_names = deserialized_fields.iter().flat_map(|field| field.aliases);
|
||||||
.iter()
|
|
||||||
.flat_map(|&(_, _, aliases)| aliases);
|
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
|
|
||||||
let in_place_impl_generics = de_impl_generics.in_place();
|
let in_place_impl_generics = de_impl_generics.in_place();
|
||||||
@@ -1225,39 +1232,38 @@ fn deserialize_homogeneous_enum(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_enum_variant_enum(variants: &[Variant]) -> (TokenStream, Stmts) {
|
fn prepare_enum_variant_enum(variants: &[Variant]) -> (TokenStream, Stmts) {
|
||||||
let mut deserialized_variants = variants
|
let deserialized_variants = variants
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(_, variant)| !variant.attrs.skip_deserializing());
|
.filter(|&(_i, variant)| !variant.attrs.skip_deserializing());
|
||||||
|
|
||||||
let variant_names_idents: Vec<_> = deserialized_variants
|
|
||||||
.clone()
|
|
||||||
.map(|(i, variant)| {
|
|
||||||
(
|
|
||||||
variant.attrs.name().deserialize_name(),
|
|
||||||
field_i(i),
|
|
||||||
variant.attrs.aliases(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let fallthrough = deserialized_variants
|
let fallthrough = deserialized_variants
|
||||||
.position(|(_, variant)| variant.attrs.other())
|
.clone()
|
||||||
.map(|other_idx| {
|
.find(|(_i, variant)| variant.attrs.other())
|
||||||
let ignore_variant = variant_names_idents[other_idx].1.clone();
|
.map(|(i, _variant)| {
|
||||||
|
let ignore_variant = field_i(i);
|
||||||
quote!(_serde::__private::Ok(__Field::#ignore_variant))
|
quote!(_serde::__private::Ok(__Field::#ignore_variant))
|
||||||
});
|
});
|
||||||
|
|
||||||
let variants_stmt = {
|
let variants_stmt = {
|
||||||
let variant_names = variant_names_idents.iter().map(|(name, _, _)| name);
|
let variant_names = deserialized_variants
|
||||||
|
.clone()
|
||||||
|
.flat_map(|(_i, variant)| variant.attrs.aliases());
|
||||||
quote! {
|
quote! {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
const VARIANTS: &'static [&'static str] = &[ #(#variant_names),* ];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let deserialized_variants: Vec<_> = deserialized_variants
|
||||||
|
.map(|(i, variant)| FieldWithAliases {
|
||||||
|
ident: field_i(i),
|
||||||
|
aliases: variant.attrs.aliases(),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
let variant_visitor = Stmts(deserialize_generated_identifier(
|
let variant_visitor = Stmts(deserialize_generated_identifier(
|
||||||
&variant_names_idents,
|
&deserialized_variants,
|
||||||
false, // variant identifiers do not depend on the presence of flatten fields
|
false, // variant identifiers do not depend on the presence of flatten fields
|
||||||
true,
|
true,
|
||||||
None,
|
None,
|
||||||
@@ -1994,19 +2000,27 @@ fn deserialize_untagged_newtype_variant(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct FieldWithAliases<'a> {
|
||||||
|
ident: Ident,
|
||||||
|
aliases: &'a BTreeSet<String>,
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_generated_identifier(
|
fn deserialize_generated_identifier(
|
||||||
fields: &[(&str, Ident, &BTreeSet<String>)],
|
deserialized_fields: &[FieldWithAliases],
|
||||||
has_flatten: bool,
|
has_flatten: bool,
|
||||||
is_variant: bool,
|
is_variant: bool,
|
||||||
ignore_variant: Option<TokenStream>,
|
ignore_variant: Option<TokenStream>,
|
||||||
fallthrough: Option<TokenStream>,
|
fallthrough: Option<TokenStream>,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let this_value = quote!(__Field);
|
let this_value = quote!(__Field);
|
||||||
let field_idents: &Vec<_> = &fields.iter().map(|(_, ident, _)| ident).collect();
|
let field_idents: &Vec<_> = &deserialized_fields
|
||||||
|
.iter()
|
||||||
|
.map(|field| &field.ident)
|
||||||
|
.collect();
|
||||||
|
|
||||||
let visitor_impl = Stmts(deserialize_identifier(
|
let visitor_impl = Stmts(deserialize_identifier(
|
||||||
&this_value,
|
&this_value,
|
||||||
fields,
|
deserialized_fields,
|
||||||
is_variant,
|
is_variant,
|
||||||
fallthrough,
|
fallthrough,
|
||||||
None,
|
None,
|
||||||
@@ -2052,7 +2066,7 @@ fn deserialize_generated_identifier(
|
|||||||
/// Generates enum and its `Deserialize` implementation that represents each
|
/// Generates enum and its `Deserialize` implementation that represents each
|
||||||
/// non-skipped field of the struct
|
/// non-skipped field of the struct
|
||||||
fn deserialize_field_identifier(
|
fn deserialize_field_identifier(
|
||||||
fields: &[(&str, Ident, &BTreeSet<String>)],
|
deserialized_fields: &[FieldWithAliases],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
has_flatten: bool,
|
has_flatten: bool,
|
||||||
) -> Stmts {
|
) -> Stmts {
|
||||||
@@ -2069,7 +2083,7 @@ fn deserialize_field_identifier(
|
|||||||
};
|
};
|
||||||
|
|
||||||
Stmts(deserialize_generated_identifier(
|
Stmts(deserialize_generated_identifier(
|
||||||
fields,
|
deserialized_fields,
|
||||||
has_flatten,
|
has_flatten,
|
||||||
false,
|
false,
|
||||||
ignore_variant,
|
ignore_variant,
|
||||||
@@ -2127,18 +2141,15 @@ fn deserialize_custom_identifier(
|
|||||||
(variants, None, None)
|
(variants, None, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let names_idents: Vec<_> = ordinary
|
let idents_aliases: Vec<_> = ordinary
|
||||||
.iter()
|
.iter()
|
||||||
.map(|variant| {
|
.map(|variant| FieldWithAliases {
|
||||||
(
|
ident: variant.ident.clone(),
|
||||||
variant.attrs.name().deserialize_name(),
|
aliases: variant.attrs.aliases(),
|
||||||
variant.ident.clone(),
|
|
||||||
variant.attrs.aliases(),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let names = names_idents.iter().flat_map(|&(_, _, aliases)| aliases);
|
let names = idents_aliases.iter().flat_map(|variant| variant.aliases);
|
||||||
|
|
||||||
let names_const = if fallthrough.is_some() {
|
let names_const = if fallthrough.is_some() {
|
||||||
None
|
None
|
||||||
@@ -2161,7 +2172,7 @@ fn deserialize_custom_identifier(
|
|||||||
let delife = params.borrowed.de_lifetime();
|
let delife = params.borrowed.de_lifetime();
|
||||||
let visitor_impl = Stmts(deserialize_identifier(
|
let visitor_impl = Stmts(deserialize_identifier(
|
||||||
&this_value,
|
&this_value,
|
||||||
&names_idents,
|
&idents_aliases,
|
||||||
is_variant,
|
is_variant,
|
||||||
fallthrough,
|
fallthrough,
|
||||||
fallthrough_borrowed,
|
fallthrough_borrowed,
|
||||||
@@ -2194,20 +2205,24 @@ fn deserialize_custom_identifier(
|
|||||||
|
|
||||||
fn deserialize_identifier(
|
fn deserialize_identifier(
|
||||||
this_value: &TokenStream,
|
this_value: &TokenStream,
|
||||||
fields: &[(&str, Ident, &BTreeSet<String>)],
|
deserialized_fields: &[FieldWithAliases],
|
||||||
is_variant: bool,
|
is_variant: bool,
|
||||||
fallthrough: Option<TokenStream>,
|
fallthrough: Option<TokenStream>,
|
||||||
fallthrough_borrowed: Option<TokenStream>,
|
fallthrough_borrowed: Option<TokenStream>,
|
||||||
collect_other_fields: bool,
|
collect_other_fields: bool,
|
||||||
expecting: Option<&str>,
|
expecting: Option<&str>,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let str_mapping = fields.iter().map(|(_, ident, aliases)| {
|
let str_mapping = deserialized_fields.iter().map(|field| {
|
||||||
|
let ident = &field.ident;
|
||||||
|
let aliases = field.aliases;
|
||||||
// `aliases` also contains a main name
|
// `aliases` also contains a main name
|
||||||
quote!(#(#aliases)|* => _serde::__private::Ok(#this_value::#ident))
|
quote!(#(#aliases)|* => _serde::__private::Ok(#this_value::#ident))
|
||||||
});
|
});
|
||||||
let bytes_mapping = fields.iter().map(|(_, ident, aliases)| {
|
let bytes_mapping = deserialized_fields.iter().map(|field| {
|
||||||
|
let ident = &field.ident;
|
||||||
// `aliases` also contains a main name
|
// `aliases` also contains a main name
|
||||||
let aliases = aliases
|
let aliases = field
|
||||||
|
.aliases
|
||||||
.iter()
|
.iter()
|
||||||
.map(|alias| Literal::byte_string(alias.as_bytes()));
|
.map(|alias| Literal::byte_string(alias.as_bytes()));
|
||||||
quote!(#(#aliases)|* => _serde::__private::Ok(#this_value::#ident))
|
quote!(#(#aliases)|* => _serde::__private::Ok(#this_value::#ident))
|
||||||
@@ -2360,8 +2375,9 @@ fn deserialize_identifier(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let u64_mapping = fields.iter().enumerate().map(|(i, (_, ident, _))| {
|
let u64_mapping = deserialized_fields.iter().enumerate().map(|(i, field)| {
|
||||||
let i = i as u64;
|
let i = i as u64;
|
||||||
|
let ident = &field.ident;
|
||||||
quote!(#i => _serde::__private::Ok(#this_value::#ident))
|
quote!(#i => _serde::__private::Ok(#this_value::#ident))
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2370,7 +2386,11 @@ fn deserialize_identifier(
|
|||||||
fallthrough
|
fallthrough
|
||||||
} else {
|
} else {
|
||||||
let index_expecting = if is_variant { "variant" } else { "field" };
|
let index_expecting = if is_variant { "variant" } else { "field" };
|
||||||
let fallthrough_msg = format!("{} index 0 <= i < {}", index_expecting, fields.len());
|
let fallthrough_msg = format!(
|
||||||
|
"{} index 0 <= i < {}",
|
||||||
|
index_expecting,
|
||||||
|
deserialized_fields.len(),
|
||||||
|
);
|
||||||
u64_fallthrough_arm_tokens = quote! {
|
u64_fallthrough_arm_tokens = quote! {
|
||||||
_serde::__private::Err(_serde::de::Error::invalid_value(
|
_serde::__private::Err(_serde::de::Error::invalid_value(
|
||||||
_serde::de::Unexpected::Unsigned(__value),
|
_serde::de::Unexpected::Unsigned(__value),
|
||||||
@@ -2647,7 +2667,11 @@ fn deserialize_map(
|
|||||||
attr::Default::Default => Some(quote!(
|
attr::Default::Default => Some(quote!(
|
||||||
let __default: Self::Value = _serde::__private::Default::default();
|
let __default: Self::Value = _serde::__private::Default::default();
|
||||||
)),
|
)),
|
||||||
attr::Default::Path(path) => Some(quote!(
|
// If #path returns wrong type, error will be reported here (^^^^^).
|
||||||
|
// We attach span of the path to the function so it will be reported
|
||||||
|
// on the #[serde(default = "...")]
|
||||||
|
// ^^^^^
|
||||||
|
attr::Default::Path(path) => Some(quote_spanned!(path.span()=>
|
||||||
let __default: Self::Value = #path();
|
let __default: Self::Value = #path();
|
||||||
)),
|
)),
|
||||||
attr::Default::None => {
|
attr::Default::None => {
|
||||||
@@ -2817,7 +2841,11 @@ fn deserialize_map_in_place(
|
|||||||
attr::Default::Default => Some(quote!(
|
attr::Default::Default => Some(quote!(
|
||||||
let __default: #this_type #ty_generics = _serde::__private::Default::default();
|
let __default: #this_type #ty_generics = _serde::__private::Default::default();
|
||||||
)),
|
)),
|
||||||
attr::Default::Path(path) => Some(quote!(
|
// If #path returns wrong type, error will be reported here (^^^^^).
|
||||||
|
// We attach span of the path to the function so it will be reported
|
||||||
|
// on the #[serde(default = "...")]
|
||||||
|
// ^^^^^
|
||||||
|
attr::Default::Path(path) => Some(quote_spanned!(path.span()=>
|
||||||
let __default: #this_type #ty_generics = #path();
|
let __default: #this_type #ty_generics = #path();
|
||||||
)),
|
)),
|
||||||
attr::Default::None => {
|
attr::Default::None => {
|
||||||
@@ -2855,7 +2883,15 @@ fn wrap_deserialize_with(
|
|||||||
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) =
|
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) =
|
||||||
split_with_de_lifetime(params);
|
split_with_de_lifetime(params);
|
||||||
let delife = params.borrowed.de_lifetime();
|
let delife = params.borrowed.de_lifetime();
|
||||||
|
let deserializer_var = quote!(__deserializer);
|
||||||
|
|
||||||
|
// If #deserialize_with returns wrong type, error will be reported here (^^^^^).
|
||||||
|
// We attach span of the path to the function so it will be reported
|
||||||
|
// on the #[serde(with = "...")]
|
||||||
|
// ^^^^^
|
||||||
|
let value = quote_spanned! {deserialize_with.span()=>
|
||||||
|
#deserialize_with(#deserializer_var)?
|
||||||
|
};
|
||||||
let wrapper = quote! {
|
let wrapper = quote! {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
struct __DeserializeWith #de_impl_generics #where_clause {
|
struct __DeserializeWith #de_impl_generics #where_clause {
|
||||||
@@ -2865,12 +2901,12 @@ fn wrap_deserialize_with(
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl #de_impl_generics _serde::Deserialize<#delife> for __DeserializeWith #de_ty_generics #where_clause {
|
impl #de_impl_generics _serde::Deserialize<#delife> for __DeserializeWith #de_ty_generics #where_clause {
|
||||||
fn deserialize<__D>(__deserializer: __D) -> _serde::__private::Result<Self, __D::Error>
|
fn deserialize<__D>(#deserializer_var: __D) -> _serde::__private::Result<Self, __D::Error>
|
||||||
where
|
where
|
||||||
__D: _serde::Deserializer<#delife>,
|
__D: _serde::Deserializer<#delife>,
|
||||||
{
|
{
|
||||||
_serde::__private::Ok(__DeserializeWith {
|
_serde::__private::Ok(__DeserializeWith {
|
||||||
value: #deserialize_with(__deserializer)?,
|
value: #value,
|
||||||
phantom: _serde::__private::PhantomData,
|
phantom: _serde::__private::PhantomData,
|
||||||
lifetime: _serde::__private::PhantomData,
|
lifetime: _serde::__private::PhantomData,
|
||||||
})
|
})
|
||||||
@@ -2961,7 +2997,11 @@ fn expr_is_missing(field: &Field, cattrs: &attr::Container) -> Fragment {
|
|||||||
return quote_expr!(#func());
|
return quote_expr!(#func());
|
||||||
}
|
}
|
||||||
attr::Default::Path(path) => {
|
attr::Default::Path(path) => {
|
||||||
return quote_expr!(#path());
|
// If #path returns wrong type, error will be reported here (^^^^^).
|
||||||
|
// We attach span of the path to the function so it will be reported
|
||||||
|
// on the #[serde(default = "...")]
|
||||||
|
// ^^^^^
|
||||||
|
return Fragment::Expr(quote_spanned!(path.span()=> #path()));
|
||||||
}
|
}
|
||||||
attr::Default::None => { /* below */ }
|
attr::Default::None => { /* below */ }
|
||||||
}
|
}
|
||||||
@@ -3004,6 +3044,10 @@ fn expr_is_missing_seq(
|
|||||||
return quote_spanned!(span=> #assign_to _serde::__private::Default::default());
|
return quote_spanned!(span=> #assign_to _serde::__private::Default::default());
|
||||||
}
|
}
|
||||||
attr::Default::Path(path) => {
|
attr::Default::Path(path) => {
|
||||||
|
// If #path returns wrong type, error will be reported here (^^^^^).
|
||||||
|
// We attach span of the path to the function so it will be reported
|
||||||
|
// on the #[serde(default = "...")]
|
||||||
|
// ^^^^^
|
||||||
return quote_spanned!(path.span()=> #assign_to #path());
|
return quote_spanned!(path.span()=> #assign_to #path());
|
||||||
}
|
}
|
||||||
attr::Default::None => { /* below */ }
|
attr::Default::None => { /* below */ }
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use std::iter::FromIterator;
|
|||||||
use syn::meta::ParseNestedMeta;
|
use syn::meta::ParseNestedMeta;
|
||||||
use syn::parse::ParseStream;
|
use syn::parse::ParseStream;
|
||||||
use syn::punctuated::Punctuated;
|
use syn::punctuated::Punctuated;
|
||||||
|
use syn::spanned::Spanned;
|
||||||
use syn::{parse_quote, token, Ident, Lifetime, Token};
|
use syn::{parse_quote, token, Ident, Lifetime, Token};
|
||||||
|
|
||||||
// This module handles parsing of `#[serde(...)]` attributes. The entrypoints
|
// This module handles parsing of `#[serde(...)]` attributes. The entrypoints
|
||||||
@@ -888,13 +889,13 @@ impl Variant {
|
|||||||
ser_path
|
ser_path
|
||||||
.path
|
.path
|
||||||
.segments
|
.segments
|
||||||
.push(Ident::new("serialize", Span::call_site()).into());
|
.push(Ident::new("serialize", ser_path.span()).into());
|
||||||
serialize_with.set(&meta.path, ser_path);
|
serialize_with.set(&meta.path, ser_path);
|
||||||
let mut de_path = path;
|
let mut de_path = path;
|
||||||
de_path
|
de_path
|
||||||
.path
|
.path
|
||||||
.segments
|
.segments
|
||||||
.push(Ident::new("deserialize", Span::call_site()).into());
|
.push(Ident::new("deserialize", de_path.span()).into());
|
||||||
deserialize_with.set(&meta.path, de_path);
|
deserialize_with.set(&meta.path, de_path);
|
||||||
}
|
}
|
||||||
} else if meta.path == SERIALIZE_WITH {
|
} else if meta.path == SERIALIZE_WITH {
|
||||||
@@ -1170,13 +1171,13 @@ impl Field {
|
|||||||
ser_path
|
ser_path
|
||||||
.path
|
.path
|
||||||
.segments
|
.segments
|
||||||
.push(Ident::new("serialize", Span::call_site()).into());
|
.push(Ident::new("serialize", ser_path.span()).into());
|
||||||
serialize_with.set(&meta.path, ser_path);
|
serialize_with.set(&meta.path, ser_path);
|
||||||
let mut de_path = path;
|
let mut de_path = path;
|
||||||
de_path
|
de_path
|
||||||
.path
|
.path
|
||||||
.segments
|
.segments
|
||||||
.push(Ident::new("deserialize", Span::call_site()).into());
|
.push(Ident::new("deserialize", de_path.span()).into());
|
||||||
deserialize_with.set(&meta.path, de_path);
|
deserialize_with.set(&meta.path, de_path);
|
||||||
}
|
}
|
||||||
} else if meta.path == BOUND {
|
} else if meta.path == BOUND {
|
||||||
|
|||||||
@@ -209,7 +209,9 @@ impl ReplaceReceiver<'_> {
|
|||||||
match bound {
|
match bound {
|
||||||
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
|
||||||
TypeParamBound::Trait(bound) => self.visit_path_mut(&mut bound.path),
|
TypeParamBound::Trait(bound) => self.visit_path_mut(&mut bound.path),
|
||||||
TypeParamBound::Lifetime(_) | TypeParamBound::Verbatim(_) => {}
|
TypeParamBound::Lifetime(_)
|
||||||
|
| TypeParamBound::PreciseCapture(_)
|
||||||
|
| TypeParamBound::Verbatim(_) => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,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 {
|
fn eq(&self, word: &Symbol) -> bool {
|
||||||
*self == word.0
|
*self == word.0
|
||||||
}
|
}
|
||||||
@@ -58,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 {
|
fn eq(&self, word: &Symbol) -> bool {
|
||||||
self.is_ident(word.0)
|
self.is_ident(word.0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.210")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.213")]
|
||||||
#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
|
#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
#![allow(
|
#![allow(
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6797
|
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6797
|
||||||
clippy::manual_map,
|
clippy::manual_map,
|
||||||
clippy::match_like_matches_macro,
|
clippy::match_like_matches_macro,
|
||||||
|
clippy::needless_lifetimes,
|
||||||
clippy::needless_pass_by_value,
|
clippy::needless_pass_by_value,
|
||||||
clippy::too_many_arguments,
|
clippy::too_many_arguments,
|
||||||
clippy::trivially_copy_pass_by_ref,
|
clippy::trivially_copy_pass_by_ref,
|
||||||
@@ -55,6 +56,7 @@
|
|||||||
clippy::single_match_else,
|
clippy::single_match_else,
|
||||||
clippy::struct_excessive_bools,
|
clippy::struct_excessive_bools,
|
||||||
clippy::too_many_lines,
|
clippy::too_many_lines,
|
||||||
|
clippy::uninlined_format_args,
|
||||||
clippy::unseparated_literal_suffix,
|
clippy::unseparated_literal_suffix,
|
||||||
clippy::unused_self,
|
clippy::unused_self,
|
||||||
clippy::use_self,
|
clippy::use_self,
|
||||||
|
|||||||
+13
-2
@@ -1220,6 +1220,17 @@ fn wrap_serialize_with(
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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!({
|
quote!({
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
struct __SerializeWith #wrapper_impl_generics #where_clause {
|
struct __SerializeWith #wrapper_impl_generics #where_clause {
|
||||||
@@ -1228,11 +1239,11 @@ fn wrap_serialize_with(
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl #wrapper_impl_generics _serde::Serialize for __SerializeWith #wrapper_ty_generics #where_clause {
|
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
|
where
|
||||||
__S: _serde::Serializer,
|
__S: _serde::Serializer,
|
||||||
{
|
{
|
||||||
#serialize_with(#(self.values.#field_access, )* __s)
|
#wrapper_serialize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ homepage = "https://serde.rs"
|
|||||||
keywords = ["serde", "serialization"]
|
keywords = ["serde", "serialization"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/serde-rs/serde"
|
repository = "https://github.com/serde-rs/serde"
|
||||||
rust-version = "1.56"
|
rust-version = "1.61"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6797
|
// clippy bug: https://github.com/rust-lang/rust-clippy/issues/6797
|
||||||
clippy::manual_map,
|
clippy::manual_map,
|
||||||
clippy::missing_panics_doc,
|
clippy::missing_panics_doc,
|
||||||
|
clippy::needless_lifetimes,
|
||||||
clippy::redundant_field_names,
|
clippy::redundant_field_names,
|
||||||
clippy::result_unit_err,
|
clippy::result_unit_err,
|
||||||
clippy::should_implement_trait,
|
clippy::should_implement_trait,
|
||||||
@@ -35,6 +36,7 @@
|
|||||||
clippy::single_match_else,
|
clippy::single_match_else,
|
||||||
clippy::struct_excessive_bools,
|
clippy::struct_excessive_bools,
|
||||||
clippy::too_many_lines,
|
clippy::too_many_lines,
|
||||||
|
clippy::uninlined_format_args,
|
||||||
clippy::unused_self,
|
clippy::unused_self,
|
||||||
clippy::wildcard_imports
|
clippy::wildcard_imports
|
||||||
)]
|
)]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use serde_derive::{Serialize, Deserialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_test::{assert_tokens, Token};
|
use serde_test::{assert_tokens, Token};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
@@ -18,11 +18,15 @@ fn simple_variant() {
|
|||||||
assert_tokens(
|
assert_tokens(
|
||||||
&Enum::Simple { a: 42 },
|
&Enum::Simple { a: 42 },
|
||||||
&[
|
&[
|
||||||
Token::StructVariant { name: "Enum", variant: "Simple", len: 1 },
|
Token::StructVariant {
|
||||||
|
name: "Enum",
|
||||||
|
variant: "Simple",
|
||||||
|
len: 1,
|
||||||
|
},
|
||||||
Token::Str("a"),
|
Token::Str("a"),
|
||||||
Token::I32(42),
|
Token::I32(42),
|
||||||
Token::StructVariantEnd,
|
Token::StructVariantEnd,
|
||||||
]
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,11 +35,14 @@ fn flatten_variant() {
|
|||||||
assert_tokens(
|
assert_tokens(
|
||||||
&Enum::Flatten { flatten: (), a: 42 },
|
&Enum::Flatten { flatten: (), a: 42 },
|
||||||
&[
|
&[
|
||||||
Token::NewtypeVariant { name: "Enum", variant: "Flatten" },
|
Token::NewtypeVariant {
|
||||||
|
name: "Enum",
|
||||||
|
variant: "Flatten",
|
||||||
|
},
|
||||||
Token::Map { len: None },
|
Token::Map { len: None },
|
||||||
Token::Str("a"),
|
Token::Str("a"),
|
||||||
Token::I32(42),
|
Token::I32(42),
|
||||||
Token::MapEnd,
|
Token::MapEnd,
|
||||||
]
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#![allow(clippy::trivially_copy_pass_by_ref)]
|
||||||
|
|
||||||
|
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!()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#![allow(clippy::trivially_copy_pass_by_ref)]
|
||||||
|
|
||||||
|
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!()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -782,7 +782,7 @@ fn test_unknown_field_rename_enum() {
|
|||||||
variant: "SailorMoon",
|
variant: "SailorMoon",
|
||||||
len: 3,
|
len: 3,
|
||||||
}],
|
}],
|
||||||
"unknown variant `SailorMoon`, expected `sailor_moon`",
|
"unknown variant `SailorMoon`, expected `sailor_moon` or `usagi_tsukino`",
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_de_tokens_error::<AliasEnum>(
|
assert_de_tokens_error::<AliasEnum>(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#![allow(
|
#![allow(
|
||||||
clippy::extra_unused_type_parameters,
|
clippy::extra_unused_type_parameters,
|
||||||
|
clippy::needless_lifetimes,
|
||||||
clippy::type_repetition_in_bounds
|
clippy::type_repetition_in_bounds
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// Tests that type error points to the path in attribute
|
||||||
|
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(tag = "tag", content = "content")]
|
||||||
|
enum Enum {
|
||||||
|
// Newtype variants do not use the provided path, so it is forbidden here
|
||||||
|
// Newtype(#[serde(default = "main")] u8),
|
||||||
|
Tuple(u8, #[serde(default = "main")] i8),
|
||||||
|
Struct {
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f1: u8,
|
||||||
|
f2: u8,
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f3: i8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:10:33
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `i8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
10 | Tuple(u8, #[serde(default = "main")] i8),
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:12:27
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `u8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
12 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `u8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:15:27
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `i8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
15 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// Tests that type error points to the path in attribute
|
||||||
|
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
enum Enum {
|
||||||
|
// Newtype variants do not use the provided path, so it is forbidden here
|
||||||
|
// Newtype(#[serde(default = "main")] u8),
|
||||||
|
Tuple(u8, #[serde(default = "main")] i8),
|
||||||
|
Struct {
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f1: u8,
|
||||||
|
f2: u8,
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f3: i8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:9:33
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `i8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
9 | Tuple(u8, #[serde(default = "main")] i8),
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:11:27
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `u8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
11 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `u8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:14:27
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `i8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
14 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// Tests that type error points to the path in attribute
|
||||||
|
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(tag = "tag")]
|
||||||
|
enum Enum {
|
||||||
|
// Newtype variants do not use the provided path, so it is forbidden here
|
||||||
|
// Newtype(#[serde(default = "main")] u8),
|
||||||
|
// Tuple variants are not supported in internally tagged enums
|
||||||
|
Struct {
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f1: u8,
|
||||||
|
f2: u8,
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f3: i8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_internally_tagged.rs:12:27
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `u8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
12 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `u8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_internally_tagged.rs:15:27
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `i8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
15 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// Tests that type error points to the path in attribute
|
||||||
|
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum Enum {
|
||||||
|
// Newtype variants do not use the provided path, so it is forbidden here
|
||||||
|
// Newtype(#[serde(default = "main")] u8),
|
||||||
|
Tuple(u8, #[serde(default = "main")] i8),
|
||||||
|
Struct {
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f1: u8,
|
||||||
|
f2: u8,
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f3: i8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_untagged.rs:10:33
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `i8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
10 | Tuple(u8, #[serde(default = "main")] i8),
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_untagged.rs:12:27
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `u8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
12 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `u8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_enum_untagged.rs:15:27
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `i8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
15 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Tests that type error points to the path in attribute
|
||||||
|
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(default = "main")]
|
||||||
|
struct Newtype(#[serde(default = "main")] u8);
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_newtype.rs:6:19
|
||||||
|
|
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^
|
||||||
|
| |
|
||||||
|
| expected `Newtype`, found `()`
|
||||||
|
| expected due to this
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_newtype.rs:7:34
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `u8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
7 | struct Newtype(#[serde(default = "main")] u8);
|
||||||
|
| ^^^^^^ expected `u8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_newtype.rs:6:19
|
||||||
|
|
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `Newtype`, found `()`
|
||||||
|
7 | struct Newtype(#[serde(default = "main")] u8);
|
||||||
|
| ------- expected due to this
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_newtype.rs:7:34
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| ----------- expected due to the type of this binding
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
7 | struct Newtype(#[serde(default = "main")] u8);
|
||||||
|
| ^^^^^^ expected `u8`, found `()`
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Tests that type error points to the path in attribute
|
||||||
|
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(default = "main")]
|
||||||
|
struct Struct {
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f1: u8,
|
||||||
|
f2: u8,
|
||||||
|
#[serde(default = "main")]
|
||||||
|
f3: i8,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_struct.rs:6:19
|
||||||
|
|
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^
|
||||||
|
| |
|
||||||
|
| expected `Struct`, found `()`
|
||||||
|
| expected due to this
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_struct.rs:8:23
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `u8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
8 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `u8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_struct.rs:11:23
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `i8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
...
|
||||||
|
11 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_struct.rs:6:19
|
||||||
|
|
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `Struct`, found `()`
|
||||||
|
7 | struct Struct {
|
||||||
|
| ------ expected due to this
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_struct.rs:8:23
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| ----------- expected due to the type of this binding
|
||||||
|
...
|
||||||
|
8 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `u8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_struct.rs:11:23
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| ----------- expected due to the type of this binding
|
||||||
|
...
|
||||||
|
11 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Tests that type error points to the path in attribute
|
||||||
|
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(default = "main")]
|
||||||
|
struct Tuple(u8, #[serde(default = "main")] i8);
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_tuple.rs:6:19
|
||||||
|
|
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^
|
||||||
|
| |
|
||||||
|
| expected `Tuple`, found `()`
|
||||||
|
| expected due to this
|
||||||
|
|
||||||
|
error[E0308]: `match` arms have incompatible types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_tuple.rs:7:36
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| -----------
|
||||||
|
| |
|
||||||
|
| this is found to be of type `i8`
|
||||||
|
| `match` arms have incompatible types
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
7 | struct Tuple(u8, #[serde(default = "main")] i8);
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_tuple.rs:6:19
|
||||||
|
|
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
| ^^^^^^ expected `Tuple`, found `()`
|
||||||
|
7 | struct Tuple(u8, #[serde(default = "main")] i8);
|
||||||
|
| ----- expected due to this
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/default-attribute/incorrect_type_tuple.rs:7:36
|
||||||
|
|
|
||||||
|
5 | #[derive(Deserialize)]
|
||||||
|
| ----------- expected due to the type of this binding
|
||||||
|
6 | #[serde(default = "main")]
|
||||||
|
7 | struct Tuple(u8, #[serde(default = "main")] i8);
|
||||||
|
| ^^^^^^ expected `i8`, found `()`
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
|
union Union {
|
||||||
|
f: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
error: #[serde(default)] can only be used on structs
|
||||||
|
--> tests/ui/default-attribute/union.rs:4:9
|
||||||
|
|
|
||||||
|
4 | #[serde(default)]
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: Serde does not support derive for unions
|
||||||
|
--> tests/ui/default-attribute/union.rs:4:1
|
||||||
|
|
|
||||||
|
4 | / #[serde(default)]
|
||||||
|
5 | | union Union {
|
||||||
|
6 | | f: u8,
|
||||||
|
7 | | }
|
||||||
|
| |_^
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(default = "default_u")]
|
||||||
|
union Union {
|
||||||
|
f: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
error: #[serde(default = "...")] can only be used on structs
|
||||||
|
--> tests/ui/default-attribute/union_path.rs:4:9
|
||||||
|
|
|
||||||
|
4 | #[serde(default = "default_u")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: Serde does not support derive for unions
|
||||||
|
--> tests/ui/default-attribute/union_path.rs:4:1
|
||||||
|
|
|
||||||
|
4 | / #[serde(default = "default_u")]
|
||||||
|
5 | | union Union {
|
||||||
|
6 | | f: u8,
|
||||||
|
7 | | }
|
||||||
|
| |_^
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
|
struct Unit;
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
error: #[serde(default)] can only be used on structs that have fields
|
||||||
|
--> tests/ui/default-attribute/unit.rs:3:10
|
||||||
|
|
|
||||||
|
3 | #[derive(Deserialize)]
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(default = "default_u")]
|
||||||
|
struct Unit;
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
error: #[serde(default = "...")] can only be used on structs that have fields
|
||||||
|
--> tests/ui/default-attribute/unit_path.rs:4:9
|
||||||
|
|
|
||||||
|
4 | #[serde(default = "default_u")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
mod w {
|
||||||
|
use serde::{Deserializer, Serializer};
|
||||||
|
|
||||||
|
pub fn deserialize<'de, D: Deserializer<'de>>(_: D) -> Result<(), D::Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct W(#[serde(with = "w")] u8, u8);
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct S(#[serde(serialize_with = "w::serialize")] u8, u8);
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct D(#[serde(deserialize_with = "w::deserialize")] u8, u8);
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
error[E0277]: the trait bound `&u8: Serializer` is not satisfied
|
||||||
|
--> tests/ui/with/incorrect_type.rs:14:10
|
||||||
|
|
|
||||||
|
14 | #[derive(Serialize, Deserialize)]
|
||||||
|
| ^^^^^^^^^ the trait `Serializer` is not implemented for `&u8`
|
||||||
|
15 | struct W(#[serde(with = "w")] u8, u8);
|
||||||
|
| --- required by a bound introduced by this call
|
||||||
|
|
|
||||||
|
= help: the following other types implement trait `Serializer`:
|
||||||
|
&mut Formatter<'a>
|
||||||
|
FlatMapSerializer<'a, M>
|
||||||
|
_::_serde::__private::ser::content::ContentSerializer<E>
|
||||||
|
note: required by a bound in `w::serialize`
|
||||||
|
--> tests/ui/with/incorrect_type.rs:9:28
|
||||||
|
|
|
||||||
|
9 | pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {
|
||||||
|
| ^^^^^^^^^^ required by this bound in `serialize`
|
||||||
|
|
||||||
|
error[E0061]: this function takes 1 argument but 2 arguments were supplied
|
||||||
|
--> tests/ui/with/incorrect_type.rs:15:25
|
||||||
|
|
|
||||||
|
14 | #[derive(Serialize, Deserialize)]
|
||||||
|
| --------- unexpected argument #2 of type `__S`
|
||||||
|
15 | struct W(#[serde(with = "w")] u8, u8);
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
note: function defined here
|
||||||
|
--> tests/ui/with/incorrect_type.rs:9:12
|
||||||
|
|
|
||||||
|
9 | pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {
|
||||||
|
| ^^^^^^^^^ ----
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `&u8: Serializer` is not satisfied
|
||||||
|
--> tests/ui/with/incorrect_type.rs:15:25
|
||||||
|
|
|
||||||
|
15 | struct W(#[serde(with = "w")] u8, u8);
|
||||||
|
| ^^^ the trait `Serializer` is not implemented for `&u8`
|
||||||
|
|
|
||||||
|
= help: the following other types implement trait `Serializer`:
|
||||||
|
&mut Formatter<'a>
|
||||||
|
FlatMapSerializer<'a, M>
|
||||||
|
_::_serde::__private::ser::content::ContentSerializer<E>
|
||||||
|
|
||||||
|
error[E0308]: `?` operator has incompatible types
|
||||||
|
--> tests/ui/with/incorrect_type.rs:15:25
|
||||||
|
|
|
||||||
|
15 | struct W(#[serde(with = "w")] u8, u8);
|
||||||
|
| ^^^ expected `u8`, found `()`
|
||||||
|
|
|
||||||
|
= note: `?` operator cannot convert from `()` to `u8`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `&u8: Serializer` is not satisfied
|
||||||
|
--> tests/ui/with/incorrect_type.rs:17:10
|
||||||
|
|
|
||||||
|
17 | #[derive(Serialize, Deserialize)]
|
||||||
|
| ^^^^^^^^^ the trait `Serializer` is not implemented for `&u8`
|
||||||
|
18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);
|
||||||
|
| -------------- required by a bound introduced by this call
|
||||||
|
|
|
||||||
|
= help: the following other types implement trait `Serializer`:
|
||||||
|
&mut Formatter<'a>
|
||||||
|
FlatMapSerializer<'a, M>
|
||||||
|
_::_serde::__private::ser::content::ContentSerializer<E>
|
||||||
|
note: required by a bound in `w::serialize`
|
||||||
|
--> tests/ui/with/incorrect_type.rs:9:28
|
||||||
|
|
|
||||||
|
9 | pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {
|
||||||
|
| ^^^^^^^^^^ required by this bound in `serialize`
|
||||||
|
|
||||||
|
error[E0061]: this function takes 1 argument but 2 arguments were supplied
|
||||||
|
--> tests/ui/with/incorrect_type.rs:18:35
|
||||||
|
|
|
||||||
|
17 | #[derive(Serialize, Deserialize)]
|
||||||
|
| --------- unexpected argument #2 of type `__S`
|
||||||
|
18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: function defined here
|
||||||
|
--> tests/ui/with/incorrect_type.rs:9:12
|
||||||
|
|
|
||||||
|
9 | pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {
|
||||||
|
| ^^^^^^^^^ ----
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `&u8: Serializer` is not satisfied
|
||||||
|
--> tests/ui/with/incorrect_type.rs:18:35
|
||||||
|
|
|
||||||
|
18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);
|
||||||
|
| ^^^^^^^^^^^^^^ the trait `Serializer` is not implemented for `&u8`
|
||||||
|
|
|
||||||
|
= help: the following other types implement trait `Serializer`:
|
||||||
|
&mut Formatter<'a>
|
||||||
|
FlatMapSerializer<'a, M>
|
||||||
|
_::_serde::__private::ser::content::ContentSerializer<E>
|
||||||
|
|
||||||
|
error[E0308]: `?` operator has incompatible types
|
||||||
|
--> tests/ui/with/incorrect_type.rs:21:37
|
||||||
|
|
|
||||||
|
21 | struct D(#[serde(deserialize_with = "w::deserialize")] u8, u8);
|
||||||
|
| ^^^^^^^^^^^^^^^^ expected `u8`, found `()`
|
||||||
|
|
|
||||||
|
= note: `?` operator cannot convert from `()` to `u8`
|
||||||
Reference in New Issue
Block a user