mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-28 12:37:58 +00:00
Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 89c4b02bf3 | |||
| eeb8e44cda | |||
| 785c2d9605 | |||
| d549f048e1 | |||
| 4c0dd63011 | |||
| 26fb134165 | |||
| 07e614b52b | |||
| b1f899fbe8 | |||
| b4f860e627 | |||
| d940fe1b49 | |||
| f2899a9e06 | |||
| 3aca38d2d3 | |||
| 8b769fcc20 | |||
| 9c954264f4 | |||
| 74b538b8ec | |||
| 291ec50d98 | |||
| 21c7fd1bd5 |
@@ -0,0 +1 @@
|
|||||||
|
github: dtolnay
|
||||||
@@ -21,6 +21,11 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: dtolnay/rust-toolchain@nightly
|
- uses: dtolnay/rust-toolchain@nightly
|
||||||
- run: cd test_suite && cargo test --features unstable
|
- run: cd test_suite && cargo test --features unstable
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: Cargo.lock
|
||||||
|
path: Cargo.lock
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
name: Test suite (windows)
|
name: Test suite (windows)
|
||||||
@@ -90,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.209"
|
version = "1.0.211"
|
||||||
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.209", path = "../serde_derive" }
|
serde_derive = { version = "=1.0.211", path = "../serde_derive" }
|
||||||
|
|
||||||
|
|
||||||
### FEATURES #################################################################
|
### FEATURES #################################################################
|
||||||
|
|||||||
+19
-5
@@ -15,6 +15,8 @@ fn main() {
|
|||||||
|
|
||||||
if minor >= 77 {
|
if minor >= 77 {
|
||||||
println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");
|
println!("cargo:rustc-check-cfg=cfg(no_core_cstr)");
|
||||||
|
println!("cargo:rustc-check-cfg=cfg(no_core_error)");
|
||||||
|
println!("cargo:rustc-check-cfg=cfg(no_core_net)");
|
||||||
println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)");
|
println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)");
|
||||||
println!("cargo:rustc-check-cfg=cfg(no_core_try_from)");
|
println!("cargo:rustc-check-cfg=cfg(no_core_try_from)");
|
||||||
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
|
println!("cargo:rustc-check-cfg=cfg(no_diagnostic_namespace)");
|
||||||
@@ -48,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");
|
||||||
@@ -74,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 {
|
||||||
@@ -86,11 +88,23 @@ fn main() {
|
|||||||
println!("cargo:rustc-cfg=no_core_num_saturating");
|
println!("cargo:rustc-cfg=no_core_num_saturating");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Support for core::net stabilized in Rust 1.77.
|
||||||
|
// https://blog.rust-lang.org/2024/03/21/Rust-1.77.0.html
|
||||||
|
if minor < 77 {
|
||||||
|
println!("cargo:rustc-cfg=no_core_net");
|
||||||
|
}
|
||||||
|
|
||||||
// Support for the `#[diagnostic]` tool attribute namespace
|
// Support for the `#[diagnostic]` tool attribute namespace
|
||||||
// https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html#diagnostic-attributes
|
// https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html#diagnostic-attributes
|
||||||
if minor < 78 {
|
if minor < 78 {
|
||||||
println!("cargo:rustc-cfg=no_diagnostic_namespace");
|
println!("cargo:rustc-cfg=no_diagnostic_namespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The Error trait became available in core in 1.81.
|
||||||
|
// https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#coreerrorerror
|
||||||
|
if minor < 81 {
|
||||||
|
println!("cargo:rustc-cfg=no_core_error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rustc_minor_version() -> Option<u32> {
|
fn rustc_minor_version() -> Option<u32> {
|
||||||
|
|||||||
+16
-30
@@ -1583,12 +1583,9 @@ map_impl! {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
macro_rules! parse_ip_impl {
|
macro_rules! parse_ip_impl {
|
||||||
(
|
($ty:ty, $expecting:expr, $size:tt) => {
|
||||||
$(#[$attr:meta])*
|
|
||||||
$ty:ty, $expecting:expr, $size:tt
|
|
||||||
) => {
|
|
||||||
$(#[$attr])*
|
|
||||||
impl<'de> Deserialize<'de> for $ty {
|
impl<'de> Deserialize<'de> for $ty {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@@ -1604,7 +1601,7 @@ macro_rules! parse_ip_impl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
macro_rules! variant_identifier {
|
macro_rules! variant_identifier {
|
||||||
(
|
(
|
||||||
$name_kind:ident ($($variant:ident; $bytes:expr; $index:expr),*)
|
$name_kind:ident ($($variant:ident; $bytes:expr; $index:expr),*)
|
||||||
@@ -1679,7 +1676,7 @@ macro_rules! variant_identifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
macro_rules! deserialize_enum {
|
macro_rules! deserialize_enum {
|
||||||
(
|
(
|
||||||
$name:ident $name_kind:ident ($($variant:ident; $bytes:expr; $index:expr),*)
|
$name:ident $name_kind:ident ($($variant:ident; $bytes:expr; $index:expr),*)
|
||||||
@@ -1716,8 +1713,7 @@ macro_rules! deserialize_enum {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
impl<'de> Deserialize<'de> for net::IpAddr {
|
impl<'de> Deserialize<'de> for net::IpAddr {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@@ -1736,25 +1732,18 @@ impl<'de> Deserialize<'de> for net::IpAddr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_ip_impl! {
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg(feature = "std")]
|
parse_ip_impl!(net::Ipv4Addr, "IPv4 address", 4);
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
net::Ipv4Addr, "IPv4 address", 4
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_ip_impl! {
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg(feature = "std")]
|
parse_ip_impl!(net::Ipv6Addr, "IPv6 address", 16);
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
net::Ipv6Addr, "IPv6 address", 16
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
macro_rules! parse_socket_impl {
|
macro_rules! parse_socket_impl {
|
||||||
(
|
(
|
||||||
$(#[$attr:meta])*
|
|
||||||
$ty:ty, $expecting:tt,
|
$ty:ty, $expecting:tt,
|
||||||
$new:expr,
|
$new:expr,
|
||||||
) => {
|
) => {
|
||||||
$(#[$attr])*
|
|
||||||
impl<'de> Deserialize<'de> for $ty {
|
impl<'de> Deserialize<'de> for $ty {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@@ -1770,8 +1759,7 @@ macro_rules! parse_socket_impl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
impl<'de> Deserialize<'de> for net::SocketAddr {
|
impl<'de> Deserialize<'de> for net::SocketAddr {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@@ -1790,16 +1778,14 @@ impl<'de> Deserialize<'de> for net::SocketAddr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
parse_socket_impl! {
|
parse_socket_impl! {
|
||||||
#[cfg(feature = "std")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
net::SocketAddrV4, "IPv4 socket address",
|
net::SocketAddrV4, "IPv4 socket address",
|
||||||
|(ip, port)| net::SocketAddrV4::new(ip, port),
|
|(ip, port)| net::SocketAddrV4::new(ip, port),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
parse_socket_impl! {
|
parse_socket_impl! {
|
||||||
#[cfg(feature = "std")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
net::SocketAddrV6, "IPv6 socket address",
|
net::SocketAddrV6, "IPv6 socket address",
|
||||||
|(ip, port)| net::SocketAddrV6::new(ip, port, 0, 0),
|
|(ip, port)| net::SocketAddrV6::new(ip, port, 0, 0),
|
||||||
}
|
}
|
||||||
@@ -3160,13 +3146,13 @@ atomic_impl! {
|
|||||||
AtomicU64 "64"
|
AtomicU64 "64"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
struct FromStrVisitor<T> {
|
struct FromStrVisitor<T> {
|
||||||
expecting: &'static str,
|
expecting: &'static str,
|
||||||
ty: PhantomData<T>,
|
ty: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
impl<T> FromStrVisitor<T> {
|
impl<T> FromStrVisitor<T> {
|
||||||
fn new(expecting: &'static str) -> Self {
|
fn new(expecting: &'static str) -> Self {
|
||||||
FromStrVisitor {
|
FromStrVisitor {
|
||||||
@@ -3176,7 +3162,7 @@ impl<T> FromStrVisitor<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
impl<'de, T> Visitor<'de> for FromStrVisitor<T>
|
impl<'de, T> Visitor<'de> for FromStrVisitor<T>
|
||||||
where
|
where
|
||||||
T: str::FromStr,
|
T: str::FromStr,
|
||||||
|
|||||||
+8
-9
@@ -118,17 +118,16 @@ use crate::lib::*;
|
|||||||
|
|
||||||
pub mod value;
|
pub mod value;
|
||||||
|
|
||||||
mod format;
|
|
||||||
mod ignored_any;
|
mod ignored_any;
|
||||||
mod impls;
|
mod impls;
|
||||||
pub(crate) mod size_hint;
|
pub(crate) mod size_hint;
|
||||||
|
|
||||||
pub use self::ignored_any::IgnoredAny;
|
pub use self::ignored_any::IgnoredAny;
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use crate::std_error::Error as StdError;
|
pub use crate::std_error::Error as StdError;
|
||||||
#[cfg(all(feature = "unstable", not(feature = "std")))]
|
#[cfg(not(any(feature = "std", no_core_error)))]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use core::error::Error as StdError;
|
pub use core::error::Error as StdError;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@@ -487,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)
|
||||||
}
|
}
|
||||||
@@ -1374,7 +1373,7 @@ pub trait Visitor<'de>: Sized {
|
|||||||
E: Error,
|
E: Error,
|
||||||
{
|
{
|
||||||
let mut buf = [0u8; 58];
|
let mut buf = [0u8; 58];
|
||||||
let mut writer = format::Buf::new(&mut buf);
|
let mut writer = crate::format::Buf::new(&mut buf);
|
||||||
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as i128", v)).unwrap();
|
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as i128", v)).unwrap();
|
||||||
Err(Error::invalid_type(
|
Err(Error::invalid_type(
|
||||||
Unexpected::Other(writer.as_str()),
|
Unexpected::Other(writer.as_str()),
|
||||||
@@ -1436,7 +1435,7 @@ pub trait Visitor<'de>: Sized {
|
|||||||
E: Error,
|
E: Error,
|
||||||
{
|
{
|
||||||
let mut buf = [0u8; 57];
|
let mut buf = [0u8; 57];
|
||||||
let mut writer = format::Buf::new(&mut buf);
|
let mut writer = crate::format::Buf::new(&mut buf);
|
||||||
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as u128", v)).unwrap();
|
fmt::Write::write_fmt(&mut writer, format_args!("integer `{}` as u128", v)).unwrap();
|
||||||
Err(Error::invalid_type(
|
Err(Error::invalid_type(
|
||||||
Unexpected::Other(writer.as_str()),
|
Unexpected::Other(writer.as_str()),
|
||||||
@@ -1742,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>,
|
||||||
{
|
{
|
||||||
@@ -1895,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>,
|
||||||
{
|
{
|
||||||
|
|||||||
+11
-3
@@ -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.209")]
|
#![doc(html_root_url = "https://docs.rs/serde/1.0.211")]
|
||||||
// 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,
|
||||||
@@ -238,8 +239,13 @@ mod lib {
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::ffi::CString;
|
pub use std::ffi::CString;
|
||||||
|
|
||||||
|
#[cfg(all(not(no_core_net), not(feature = "std")))]
|
||||||
|
pub use self::core::net;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::{error, net};
|
pub use std::net;
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub use std::error;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::collections::{HashMap, HashSet};
|
pub use std::collections::{HashMap, HashSet};
|
||||||
@@ -305,6 +311,8 @@ mod integer128;
|
|||||||
pub mod de;
|
pub mod de;
|
||||||
pub mod ser;
|
pub mod ser;
|
||||||
|
|
||||||
|
mod format;
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use crate::de::{Deserialize, Deserializer};
|
pub use crate::de::{Deserialize, Deserializer};
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
@@ -318,7 +326,7 @@ pub mod __private;
|
|||||||
#[path = "de/seed.rs"]
|
#[path = "de/seed.rs"]
|
||||||
mod seed;
|
mod seed;
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||||
mod std_error;
|
mod std_error;
|
||||||
|
|
||||||
// Re-export #[derive(Serialize, Deserialize)].
|
// Re-export #[derive(Serialize, Deserialize)].
|
||||||
|
|||||||
+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>;
|
||||||
|
|||||||
+13
-29
@@ -773,28 +773,17 @@ impl Serialize for SystemTime {
|
|||||||
/// statically known to never have more than a constant `MAX_LEN` bytes.
|
/// statically known to never have more than a constant `MAX_LEN` bytes.
|
||||||
///
|
///
|
||||||
/// Panics if the `Display` impl tries to write more than `MAX_LEN` bytes.
|
/// Panics if the `Display` impl tries to write more than `MAX_LEN` bytes.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
macro_rules! serialize_display_bounded_length {
|
macro_rules! serialize_display_bounded_length {
|
||||||
($value:expr, $max:expr, $serializer:expr) => {{
|
($value:expr, $max:expr, $serializer:expr) => {{
|
||||||
let mut buffer = [0u8; $max];
|
let mut buffer = [0u8; $max];
|
||||||
let remaining_len = {
|
let mut writer = crate::format::Buf::new(&mut buffer);
|
||||||
let mut remaining = &mut buffer[..];
|
write!(&mut writer, "{}", $value).unwrap();
|
||||||
write!(remaining, "{}", $value).unwrap();
|
$serializer.serialize_str(writer.as_str())
|
||||||
remaining.len()
|
|
||||||
};
|
|
||||||
let written_len = buffer.len() - remaining_len;
|
|
||||||
let written = &buffer[..written_len];
|
|
||||||
|
|
||||||
// write! only provides fmt::Formatter to Display implementations, which
|
|
||||||
// has methods write_str and write_char but no method to write arbitrary
|
|
||||||
// bytes. Therefore `written` must be valid UTF-8.
|
|
||||||
let written_str = str::from_utf8(written).expect("must be valid UTF-8");
|
|
||||||
$serializer.serialize_str(written_str)
|
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
impl Serialize for net::IpAddr {
|
impl Serialize for net::IpAddr {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@@ -818,7 +807,7 @@ impl Serialize for net::IpAddr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
const DEC_DIGITS_LUT: &[u8] = b"\
|
const DEC_DIGITS_LUT: &[u8] = b"\
|
||||||
0001020304050607080910111213141516171819\
|
0001020304050607080910111213141516171819\
|
||||||
2021222324252627282930313233343536373839\
|
2021222324252627282930313233343536373839\
|
||||||
@@ -826,7 +815,7 @@ const DEC_DIGITS_LUT: &[u8] = b"\
|
|||||||
6061626364656667686970717273747576777879\
|
6061626364656667686970717273747576777879\
|
||||||
8081828384858687888990919293949596979899";
|
8081828384858687888990919293949596979899";
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn format_u8(mut n: u8, out: &mut [u8]) -> usize {
|
fn format_u8(mut n: u8, out: &mut [u8]) -> usize {
|
||||||
if n >= 100 {
|
if n >= 100 {
|
||||||
@@ -847,7 +836,7 @@ fn format_u8(mut n: u8, out: &mut [u8]) -> usize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_format_u8() {
|
fn test_format_u8() {
|
||||||
let mut i = 0u8;
|
let mut i = 0u8;
|
||||||
@@ -864,8 +853,7 @@ fn test_format_u8() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
impl Serialize for net::Ipv4Addr {
|
impl Serialize for net::Ipv4Addr {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@@ -889,8 +877,7 @@ impl Serialize for net::Ipv4Addr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
impl Serialize for net::Ipv6Addr {
|
impl Serialize for net::Ipv6Addr {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@@ -906,8 +893,7 @@ impl Serialize for net::Ipv6Addr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
impl Serialize for net::SocketAddr {
|
impl Serialize for net::SocketAddr {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@@ -931,8 +917,7 @@ impl Serialize for net::SocketAddr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
impl Serialize for net::SocketAddrV4 {
|
impl Serialize for net::SocketAddrV4 {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@@ -948,8 +933,7 @@ impl Serialize for net::SocketAddrV4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(any(feature = "std", not(no_core_net)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
|
||||||
impl Serialize for net::SocketAddrV6 {
|
impl Serialize for net::SocketAddrV6 {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -115,10 +115,10 @@ mod impossible;
|
|||||||
|
|
||||||
pub use self::impossible::Impossible;
|
pub use self::impossible::Impossible;
|
||||||
|
|
||||||
#[cfg(not(any(feature = "std", feature = "unstable")))]
|
#[cfg(all(not(feature = "std"), no_core_error))]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use crate::std_error::Error as StdError;
|
pub use crate::std_error::Error as StdError;
|
||||||
#[cfg(all(feature = "unstable", not(feature = "std")))]
|
#[cfg(not(any(feature = "std", no_core_error)))]
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use core::error::Error as StdError;
|
pub use core::error::Error as StdError;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.209"
|
version = "1.0.211"
|
||||||
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(_) => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+112
-70
@@ -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 => {
|
||||||
@@ -873,7 +885,11 @@ fn deserialize_newtype_struct(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
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(with = "...")]
|
||||||
|
// ^^^^^
|
||||||
|
quote_spanned! {path.span()=>
|
||||||
#path(__e)?
|
#path(__e)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -950,23 +966,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 +987,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 +1035,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 +1128,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 +1231,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 +1999,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 +2065,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 +2082,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 +2140,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 +2171,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 +2204,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 +2374,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 +2385,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 +2666,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 +2840,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 => {
|
||||||
@@ -2856,6 +2883,13 @@ fn wrap_deserialize_with(
|
|||||||
split_with_de_lifetime(params);
|
split_with_de_lifetime(params);
|
||||||
let delife = params.borrowed.de_lifetime();
|
let delife = params.borrowed.de_lifetime();
|
||||||
|
|
||||||
|
// 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)?
|
||||||
|
};
|
||||||
let wrapper = quote! {
|
let wrapper = quote! {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
struct __DeserializeWith #de_impl_generics #where_clause {
|
struct __DeserializeWith #de_impl_generics #where_clause {
|
||||||
@@ -2870,7 +2904,7 @@ fn wrap_deserialize_with(
|
|||||||
__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 +2995,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 +3042,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.209")]
|
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.211")]
|
||||||
#![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,
|
||||||
|
|||||||
@@ -1220,6 +1220,14 @@ fn wrap_serialize_with(
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 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.values.#field_access, )* __s)
|
||||||
|
};
|
||||||
|
|
||||||
quote!({
|
quote!({
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
struct __SerializeWith #wrapper_impl_generics #where_clause {
|
struct __SerializeWith #wrapper_impl_generics #where_clause {
|
||||||
@@ -1232,7 +1240,7 @@ fn wrap_serialize_with(
|
|||||||
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
|
||||||
)]
|
)]
|
||||||
|
|||||||
@@ -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,97 @@
|
|||||||
|
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
|
||||||
|
|
|
||||||
|
15 | struct W(#[serde(with = "w")] u8, u8);
|
||||||
|
| ^^^ unexpected argument #2 of type `__S`
|
||||||
|
|
|
||||||
|
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
|
||||||
|
|
|
||||||
|
18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);
|
||||||
|
| ^^^^^^^^^^^^^^ unexpected argument #2 of type `__S`
|
||||||
|
|
|
||||||
|
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