mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-28 18:27:55 +00:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dcbc3e0162 | |||
| 0289d31724 | |||
| 015e39776f | |||
| 6a9a21f178 | |||
| 81ac54b20d | |||
| 6b4e75520a | |||
| b053b4f492 | |||
| c0ba323166 | |||
| 20a48c9580 | |||
| 09938803af | |||
| 6d0b43a220 | |||
| 8a4dfa7231 | |||
| 107018c628 | |||
| a398237930 | |||
| b63c65d7f5 | |||
| f60324e883 | |||
| 361c23a09a | |||
| 43b23c7ea0 | |||
| 6081497506 | |||
| 48e5753e76 | |||
| bbba632ab3 | |||
| e77db40b8d | |||
| 2c1f62d4b4 | |||
| 1aebdc2760 | |||
| 705e58be8c | |||
| 7c2c12aa43 | |||
| a0f850f15b |
@@ -3,6 +3,7 @@ name: CI
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
schedule: [cron: "40 1 * * *"]
|
schedule: [cron: "40 1 * * *"]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
@@ -149,6 +150,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: dtolnay/rust-toolchain@miri
|
- uses: dtolnay/rust-toolchain@miri
|
||||||
|
- run: cargo miri setup
|
||||||
- run: cd serde && cargo miri test --features derive,rc,unstable
|
- run: cd serde && cargo miri test --features derive,rc,unstable
|
||||||
env:
|
env:
|
||||||
MIRIFLAGS: -Zmiri-strict-provenance
|
MIRIFLAGS: -Zmiri-strict-provenance
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
msrv = "1.13.0"
|
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.163" # remember to update html_root_url and serde_derive dependency
|
version = "1.0.165" # remember to update html_root_url and serde_derive dependency
|
||||||
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"]
|
categories = ["encoding", "no-std"]
|
||||||
@@ -15,7 +15,7 @@ repository = "https://github.com/serde-rs/serde"
|
|||||||
rust-version = "1.19"
|
rust-version = "1.19"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde_derive = { version = "=1.0.163", optional = true, path = "../serde_derive" }
|
serde_derive = { version = "=1.0.165", optional = true, path = "../serde_derive" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_derive = { version = "1.0", path = "../serde_derive" }
|
serde_derive = { version = "1.0", path = "../serde_derive" }
|
||||||
|
|||||||
+9
-11
@@ -1587,7 +1587,7 @@ macro_rules! parse_socket_impl {
|
|||||||
if deserializer.is_human_readable() {
|
if deserializer.is_human_readable() {
|
||||||
deserializer.deserialize_str(FromStrVisitor::new($expecting))
|
deserializer.deserialize_str(FromStrVisitor::new($expecting))
|
||||||
} else {
|
} else {
|
||||||
<(_, u16)>::deserialize(deserializer).map(|(ip, port)| $new(ip, port))
|
<(_, u16)>::deserialize(deserializer).map($new)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1614,12 +1614,10 @@ impl<'de> Deserialize<'de> for net::SocketAddr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
parse_socket_impl!("IPv4 socket address" net::SocketAddrV4, net::SocketAddrV4::new);
|
parse_socket_impl!("IPv4 socket address" net::SocketAddrV4, |(ip, port)| net::SocketAddrV4::new(ip, port));
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
parse_socket_impl!("IPv6 socket address" net::SocketAddrV6, |ip, port| net::SocketAddrV6::new(
|
parse_socket_impl!("IPv6 socket address" net::SocketAddrV6, |(ip, port)| net::SocketAddrV6::new(ip, port, 0, 0));
|
||||||
ip, port, 0, 0
|
|
||||||
));
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -2098,7 +2096,7 @@ impl<'de> Deserialize<'de> for Duration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const FIELDS: &'static [&'static str] = &["secs", "nanos"];
|
const FIELDS: &[&str] = &["secs", "nanos"];
|
||||||
deserializer.deserialize_struct("Duration", FIELDS, DurationVisitor)
|
deserializer.deserialize_struct("Duration", FIELDS, DurationVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2240,7 +2238,7 @@ impl<'de> Deserialize<'de> for SystemTime {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const FIELDS: &'static [&'static str] = &["secs_since_epoch", "nanos_since_epoch"];
|
const FIELDS: &[&str] = &["secs_since_epoch", "nanos_since_epoch"];
|
||||||
let duration = try!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor));
|
let duration = try!(deserializer.deserialize_struct("SystemTime", FIELDS, DurationVisitor));
|
||||||
#[cfg(not(no_systemtime_checked_add))]
|
#[cfg(not(no_systemtime_checked_add))]
|
||||||
let ret = UNIX_EPOCH
|
let ret = UNIX_EPOCH
|
||||||
@@ -2308,7 +2306,7 @@ mod range {
|
|||||||
|
|
||||||
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
|
||||||
|
|
||||||
pub const FIELDS: &'static [&'static str] = &["start", "end"];
|
pub const FIELDS: &[&str] = &["start", "end"];
|
||||||
|
|
||||||
// If this were outside of the serde crate, it would just use:
|
// If this were outside of the serde crate, it would just use:
|
||||||
//
|
//
|
||||||
@@ -2534,7 +2532,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const VARIANTS: &'static [&'static str] = &["Unbounded", "Included", "Excluded"];
|
const VARIANTS: &[&str] = &["Unbounded", "Included", "Excluded"];
|
||||||
|
|
||||||
deserializer.deserialize_enum("Bound", VARIANTS, BoundVisitor(PhantomData))
|
deserializer.deserialize_enum("Bound", VARIANTS, BoundVisitor(PhantomData))
|
||||||
}
|
}
|
||||||
@@ -2642,7 +2640,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const VARIANTS: &'static [&'static str] = &["Ok", "Err"];
|
const VARIANTS: &[&str] = &["Ok", "Err"];
|
||||||
|
|
||||||
deserializer.deserialize_enum("Result", VARIANTS, ResultVisitor(PhantomData))
|
deserializer.deserialize_enum("Result", VARIANTS, ResultVisitor(PhantomData))
|
||||||
}
|
}
|
||||||
@@ -2708,7 +2706,7 @@ struct FromStrVisitor<T> {
|
|||||||
impl<T> FromStrVisitor<T> {
|
impl<T> FromStrVisitor<T> {
|
||||||
fn new(expecting: &'static str) -> Self {
|
fn new(expecting: &'static str) -> Self {
|
||||||
FromStrVisitor {
|
FromStrVisitor {
|
||||||
expecting: expecting,
|
expecting,
|
||||||
ty: PhantomData,
|
ty: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ pub fn encode(c: char) -> Encode {
|
|||||||
buf[3] = (code & 0x3F) as u8 | TAG_CONT;
|
buf[3] = (code & 0x3F) as u8 | TAG_CONT;
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
Encode { buf: buf, pos: pos }
|
Encode { buf, pos }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Encode {
|
pub struct Encode {
|
||||||
|
|||||||
+14
-18
@@ -251,7 +251,7 @@ macro_rules! primitive_deserializer {
|
|||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn new(value: $ty) -> Self {
|
pub fn new(value: $ty) -> Self {
|
||||||
$name {
|
$name {
|
||||||
value: value,
|
value,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,7 +330,7 @@ impl<E> U32Deserializer<E> {
|
|||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn new(value: u32) -> Self {
|
pub fn new(value: u32) -> Self {
|
||||||
U32Deserializer {
|
U32Deserializer {
|
||||||
value: value,
|
value,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -419,7 +419,7 @@ impl<'a, E> StrDeserializer<'a, E> {
|
|||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn new(value: &'a str) -> Self {
|
pub fn new(value: &'a str) -> Self {
|
||||||
StrDeserializer {
|
StrDeserializer {
|
||||||
value: value,
|
value,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -498,7 +498,7 @@ impl<'de, E> BorrowedStrDeserializer<'de, E> {
|
|||||||
/// Create a new borrowed deserializer from the given string.
|
/// Create a new borrowed deserializer from the given string.
|
||||||
pub fn new(value: &'de str) -> BorrowedStrDeserializer<'de, E> {
|
pub fn new(value: &'de str) -> BorrowedStrDeserializer<'de, E> {
|
||||||
BorrowedStrDeserializer {
|
BorrowedStrDeserializer {
|
||||||
value: value,
|
value,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -598,7 +598,7 @@ impl<E> StringDeserializer<E> {
|
|||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn new(value: String) -> Self {
|
pub fn new(value: String) -> Self {
|
||||||
StringDeserializer {
|
StringDeserializer {
|
||||||
value: value,
|
value,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -701,7 +701,7 @@ impl<'a, E> CowStrDeserializer<'a, E> {
|
|||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn new(value: Cow<'a, str>) -> Self {
|
pub fn new(value: Cow<'a, str>) -> Self {
|
||||||
CowStrDeserializer {
|
CowStrDeserializer {
|
||||||
value: value,
|
value,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -783,7 +783,7 @@ impl<'a, E> BytesDeserializer<'a, E> {
|
|||||||
/// Create a new deserializer from the given bytes.
|
/// Create a new deserializer from the given bytes.
|
||||||
pub fn new(value: &'a [u8]) -> Self {
|
pub fn new(value: &'a [u8]) -> Self {
|
||||||
BytesDeserializer {
|
BytesDeserializer {
|
||||||
value: value,
|
value,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -842,7 +842,7 @@ impl<'de, E> BorrowedBytesDeserializer<'de, E> {
|
|||||||
/// Create a new borrowed deserializer from the given borrowed bytes.
|
/// Create a new borrowed deserializer from the given borrowed bytes.
|
||||||
pub fn new(value: &'de [u8]) -> Self {
|
pub fn new(value: &'de [u8]) -> Self {
|
||||||
BorrowedBytesDeserializer {
|
BorrowedBytesDeserializer {
|
||||||
value: value,
|
value,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1053,7 +1053,7 @@ pub struct SeqAccessDeserializer<A> {
|
|||||||
impl<A> SeqAccessDeserializer<A> {
|
impl<A> SeqAccessDeserializer<A> {
|
||||||
/// Construct a new `SeqAccessDeserializer<A>`.
|
/// Construct a new `SeqAccessDeserializer<A>`.
|
||||||
pub fn new(seq: A) -> Self {
|
pub fn new(seq: A) -> Self {
|
||||||
SeqAccessDeserializer { seq: seq }
|
SeqAccessDeserializer { seq }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1454,7 +1454,7 @@ pub struct MapAccessDeserializer<A> {
|
|||||||
impl<A> MapAccessDeserializer<A> {
|
impl<A> MapAccessDeserializer<A> {
|
||||||
/// Construct a new `MapAccessDeserializer<A>`.
|
/// Construct a new `MapAccessDeserializer<A>`.
|
||||||
pub fn new(map: A) -> Self {
|
pub fn new(map: A) -> Self {
|
||||||
MapAccessDeserializer { map: map }
|
MapAccessDeserializer { map }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1519,7 +1519,7 @@ pub struct EnumAccessDeserializer<A> {
|
|||||||
impl<A> EnumAccessDeserializer<A> {
|
impl<A> EnumAccessDeserializer<A> {
|
||||||
/// Construct a new `EnumAccessDeserializer<A>`.
|
/// Construct a new `EnumAccessDeserializer<A>`.
|
||||||
pub fn new(access: A) -> Self {
|
pub fn new(access: A) -> Self {
|
||||||
EnumAccessDeserializer { access: access }
|
EnumAccessDeserializer { access }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1613,7 +1613,7 @@ mod private {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn map_as_enum<A>(map: A) -> MapAsEnum<A> {
|
pub fn map_as_enum<A>(map: A) -> MapAsEnum<A> {
|
||||||
MapAsEnum { map: map }
|
MapAsEnum { map }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de, A> VariantAccess<'de> for MapAsEnum<A>
|
impl<'de, A> VariantAccess<'de> for MapAsEnum<A>
|
||||||
@@ -1637,10 +1637,7 @@ mod private {
|
|||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
self.map.next_value_seed(SeedTupleVariant {
|
self.map.next_value_seed(SeedTupleVariant { len, visitor })
|
||||||
len: len,
|
|
||||||
visitor: visitor,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn struct_variant<V>(
|
fn struct_variant<V>(
|
||||||
@@ -1651,8 +1648,7 @@ mod private {
|
|||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
self.map
|
self.map.next_value_seed(SeedStructVariant { visitor })
|
||||||
.next_value_seed(SeedStructVariant { visitor: visitor })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -93,7 +93,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.163")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.165")]
|
||||||
// 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)]
|
||||||
// Unstable functionality only if the user asks for it. For tracking and
|
// Unstable functionality only if the user asks for it. For tracking and
|
||||||
|
|||||||
+24
-16
@@ -518,7 +518,7 @@ mod content {
|
|||||||
impl<'de> TagOrContentVisitor<'de> {
|
impl<'de> TagOrContentVisitor<'de> {
|
||||||
fn new(name: &'static str) -> Self {
|
fn new(name: &'static str) -> Self {
|
||||||
TagOrContentVisitor {
|
TagOrContentVisitor {
|
||||||
name: name,
|
name,
|
||||||
value: PhantomData,
|
value: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -815,7 +815,7 @@ mod content {
|
|||||||
pub fn new(name: &'static str, expecting: &'static str) -> Self {
|
pub fn new(name: &'static str, expecting: &'static str) -> Self {
|
||||||
TaggedContentVisitor {
|
TaggedContentVisitor {
|
||||||
tag_name: name,
|
tag_name: name,
|
||||||
expecting: expecting,
|
expecting,
|
||||||
value: PhantomData,
|
value: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -859,7 +859,7 @@ mod content {
|
|||||||
};
|
};
|
||||||
let rest = de::value::SeqAccessDeserializer::new(seq);
|
let rest = de::value::SeqAccessDeserializer::new(seq);
|
||||||
Ok(TaggedContent {
|
Ok(TaggedContent {
|
||||||
tag: tag,
|
tag,
|
||||||
content: try!(Content::deserialize(rest)),
|
content: try!(Content::deserialize(rest)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -887,7 +887,7 @@ mod content {
|
|||||||
match tag {
|
match tag {
|
||||||
None => Err(de::Error::missing_field(self.tag_name)),
|
None => Err(de::Error::missing_field(self.tag_name)),
|
||||||
Some(tag) => Ok(TaggedContent {
|
Some(tag) => Ok(TaggedContent {
|
||||||
tag: tag,
|
tag,
|
||||||
content: Content::Map(vec),
|
content: Content::Map(vec),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@@ -1464,7 +1464,7 @@ mod content {
|
|||||||
/// private API, don't use
|
/// private API, don't use
|
||||||
pub fn new(content: Content<'de>) -> Self {
|
pub fn new(content: Content<'de>) -> Self {
|
||||||
ContentDeserializer {
|
ContentDeserializer {
|
||||||
content: content,
|
content,
|
||||||
err: PhantomData,
|
err: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1485,8 +1485,8 @@ mod content {
|
|||||||
{
|
{
|
||||||
pub fn new(variant: Content<'de>, value: Option<Content<'de>>) -> EnumDeserializer<'de, E> {
|
pub fn new(variant: Content<'de>, value: Option<Content<'de>>) -> EnumDeserializer<'de, E> {
|
||||||
EnumDeserializer {
|
EnumDeserializer {
|
||||||
variant: variant,
|
variant,
|
||||||
value: value,
|
value,
|
||||||
err: PhantomData,
|
err: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2142,8 +2142,8 @@ mod content {
|
|||||||
};
|
};
|
||||||
|
|
||||||
visitor.visit_enum(EnumRefDeserializer {
|
visitor.visit_enum(EnumRefDeserializer {
|
||||||
variant: variant,
|
variant,
|
||||||
value: value,
|
value,
|
||||||
err: PhantomData,
|
err: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -2187,12 +2187,20 @@ mod content {
|
|||||||
/// private API, don't use
|
/// private API, don't use
|
||||||
pub fn new(content: &'a Content<'de>) -> Self {
|
pub fn new(content: &'a Content<'de>) -> Self {
|
||||||
ContentRefDeserializer {
|
ContentRefDeserializer {
|
||||||
content: content,
|
content,
|
||||||
err: PhantomData,
|
err: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'de: 'a, E> Copy for ContentRefDeserializer<'a, 'de, E> {}
|
||||||
|
|
||||||
|
impl<'a, 'de: 'a, E> Clone for ContentRefDeserializer<'a, 'de, E> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct EnumRefDeserializer<'a, 'de: 'a, E>
|
struct EnumRefDeserializer<'a, 'de: 'a, E>
|
||||||
where
|
where
|
||||||
E: de::Error,
|
E: de::Error,
|
||||||
@@ -2488,8 +2496,8 @@ mod content {
|
|||||||
/// Not public API.
|
/// Not public API.
|
||||||
pub fn new(type_name: &'a str, variant_name: &'a str) -> Self {
|
pub fn new(type_name: &'a str, variant_name: &'a str) -> Self {
|
||||||
InternallyTaggedUnitVisitor {
|
InternallyTaggedUnitVisitor {
|
||||||
type_name: type_name,
|
type_name,
|
||||||
variant_name: variant_name,
|
variant_name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2533,8 +2541,8 @@ mod content {
|
|||||||
/// Not public API.
|
/// Not public API.
|
||||||
pub fn new(type_name: &'a str, variant_name: &'a str) -> Self {
|
pub fn new(type_name: &'a str, variant_name: &'a str) -> Self {
|
||||||
UntaggedUnitVisitor {
|
UntaggedUnitVisitor {
|
||||||
type_name: type_name,
|
type_name,
|
||||||
variant_name: variant_name,
|
variant_name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2750,7 +2758,7 @@ where
|
|||||||
where
|
where
|
||||||
V: Visitor<'de>,
|
V: Visitor<'de>,
|
||||||
{
|
{
|
||||||
for entry in self.0.iter_mut() {
|
for entry in self.0 {
|
||||||
if let Some((key, value)) = flat_map_take_entry(entry, variants) {
|
if let Some((key, value)) = flat_map_take_entry(entry, variants) {
|
||||||
return visitor.visit_enum(EnumDeserializer::new(key, Some(value)));
|
return visitor.visit_enum(EnumDeserializer::new(key, Some(value)));
|
||||||
}
|
}
|
||||||
@@ -2785,7 +2793,7 @@ where
|
|||||||
visitor.visit_map(FlatStructAccess {
|
visitor.visit_map(FlatStructAccess {
|
||||||
iter: self.0.iter_mut(),
|
iter: self.0.iter_mut(),
|
||||||
pending_content: None,
|
pending_content: None,
|
||||||
fields: fields,
|
fields,
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-18
@@ -27,10 +27,10 @@ where
|
|||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
value.serialize(TaggedSerializer {
|
value.serialize(TaggedSerializer {
|
||||||
type_ident: type_ident,
|
type_ident,
|
||||||
variant_ident: variant_ident,
|
variant_ident,
|
||||||
tag: tag,
|
tag,
|
||||||
variant_name: variant_name,
|
variant_name,
|
||||||
delegate: serializer,
|
delegate: serializer,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -350,8 +350,8 @@ mod content {
|
|||||||
impl<M> SerializeTupleVariantAsMapValue<M> {
|
impl<M> SerializeTupleVariantAsMapValue<M> {
|
||||||
pub fn new(map: M, name: &'static str, len: usize) -> Self {
|
pub fn new(map: M, name: &'static str, len: usize) -> Self {
|
||||||
SerializeTupleVariantAsMapValue {
|
SerializeTupleVariantAsMapValue {
|
||||||
map: map,
|
map,
|
||||||
name: name,
|
name,
|
||||||
fields: Vec::with_capacity(len),
|
fields: Vec::with_capacity(len),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -390,8 +390,8 @@ mod content {
|
|||||||
impl<M> SerializeStructVariantAsMapValue<M> {
|
impl<M> SerializeStructVariantAsMapValue<M> {
|
||||||
pub fn new(map: M, name: &'static str, len: usize) -> Self {
|
pub fn new(map: M, name: &'static str, len: usize) -> Self {
|
||||||
SerializeStructVariantAsMapValue {
|
SerializeStructVariantAsMapValue {
|
||||||
map: map,
|
map,
|
||||||
name: name,
|
name,
|
||||||
fields: Vec::with_capacity(len),
|
fields: Vec::with_capacity(len),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -711,7 +711,7 @@ mod content {
|
|||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<Self::SerializeTupleStruct, E> {
|
) -> Result<Self::SerializeTupleStruct, E> {
|
||||||
Ok(SerializeTupleStruct {
|
Ok(SerializeTupleStruct {
|
||||||
name: name,
|
name,
|
||||||
fields: Vec::with_capacity(len),
|
fields: Vec::with_capacity(len),
|
||||||
error: PhantomData,
|
error: PhantomData,
|
||||||
})
|
})
|
||||||
@@ -725,9 +725,9 @@ mod content {
|
|||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<Self::SerializeTupleVariant, E> {
|
) -> Result<Self::SerializeTupleVariant, E> {
|
||||||
Ok(SerializeTupleVariant {
|
Ok(SerializeTupleVariant {
|
||||||
name: name,
|
name,
|
||||||
variant_index: variant_index,
|
variant_index,
|
||||||
variant: variant,
|
variant,
|
||||||
fields: Vec::with_capacity(len),
|
fields: Vec::with_capacity(len),
|
||||||
error: PhantomData,
|
error: PhantomData,
|
||||||
})
|
})
|
||||||
@@ -747,7 +747,7 @@ mod content {
|
|||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<Self::SerializeStruct, E> {
|
) -> Result<Self::SerializeStruct, E> {
|
||||||
Ok(SerializeStruct {
|
Ok(SerializeStruct {
|
||||||
name: name,
|
name,
|
||||||
fields: Vec::with_capacity(len),
|
fields: Vec::with_capacity(len),
|
||||||
error: PhantomData,
|
error: PhantomData,
|
||||||
})
|
})
|
||||||
@@ -761,9 +761,9 @@ mod content {
|
|||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<Self::SerializeStructVariant, E> {
|
) -> Result<Self::SerializeStructVariant, E> {
|
||||||
Ok(SerializeStructVariant {
|
Ok(SerializeStructVariant {
|
||||||
name: name,
|
name,
|
||||||
variant_index: variant_index,
|
variant_index,
|
||||||
variant: variant,
|
variant,
|
||||||
fields: Vec::with_capacity(len),
|
fields: Vec::with_capacity(len),
|
||||||
error: PhantomData,
|
error: PhantomData,
|
||||||
})
|
})
|
||||||
@@ -1273,8 +1273,8 @@ where
|
|||||||
{
|
{
|
||||||
fn new(map: &'a mut M, name: &'static str) -> FlatMapSerializeStructVariantAsMapValue<'a, M> {
|
fn new(map: &'a mut M, name: &'static str) -> FlatMapSerializeStructVariantAsMapValue<'a, M> {
|
||||||
FlatMapSerializeStructVariantAsMapValue {
|
FlatMapSerializeStructVariantAsMapValue {
|
||||||
map: map,
|
map,
|
||||||
name: name,
|
name,
|
||||||
fields: Vec::new(),
|
fields: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -713,7 +713,7 @@ impl Serialize for net::IpAddr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
const DEC_DIGITS_LUT: &'static [u8] = b"\
|
const DEC_DIGITS_LUT: &[u8] = b"\
|
||||||
0001020304050607080910111213141516171819\
|
0001020304050607080910111213141516171819\
|
||||||
2021222324252627282930313233343536373839\
|
2021222324252627282930313233343536373839\
|
||||||
4041424344454647484950515253545556575859\
|
4041424344454647484950515253545556575859\
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
msrv = "1.31.0"
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.163" # remember to update html_root_url
|
version = "1.0.165" # remember to update html_root_url
|
||||||
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"]
|
categories = ["no-std"]
|
||||||
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
|
||||||
@@ -24,7 +24,7 @@ proc-macro = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
syn = "2.0.3"
|
syn = "2.0.21"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = { version = "1.0", path = "../serde" }
|
serde = { version = "1.0", path = "../serde" }
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ pub fn with_bound(
|
|||||||
};
|
};
|
||||||
match &cont.data {
|
match &cont.data {
|
||||||
Data::Enum(variants) => {
|
Data::Enum(variants) => {
|
||||||
for variant in variants.iter() {
|
for variant in variants {
|
||||||
let relevant_fields = variant
|
let relevant_fields = variant
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
+52
-21
@@ -15,9 +15,7 @@ use this;
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
pub fn expand_derive_deserialize(
|
pub fn expand_derive_deserialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
|
||||||
input: &mut syn::DeriveInput,
|
|
||||||
) -> Result<TokenStream, Vec<syn::Error>> {
|
|
||||||
replace_receiver(input);
|
replace_receiver(input);
|
||||||
|
|
||||||
let ctxt = Ctxt::new();
|
let ctxt = Ctxt::new();
|
||||||
@@ -447,14 +445,19 @@ fn deserialize_tuple(
|
|||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
deserializer: Option<TokenStream>,
|
deserializer: Option<TokenStream>,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
|
assert!(!cattrs.has_flatten());
|
||||||
|
|
||||||
|
let field_count = fields
|
||||||
|
.iter()
|
||||||
|
.filter(|field| !field.attrs.skip_deserializing())
|
||||||
|
.count();
|
||||||
|
|
||||||
let this_type = ¶ms.this_type;
|
let this_type = ¶ms.this_type;
|
||||||
let this_value = ¶ms.this_value;
|
let this_value = ¶ms.this_value;
|
||||||
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();
|
||||||
|
|
||||||
assert!(!cattrs.has_flatten());
|
|
||||||
|
|
||||||
// If there are getters (implying private fields), construct the local type
|
// If there are getters (implying private fields), construct the local type
|
||||||
// and use an `Into` conversion to get the remote type. If there are no
|
// and use an `Into` conversion to get the remote type. If there are no
|
||||||
// getters then construct the target type directly.
|
// getters then construct the target type directly.
|
||||||
@@ -495,19 +498,18 @@ fn deserialize_tuple(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let dispatch = if let Some(deserializer) = deserializer {
|
let dispatch = if let Some(deserializer) = deserializer {
|
||||||
quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #nfields, #visitor_expr))
|
quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #field_count, #visitor_expr))
|
||||||
} else if is_enum {
|
} else if is_enum {
|
||||||
quote!(_serde::de::VariantAccess::tuple_variant(__variant, #nfields, #visitor_expr))
|
quote!(_serde::de::VariantAccess::tuple_variant(__variant, #field_count, #visitor_expr))
|
||||||
} else if nfields == 1 {
|
} else if nfields == 1 {
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
quote!(_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr))
|
quote!(_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr))
|
||||||
} else {
|
} else {
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
quote!(_serde::Deserializer::deserialize_tuple_struct(__deserializer, #type_name, #nfields, #visitor_expr))
|
quote!(_serde::Deserializer::deserialize_tuple_struct(__deserializer, #type_name, #field_count, #visitor_expr))
|
||||||
};
|
};
|
||||||
|
|
||||||
let all_skipped = fields.iter().all(|field| field.attrs.skip_deserializing());
|
let visitor_var = if field_count == 0 {
|
||||||
let visitor_var = if all_skipped {
|
|
||||||
quote!(_)
|
quote!(_)
|
||||||
} else {
|
} else {
|
||||||
quote!(mut __seq)
|
quote!(mut __seq)
|
||||||
@@ -550,13 +552,18 @@ fn deserialize_tuple_in_place(
|
|||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
deserializer: Option<TokenStream>,
|
deserializer: Option<TokenStream>,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
|
assert!(!cattrs.has_flatten());
|
||||||
|
|
||||||
|
let field_count = fields
|
||||||
|
.iter()
|
||||||
|
.filter(|field| !field.attrs.skip_deserializing())
|
||||||
|
.count();
|
||||||
|
|
||||||
let this_type = ¶ms.this_type;
|
let this_type = ¶ms.this_type;
|
||||||
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();
|
||||||
|
|
||||||
assert!(!cattrs.has_flatten());
|
|
||||||
|
|
||||||
let is_enum = variant_ident.is_some();
|
let is_enum = variant_ident.is_some();
|
||||||
let expecting = match variant_ident {
|
let expecting = match variant_ident {
|
||||||
Some(variant_ident) => format!("tuple variant {}::{}", params.type_name(), variant_ident),
|
Some(variant_ident) => format!("tuple variant {}::{}", params.type_name(), variant_ident),
|
||||||
@@ -582,19 +589,18 @@ fn deserialize_tuple_in_place(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let dispatch = if let Some(deserializer) = deserializer {
|
let dispatch = if let Some(deserializer) = deserializer {
|
||||||
quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #nfields, #visitor_expr))
|
quote!(_serde::Deserializer::deserialize_tuple(#deserializer, #field_count, #visitor_expr))
|
||||||
} else if is_enum {
|
} else if is_enum {
|
||||||
quote!(_serde::de::VariantAccess::tuple_variant(__variant, #nfields, #visitor_expr))
|
quote!(_serde::de::VariantAccess::tuple_variant(__variant, #field_count, #visitor_expr))
|
||||||
} else if nfields == 1 {
|
} else if nfields == 1 {
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
quote!(_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr))
|
quote!(_serde::Deserializer::deserialize_newtype_struct(__deserializer, #type_name, #visitor_expr))
|
||||||
} else {
|
} else {
|
||||||
let type_name = cattrs.name().deserialize_name();
|
let type_name = cattrs.name().deserialize_name();
|
||||||
quote!(_serde::Deserializer::deserialize_tuple_struct(__deserializer, #type_name, #nfields, #visitor_expr))
|
quote!(_serde::Deserializer::deserialize_tuple_struct(__deserializer, #type_name, #field_count, #visitor_expr))
|
||||||
};
|
};
|
||||||
|
|
||||||
let all_skipped = fields.iter().all(|field| field.attrs.skip_deserializing());
|
let visitor_var = if field_count == 0 {
|
||||||
let visitor_var = if all_skipped {
|
|
||||||
quote!(_)
|
quote!(_)
|
||||||
} else {
|
} else {
|
||||||
quote!(mut __seq)
|
quote!(mut __seq)
|
||||||
@@ -1168,6 +1174,22 @@ fn deserialize_enum(
|
|||||||
params: &Parameters,
|
params: &Parameters,
|
||||||
variants: &[Variant],
|
variants: &[Variant],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
|
) -> Fragment {
|
||||||
|
// The variants have already been checked (in ast.rs) that all untagged variants appear at the end
|
||||||
|
match variants.iter().position(|var| var.attrs.untagged()) {
|
||||||
|
Some(variant_idx) => {
|
||||||
|
let (tagged, untagged) = variants.split_at(variant_idx);
|
||||||
|
let tagged_frag = Expr(deserialize_homogeneous_enum(params, tagged, cattrs));
|
||||||
|
deserialize_untagged_enum_after(params, untagged, cattrs, Some(tagged_frag))
|
||||||
|
}
|
||||||
|
None => deserialize_homogeneous_enum(params, variants, cattrs),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_homogeneous_enum(
|
||||||
|
params: &Parameters,
|
||||||
|
variants: &[Variant],
|
||||||
|
cattrs: &attr::Container,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
match cattrs.tag() {
|
match cattrs.tag() {
|
||||||
attr::TagType::External => deserialize_externally_tagged_enum(params, variants, cattrs),
|
attr::TagType::External => deserialize_externally_tagged_enum(params, variants, cattrs),
|
||||||
@@ -1668,6 +1690,16 @@ fn deserialize_untagged_enum(
|
|||||||
params: &Parameters,
|
params: &Parameters,
|
||||||
variants: &[Variant],
|
variants: &[Variant],
|
||||||
cattrs: &attr::Container,
|
cattrs: &attr::Container,
|
||||||
|
) -> Fragment {
|
||||||
|
let first_attempt = None;
|
||||||
|
deserialize_untagged_enum_after(params, variants, cattrs, first_attempt)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_untagged_enum_after(
|
||||||
|
params: &Parameters,
|
||||||
|
variants: &[Variant],
|
||||||
|
cattrs: &attr::Container,
|
||||||
|
first_attempt: Option<Expr>,
|
||||||
) -> Fragment {
|
) -> Fragment {
|
||||||
let attempts = variants
|
let attempts = variants
|
||||||
.iter()
|
.iter()
|
||||||
@@ -1677,12 +1709,10 @@ fn deserialize_untagged_enum(
|
|||||||
params,
|
params,
|
||||||
variant,
|
variant,
|
||||||
cattrs,
|
cattrs,
|
||||||
quote!(
|
quote!(__deserializer),
|
||||||
_serde::__private::de::ContentRefDeserializer::<__D::Error>::new(&__content)
|
|
||||||
),
|
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
let attempts = first_attempt.into_iter().chain(attempts);
|
||||||
// TODO this message could be better by saving the errors from the failed
|
// TODO this message could be better by saving the errors from the failed
|
||||||
// attempts. The heuristic used by TOML was to count the number of fields
|
// attempts. The heuristic used by TOML was to count the number of fields
|
||||||
// processed before an error, and use the error that happened after the
|
// processed before an error, and use the error that happened after the
|
||||||
@@ -1697,6 +1727,7 @@ fn deserialize_untagged_enum(
|
|||||||
|
|
||||||
quote_block! {
|
quote_block! {
|
||||||
let __content = try!(<_serde::__private::de::Content as _serde::Deserialize>::deserialize(__deserializer));
|
let __content = try!(<_serde::__private::de::Content as _serde::Deserialize>::deserialize(__deserializer));
|
||||||
|
let __deserializer = _serde::__private::de::ContentRefDeserializer::<__D::Error>::new(&__content);
|
||||||
|
|
||||||
#(
|
#(
|
||||||
if let _serde::__private::Ok(__ok) = #attempts {
|
if let _serde::__private::Ok(__ok) = #attempts {
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ fn enum_from_ast<'a>(
|
|||||||
variants: &'a Punctuated<syn::Variant, Token![,]>,
|
variants: &'a Punctuated<syn::Variant, Token![,]>,
|
||||||
container_default: &attr::Default,
|
container_default: &attr::Default,
|
||||||
) -> Vec<Variant<'a>> {
|
) -> Vec<Variant<'a>> {
|
||||||
variants
|
let variants: Vec<Variant> = variants
|
||||||
.iter()
|
.iter()
|
||||||
.map(|variant| {
|
.map(|variant| {
|
||||||
let attrs = attr::Variant::from_ast(cx, variant);
|
let attrs = attr::Variant::from_ast(cx, variant);
|
||||||
@@ -154,7 +154,20 @@ fn enum_from_ast<'a>(
|
|||||||
original: variant,
|
original: variant,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect();
|
||||||
|
|
||||||
|
let index_of_last_tagged_variant = variants
|
||||||
|
.iter()
|
||||||
|
.rposition(|variant| !variant.attrs.untagged());
|
||||||
|
if let Some(index_of_last_tagged_variant) = index_of_last_tagged_variant {
|
||||||
|
for variant in &variants[..index_of_last_tagged_variant] {
|
||||||
|
if variant.attrs.untagged() {
|
||||||
|
cx.error_spanned_by(&variant.ident, "all variants with the #[serde(untagged)] attribute must be placed at the end of the enum");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variants
|
||||||
}
|
}
|
||||||
|
|
||||||
fn struct_from_ast<'a>(
|
fn struct_from_ast<'a>(
|
||||||
|
|||||||
@@ -740,6 +740,7 @@ pub struct Variant {
|
|||||||
serialize_with: Option<syn::ExprPath>,
|
serialize_with: Option<syn::ExprPath>,
|
||||||
deserialize_with: Option<syn::ExprPath>,
|
deserialize_with: Option<syn::ExprPath>,
|
||||||
borrow: Option<BorrowAttribute>,
|
borrow: Option<BorrowAttribute>,
|
||||||
|
untagged: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BorrowAttribute {
|
struct BorrowAttribute {
|
||||||
@@ -762,6 +763,7 @@ impl Variant {
|
|||||||
let mut serialize_with = Attr::none(cx, SERIALIZE_WITH);
|
let mut serialize_with = Attr::none(cx, SERIALIZE_WITH);
|
||||||
let mut deserialize_with = Attr::none(cx, DESERIALIZE_WITH);
|
let mut deserialize_with = Attr::none(cx, DESERIALIZE_WITH);
|
||||||
let mut borrow = Attr::none(cx, BORROW);
|
let mut borrow = Attr::none(cx, BORROW);
|
||||||
|
let mut untagged = BoolAttr::none(cx, UNTAGGED);
|
||||||
|
|
||||||
for attr in &variant.attrs {
|
for attr in &variant.attrs {
|
||||||
if attr.path() != SERDE {
|
if attr.path() != SERDE {
|
||||||
@@ -879,6 +881,8 @@ impl Variant {
|
|||||||
cx.error_spanned_by(variant, msg);
|
cx.error_spanned_by(variant, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if meta.path == UNTAGGED {
|
||||||
|
untagged.set_true(&meta.path);
|
||||||
} else {
|
} else {
|
||||||
let path = meta.path.to_token_stream().to_string().replace(' ', "");
|
let path = meta.path.to_token_stream().to_string().replace(' ', "");
|
||||||
return Err(
|
return Err(
|
||||||
@@ -905,6 +909,7 @@ impl Variant {
|
|||||||
serialize_with: serialize_with.get(),
|
serialize_with: serialize_with.get(),
|
||||||
deserialize_with: deserialize_with.get(),
|
deserialize_with: deserialize_with.get(),
|
||||||
borrow: borrow.get(),
|
borrow: borrow.get(),
|
||||||
|
untagged: untagged.get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -956,6 +961,10 @@ impl Variant {
|
|||||||
pub fn deserialize_with(&self) -> Option<&syn::ExprPath> {
|
pub fn deserialize_with(&self) -> Option<&syn::ExprPath> {
|
||||||
self.deserialize_with.as_ref()
|
self.deserialize_with.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn untagged(&self) -> bool {
|
||||||
|
self.untagged
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents field attribute information
|
/// Represents field attribute information
|
||||||
|
|||||||
@@ -110,9 +110,7 @@ fn check_flatten_field(cx: &Ctxt, style: Style, field: &Field) {
|
|||||||
fn check_identifier(cx: &Ctxt, cont: &Container) {
|
fn check_identifier(cx: &Ctxt, cont: &Container) {
|
||||||
let variants = match &cont.data {
|
let variants = match &cont.data {
|
||||||
Data::Enum(variants) => variants,
|
Data::Enum(variants) => variants,
|
||||||
Data::Struct(_, _) => {
|
Data::Struct(_, _) => return,
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i, variant) in variants.iter().enumerate() {
|
for (i, variant) in variants.iter().enumerate() {
|
||||||
@@ -194,12 +192,10 @@ fn check_identifier(cx: &Ctxt, cont: &Container) {
|
|||||||
fn check_variant_skip_attrs(cx: &Ctxt, cont: &Container) {
|
fn check_variant_skip_attrs(cx: &Ctxt, cont: &Container) {
|
||||||
let variants = match &cont.data {
|
let variants = match &cont.data {
|
||||||
Data::Enum(variants) => variants,
|
Data::Enum(variants) => variants,
|
||||||
Data::Struct(_, _) => {
|
Data::Struct(_, _) => return,
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for variant in variants.iter() {
|
for variant in variants {
|
||||||
if variant.attrs.serialize_with().is_some() {
|
if variant.attrs.serialize_with().is_some() {
|
||||||
if variant.attrs.skip_serializing() {
|
if variant.attrs.skip_serializing() {
|
||||||
cx.error_spanned_by(
|
cx.error_spanned_by(
|
||||||
|
|||||||
@@ -44,12 +44,19 @@ impl Ctxt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Consume this object, producing a formatted error string if there are errors.
|
/// Consume this object, producing a formatted error string if there are errors.
|
||||||
pub fn check(self) -> Result<(), Vec<syn::Error>> {
|
pub fn check(self) -> syn::Result<()> {
|
||||||
let errors = self.errors.borrow_mut().take().unwrap();
|
let mut errors = self.errors.borrow_mut().take().unwrap().into_iter();
|
||||||
match errors.len() {
|
|
||||||
0 => Ok(()),
|
let mut combined = match errors.next() {
|
||||||
_ => Err(errors),
|
Some(first) => first,
|
||||||
|
None => return Ok(()),
|
||||||
|
};
|
||||||
|
|
||||||
|
for rest in errors {
|
||||||
|
combined.combine(rest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Err(combined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.163")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.165")]
|
||||||
#![allow(unknown_lints, bare_trait_objects)]
|
#![allow(unknown_lints, bare_trait_objects)]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
#![allow(
|
#![allow(
|
||||||
@@ -92,7 +92,7 @@ mod try;
|
|||||||
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
||||||
let mut input = parse_macro_input!(input as DeriveInput);
|
let mut input = parse_macro_input!(input as DeriveInput);
|
||||||
ser::expand_derive_serialize(&mut input)
|
ser::expand_derive_serialize(&mut input)
|
||||||
.unwrap_or_else(to_compile_errors)
|
.unwrap_or_else(syn::Error::into_compile_error)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,11 +100,6 @@ pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
|||||||
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
||||||
let mut input = parse_macro_input!(input as DeriveInput);
|
let mut input = parse_macro_input!(input as DeriveInput);
|
||||||
de::expand_derive_deserialize(&mut input)
|
de::expand_derive_deserialize(&mut input)
|
||||||
.unwrap_or_else(to_compile_errors)
|
.unwrap_or_else(syn::Error::into_compile_error)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_compile_errors(errors: Vec<syn::Error>) -> proc_macro2::TokenStream {
|
|
||||||
let compile_errors = errors.iter().map(syn::Error::to_compile_error);
|
|
||||||
quote!(#(#compile_errors)*)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ use internals::{attr, replace_receiver, Ctxt, Derive};
|
|||||||
use pretend;
|
use pretend;
|
||||||
use this;
|
use this;
|
||||||
|
|
||||||
pub fn expand_derive_serialize(
|
pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
|
||||||
input: &mut syn::DeriveInput,
|
|
||||||
) -> Result<TokenStream, Vec<syn::Error>> {
|
|
||||||
replace_receiver(input);
|
replace_receiver(input);
|
||||||
|
|
||||||
let ctxt = Ctxt::new();
|
let ctxt = Ctxt::new();
|
||||||
@@ -475,17 +473,19 @@ fn serialize_variant(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = Match(match cattrs.tag() {
|
let body = Match(match (cattrs.tag(), variant.attrs.untagged()) {
|
||||||
attr::TagType::External => {
|
(attr::TagType::External, false) => {
|
||||||
serialize_externally_tagged_variant(params, variant, variant_index, cattrs)
|
serialize_externally_tagged_variant(params, variant, variant_index, cattrs)
|
||||||
}
|
}
|
||||||
attr::TagType::Internal { tag } => {
|
(attr::TagType::Internal { tag }, false) => {
|
||||||
serialize_internally_tagged_variant(params, variant, cattrs, tag)
|
serialize_internally_tagged_variant(params, variant, cattrs, tag)
|
||||||
}
|
}
|
||||||
attr::TagType::Adjacent { tag, content } => {
|
(attr::TagType::Adjacent { tag, content }, false) => {
|
||||||
serialize_adjacently_tagged_variant(params, variant, cattrs, tag, content)
|
serialize_adjacently_tagged_variant(params, variant, cattrs, tag, content)
|
||||||
}
|
}
|
||||||
attr::TagType::None => serialize_untagged_variant(params, variant, cattrs),
|
(attr::TagType::None, _) | (_, true) => {
|
||||||
|
serialize_untagged_variant(params, variant, cattrs)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
msrv = "1.31.0"
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive_internals"
|
name = "serde_derive_internals"
|
||||||
version = "0.27.0" # remember to update html_root_url
|
version = "0.28.0" # remember to update html_root_url
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
|
||||||
description = "AST representation used by Serde derive macros. Unstable."
|
description = "AST representation used by Serde derive macros. Unstable."
|
||||||
documentation = "https://docs.rs/serde_derive_internals"
|
documentation = "https://docs.rs/serde_derive_internals"
|
||||||
@@ -17,7 +17,7 @@ path = "lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
syn = { version = "2.0", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] }
|
syn = { version = "2.0.21", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.27.0")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.28.0")]
|
||||||
#![allow(unknown_lints, bare_trait_objects)]
|
#![allow(unknown_lints, bare_trait_objects)]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
#![allow(
|
#![allow(
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
msrv = "1.13.0"
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_test"
|
name = "serde_test"
|
||||||
version = "1.0.163" # remember to update html_root_url
|
version = "1.0.165" # remember to update html_root_url
|
||||||
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 = ["development-tools::testing"]
|
categories = ["development-tools::testing"]
|
||||||
|
|||||||
@@ -140,7 +140,7 @@
|
|||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.163")]
|
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.165")]
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||||
// Ignored clippy lints
|
// Ignored clippy lints
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp, needless_doctest_main))]
|
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp, needless_doctest_main))]
|
||||||
|
|||||||
@@ -1533,7 +1533,7 @@ fn test_invalid_length_enum() {
|
|||||||
Token::TupleVariant {
|
Token::TupleVariant {
|
||||||
name: "InvalidLengthEnum",
|
name: "InvalidLengthEnum",
|
||||||
variant: "B",
|
variant: "B",
|
||||||
len: 3,
|
len: 2,
|
||||||
},
|
},
|
||||||
Token::I32(1),
|
Token::I32(1),
|
||||||
Token::TupleVariantEnd,
|
Token::TupleVariantEnd,
|
||||||
@@ -2442,6 +2442,162 @@ fn test_untagged_enum_containing_flatten() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_partially_untagged_enum() {
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
enum Exp {
|
||||||
|
Lambda(u32, Box<Exp>),
|
||||||
|
#[serde(untagged)]
|
||||||
|
App(Box<Exp>, Box<Exp>),
|
||||||
|
#[serde(untagged)]
|
||||||
|
Var(u32),
|
||||||
|
}
|
||||||
|
use Exp::*;
|
||||||
|
|
||||||
|
let data = Lambda(0, Box::new(App(Box::new(Var(0)), Box::new(Var(0)))));
|
||||||
|
assert_tokens(
|
||||||
|
&data,
|
||||||
|
&[
|
||||||
|
Token::TupleVariant {
|
||||||
|
name: "Exp",
|
||||||
|
variant: "Lambda",
|
||||||
|
len: 2,
|
||||||
|
},
|
||||||
|
Token::U32(0),
|
||||||
|
Token::Tuple { len: 2 },
|
||||||
|
Token::U32(0),
|
||||||
|
Token::U32(0),
|
||||||
|
Token::TupleEnd,
|
||||||
|
Token::TupleVariantEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_partially_untagged_enum_generic() {
|
||||||
|
trait Trait<T> {
|
||||||
|
type Assoc;
|
||||||
|
type Assoc2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
enum E<A, B, C>
|
||||||
|
where
|
||||||
|
A: Trait<C, Assoc2 = B>,
|
||||||
|
{
|
||||||
|
A(A::Assoc),
|
||||||
|
#[serde(untagged)]
|
||||||
|
B(A::Assoc2),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Trait<T> for () {
|
||||||
|
type Assoc = T;
|
||||||
|
type Assoc2 = bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
type MyE = E<(), bool, u32>;
|
||||||
|
use E::*;
|
||||||
|
|
||||||
|
assert_tokens::<MyE>(&B(true), &[Token::Bool(true)]);
|
||||||
|
|
||||||
|
assert_tokens::<MyE>(
|
||||||
|
&A(5),
|
||||||
|
&[
|
||||||
|
Token::NewtypeVariant {
|
||||||
|
name: "E",
|
||||||
|
variant: "A",
|
||||||
|
},
|
||||||
|
Token::U32(5),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_partially_untagged_enum_desugared() {
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
enum Test {
|
||||||
|
A(u32, u32),
|
||||||
|
B(u32),
|
||||||
|
#[serde(untagged)]
|
||||||
|
C(u32),
|
||||||
|
#[serde(untagged)]
|
||||||
|
D(u32, u32),
|
||||||
|
}
|
||||||
|
use Test::*;
|
||||||
|
|
||||||
|
mod desugared {
|
||||||
|
use super::*;
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
pub(super) enum Test {
|
||||||
|
A(u32, u32),
|
||||||
|
B(u32),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
use desugared::Test as TestTagged;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum TestUntagged {
|
||||||
|
Tagged(TestTagged),
|
||||||
|
C(u32),
|
||||||
|
D(u32, u32),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Test> for TestUntagged {
|
||||||
|
fn from(test: Test) -> Self {
|
||||||
|
match test {
|
||||||
|
A(x, y) => TestUntagged::Tagged(TestTagged::A(x, y)),
|
||||||
|
B(x) => TestUntagged::Tagged(TestTagged::B(x)),
|
||||||
|
C(x) => TestUntagged::C(x),
|
||||||
|
D(x, y) => TestUntagged::D(x, y),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn assert_tokens_desugared(value: Test, tokens: &[Token]) {
|
||||||
|
assert_tokens(&value, tokens);
|
||||||
|
let desugared: TestUntagged = value.into();
|
||||||
|
assert_tokens(&desugared, tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_tokens_desugared(
|
||||||
|
A(0, 1),
|
||||||
|
&[
|
||||||
|
Token::TupleVariant {
|
||||||
|
name: "Test",
|
||||||
|
variant: "A",
|
||||||
|
len: 2,
|
||||||
|
},
|
||||||
|
Token::U32(0),
|
||||||
|
Token::U32(1),
|
||||||
|
Token::TupleVariantEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_tokens_desugared(
|
||||||
|
B(1),
|
||||||
|
&[
|
||||||
|
Token::NewtypeVariant {
|
||||||
|
name: "Test",
|
||||||
|
variant: "B",
|
||||||
|
},
|
||||||
|
Token::U32(1),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_tokens_desugared(C(2), &[Token::U32(2)]);
|
||||||
|
|
||||||
|
assert_tokens_desugared(
|
||||||
|
D(3, 5),
|
||||||
|
&[
|
||||||
|
Token::Tuple { len: 2 },
|
||||||
|
Token::U32(3),
|
||||||
|
Token::U32(5),
|
||||||
|
Token::TupleEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_flatten_untagged_enum() {
|
fn test_flatten_untagged_enum() {
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
|||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::ffi::{CStr, CString, OsString};
|
use std::ffi::{CStr, CString, OsString};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
use std::iter;
|
||||||
use std::net;
|
use std::net;
|
||||||
use std::num::{
|
use std::num::{
|
||||||
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
|
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
|
||||||
@@ -199,7 +200,7 @@ fn assert_de_tokens_ignore(ignorable_tokens: &[Token]) {
|
|||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(ignorable_tokens.iter().copied())
|
.chain(ignorable_tokens.iter().copied())
|
||||||
.chain(vec![Token::MapEnd].into_iter())
|
.chain(iter::once(Token::MapEnd))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let expected = IgnoreBase { a: 1 };
|
let expected = IgnoreBase { a: 1 };
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
use serde_derive::Serialize;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
enum E {
|
||||||
|
#[serde(untagged)]
|
||||||
|
A(u8),
|
||||||
|
B(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
error: all variants with the #[serde(untagged)] attribute must be placed at the end of the enum
|
||||||
|
--> tests/ui/enum-representation/partially_tagged_wrong_order.rs:6:5
|
||||||
|
|
|
||||||
|
6 | A(u8),
|
||||||
|
| ^
|
||||||
Reference in New Issue
Block a user