Compare commits

...

44 Commits

Author SHA1 Message Date
David Tolnay fea4e8e5b6 Release 1.0.84 2018-12-31 23:45:34 -05:00
David Tolnay 1df8b5785b Test with same features in Travis and AppVeyor 2018-12-31 23:31:49 -05:00
David Tolnay 981a75d7c9 Enable extra features in playground 2018-12-31 23:28:10 -05:00
David Tolnay 11cc7014b3 Set all doc tests to 2018 edition 2018-12-31 23:22:13 -05:00
David Tolnay 0b667c88fa Remove unneeded main functions in doc tests
These used to be needed because `#[macro_use] extern crate serde`
couldn't go inside of rustdoc's implicit main function.
2018-12-31 23:22:12 -05:00
David Tolnay 054ab1adaf Update serde documentation to 2018 edition 2018-12-31 23:22:11 -05:00
David Tolnay f1f8386f2e Update serde_derive_internals ignored lints 2018-12-31 22:53:09 -05:00
David Tolnay ba8c3970b0 Use tool lint naming in clippy invocation 2018-12-31 22:51:38 -05:00
David Tolnay 2f36b26a5c Clarify that these lints are ignored 2018-12-31 22:49:38 -05:00
David Tolnay 9b4edb3a1d Address match_ref_pats lint in serde_derive 2018-12-31 22:47:48 -05:00
David Tolnay b8adc5ffa2 Update name of stutter lint in serde_derive 2018-12-31 22:47:18 -05:00
David Tolnay bd90cafda7 Ignore trivially_copy_pass_by_ref lint in serde_derive 2018-12-31 22:47:03 -05:00
David Tolnay 6d43a08a1d Remove dev-dependencies features from serde_test
Apparently Cargo is applying these features to the non-dev dependency on
serde as well. Concluded by running `cargo clean && cargo build` and
observing that serde_derive was getting built.
2018-12-31 22:43:15 -05:00
David Tolnay e71b8598ae Update serde_test examples to 2018 edition 2018-12-31 22:41:23 -05:00
David Tolnay 95d0f437e3 Update ui tests to nightly 2019-01-01 2018-12-31 22:09:07 -05:00
David Tolnay c95ee3968a Format with rustfmt 2018-12-10 2018-12-31 22:09:06 -05:00
David Tolnay c22dd4ada5 Suppress trivially_copy_pass_by_ref lint on fn is_zero 2018-12-31 22:09:05 -05:00
David Tolnay 727a40fc5a Update test suite to use tool attrs 2018-12-31 21:59:40 -05:00
David Tolnay ce84a5f1d3 Update name of deprecated stutter lint 2018-12-31 21:59:39 -05:00
David Tolnay e6fda1c410 Fix clippy command to run against test suite 2018-12-31 21:56:10 -05:00
David Tolnay 294dccc5be Update test suite to 2018 edition 2018-12-31 21:53:37 -05:00
David Tolnay da346a8878 Replace try! macro in test suite 2018-12-31 21:46:14 -05:00
David Tolnay c5ccb995ad Update no_std test to 2018 edition 2018-12-31 21:42:22 -05:00
David Tolnay 05ab569a80 Update ui tests to 2018 edition 2018-12-31 21:38:13 -05:00
David Tolnay ab3f4971f0 Move compiletest out of the unstable feature flag 2018-12-31 21:28:39 -05:00
David Tolnay 47e238aa13 Add missing imports in ui tests
There is a new fallback as of nightly-2018-12-29 that makes these emit a
new error unrelated to Serde.
2018-12-29 00:19:29 -05:00
David Tolnay e49b6c708b Add main function to ui tests without main
These emit a new error not relevant to Serde as of nightly-2018-12-29.
2018-12-29 00:18:55 -05:00
David Tolnay eb7250792b Format with rustfmt 2018-12-10 2018-12-28 12:19:32 -05:00
David Tolnay 7e5066b878 Merge pull request #1450 from motu42/master
Bug fix to support the tag attribute on braced structs with zero fields
2018-12-27 21:48:14 -05:00
Johannes Willbold 889e17816f Bug fix for #1449
Modified serialize_struct_as_struct.
Added test test_internally_tagged_braced_struct_with_zero_fields
2018-12-28 02:50:24 +01:00
David Tolnay b1b9702daf Release 1.0.83 2018-12-27 19:53:48 -05:00
David Tolnay 32728d2f1d Format with rustfmt 2018-12-10 2018-12-27 19:52:26 -05:00
David Tolnay 807a097387 Fix spelling in ui test name 2018-12-27 19:51:53 -05:00
David Tolnay 794ee15386 Merge pull request #1448 from motu42/master
Allow #[serde(tag="...")] on structs
2018-12-27 19:47:28 -05:00
Johannes Willbold 2359417804 Added ui tests, Limited serde(tag = "...") to structs with named field
Added ui test struct-representation/internally-tagged-unit
Added ui test struct-representation/internally-tagged-tuple
    
Limited the serde(tag = "...") to enums and structs with named field
2018-12-28 01:29:33 +01:00
David Tolnay 7950f3cdc5 Format with rustfmt 2018-12-10 2018-12-27 15:35:43 -05:00
David Tolnay b87f8f35ee Merge pull request 1447 from vincascm/master 2018-12-27 15:29:16 -05:00
Johannes Willbold 9e53405f43 Fix for rustc 1.15.0 2018-12-27 21:21:46 +01:00
David Tolnay c6c1d8fa86 Work around deprecation of str::trim_left_matches 2018-12-27 15:20:32 -05:00
Johannes Willbold 8aa5c2b45d Removed deprected ui/enum-representation/internally-tagged-struct test 2018-12-27 20:53:08 +01:00
Johannes Willbold 414fd694c0 Allowed serde(tag="...") on structs
Added test test_internally_tagged_struct
Renamed EnumTag to TagType as it now also used for structs 
Modified serialize_struct_as_struct
2018-12-27 20:18:36 +01:00
vinoca 7e82809592 Fix tests fail since modify Container attributes rename_all 2018-12-20 14:30:23 +08:00
vinoca 0dae5db30e Support Container attributes rename_all only for Serialize or Deserialize 2018-12-19 09:46:52 +08:00
David Tolnay 5c24f0f0f3 Clean up some indentation that isn't visible to rustfmt 2018-12-10 22:31:39 -08:00
232 changed files with 1001 additions and 1113 deletions
+9 -9
View File
@@ -9,7 +9,7 @@ matrix:
- cargo build --no-default-features
- cd "${TRAVIS_BUILD_DIR}/serde_test"
- cargo build
- cargo test
- cargo test --features serde/derive,serde/rc
- rust: beta
script:
@@ -25,11 +25,11 @@ matrix:
- cargo build --no-default-features
- cargo build --no-default-features --features alloc
- cargo build --no-default-features --features rc,alloc
- cargo test --features rc,unstable
- cargo test --features derive,rc,unstable
- cd "${TRAVIS_BUILD_DIR}/test_suite/deps"
- cargo build
- cd "${TRAVIS_BUILD_DIR}/test_suite"
- cargo test --features unstable
- cargo test --features compiletest,unstable
- cd "${TRAVIS_BUILD_DIR}/test_suite/no_std"
- cargo build
@@ -55,17 +55,17 @@ matrix:
name: Clippy
script:
- rustup component add clippy-preview || travis_terminate 0
- cargo clippy -- -Dclippy
- cargo clippy -- -D clippy::all
- cd "${TRAVIS_BUILD_DIR}/serde"
- cargo clippy --features rc,unstable -- -Dclippy
- cargo clippy --features rc,unstable -- -D clippy::all
- cd "${TRAVIS_BUILD_DIR}/serde_derive"
- cargo clippy -- -Dclippy
- cargo clippy -- -D clippy::all
- cd "${TRAVIS_BUILD_DIR}/serde_test"
- cargo clippy -- -Dclippy
- cargo clippy -- -D clippy::all
- cd "${TRAVIS_BUILD_DIR}/test_suite"
- cargo clippy --features unstable -- -Dclippy
- cargo clippy --tests --features unstable -- -D clippy::all
- cd "${TRAVIS_BUILD_DIR}/test_suite/no_std"
- cargo clippy -- -Dclippy
- cargo clippy -- -D clippy::all
- rust: nightly
name: Emscripten
+3 -3
View File
@@ -23,7 +23,7 @@ for:
- cargo build --no-default-features
- cd %APPVEYOR_BUILD_FOLDER%\serde_test
- cargo build
- cargo test
- cargo test --features serde/derive,serde/rc
- matrix:
only:
@@ -34,8 +34,8 @@ for:
- cargo build --no-default-features
- cargo build --no-default-features --features alloc
- cargo build --no-default-features --features rc,alloc
- cargo test --features rc,unstable
- cargo test --features derive,rc,unstable
- cd %APPVEYOR_BUILD_FOLDER%\test_suite\deps
- cargo build
- cd %APPVEYOR_BUILD_FOLDER%\test_suite
- cargo test --features unstable
- cargo test --features compiletest,unstable
+4 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde"
version = "1.0.82" # remember to update html_root_url
version = "1.0.84" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A generic serialization/deserialization framework"
@@ -23,6 +23,9 @@ serde_derive = { version = "1.0", optional = true, path = "../serde_derive" }
[dev-dependencies]
serde_derive = { version = "1.0", path = "../serde_derive" }
[package.metadata.playground]
features = ["derive", "rc"]
### FEATURES #################################################################
+2 -2
View File
@@ -8,7 +8,7 @@ use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
/// any type, except that it does not store any information about the data that
/// gets deserialized.
///
/// ```rust
/// ```edition2018
/// use std::fmt;
/// use std::marker::PhantomData;
///
@@ -21,7 +21,7 @@ use de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor};
/// ///
/// /// For example to deserialize only the element at index 3:
/// ///
/// /// ```rust
/// /// ```
/// /// NthElement::new(3).deserialize(deserializer)
/// /// ```
/// pub struct NthElement<T> {
+37 -35
View File
@@ -153,7 +153,7 @@ macro_rules! declare_error_trait {
///
/// The message should not be capitalized and should not end with a period.
///
/// ```rust
/// ```edition2018
/// # use std::str::FromStr;
/// #
/// # struct IpAddr;
@@ -173,7 +173,7 @@ macro_rules! declare_error_trait {
/// where
/// D: Deserializer<'de>,
/// {
/// let s = try!(String::deserialize(deserializer));
/// let s = String::deserialize(deserializer)?;
/// s.parse().map_err(de::Error::custom)
/// }
/// }
@@ -237,12 +237,16 @@ macro_rules! declare_error_trait {
#[cold]
fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self {
if expected.is_empty() {
Error::custom(format_args!("unknown variant `{}`, there are no variants",
variant))
Error::custom(format_args!(
"unknown variant `{}`, there are no variants",
variant
))
} else {
Error::custom(format_args!("unknown variant `{}`, expected {}",
variant,
OneOf { names: expected }))
Error::custom(format_args!(
"unknown variant `{}`, expected {}",
variant,
OneOf { names: expected }
))
}
}
@@ -251,12 +255,16 @@ macro_rules! declare_error_trait {
#[cold]
fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self {
if expected.is_empty() {
Error::custom(format_args!("unknown field `{}`, there are no fields",
field))
Error::custom(format_args!(
"unknown field `{}`, there are no fields",
field
))
} else {
Error::custom(format_args!("unknown field `{}`, expected {}",
field,
OneOf { names: expected }))
Error::custom(format_args!(
"unknown field `{}`, expected {}",
field,
OneOf { names: expected }
))
}
}
@@ -290,7 +298,7 @@ declare_error_trait!(Error: Sized + Debug + Display);
/// This is used as an argument to the `invalid_type`, `invalid_value`, and
/// `invalid_length` methods of the `Error` trait to build error messages.
///
/// ```rust
/// ```edition2018
/// # use std::fmt;
/// #
/// # use serde::de::{self, Unexpected, Visitor};
@@ -415,7 +423,7 @@ impl<'a> fmt::Display for Unexpected<'a> {
/// Within the context of a `Visitor` implementation, the `Visitor` itself
/// (`&self`) is an implementation of this trait.
///
/// ```rust
/// ```edition2018
/// # use std::fmt;
/// #
/// # use serde::de::{self, Unexpected, Visitor};
@@ -440,7 +448,7 @@ impl<'a> fmt::Display for Unexpected<'a> {
///
/// Outside of a `Visitor`, `&"..."` can be used.
///
/// ```rust
/// ```edition2018
/// # use serde::de::{self, Unexpected};
/// #
/// # fn example<E>() -> Result<(), E>
@@ -561,7 +569,7 @@ pub trait Deserialize<'de>: Sized {
/// from the input string, but a `from_reader` function may only deserialize
/// owned data.
///
/// ```rust
/// ```edition2018
/// # use serde::de::{Deserialize, DeserializeOwned};
/// # use std::io::{Read, Result};
/// #
@@ -600,7 +608,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
///
/// The canonical API for stateless deserialization looks like this:
///
/// ```rust
/// ```edition2018
/// # use serde::Deserialize;
/// #
/// # enum Error {}
@@ -614,7 +622,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
/// Adjusting an API like this to support stateful deserialization is a matter
/// of accepting a seed as input:
///
/// ```rust
/// ```edition2018
/// # use serde::de::DeserializeSeed;
/// #
/// # enum Error {}
@@ -647,7 +655,7 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
/// into it. This requires stateful deserialization using the `DeserializeSeed`
/// trait.
///
/// ```rust
/// ```edition2018
/// use std::fmt;
/// use std::marker::PhantomData;
///
@@ -1137,7 +1145,7 @@ pub trait Deserializer<'de>: Sized {
/// human-readable one and binary formats like Bincode will prefer the
/// compact one.
///
/// ```
/// ```edition2018
/// # use std::ops::Add;
/// # use std::str::FromStr;
/// #
@@ -1214,7 +1222,7 @@ pub trait Deserializer<'de>: Sized {
///
/// # Example
///
/// ```rust
/// ```edition2018
/// # use std::fmt;
/// #
/// # use serde::de::{self, Unexpected, Visitor};
@@ -1255,7 +1263,7 @@ pub trait Visitor<'de>: Sized {
/// "an integer between 0 and 64". The message should not be capitalized and
/// should not end with a period.
///
/// ```rust
/// ```edition2018
/// # use std::fmt;
/// #
/// # struct S {
@@ -1996,7 +2004,7 @@ pub trait VariantAccess<'de>: Sized {
/// If the data contains a different type of variant, the following
/// `invalid_type` error should be constructed:
///
/// ```rust
/// ```edition2018
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
/// #
/// # struct X;
@@ -2036,7 +2044,7 @@ pub trait VariantAccess<'de>: Sized {
/// If the data contains a different type of variant, the following
/// `invalid_type` error should be constructed:
///
/// ```rust
/// ```edition2018
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
/// #
/// # struct X;
@@ -2092,7 +2100,7 @@ pub trait VariantAccess<'de>: Sized {
/// If the data contains a different type of variant, the following
/// `invalid_type` error should be constructed:
///
/// ```rust
/// ```edition2018
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
/// #
/// # struct X;
@@ -2139,7 +2147,7 @@ pub trait VariantAccess<'de>: Sized {
/// If the data contains a different type of variant, the following
/// `invalid_type` error should be constructed:
///
/// ```rust
/// ```edition2018
/// # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected};
/// #
/// # struct X;
@@ -2199,14 +2207,10 @@ pub trait VariantAccess<'de>: Sized {
///
/// # Example
///
/// ```rust
/// #[macro_use]
/// extern crate serde_derive;
///
/// extern crate serde;
///
/// ```edition2018
/// use std::str::FromStr;
/// use serde::de::{value, Deserialize, IntoDeserializer};
/// use serde::Deserialize;
/// use serde::de::{value, IntoDeserializer};
///
/// #[derive(Deserialize)]
/// enum Setting {
@@ -2221,8 +2225,6 @@ pub trait VariantAccess<'de>: Sized {
/// Self::deserialize(s.into_deserializer())
/// }
/// }
/// #
/// # fn main() {}
/// ```
pub trait IntoDeserializer<'de, E: Error = value::Error> {
/// The type of the deserializer being converted into.
+3 -9
View File
@@ -1,14 +1,10 @@
//! Building blocks for deserializing basic values using the `IntoDeserializer`
//! trait.
//!
//! ```rust
//! #[macro_use]
//! extern crate serde_derive;
//!
//! extern crate serde;
//!
//! ```edition2018
//! use std::str::FromStr;
//! use serde::de::{value, Deserialize, IntoDeserializer};
//! use serde::Deserialize;
//! use serde::de::{value, IntoDeserializer};
//!
//! #[derive(Deserialize)]
//! enum Setting {
@@ -23,8 +19,6 @@
//! Self::deserialize(s.into_deserializer())
//! }
//! }
//! #
//! # fn main() {}
//! ```
use lib::*;
+6 -10
View File
@@ -9,14 +9,12 @@
/// do not need to bother with this macro and may assume support for 128-bit
/// integers.
///
/// ```rust
/// #[macro_use]
/// extern crate serde;
///
/// use serde::Serializer;
/// ```edition2018
/// # use serde::private::ser::Error;
/// #
/// # struct MySerializer;
/// #
/// use serde::{serde_if_integer128, Serializer};
///
/// impl Serializer for MySerializer {
/// type Ok = ();
@@ -41,20 +39,18 @@
/// }
/// }
/// #
/// # __serialize_unimplemented! {
/// # serde::__serialize_unimplemented! {
/// # bool i8 i16 i32 u8 u16 u32 u64 f32 f64 char str bytes none some
/// # unit unit_struct unit_variant newtype_struct newtype_variant seq
/// # tuple tuple_struct tuple_variant map struct struct_variant
/// # }
/// }
/// #
/// # fn main() {}
/// ```
///
/// When Serde is built with support for 128-bit integers, this macro expands
/// transparently into just the input tokens.
///
/// ```rust
/// ```edition2018
/// macro_rules! serde_if_integer128 {
/// ($($tt:tt)*) => {
/// $($tt)*
@@ -65,7 +61,7 @@
/// When built without support for 128-bit integers, this macro expands to
/// nothing.
///
/// ```rust
/// ```edition2018
/// macro_rules! serde_if_integer128 {
/// ($($tt:tt)*) => {};
/// }
+4 -4
View File
@@ -75,7 +75,7 @@
////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde/1.0.82")]
#![doc(html_root_url = "https://docs.rs/serde/1.0.84")]
// Support using Serde without the standard library!
#![cfg_attr(not(feature = "std"), no_std)]
// Unstable functionality only if the user asks for it. For tracking and
@@ -86,7 +86,7 @@
#![cfg_attr(feature = "alloc", feature(alloc))]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Whitelisted clippy lints
// Ignored clippy lints
#![cfg_attr(
feature = "cargo-clippy",
allow(
@@ -101,7 +101,7 @@
zero_prefixed_literal
)
)]
// Whitelisted clippy_pedantic lints
// Ignored clippy_pedantic lints
#![cfg_attr(feature = "cargo-clippy", allow(
// integer and float ser/de requires these sorts of casts
cast_possible_truncation,
@@ -112,11 +112,11 @@
invalid_upcast_comparisons,
// things are often more readable this way
decimal_literal_representation,
module_name_repetitions,
option_unwrap_used,
result_unwrap_used,
shadow_reuse,
single_match_else,
stutter,
use_self,
// not practical
indexing_slicing,
+6 -18
View File
@@ -11,10 +11,8 @@
/// input. This requires repetitive implementations of all the [`Deserializer`]
/// trait methods.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::forward_to_deserialize_any;
/// # use serde::de::{value, Deserializer, Visitor};
/// #
/// # struct MyDeserializer;
@@ -43,18 +41,14 @@
/// # tuple_struct map struct enum identifier ignored_any
/// # }
/// # }
/// #
/// # fn main() {}
/// ```
///
/// The `forward_to_deserialize_any!` macro implements these simple forwarding
/// methods so that they forward directly to [`Deserializer::deserialize_any`].
/// You can choose which methods to forward.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::forward_to_deserialize_any;
/// # use serde::de::{value, Deserializer, Visitor};
/// #
/// # struct MyDeserializer;
@@ -77,8 +71,6 @@
/// tuple_struct map struct enum identifier ignored_any
/// }
/// }
/// #
/// # fn main() {}
/// ```
///
/// The macro assumes the convention that your `Deserializer` lifetime parameter
@@ -86,12 +78,10 @@
/// called `V`. A different type parameter and a different lifetime can be
/// specified explicitly if necessary.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # use serde::forward_to_deserialize_any;
/// # use serde::de::{value, Deserializer, Visitor};
/// #
/// # struct MyDeserializer<V>(PhantomData<V>);
@@ -113,8 +103,6 @@
/// tuple_struct map struct enum identifier ignored_any
/// }
/// # }
/// #
/// # fn main() {}
/// ```
///
/// [`Deserializer`]: trait.Deserializer.html
+2 -7
View File
@@ -15,10 +15,7 @@ use ser::{
/// [`SerializeTuple`], [`SerializeTupleStruct`], [`SerializeTupleVariant`],
/// [`SerializeMap`], [`SerializeStruct`], and [`SerializeStructVariant`].
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::ser::{Serializer, Impossible};
/// # use serde::private::ser::Error;
/// #
@@ -44,14 +41,12 @@ use ser::{
/// }
///
/// /* other Serializer methods */
/// # __serialize_unimplemented! {
/// # serde::__serialize_unimplemented! {
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str bytes none some
/// # unit unit_struct unit_variant newtype_struct newtype_variant
/// # tuple tuple_struct tuple_variant map struct struct_variant
/// # }
/// }
/// #
/// # fn main() {}
/// ```
///
/// [`Serializer`]: trait.Serializer.html
+65 -154
View File
@@ -137,7 +137,7 @@ macro_rules! declare_error_trait {
/// For example, a filesystem [`Path`] may refuse to serialize
/// itself if it contains invalid UTF-8 data.
///
/// ```rust
/// ```edition2018
/// # struct Path;
/// #
/// # impl Path {
@@ -210,7 +210,7 @@ pub trait Serialize {
/// See the [Implementing `Serialize`] section of the manual for more
/// information about how to implement this method.
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
///
/// struct Person {
@@ -377,13 +377,10 @@ pub trait Serializer: Sized {
/// Serialize a `bool` value.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for bool {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -393,8 +390,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_bool(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error>;
@@ -404,13 +399,10 @@ pub trait Serializer: Sized {
/// reasonable implementation would be to cast the value to `i64` and
/// forward to `serialize_i64`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for i8 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -420,8 +412,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_i8(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error>;
@@ -431,13 +421,10 @@ pub trait Serializer: Sized {
/// reasonable implementation would be to cast the value to `i64` and
/// forward to `serialize_i64`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for i16 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -447,8 +434,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_i16(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error>;
@@ -458,13 +443,10 @@ pub trait Serializer: Sized {
/// reasonable implementation would be to cast the value to `i64` and
/// forward to `serialize_i64`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for i32 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -474,20 +456,15 @@ pub trait Serializer: Sized {
/// serializer.serialize_i32(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error>;
/// Serialize an `i64` value.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for i64 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -497,21 +474,16 @@ pub trait Serializer: Sized {
/// serializer.serialize_i64(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error>;
serde_if_integer128! {
/// Serialize an `i128` value.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for i128 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -521,8 +493,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_i128(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
///
/// This method is available only on Rust compiler versions >=1.26. The
@@ -539,13 +509,10 @@ pub trait Serializer: Sized {
/// reasonable implementation would be to cast the value to `u64` and
/// forward to `serialize_u64`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for u8 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -555,8 +522,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_u8(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error>;
@@ -566,13 +531,10 @@ pub trait Serializer: Sized {
/// reasonable implementation would be to cast the value to `u64` and
/// forward to `serialize_u64`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for u16 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -582,8 +544,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_u16(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error>;
@@ -593,13 +553,10 @@ pub trait Serializer: Sized {
/// reasonable implementation would be to cast the value to `u64` and
/// forward to `serialize_u64`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for u32 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -609,20 +566,15 @@ pub trait Serializer: Sized {
/// serializer.serialize_u32(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error>;
/// Serialize a `u64` value.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for u64 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -632,21 +584,16 @@ pub trait Serializer: Sized {
/// serializer.serialize_u64(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error>;
serde_if_integer128! {
/// Serialize a `u128` value.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for u128 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -656,8 +603,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_u128(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
///
/// This method is available only on Rust compiler versions >=1.26. The
@@ -674,13 +619,10 @@ pub trait Serializer: Sized {
/// reasonable implementation would be to cast the value to `f64` and
/// forward to `serialize_f64`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for f32 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -690,20 +632,15 @@ pub trait Serializer: Sized {
/// serializer.serialize_f32(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error>;
/// Serialize an `f64` value.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for f64 {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -713,8 +650,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_f64(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error>;
@@ -723,13 +658,10 @@ pub trait Serializer: Sized {
/// If the format does not support characters, it is reasonable to serialize
/// it as a single element `str` or a `u32`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for char {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -739,20 +671,15 @@ pub trait Serializer: Sized {
/// serializer.serialize_char(*self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error>;
/// Serialize a `&str`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for str {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -762,8 +689,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_str(self)
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error>;
@@ -775,10 +700,7 @@ pub trait Serializer: Sized {
/// `serialize_seq`. If forwarded, the implementation looks usually just
/// like this:
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::ser::{Serializer, SerializeSeq};
/// # use serde::private::ser::Error;
/// #
@@ -796,22 +718,18 @@ pub trait Serializer: Sized {
/// seq.end()
/// }
/// #
/// # __serialize_unimplemented! {
/// # serde::__serialize_unimplemented! {
/// # bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char str none some
/// # unit unit_struct unit_variant newtype_struct newtype_variant
/// # seq tuple tuple_struct tuple_variant map struct struct_variant
/// # }
/// # }
/// #
/// # fn main() {}
/// ```
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error>;
/// Serialize a [`None`] value.
///
/// ```rust
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::{Serialize, Serializer};
/// #
/// # enum Option<T> {
@@ -819,7 +737,7 @@ pub trait Serializer: Sized {
/// # None,
/// # }
/// #
/// # use Option::{Some, None};
/// # use self::Option::{Some, None};
/// #
/// impl<T> Serialize for Option<T>
/// where
@@ -844,9 +762,7 @@ pub trait Serializer: Sized {
/// Serialize a [`Some(T)`] value.
///
/// ```rust
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::{Serialize, Serializer};
/// #
/// # enum Option<T> {
@@ -854,7 +770,7 @@ pub trait Serializer: Sized {
/// # None,
/// # }
/// #
/// # use Option::{Some, None};
/// # use self::Option::{Some, None};
/// #
/// impl<T> Serialize for Option<T>
/// where
@@ -881,13 +797,10 @@ pub trait Serializer: Sized {
/// Serialize a `()` value.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde;
/// #
/// ```edition2018
/// # use serde::Serializer;
/// #
/// # __private_serialize!();
/// # serde::__private_serialize!();
/// #
/// impl Serialize for () {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -897,8 +810,6 @@ pub trait Serializer: Sized {
/// serializer.serialize_unit()
/// }
/// }
/// #
/// # fn main() {}
/// ```
fn serialize_unit(self) -> Result<Self::Ok, Self::Error>;
@@ -906,7 +817,7 @@ pub trait Serializer: Sized {
///
/// A reasonable implementation would be to forward to `serialize_unit`.
///
/// ```rust
/// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// struct Nothing;
@@ -928,7 +839,7 @@ pub trait Serializer: Sized {
/// this variant within the enum, and the `variant` is the name of the
/// variant.
///
/// ```rust
/// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// enum E {
@@ -961,7 +872,7 @@ pub trait Serializer: Sized {
/// wrappers around the data they contain. A reasonable implementation would
/// be to forward to `value.serialize(self)`.
///
/// ```rust
/// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// struct Millimeters(u8);
@@ -989,7 +900,7 @@ pub trait Serializer: Sized {
/// this variant within the enum, and the `variant` is the name of the
/// variant. The `value` is the data contained within this newtype variant.
///
/// ```rust
/// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// enum E {
@@ -1027,7 +938,7 @@ pub trait Serializer: Sized {
/// not be computable before the sequence is iterated. Some serializers only
/// support sequences whose length is known up front.
///
/// ```rust
/// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct Vec<T>(PhantomData<T>);
@@ -1072,7 +983,7 @@ pub trait Serializer: Sized {
/// This call must be followed by zero or more calls to `serialize_element`,
/// then a call to `end`.
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
///
/// # mod fool {
@@ -1102,7 +1013,7 @@ pub trait Serializer: Sized {
/// }
/// ```
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeTuple, Serializer};
///
/// const VRAM_SIZE: usize = 386;
@@ -1130,7 +1041,7 @@ pub trait Serializer: Sized {
/// The `name` is the name of the tuple struct and the `len` is the number
/// of data fields that will be serialized.
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
///
/// struct Rgb(u8, u8, u8);
@@ -1162,7 +1073,7 @@ pub trait Serializer: Sized {
/// this variant within the enum, the `variant` is the name of the variant,
/// and the `len` is the number of data fields that will be serialized.
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
///
/// enum E {
@@ -1208,7 +1119,7 @@ pub trait Serializer: Sized {
/// be computable before the map is iterated. Some serializers only support
/// maps whose length is known up front.
///
/// ```rust
/// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
@@ -1256,7 +1167,7 @@ pub trait Serializer: Sized {
/// The `name` is the name of the struct and the `len` is the number of
/// data fields that will be serialized.
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
///
/// struct Rgb {
@@ -1292,7 +1203,7 @@ pub trait Serializer: Sized {
/// this variant within the enum, the `variant` is the name of the variant,
/// and the `len` is the number of data fields that will be serialized.
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
///
/// enum E {
@@ -1334,7 +1245,7 @@ pub trait Serializer: Sized {
/// using [`serialize_seq`]. Implementors should not need to override this
/// method.
///
/// ```rust
/// ```edition2018
/// use serde::{Serialize, Serializer};
///
/// struct SecretlyOneHigher {
@@ -1371,7 +1282,7 @@ pub trait Serializer: Sized {
/// using [`serialize_map`]. Implementors should not need to override this
/// method.
///
/// ```rust
/// ```edition2018
/// use serde::{Serialize, Serializer};
/// use std::collections::BTreeSet;
///
@@ -1411,7 +1322,7 @@ pub trait Serializer: Sized {
/// delegates to [`serialize_str`]. Serializers are encouraged to provide a
/// more efficient implementation if possible.
///
/// ```rust
/// ```edition2018
/// # struct DateTime;
/// #
/// # impl DateTime {
@@ -1452,7 +1363,7 @@ pub trait Serializer: Sized {
/// of this method. If no more sensible behavior is possible, the
/// implementation is expected to return an error.
///
/// ```rust
/// ```edition2018
/// # struct DateTime;
/// #
/// # impl DateTime {
@@ -1487,7 +1398,7 @@ pub trait Serializer: Sized {
/// human-readable one and binary formats like Bincode will prefer the
/// compact one.
///
/// ```
/// ```edition2018
/// # use std::fmt::{self, Display};
/// #
/// # struct Timestamp;
@@ -1536,7 +1447,7 @@ pub trait Serializer: Sized {
///
/// # Example use
///
/// ```rust
/// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct Vec<T>(PhantomData<T>);
@@ -1600,7 +1511,7 @@ pub trait SerializeSeq {
///
/// # Example use
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, Serializer, SerializeTuple};
///
/// # mod fool {
@@ -1630,7 +1541,7 @@ pub trait SerializeSeq {
/// }
/// ```
///
/// ```rust
/// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct Array<T>(PhantomData<T>);
@@ -1700,7 +1611,7 @@ pub trait SerializeTuple {
///
/// # Example use
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
///
/// struct Rgb(u8, u8, u8);
@@ -1745,7 +1656,7 @@ pub trait SerializeTupleStruct {
///
/// # Example use
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeTupleVariant, Serializer};
///
/// enum E {
@@ -1803,7 +1714,7 @@ pub trait SerializeTupleVariant {
///
/// # Example use
///
/// ```rust
/// ```edition2018
/// # use std::marker::PhantomData;
/// #
/// # struct HashMap<K, V>(PhantomData<K>, PhantomData<V>);
@@ -1914,7 +1825,7 @@ pub trait SerializeMap {
///
/// # Example use
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
///
/// struct Rgb {
@@ -1974,7 +1885,7 @@ pub trait SerializeStruct {
///
/// # Example use
///
/// ```rust
/// ```edition2018
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
///
/// enum E {
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_derive"
version = "1.0.82" # remember to update html_root_url
version = "1.0.84" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
+32 -38
View File
@@ -5,11 +5,11 @@ use syn::spanned::Spanned;
use syn::{self, Ident, Index, Member};
use bound;
use dummy;
use fragment::{Expr, Fragment, Match, Stmts};
use internals::ast::{Container, Data, Field, Style, Variant};
use internals::{attr, Ctxt, Derive};
use pretend;
use try;
use std::collections::BTreeSet;
@@ -25,11 +25,6 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<TokenStream
let ident = &cont.ident;
let params = Parameters::new(&cont);
let (de_impl_generics, _, ty_generics, where_clause) = split_with_de_lifetime(&params);
let suffix = ident.to_string().trim_left_matches("r#").to_owned();
let dummy_const = Ident::new(
&format!("_IMPL_DESERIALIZE_FOR_{}", suffix),
Span::call_site(),
);
let body = Stmts(deserialize_body(&cont, &params));
let delife = params.borrowed.de_lifetime();
@@ -65,19 +60,7 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result<TokenStream
}
};
let try_replacement = try::replacement();
let generated = quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const #dummy_const: () = {
#[allow(unknown_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
#[allow(rust_2018_idioms)]
extern crate serde as _serde;
#try_replacement
#impl_block
};
};
Ok(generated)
Ok(dummy::wrap_in_const("DESERIALIZE", ident, impl_block))
}
fn precondition(cx: &Ctxt, cont: &Container) {
@@ -1145,15 +1128,15 @@ fn deserialize_enum(
cattrs: &attr::Container,
) -> Fragment {
match *cattrs.tag() {
attr::EnumTag::External => deserialize_externally_tagged_enum(params, variants, cattrs),
attr::EnumTag::Internal { ref tag } => {
attr::TagType::External => deserialize_externally_tagged_enum(params, variants, cattrs),
attr::TagType::Internal { ref tag } => {
deserialize_internally_tagged_enum(params, variants, cattrs, tag)
}
attr::EnumTag::Adjacent {
attr::TagType::Adjacent {
ref tag,
ref content,
} => deserialize_adjacently_tagged_enum(params, variants, cattrs, tag, content),
attr::EnumTag::None => deserialize_untagged_enum(params, variants, cattrs),
attr::TagType::None => deserialize_untagged_enum(params, variants, cattrs),
}
}
@@ -1260,11 +1243,15 @@ fn deserialize_externally_tagged_enum(
#variants_stmt
_serde::Deserializer::deserialize_enum(__deserializer, #type_name, VARIANTS,
__Visitor {
marker: _serde::export::PhantomData::<#this #ty_generics>,
lifetime: _serde::export::PhantomData,
})
_serde::Deserializer::deserialize_enum(
__deserializer,
#type_name,
VARIANTS,
__Visitor {
marker: _serde::export::PhantomData::<#this #ty_generics>,
lifetime: _serde::export::PhantomData,
},
)
}
}
@@ -1615,12 +1602,14 @@ fn deserialize_adjacently_tagged_enum(
match try!(_serde::de::SeqAccess::next_element(&mut __seq)) {
_serde::export::Some(__field) => {
// Visit the second element - the content.
match try!(_serde::de::SeqAccess::next_element_seed(&mut __seq,
__Seed {
field: __field,
marker: _serde::export::PhantomData,
lifetime: _serde::export::PhantomData,
})) {
match try!(_serde::de::SeqAccess::next_element_seed(
&mut __seq,
__Seed {
field: __field,
marker: _serde::export::PhantomData,
lifetime: _serde::export::PhantomData,
},
)) {
_serde::export::Some(__ret) => _serde::export::Ok(__ret),
// There is no second element.
_serde::export::None => {
@@ -1637,11 +1626,15 @@ fn deserialize_adjacently_tagged_enum(
}
const FIELDS: &'static [&'static str] = &[#tag, #content];
_serde::Deserializer::deserialize_struct(__deserializer, #type_name, FIELDS,
_serde::Deserializer::deserialize_struct(
__deserializer,
#type_name,
FIELDS,
__Visitor {
marker: _serde::export::PhantomData::<#this #ty_generics>,
lifetime: _serde::export::PhantomData,
})
},
)
}
}
@@ -2247,8 +2240,9 @@ fn deserialize_identifier(
#variant_indices => _serde::export::Ok(#constructors),
)*
_ => _serde::export::Err(_serde::de::Error::invalid_value(
_serde::de::Unexpected::Unsigned(__value),
&#fallthrough_msg))
_serde::de::Unexpected::Unsigned(__value),
&#fallthrough_msg,
))
}
}
}
+32
View File
@@ -0,0 +1,32 @@
use proc_macro2::{Ident, Span, TokenStream};
use try;
pub fn wrap_in_const(trait_: &str, ty: &Ident, code: TokenStream) -> TokenStream {
let try_replacement = try::replacement();
let dummy_const = Ident::new(
&format!("_IMPL_{}_FOR_{}", trait_, unraw(ty)),
Span::call_site(),
);
quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const #dummy_const: () = {
#[allow(unknown_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
#[allow(rust_2018_idioms)]
extern crate serde as _serde;
#try_replacement
#code
};
}
}
#[allow(deprecated)]
fn unraw(ident: &Ident) -> String {
// str::trim_start_matches was added in 1.30, trim_left_matches deprecated
// in 1.33. We currently support rustc back to 1.15 so we need to continue
// to use the deprecated one.
ident.to_string().trim_left_matches("r#").to_owned()
}
+5 -3
View File
@@ -85,12 +85,14 @@ impl<'a> Container<'a> {
match data {
Data::Enum(ref mut variants) => {
for variant in variants {
variant.attrs.rename_by_rule(attrs.rename_all());
variant.attrs.rename_by_rules(attrs.rename_all_rules());
for field in &mut variant.fields {
if field.attrs.flatten() {
has_flatten = true;
}
field.attrs.rename_by_rule(variant.attrs.rename_all());
field
.attrs
.rename_by_rules(variant.attrs.rename_all_rules());
}
}
}
@@ -99,7 +101,7 @@ impl<'a> Container<'a> {
if field.attrs.flatten() {
has_flatten = true;
}
field.attrs.rename_by_rule(attrs.rename_all());
field.attrs.rename_by_rules(attrs.rename_all_rules());
}
}
}
+140 -38
View File
@@ -95,7 +95,11 @@ pub struct Name {
deserialize: String,
}
#[allow(deprecated)]
fn unraw(ident: &Ident) -> String {
// str::trim_start_matches was added in 1.30, trim_left_matches deprecated
// in 1.33. We currently support rustc back to 1.15 so we need to continue
// to use the deprecated one.
ident.to_string().trim_left_matches("r#").to_owned()
}
@@ -111,16 +115,21 @@ impl Name {
}
}
pub struct RenameAllRules {
serialize: RenameRule,
deserialize: RenameRule,
}
/// Represents struct or enum attribute information.
pub struct Container {
name: Name,
transparent: bool,
deny_unknown_fields: bool,
default: Default,
rename_all: RenameRule,
rename_all_rules: RenameAllRules,
ser_bound: Option<Vec<syn::WherePredicate>>,
de_bound: Option<Vec<syn::WherePredicate>>,
tag: EnumTag,
tag: TagType,
type_from: Option<syn::Type>,
type_into: Option<syn::Type>,
remote: Option<syn::Path>,
@@ -129,7 +138,7 @@ pub struct Container {
}
/// Styles of representing an enum.
pub enum EnumTag {
pub enum TagType {
/// The default.
///
/// ```json
@@ -194,7 +203,8 @@ impl Container {
let mut transparent = BoolAttr::none(cx, "transparent");
let mut deny_unknown_fields = BoolAttr::none(cx, "deny_unknown_fields");
let mut default = Attr::none(cx, "default");
let mut rename_all = Attr::none(cx, "rename_all");
let mut rename_all_ser_rule = Attr::none(cx, "rename_all");
let mut rename_all_de_rule = Attr::none(cx, "rename_all");
let mut ser_bound = Attr::none(cx, "bound");
let mut de_bound = Attr::none(cx, "bound");
let mut untagged = BoolAttr::none(cx, "untagged");
@@ -229,7 +239,10 @@ impl Container {
Meta(NameValue(ref m)) if m.ident == "rename_all" => {
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
match RenameRule::from_str(&s.value()) {
Ok(rename_rule) => rename_all.set(&m.ident, rename_rule),
Ok(rename_rule) => {
rename_all_ser_rule.set(&m.ident, rename_rule);
rename_all_de_rule.set(&m.ident, rename_rule);
}
Err(()) => cx.error_spanned_by(
s,
format!(
@@ -242,6 +255,42 @@ impl Container {
}
}
// Parse `#[serde(rename_all(serialize = "foo", deserialize = "bar"))]`
Meta(List(ref m)) if m.ident == "rename_all" => {
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
if let Some(ser) = ser {
match RenameRule::from_str(&ser.value()) {
Ok(rename_rule) => {
rename_all_ser_rule.set(&m.ident, rename_rule)
}
Err(()) => cx.error_spanned_by(
ser,
format!(
"unknown rename rule for #[serde(rename_all \
= {:?})]",
ser.value(),
),
),
}
}
if let Some(de) = de {
match RenameRule::from_str(&de.value()) {
Ok(rename_rule) => {
rename_all_de_rule.set(&m.ident, rename_rule)
}
Err(()) => cx.error_spanned_by(
de,
format!(
"unknown rename rule for #[serde(rename_all \
= {:?})]",
de.value(),
),
),
}
}
}
}
// Parse `#[serde(transparent)]`
Meta(Word(ref word)) if word == "transparent" => {
transparent.set_true(word);
@@ -361,20 +410,27 @@ impl Container {
syn::Data::Enum(_) => {
internal_tag.set(&m.ident, s.value());
}
syn::Data::Struct(syn::DataStruct {
ref struct_token, ..
}) => {
cx.error_spanned_by(
struct_token,
"#[serde(tag = \"...\")] can only be used on enums",
);
syn::Data::Struct(syn::DataStruct { ref fields, .. }) => {
match *fields {
syn::Fields::Named(_) => {
internal_tag.set(&m.ident, s.value());
}
syn::Fields::Unnamed(_) | syn::Fields::Unit => {
cx.error_spanned_by(
fields,
"#[serde(tag = \"...\")] can only be used on enums \
and structs with named fields",
);
}
}
}
syn::Data::Union(syn::DataUnion {
ref union_token, ..
}) => {
cx.error_spanned_by(
union_token,
"#[serde(tag = \"...\")] can only be used on enums",
"#[serde(tag = \"...\")] can only be used on enums \
and structs with named fields",
);
}
}
@@ -465,7 +521,10 @@ impl Container {
transparent: transparent.get(),
deny_unknown_fields: deny_unknown_fields.get(),
default: default.get().unwrap_or(Default::None),
rename_all: rename_all.get().unwrap_or(RenameRule::None),
rename_all_rules: RenameAllRules {
serialize: rename_all_ser_rule.get().unwrap_or(RenameRule::None),
deserialize: rename_all_de_rule.get().unwrap_or(RenameRule::None),
},
ser_bound: ser_bound.get(),
de_bound: de_bound.get(),
tag: decide_tag(cx, item, untagged, internal_tag, content),
@@ -481,8 +540,8 @@ impl Container {
&self.name
}
pub fn rename_all(&self) -> &RenameRule {
&self.rename_all
pub fn rename_all_rules(&self) -> &RenameAllRules {
&self.rename_all_rules
}
pub fn transparent(&self) -> bool {
@@ -505,7 +564,7 @@ impl Container {
self.de_bound.as_ref().map(|vec| &vec[..])
}
pub fn tag(&self) -> &EnumTag {
pub fn tag(&self) -> &TagType {
&self.tag
}
@@ -540,14 +599,14 @@ fn decide_tag(
untagged: BoolAttr,
internal_tag: Attr<String>,
content: Attr<String>,
) -> EnumTag {
) -> TagType {
match (
untagged.0.get_with_tokens(),
internal_tag.get_with_tokens(),
content.get_with_tokens(),
) {
(None, None, None) => EnumTag::External,
(Some(_), None, None) => EnumTag::None,
(None, None, None) => TagType::External,
(Some(_), None, None) => TagType::None,
(None, Some((_, tag)), None) => {
// Check that there are no tuple variants.
if let syn::Data::Enum(ref data) = item.data {
@@ -567,7 +626,7 @@ fn decide_tag(
}
}
}
EnumTag::Internal { tag: tag }
TagType::Internal { tag: tag }
}
(Some((untagged_tokens, _)), Some((tag_tokens, _)), None) => {
cx.error_spanned_by(
@@ -578,14 +637,14 @@ fn decide_tag(
tag_tokens,
"enum cannot be both untagged and internally tagged",
);
EnumTag::External // doesn't matter, will error
TagType::External // doesn't matter, will error
}
(None, None, Some((content_tokens, _))) => {
cx.error_spanned_by(
content_tokens,
"#[serde(tag = \"...\", content = \"...\")] must be used together",
);
EnumTag::External
TagType::External
}
(Some((untagged_tokens, _)), None, Some((content_tokens, _))) => {
cx.error_spanned_by(
@@ -596,9 +655,9 @@ fn decide_tag(
content_tokens,
"untagged enum cannot have #[serde(content = \"...\")]",
);
EnumTag::External
TagType::External
}
(None, Some((_, tag)), Some((_, content))) => EnumTag::Adjacent {
(None, Some((_, tag)), Some((_, content))) => TagType::Adjacent {
tag: tag,
content: content,
},
@@ -615,7 +674,7 @@ fn decide_tag(
content_tokens,
"untagged enum cannot have #[serde(tag = \"...\", content = \"...\")]",
);
EnumTag::External
TagType::External
}
}
}
@@ -705,7 +764,7 @@ pub struct Variant {
name: Name,
ser_renamed: bool,
de_renamed: bool,
rename_all: RenameRule,
rename_all_rules: RenameAllRules,
ser_bound: Option<Vec<syn::WherePredicate>>,
de_bound: Option<Vec<syn::WherePredicate>>,
skip_deserializing: bool,
@@ -722,7 +781,8 @@ impl Variant {
let mut de_name = Attr::none(cx, "rename");
let mut skip_deserializing = BoolAttr::none(cx, "skip_deserializing");
let mut skip_serializing = BoolAttr::none(cx, "skip_serializing");
let mut rename_all = Attr::none(cx, "rename_all");
let mut rename_all_ser_rule = Attr::none(cx, "rename_all");
let mut rename_all_de_rule = Attr::none(cx, "rename_all");
let mut ser_bound = Attr::none(cx, "bound");
let mut de_bound = Attr::none(cx, "bound");
let mut other = BoolAttr::none(cx, "other");
@@ -753,7 +813,10 @@ impl Variant {
Meta(NameValue(ref m)) if m.ident == "rename_all" => {
if let Ok(s) = get_lit_str(cx, &m.ident, &m.ident, &m.lit) {
match RenameRule::from_str(&s.value()) {
Ok(rename_rule) => rename_all.set(&m.ident, rename_rule),
Ok(rename_rule) => {
rename_all_ser_rule.set(&m.ident, rename_rule);
rename_all_de_rule.set(&m.ident, rename_rule);
}
Err(()) => cx.error_spanned_by(
s,
format!(
@@ -766,6 +829,42 @@ impl Variant {
}
}
// Parse `#[serde(rename_all(serialize = "foo", deserialize = "bar"))]`
Meta(List(ref m)) if m.ident == "rename_all" => {
if let Ok((ser, de)) = get_renames(cx, &m.nested) {
if let Some(ser) = ser {
match RenameRule::from_str(&ser.value()) {
Ok(rename_rule) => {
rename_all_ser_rule.set(&m.ident, rename_rule)
}
Err(()) => cx.error_spanned_by(
ser,
format!(
"unknown rename rule for #[serde(rename_all \
= {:?})]",
ser.value(),
),
),
}
}
if let Some(de) = de {
match RenameRule::from_str(&de.value()) {
Ok(rename_rule) => {
rename_all_de_rule.set(&m.ident, rename_rule)
}
Err(()) => cx.error_spanned_by(
de,
format!(
"unknown rename rule for #[serde(rename_all \
= {:?})]",
de.value(),
),
),
}
}
}
}
// Parse `#[serde(skip)]`
Meta(Word(ref word)) if word == "skip" => {
skip_serializing.set_true(word);
@@ -875,7 +974,10 @@ impl Variant {
},
ser_renamed: ser_renamed,
de_renamed: de_renamed,
rename_all: rename_all.get().unwrap_or(RenameRule::None),
rename_all_rules: RenameAllRules {
serialize: rename_all_ser_rule.get().unwrap_or(RenameRule::None),
deserialize: rename_all_de_rule.get().unwrap_or(RenameRule::None),
},
ser_bound: ser_bound.get(),
de_bound: de_bound.get(),
skip_deserializing: skip_deserializing.get(),
@@ -891,17 +993,17 @@ impl Variant {
&self.name
}
pub fn rename_by_rule(&mut self, rule: &RenameRule) {
pub fn rename_by_rules(&mut self, rules: &RenameAllRules) {
if !self.ser_renamed {
self.name.serialize = rule.apply_to_variant(&self.name.serialize);
self.name.serialize = rules.serialize.apply_to_variant(&self.name.serialize);
}
if !self.de_renamed {
self.name.deserialize = rule.apply_to_variant(&self.name.deserialize);
self.name.deserialize = rules.deserialize.apply_to_variant(&self.name.deserialize);
}
}
pub fn rename_all(&self) -> &RenameRule {
&self.rename_all
pub fn rename_all_rules(&self) -> &RenameAllRules {
&self.rename_all_rules
}
pub fn ser_bound(&self) -> Option<&[syn::WherePredicate]> {
@@ -1260,12 +1362,12 @@ impl Field {
&self.name
}
pub fn rename_by_rule(&mut self, rule: &RenameRule) {
pub fn rename_by_rules(&mut self, rules: &RenameAllRules) {
if !self.ser_renamed {
self.name.serialize = rule.apply_to_field(&self.name.serialize);
self.name.serialize = rules.serialize.apply_to_field(&self.name.serialize);
}
if !self.de_renamed {
self.name.deserialize = rule.apply_to_field(&self.name.deserialize);
self.name.deserialize = rules.deserialize.apply_to_field(&self.name.deserialize);
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ use std::str::FromStr;
use self::RenameRule::*;
/// The different possible ways to change case of fields in a struct, or variants in an enum.
#[derive(PartialEq)]
#[derive(Copy, Clone, PartialEq)]
pub enum RenameRule {
/// Don't apply a default rename rule.
None,
+6 -6
View File
@@ -1,5 +1,5 @@
use internals::ast::{Container, Data, Field, Style};
use internals::attr::{EnumTag, Identifier};
use internals::attr::{Identifier, TagType};
use internals::{Ctxt, Derive};
use syn::{Member, Type};
@@ -127,7 +127,7 @@ fn check_identifier(cx: &Ctxt, cont: &Container) {
}
// Variant with `other` attribute cannot appear in untagged enum
(_, Identifier::No, true, &EnumTag::None) => {
(_, Identifier::No, true, &TagType::None) => {
cx.error_spanned_by(
variant.original,
"#[serde(other)] cannot appear on untagged enum",
@@ -276,8 +276,8 @@ fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
};
let tag = match *cont.attrs.tag() {
EnumTag::Internal { ref tag } => tag.as_str(),
EnumTag::External | EnumTag::Adjacent { .. } | EnumTag::None => return,
TagType::Internal { ref tag } => tag.as_str(),
TagType::External | TagType::Adjacent { .. } | TagType::None => return,
};
let diagnose_conflict = || {
@@ -312,11 +312,11 @@ fn check_internal_tag_field_name_conflict(cx: &Ctxt, cont: &Container) {
/// contents tag must differ, for the same reason.
fn check_adjacent_tag_conflict(cx: &Ctxt, cont: &Container) {
let (type_tag, content_tag) = match *cont.attrs.tag() {
EnumTag::Adjacent {
TagType::Adjacent {
ref tag,
ref content,
} => (tag, content),
EnumTag::Internal { .. } | EnumTag::External | EnumTag::None => return,
TagType::Internal { .. } | TagType::External | TagType::None => return,
};
if type_tag == content_tag {
+8 -7
View File
@@ -1,8 +1,7 @@
//! This crate provides Serde's two derive macros.
//!
//! ```rust
//! # #[macro_use]
//! # extern crate serde_derive;
//! ```edition2018
//! # use serde_derive::{Serialize, Deserialize};
//! #
//! #[derive(Serialize, Deserialize)]
//! # struct S;
@@ -14,10 +13,10 @@
//!
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.82")]
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.84")]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Whitelisted clippy lints
// Ignored clippy lints
#![cfg_attr(
feature = "cargo-clippy",
allow(
@@ -26,10 +25,11 @@
needless_pass_by_value,
redundant_field_names,
too_many_arguments,
trivially_copy_pass_by_ref,
used_underscore_binding,
)
)]
// Whitelisted clippy_pedantic lints
// Ignored clippy_pedantic lints
#![cfg_attr(
feature = "cargo-clippy",
allow(
@@ -40,9 +40,9 @@
indexing_slicing,
items_after_statements,
match_same_arms,
module_name_repetitions,
similar_names,
single_match_else,
stutter,
unseparated_literal_suffix,
use_self,
)
@@ -69,6 +69,7 @@ mod bound;
mod fragment;
mod de;
mod dummy;
mod pretend;
mod ser;
mod try;
+27 -26
View File
@@ -3,11 +3,11 @@ use syn::spanned::Spanned;
use syn::{self, Ident, Index, Member};
use bound;
use dummy;
use fragment::{Fragment, Match, Stmts};
use internals::ast::{Container, Data, Field, Style, Variant};
use internals::{attr, Ctxt, Derive};
use pretend;
use try;
pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream, Vec<syn::Error>> {
let ctxt = Ctxt::new();
@@ -21,11 +21,6 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream,
let ident = &cont.ident;
let params = Parameters::new(&cont);
let (impl_generics, ty_generics, where_clause) = params.generics.split_for_impl();
let suffix = ident.to_string().trim_left_matches("r#").to_owned();
let dummy_const = Ident::new(
&format!("_IMPL_SERIALIZE_FOR_{}", suffix),
Span::call_site(),
);
let body = Stmts(serialize_body(&cont, &params));
let impl_block = if let Some(remote) = cont.attrs.remote() {
@@ -56,19 +51,7 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<TokenStream,
}
};
let try_replacement = try::replacement();
let generated = quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
const #dummy_const: () = {
#[allow(unknown_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
#[allow(rust_2018_idioms)]
extern crate serde as _serde;
#try_replacement
#impl_block
};
};
Ok(generated)
Ok(dummy::wrap_in_const("SERIALIZE", ident, impl_block))
}
fn precondition(cx: &Ctxt, cont: &Container) {
@@ -311,17 +294,32 @@ fn serialize_struct_as_struct(
fields: &[Field],
cattrs: &attr::Container,
) -> Fragment {
let serialize_fields =
let mut serialize_fields =
serialize_struct_visitor(fields, params, false, &StructTrait::SerializeStruct);
let type_name = cattrs.name().serialize_name();
let additional_field_count: usize = match *cattrs.tag() {
attr::TagType::Internal { ref tag } => {
let func = StructTrait::SerializeStruct.serialize_field(Span::call_site());
serialize_fields.insert(
0,
quote! {
try!(#func(&mut __serde_state, #tag, #type_name));
},
);
1
}
_ => 0,
};
let mut serialized_fields = fields
.iter()
.filter(|&field| !field.attrs.skip_serializing())
.peekable();
let let_mut = mut_if(serialized_fields.peek().is_some());
let let_mut = mut_if(serialized_fields.peek().is_some() || additional_field_count > 0);
let len = serialized_fields
.map(|field| match field.attrs.skip_serializing_if() {
@@ -331,7 +329,10 @@ fn serialize_struct_as_struct(
quote!(if #path(#field_expr) { 0 } else { 1 })
}
})
.fold(quote!(0), |sum, expr| quote!(#sum + #expr));
.fold(
quote!(#additional_field_count),
|sum, expr| quote!(#sum + #expr),
);
quote_block! {
let #let_mut __serde_state = try!(_serde::Serializer::serialize_struct(__serializer, #type_name, #len));
@@ -452,17 +453,17 @@ fn serialize_variant(
};
let body = Match(match *cattrs.tag() {
attr::EnumTag::External => {
attr::TagType::External => {
serialize_externally_tagged_variant(params, variant, variant_index, cattrs)
}
attr::EnumTag::Internal { ref tag } => {
attr::TagType::Internal { ref tag } => {
serialize_internally_tagged_variant(params, variant, cattrs, tag)
}
attr::EnumTag::Adjacent {
attr::TagType::Adjacent {
ref tag,
ref content,
} => serialize_adjacently_tagged_variant(params, variant, cattrs, tag, content),
attr::EnumTag::None => serialize_untagged_variant(params, variant, cattrs),
attr::TagType::None => serialize_untagged_variant(params, variant, cattrs),
});
quote! {
+2 -3
View File
@@ -4,9 +4,8 @@
feature = "cargo-clippy",
allow(
cyclomatic_complexity,
doc_markdown,
match_same_arms,
redundant_field_names
redundant_field_names,
trivially_copy_pass_by_ref
)
)]
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_test"
version = "1.0.82" # remember to update html_root_url
version = "1.0.84" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Token De/Serializer for testing De/Serialize implementations"
@@ -15,7 +15,7 @@ include = ["Cargo.toml", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-AP
serde = { version = "1.0.60", path = "../serde" }
[dev-dependencies]
serde = { version = "1.0", path = "../serde", features = ["rc"] }
serde = { version = "1.0", path = "../serde" }
serde_derive = { version = "1.0", path = "../serde_derive" }
[badges]
+28 -52
View File
@@ -8,13 +8,8 @@ use std::fmt::Debug;
/// Runs both `assert_ser_tokens` and `assert_de_tokens`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
@@ -45,13 +40,8 @@ where
/// Asserts that `value` serializes to the given `tokens`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_ser_tokens, Token};
/// #
/// # fn main() {
@@ -90,16 +80,11 @@ where
/// Asserts that `value` serializes to the given `tokens`, and then yields
/// `error`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde_test;
/// #
/// # fn main() {
/// ```edition2018
/// use std::sync::{Arc, Mutex};
/// use std::thread;
///
/// use serde::Serialize;
/// use serde_test::{assert_ser_tokens_error, Token};
///
/// #[derive(Serialize)]
@@ -107,26 +92,27 @@ where
/// lock: Arc<Mutex<u32>>,
/// }
///
/// let example = Example { lock: Arc::new(Mutex::new(0)) };
/// let lock = example.lock.clone();
/// fn main() {
/// let example = Example { lock: Arc::new(Mutex::new(0)) };
/// let lock = example.lock.clone();
///
/// let _ = thread::spawn(move || {
/// // This thread will acquire the mutex first, unwrapping the result
/// // of `lock` because the lock has not been poisoned.
/// let _guard = lock.lock().unwrap();
/// let _ = thread::spawn(move || {
/// // This thread will acquire the mutex first, unwrapping the result
/// // of `lock` because the lock has not been poisoned.
/// let _guard = lock.lock().unwrap();
///
/// // This panic while holding the lock (`_guard` is in scope) will
/// // poison the mutex.
/// panic!()
/// }).join();
/// // This panic while holding the lock (`_guard` is in scope) will
/// // poison the mutex.
/// panic!()
/// }).join();
///
/// let expected = &[
/// Token::Struct { name: "Example", len: 1 },
/// Token::Str("lock"),
/// ];
/// let error = "lock poison error while serializing";
/// assert_ser_tokens_error(&example, expected, error);
/// # }
/// let expected = &[
/// Token::Struct { name: "Example", len: 1 },
/// Token::Str("lock"),
/// ];
/// let error = "lock poison error while serializing";
/// assert_ser_tokens_error(&example, expected, error);
/// }
/// ```
pub fn assert_ser_tokens_error<T>(value: &T, tokens: &[Token], error: &str)
where
@@ -145,13 +131,8 @@ where
/// Asserts that the given `tokens` deserialize into `value`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_de_tokens, Token};
/// #
/// # fn main() {
@@ -205,13 +186,8 @@ where
/// Asserts that the given `tokens` yield `error` when deserializing.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_de_tokens_error, Token};
/// #
/// # fn main() {
+1 -4
View File
@@ -14,10 +14,7 @@ pub struct Compact<T: ?Sized>(T);
/// Trait to determine whether a value is represented in human-readable or
/// compact form.
///
/// ```
/// extern crate serde;
/// extern crate serde_test;
///
/// ```edition2018
/// use serde::{Deserialize, Deserializer, Serialize, Serializer};
/// use serde_test::{assert_tokens, Configure, Token};
///
+7 -16
View File
@@ -24,19 +24,10 @@
//!
//! [`linked-hash-map`]: https://github.com/contain-rs/linked-hash-map
//!
//! ```rust
//! # extern crate serde;
//! #
//! # macro_rules! ignore {
//! # ($($tt:tt)+) => {}
//! # }
//! #
//! # ignore! {
//! extern crate linked_hash_map;
//! ```edition2018
//! # const IGNORE: &str = stringify! {
//! use linked_hash_map::LinkedHashMap;
//! # }
//!
//! extern crate serde_test;
//! # };
//! use serde_test::{Token, assert_tokens};
//!
//! # use std::fmt;
@@ -153,19 +144,19 @@
//! # }
//! ```
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.82")]
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.84")]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Whitelisted clippy lints
// Ignored clippy lints
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
// Whitelisted clippy_pedantic lints
// Ignored clippy_pedantic lints
#![cfg_attr(
feature = "cargo-clippy",
allow(
empty_line_after_outer_attr,
missing_docs_in_private_items,
module_name_repetitions,
redundant_field_names,
stutter,
use_debug,
use_self
)
+39 -84
View File
@@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Display};
pub enum Token {
/// A serialized `bool`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&true, &[Token::Bool(true)]);
@@ -13,7 +13,7 @@ pub enum Token {
/// A serialized `i8`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0i8, &[Token::I8(0)]);
@@ -22,7 +22,7 @@ pub enum Token {
/// A serialized `i16`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0i16, &[Token::I16(0)]);
@@ -31,7 +31,7 @@ pub enum Token {
/// A serialized `i32`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0i32, &[Token::I32(0)]);
@@ -40,7 +40,7 @@ pub enum Token {
/// A serialized `i64`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0i64, &[Token::I64(0)]);
@@ -49,7 +49,7 @@ pub enum Token {
/// A serialized `u8`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0u8, &[Token::U8(0)]);
@@ -58,7 +58,7 @@ pub enum Token {
/// A serialized `u16`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0u16, &[Token::U16(0)]);
@@ -67,7 +67,7 @@ pub enum Token {
/// A serialized `u32`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0u32, &[Token::U32(0)]);
@@ -76,7 +76,7 @@ pub enum Token {
/// A serialized `u64`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0u64, &[Token::U64(0)]);
@@ -85,7 +85,7 @@ pub enum Token {
/// A serialized `f32`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0f32, &[Token::F32(0.0)]);
@@ -94,7 +94,7 @@ pub enum Token {
/// A serialized `f64`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&0f64, &[Token::F64(0.0)]);
@@ -103,7 +103,7 @@ pub enum Token {
/// A serialized `char`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&'\n', &[Token::Char('\n')]);
@@ -112,7 +112,7 @@ pub enum Token {
/// A serialized `str`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// let s = String::from("transient");
@@ -122,7 +122,7 @@ pub enum Token {
/// A borrowed `str`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// let s: &str = "borrowed";
@@ -132,7 +132,7 @@ pub enum Token {
/// A serialized `String`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// let s = String::from("owned");
@@ -151,7 +151,7 @@ pub enum Token {
/// A serialized `Option<T>` containing none.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// let opt = None::<char>;
@@ -163,7 +163,7 @@ pub enum Token {
///
/// The tokens of the value follow after this header.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// let opt = Some('c');
@@ -176,7 +176,7 @@ pub enum Token {
/// A serialized `()`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// assert_tokens(&(), &[Token::Unit]);
@@ -185,13 +185,8 @@ pub enum Token {
/// A serialized unit struct of the given name.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
@@ -205,13 +200,8 @@ pub enum Token {
/// A unit variant of an enum.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
@@ -233,13 +223,8 @@ pub enum Token {
///
/// After this header is the value contained in the newtype struct.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
@@ -259,13 +244,8 @@ pub enum Token {
///
/// After this header is the value contained in the newtype variant.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
@@ -291,7 +271,7 @@ pub enum Token {
/// After this header are the elements of the sequence, followed by
/// `SeqEnd`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// let vec = vec!['a', 'b', 'c'];
@@ -312,7 +292,7 @@ pub enum Token {
///
/// After this header are the elements of the tuple, followed by `TupleEnd`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// let tuple = ('a', 100);
@@ -333,13 +313,8 @@ pub enum Token {
/// After this header are the fields of the tuple struct, followed by
/// `TupleStructEnd`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
@@ -365,13 +340,8 @@ pub enum Token {
/// After this header are the fields of the tuple variant, followed by
/// `TupleVariantEnd`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
@@ -402,7 +372,7 @@ pub enum Token {
///
/// After this header are the entries of the map, followed by `MapEnd`.
///
/// ```rust
/// ```edition2018
/// # use serde_test::{assert_tokens, Token};
/// #
/// use std::collections::BTreeMap;
@@ -429,13 +399,8 @@ pub enum Token {
///
/// After this header are the fields of the struct, followed by `StructEnd`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
@@ -466,13 +431,8 @@ pub enum Token {
/// After this header are the fields of the struct variant, followed by
/// `StructVariantEnd`.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
@@ -501,13 +461,8 @@ pub enum Token {
/// The header to an enum of the given name.
///
/// ```rust
/// # #[macro_use]
/// # extern crate serde_derive;
/// #
/// # extern crate serde;
/// # extern crate serde_test;
/// #
/// ```edition2018
/// # use serde::{Serialize, Deserialize};
/// # use serde_test::{assert_tokens, Token};
/// #
/// # fn main() {
+4 -2
View File
@@ -2,15 +2,17 @@
name = "serde_test_suite"
version = "0.0.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
edition = "2018"
publish = false
[features]
unstable = ["serde/unstable", "compiletest_rs"]
unstable = ["serde/unstable"]
compiletest = ["compiletest_rs"]
[dev-dependencies]
fnv = "1.0"
rustc-serialize = "0.3.16"
serde = { path = "../serde", features = ["rc"] }
serde = { path = "../serde", features = ["rc", "derive"] }
serde_derive = { path = "../serde_derive", features = ["deserialize_in_place"] }
serde_test = { path = "../serde_test" }
+2 -2
View File
@@ -1,11 +1,11 @@
[package]
name = "serde_derive_tests_no_std"
version = "0.0.0"
edition = "2018"
publish = false
[dependencies]
libc = { version = "0.2", default-features = false }
serde = { path = "../../serde", default-features = false }
serde_derive = { path = "../../serde_derive" }
serde = { path = "../../serde", default-features = false, features = ["derive"] }
[workspace]
+1 -4
View File
@@ -1,8 +1,6 @@
#![feature(lang_items, start)]
#![no_std]
extern crate libc;
#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
0
@@ -21,8 +19,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
//////////////////////////////////////////////////////////////////////////////
#[macro_use]
extern crate serde_derive;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct Unit;
+1 -1
View File
@@ -22,7 +22,7 @@ impl<'de> Visitor<'de> for ByteBufVisitor {
V: SeqAccess<'de>,
{
let mut values = Vec::new();
while let Some(value) = try!(visitor.next_element()) {
while let Some(value) = visitor.next_element()? {
values.push(value);
}
Ok(values)
+10 -3
View File
@@ -1,13 +1,20 @@
#![cfg(feature = "unstable")]
#![cfg(feature = "compiletest")]
extern crate compiletest_rs as compiletest;
use compiletest_rs as compiletest;
#[test]
fn ui() {
let config = compiletest::Config {
mode: compiletest::common::Mode::Ui,
src_base: std::path::PathBuf::from("tests/ui"),
target_rustcflags: Some("-L deps/target/debug/deps".to_owned()),
target_rustcflags: Some(String::from(
"\
--edition=2018 \
-L deps/target/debug/deps \
-Z unstable-options \
--extern serde_derive \
",
)),
..Default::default()
};
+5 -11
View File
@@ -1,19 +1,13 @@
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
#![allow(clippy::cast_lossless, clippy::trivially_copy_pass_by_ref)]
#[macro_use]
extern crate serde_derive;
extern crate serde;
use self::serde::de::{self, MapAccess, Unexpected, Visitor};
use self::serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::de::{self, MapAccess, Unexpected, Visitor};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::{BTreeMap, HashMap};
use std::fmt;
use std::marker::PhantomData;
extern crate serde_test;
use self::serde_test::{
use serde_test::{
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_ser_tokens_error,
assert_tokens, Token,
};
@@ -68,7 +62,7 @@ impl DeserializeWith for i32 {
where
D: Deserializer<'de>,
{
if try!(Deserialize::deserialize(de)) {
if Deserialize::deserialize(de)? {
Ok(123)
} else {
Ok(2)
-6
View File
@@ -1,10 +1,4 @@
#[macro_use]
extern crate serde_derive;
extern crate serde;
use serde::{Deserialize, Deserializer};
extern crate serde_test;
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};
use std::borrow::Cow;
+3 -12
View File
@@ -1,10 +1,6 @@
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", allow(decimal_literal_representation))]
#![allow(clippy::decimal_literal_representation)]
#![cfg_attr(feature = "unstable", feature(never_type))]
#[macro_use]
extern crate serde_derive;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::ffi::{CStr, CString, OsString};
@@ -15,14 +11,9 @@ use std::rc::{Rc, Weak as RcWeak};
use std::sync::{Arc, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};
extern crate serde;
use fnv::FnvHasher;
use serde::{Deserialize, Deserializer};
extern crate fnv;
use self::fnv::FnvHasher;
extern crate serde_test;
use self::serde_test::{assert_de_tokens, assert_de_tokens_error, Configure, Token};
use serde_test::{assert_de_tokens, assert_de_tokens_error, Configure, Token};
#[macro_use]
mod macros;
+7 -6
View File
@@ -4,13 +4,10 @@
#![deny(warnings)]
#![cfg_attr(feature = "unstable", feature(non_ascii_idents))]
#![allow(clippy::trivially_copy_pass_by_ref)]
#[macro_use]
extern crate serde_derive;
extern crate serde;
use self::serde::de::{DeserializeOwned, Deserializer};
use self::serde::ser::{Serialize, Serializer};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::Cow;
use std::marker::PhantomData;
@@ -384,6 +381,8 @@ fn test_gen() {
}
mod vis {
use serde::{Deserialize, Serialize};
pub struct S;
#[derive(Serialize, Deserialize)]
@@ -607,6 +606,8 @@ fn test_gen() {
mod restricted {
mod inner {
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct Restricted {
pub(super) a: usize,
+1 -4
View File
@@ -1,7 +1,4 @@
#[macro_use]
extern crate serde_derive;
extern crate serde_test;
use serde::Deserialize;
use serde_test::{assert_de_tokens, Token};
#[test]
+57 -9
View File
@@ -1,16 +1,10 @@
#![deny(trivial_numeric_casts)]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_test;
#![allow(clippy::redundant_field_names)]
mod bytes;
use self::serde_test::{
use serde::{Deserialize, Serialize};
use serde_test::{
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_tokens, Token,
};
@@ -1376,6 +1370,60 @@ fn test_enum_in_internally_tagged_enum() {
);
}
#[test]
fn test_internally_tagged_struct() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub struct Struct {
a: u8,
}
assert_tokens(
&Struct { a: 1 },
&[
Token::Struct {
name: "Struct",
len: 2,
},
Token::Str("type"),
Token::Str("Struct"),
Token::Str("a"),
Token::U8(1),
Token::StructEnd,
],
);
assert_de_tokens(
&Struct { a: 1 },
&[
Token::Struct {
name: "Struct",
len: 1,
},
Token::Str("a"),
Token::U8(1),
Token::StructEnd,
],
);
}
#[test]
fn test_internally_tagged_braced_struct_with_zero_fields() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
struct S {}
assert_tokens(
&S {},
&[
Token::Struct { name: "S", len: 1 },
Token::Str("type"),
Token::Str("S"),
Token::StructEnd,
],
);
}
#[test]
fn test_enum_in_untagged_enum() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
+2 -4
View File
@@ -1,8 +1,6 @@
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]
#![allow(clippy::redundant_field_names)]
#[macro_use]
extern crate serde_derive;
use serde::{Deserialize, Serialize};
mod remote {
pub struct Unit;
+1 -2
View File
@@ -1,5 +1,4 @@
extern crate serde_test;
use self::serde_test::{assert_tokens, Configure, Token};
use serde_test::{assert_tokens, Configure, Token};
use std::net;
+3 -8
View File
@@ -1,8 +1,5 @@
#![cfg_attr(feature = "unstable", feature(never_type))]
#[macro_use]
extern crate serde_derive;
use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::ffi::CString;
@@ -17,11 +14,9 @@ use std::time::{Duration, UNIX_EPOCH};
#[cfg(unix)]
use std::str;
extern crate serde_test;
use self::serde_test::{assert_ser_tokens, assert_ser_tokens_error, Configure, Token};
extern crate fnv;
use self::fnv::FnvHasher;
use fnv::FnvHasher;
use serde::Serialize;
use serde_test::{assert_ser_tokens, assert_ser_tokens_error, Configure, Token};
#[macro_use]
mod macros;
-9
View File
@@ -1,14 +1,5 @@
#![deny(warnings)]
#[cfg(feature = "unstable")]
#[macro_use]
extern crate serde_derive;
#[cfg(feature = "unstable")]
extern crate serde;
#[cfg(feature = "unstable")]
extern crate serde_test;
// This test target is convoluted with the actual #[test] in a separate file to
// get it so that the stable compiler does not need to parse the code of the
// test. If the test were written with #[cfg(feature = "unstable")] #[test]
-4
View File
@@ -1,7 +1,3 @@
#[macro_use]
extern crate serde_derive;
extern crate serde;
use serde::de::{value, IntoDeserializer};
use serde::Deserialize;
+1 -2
View File
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Test<'a> {
@@ -1,7 +1,7 @@
error: failed to parse borrowed lifetimes: "zzz"
--> $DIR/bad_lifetimes.rs:6:22
--> $DIR/bad_lifetimes.rs:5:22
|
6 | #[serde(borrow = "zzz")]
5 | #[serde(borrow = "zzz")]
| ^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Test<'a> {
@@ -1,7 +1,7 @@
error: duplicate borrowed lifetime `'a`
--> $DIR/duplicate_lifetime.rs:6:22
--> $DIR/duplicate_lifetime.rs:5:22
|
6 | #[serde(borrow = "'a + 'a")]
5 | #[serde(borrow = "'a + 'a")]
| ^^^^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Str<'a>(&'a str);
@@ -1,7 +1,7 @@
error: duplicate serde attribute `borrow`
--> $DIR/duplicate_variant.rs:9:13
--> $DIR/duplicate_variant.rs:8:13
|
9 | #[serde(borrow)]
8 | #[serde(borrow)]
| ^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Test<'a> {
@@ -1,7 +1,7 @@
error: at least one lifetime must be borrowed
--> $DIR/empty_lifetimes.rs:6:22
--> $DIR/empty_lifetimes.rs:5:22
|
6 | #[serde(borrow = "")]
5 | #[serde(borrow = "")]
| ^^
error: aborting due to previous error
+1 -2
View File
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Test {
@@ -1,8 +1,8 @@
error: field `s` has no lifetimes to borrow
--> $DIR/no_lifetimes.rs:6:5
--> $DIR/no_lifetimes.rs:5:5
|
6 | / #[serde(borrow)]
7 | | s: String,
5 | / #[serde(borrow)]
6 | | s: String,
| |_____________^
error: aborting due to previous error
+1 -2
View File
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Str<'a>(&'a str);
@@ -1,9 +1,9 @@
error: #[serde(borrow)] may only be used on newtype variants
--> $DIR/struct_variant.rs:9:5
|
9 | / #[serde(borrow)]
10 | | S { s: Str<'a> },
| |____________________^
--> $DIR/struct_variant.rs:8:5
|
8 | / #[serde(borrow)]
9 | | S { s: Str<'a> },
| |____________________^
error: aborting due to previous error
+1 -2
View File
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Test<'a> {
@@ -1,8 +1,8 @@
error: field `s` does not have lifetime 'b
--> $DIR/wrong_lifetime.rs:6:5
--> $DIR/wrong_lifetime.rs:5:5
|
6 | / #[serde(borrow = "'b")]
7 | | s: &'a str,
5 | / #[serde(borrow = "'b")]
6 | | s: &'a str,
| |______________^
error: aborting due to previous error
+1 -2
View File
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
#[serde(tag = "conflict", content = "conflict")]
@@ -1,11 +1,11 @@
error: enum tags `conflict` for type and content conflict with each other
--> $DIR/adjacent-tag.rs:5:1
--> $DIR/adjacent-tag.rs:4:1
|
5 | / #[serde(tag = "conflict", content = "conflict")]
6 | | enum E {
7 | | A,
8 | | B,
9 | | }
4 | / #[serde(tag = "conflict", content = "conflict")]
5 | | enum E {
6 | | A,
7 | | B,
8 | | }
| |_^
error: aborting due to previous error
@@ -1,5 +1,6 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
use std::collections::HashMap;
#[derive(Serialize)]
struct Foo(#[serde(flatten)] HashMap<String, String>);
@@ -1,7 +1,7 @@
error: #[serde(flatten)] cannot be used on newtype structs
--> $DIR/flatten-newtype-struct.rs:5:12
--> $DIR/flatten-newtype-struct.rs:6:12
|
5 | struct Foo(#[serde(flatten)] HashMap<String, String>);
6 | struct Foo(#[serde(flatten)] HashMap<String, String>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
struct Foo {
@@ -1,8 +1,8 @@
error: #[serde(flatten)] can not be combined with #[serde(skip_deserializing)]
--> $DIR/flatten-skip-deserializing.rs:6:5
--> $DIR/flatten-skip-deserializing.rs:5:5
|
6 | / #[serde(flatten, skip_deserializing)]
7 | | other: Other,
5 | / #[serde(flatten, skip_deserializing)]
6 | | other: Other,
| |________________^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
struct Foo {
@@ -1,8 +1,8 @@
error: #[serde(flatten)] can not be combined with #[serde(skip_serializing_if = "...")]
--> $DIR/flatten-skip-serializing-if.rs:6:5
--> $DIR/flatten-skip-serializing-if.rs:5:5
|
6 | / #[serde(flatten, skip_serializing_if = "Option::is_none")]
7 | | other: Option<Other>,
5 | / #[serde(flatten, skip_serializing_if = "Option::is_none")]
6 | | other: Option<Other>,
| |________________________^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
struct Foo {
@@ -1,8 +1,8 @@
error: #[serde(flatten)] can not be combined with #[serde(skip_serializing)]
--> $DIR/flatten-skip-serializing.rs:6:5
--> $DIR/flatten-skip-serializing.rs:5:5
|
6 | / #[serde(flatten, skip_serializing)]
7 | | other: Other,
5 | / #[serde(flatten, skip_serializing)]
6 | | other: Other,
| |________________^
error: aborting due to previous error
@@ -1,5 +1,6 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
use std::collections::HashMap;
#[derive(Serialize)]
struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
@@ -1,7 +1,7 @@
error: #[serde(flatten)] cannot be used on tuple structs
--> $DIR/flatten-tuple-struct.rs:5:17
--> $DIR/flatten-tuple-struct.rs:6:17
|
5 | struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
6 | struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
+1 -2
View File
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
#[serde(tag = "conflict")]
@@ -1,13 +1,13 @@
error: variant field name `conflict` conflicts with internal tag
--> $DIR/internal-tag.rs:5:1
--> $DIR/internal-tag.rs:4:1
|
5 | / #[serde(tag = "conflict")]
6 | | enum E {
7 | | A {
8 | | #[serde(rename = "conflict")]
9 | | x: (),
10 | | },
11 | | }
4 | / #[serde(tag = "conflict")]
5 | | enum E {
6 | | A {
7 | | #[serde(rename = "conflict")]
8 | | x: (),
9 | | },
10 | | }
| |_^
error: aborting due to previous error
@@ -1,8 +1,9 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
#[serde(default)]
enum E {
S { f: u8 },
}
fn main() {}
@@ -1,7 +1,7 @@
error: #[serde(default)] can only be used on structs with named fields
--> $DIR/enum.rs:6:1
--> $DIR/enum.rs:5:1
|
6 | enum E {
5 | enum E {
| ^^^^
error: aborting due to previous error
@@ -1,8 +1,9 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
#[serde(default = "default_e")]
enum E {
S { f: u8 },
}
fn main() {}
@@ -1,7 +1,7 @@
error: #[serde(default = "...")] can only be used on structs with named fields
--> $DIR/enum_path.rs:6:1
--> $DIR/enum_path.rs:5:1
|
6 | enum E {
5 | enum E {
| ^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
#[serde(default)]
@@ -1,7 +1,7 @@
error: #[serde(default)] can only be used on structs with named fields
--> $DIR/nameless_struct_fields.rs:6:9
--> $DIR/nameless_struct_fields.rs:5:9
|
6 | struct T(u8, u8);
5 | struct T(u8, u8);
| ^^^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Deserialize;
#[derive(Deserialize)]
#[serde(default = "default_t")]
@@ -1,7 +1,7 @@
error: #[serde(default = "...")] can only be used on structs with named fields
--> $DIR/nameless_struct_fields_path.rs:6:9
--> $DIR/nameless_struct_fields_path.rs:5:9
|
6 | struct T(u8, u8);
5 | struct T(u8, u8);
| ^^^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
struct S {
@@ -1,7 +1,7 @@
error: unknown serde field attribute `serialize`
--> $DIR/rename-and-ser.rs:6:27
--> $DIR/rename-and-ser.rs:5:27
|
6 | #[serde(rename = "x", serialize = "y")]
5 | #[serde(rename = "x", serialize = "y")]
| ^^^^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
struct S {
@@ -1,7 +1,7 @@
error: duplicate serde attribute `rename`
--> $DIR/rename-rename-de.rs:7:13
--> $DIR/rename-rename-de.rs:6:13
|
7 | #[serde(rename(deserialize = "y"))]
6 | #[serde(rename(deserialize = "y"))]
| ^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
struct S {
@@ -1,7 +1,7 @@
error: duplicate serde attribute `rename`
--> $DIR/rename-ser-rename-ser.rs:6:38
--> $DIR/rename-ser-rename-ser.rs:5:38
|
6 | #[serde(rename(serialize = "x"), rename(serialize = "y"))]
5 | #[serde(rename(serialize = "x"), rename(serialize = "y"))]
| ^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
struct S {
@@ -1,7 +1,7 @@
error: duplicate serde attribute `rename`
--> $DIR/rename-ser-rename.rs:7:13
--> $DIR/rename-ser-rename.rs:6:13
|
7 | #[serde(rename = "y")]
6 | #[serde(rename = "y")]
| ^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
struct S {
@@ -1,7 +1,7 @@
error: duplicate serde attribute `rename`
--> $DIR/rename-ser-ser.rs:6:37
--> $DIR/rename-ser-ser.rs:5:37
|
6 | #[serde(rename(serialize = "x", serialize = "y"))]
5 | #[serde(rename(serialize = "x", serialize = "y"))]
| ^^^^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
struct S {
@@ -1,7 +1,7 @@
error: duplicate serde attribute `rename`
--> $DIR/two-rename-ser.rs:7:13
--> $DIR/two-rename-ser.rs:6:13
|
7 | #[serde(rename(serialize = "y"))]
6 | #[serde(rename(serialize = "y"))]
| ^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
struct S {
@@ -1,7 +1,7 @@
error: duplicate serde attribute `serialize_with`
--> $DIR/with-and-serialize-with.rs:6:25
--> $DIR/with-and-serialize-with.rs:5:25
|
6 | #[serde(with = "w", serialize_with = "s")]
5 | #[serde(with = "w", serialize_with = "s")]
| ^^^^^^^^^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
#[serde(content = "c")]
@@ -1,7 +1,7 @@
error: #[serde(tag = "...", content = "...")] must be used together
--> $DIR/content-no-tag.rs:5:9
--> $DIR/content-no-tag.rs:4:9
|
5 | #[serde(content = "c")]
4 | #[serde(content = "c")]
| ^^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
#[serde(tag = "type")]
@@ -1,7 +1,7 @@
error: #[serde(tag = "...")] cannot be used with tuple variants
--> $DIR/internal-tuple-variant.rs:7:5
--> $DIR/internal-tuple-variant.rs:6:5
|
7 | Tuple(u8, u8),
6 | Tuple(u8, u8),
| ^^^^^^^^^^^^^
error: aborting due to previous error
@@ -1,8 +0,0 @@
error: #[serde(tag = "...")] can only be used on enums
--> $DIR/internally-tagged-struct.rs:6:1
|
6 | struct S;
| ^^^^^^
error: aborting due to previous error
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
#[serde(untagged)]
@@ -1,19 +1,19 @@
error: untagged enum cannot have #[serde(tag = "...", content = "...")]
--> $DIR/untagged-and-adjacent.rs:5:9
--> $DIR/untagged-and-adjacent.rs:4:9
|
5 | #[serde(untagged)]
4 | #[serde(untagged)]
| ^^^^^^^^
error: untagged enum cannot have #[serde(tag = "...", content = "...")]
--> $DIR/untagged-and-adjacent.rs:6:9
--> $DIR/untagged-and-adjacent.rs:5:9
|
6 | #[serde(tag = "t", content = "c")]
5 | #[serde(tag = "t", content = "c")]
| ^^^
error: untagged enum cannot have #[serde(tag = "...", content = "...")]
--> $DIR/untagged-and-adjacent.rs:6:20
--> $DIR/untagged-and-adjacent.rs:5:20
|
6 | #[serde(tag = "t", content = "c")]
5 | #[serde(tag = "t", content = "c")]
| ^^^^^^^
error: aborting due to 3 previous errors
@@ -1,5 +1,4 @@
#[macro_use]
extern crate serde_derive;
use serde_derive::Serialize;
#[derive(Serialize)]
#[serde(untagged)]

Some files were not shown because too many files have changed in this diff Show More