Compare commits

...

31 Commits

Author SHA1 Message Date
David Tolnay 108cca687c Release 1.0.77 2018-09-06 21:36:27 -07:00
David Tolnay bca8c115c7 Merge pull request #1372 from dtolnay/syn
Update to syn 0.15
2018-09-06 21:34:14 -07:00
David Tolnay b49bd52a53 Use parse_macro_input to report parse errors 2018-09-06 21:16:12 -07:00
David Tolnay 27bd640812 Update to syn 0.15 2018-09-06 21:16:08 -07:00
David Tolnay 8d5cda8464 Merge pull request #1376 from dreid/fix-internally-tagged-enum-deserialization-with-unknown-fields
Fix internally tagged enum deserialization with unknown fields
2018-09-06 21:10:41 -07:00
David Reid 389b9b5fe7 Add a test for an internally tagged unit enum flattened with a second internally tagged unit enum. 2018-09-06 14:55:10 -07:00
David Reid 27478b6f71 Internally tagged unit enum variants should ignore unknown fields. 2018-09-06 14:29:49 -07:00
David Tolnay 480f858fc3 Update panic_handler attribute name changed in nightly 2018-09-03 08:24:27 -07:00
David Tolnay 7d752c5a60 Merge pull request #1373 from dtolnay/emscripten
Add Emscripten build in Travis
2018-09-02 13:56:41 -07:00
David Tolnay 33b7841300 Skip asmjs 2018-09-02 13:21:36 -07:00
David Tolnay 2244b92eb0 Nvm install in .travis.yml
The one in travis.sh was failing:

    ./travis.sh: line 56: nvm: command not found
    The command "./travis.sh" exited with 127.
2018-09-02 12:45:12 -07:00
David Tolnay d0464fbff7 Add Emscripten build in Travis 2018-09-02 12:34:13 -07:00
David Tolnay 98eddf9b29 Update to syn 0.15-rc1 2018-09-01 23:03:59 -07:00
David Tolnay d23a40c1bb Format with rustfmt 0.99.2 2018-09-01 23:03:41 -07:00
David Tolnay 55cecace29 Release 1.0.76 2018-09-01 15:25:53 -07:00
David Tolnay 3da0deaa50 Merge pull request #1371 from hcpl/nonzero_u128
Add support for `NonZeroU128`
2018-09-01 15:25:10 -07:00
hcpl 585550a5be Add support for NonZeroU128 2018-09-02 00:34:56 +03:00
David Tolnay 5b7b8abf9f Move some compile-fail errors based on proc-macro2 update 2018-08-28 20:35:49 -07:00
David Tolnay 2aab0ce2f6 Release 1.0.75 2018-08-24 23:03:04 -04:00
David Tolnay a157c56d7d Merge pull request #1367 from Eh2406/master
update a deb for minimal-versions
2018-08-24 23:02:02 -04:00
Eh2406 6c45593ee4 update a deb for minimal-versions 2018-08-24 22:50:17 -04:00
David Tolnay 1175d54fb7 Stabilize raw_identifiers 2018-08-24 19:49:13 -04:00
David Tolnay cfdbbee845 Release 1.0.74 2018-08-23 18:29:16 -04:00
David Tolnay c1583bf2b8 Merge pull request #1365 from koute/master
Disable i128 integers on Emscripten targets
2018-08-23 18:28:51 -04:00
Jan Bujak 7385b50249 Disable i128 integers on Emscripten targets 2018-08-24 00:02:40 +02:00
David Tolnay db6aaf5110 Release 1.0.73 2018-08-22 21:47:15 -04:00
David Tolnay c4a4501d71 Merge pull request #1363 from dtolnay/raw
Trim the r# from raw identifiers in user-facing strings
2018-08-22 21:46:31 -04:00
David Tolnay a3ae14d090 Test raw identifiers 2018-08-22 21:09:37 -04:00
David Tolnay dc4bb0bf08 Trim the r# from raw identifiers in user-facing strings 2018-08-22 20:50:29 -04:00
David Tolnay c69a3e083f Merge pull request #1360 from Pratyush/master
Update travis.sh to also test `--no-default-features --features "rc alloc"`
2018-08-20 21:38:55 -04:00
Pratyush Mishra c790bd2a69 Update travis.sh 2018-08-20 18:30:43 -07:00
25 changed files with 216 additions and 40 deletions
+3
View File
@@ -18,5 +18,8 @@ matrix:
include:
- rust: nightly
env: CLIPPY=true
- rust: nightly
env: EMSCRIPTEN=true
script: nvm install 9 && ./travis.sh
script: ./travis.sh
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde"
version = "1.0.72" # remember to update html_root_url
version = "1.0.77" # 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"
+7 -1
View File
@@ -11,6 +11,9 @@ fn main() {
None => return,
};
let target = env::var("TARGET").unwrap();
let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten";
// CString::into_boxed_c_str stabilized in Rust 1.20:
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
if minor >= 20 {
@@ -32,7 +35,10 @@ fn main() {
// 128-bit integers stabilized in Rust 1.26:
// https://blog.rust-lang.org/2018/05/10/Rust-1.26.html
if minor >= 26 {
//
// Disabled on Emscripten targets as Emscripten doesn't
// currently support integers larger than 64 bits.
if minor >= 26 && !emscripten {
println!("cargo:rustc-cfg=integer128");
}
+8 -1
View File
@@ -2242,10 +2242,17 @@ nonzero_integers! {
NonZeroU16,
NonZeroU32,
NonZeroU64,
// FIXME: https://github.com/serde-rs/serde/issues/1136 NonZeroU128,
NonZeroUsize,
}
// Currently 128-bit integers do not work on Emscripten targets so we need an
// additional `#[cfg]`
serde_if_integer128! {
nonzero_integers! {
NonZeroU128,
}
}
////////////////////////////////////////////////////////////////////////////////
impl<'de, T, E> Deserialize<'de> for Result<T, E>
+1 -1
View File
@@ -82,7 +82,7 @@
////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde/1.0.72")]
#![doc(html_root_url = "https://docs.rs/serde/1.0.77")]
// 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
+4 -3
View File
@@ -231,8 +231,8 @@ mod content {
use super::size_hint;
use de::{
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, MapAccess,
SeqAccess, Unexpected, Visitor,
self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny,
MapAccess, SeqAccess, Unexpected, Visitor,
};
/// Used from generated code to buffer the contents of the Deserializer when
@@ -2470,10 +2470,11 @@ mod content {
Ok(())
}
fn visit_map<M>(self, _: M) -> Result<(), M::Error>
fn visit_map<M>(self, mut access: M) -> Result<(), M::Error>
where
M: MapAccess<'de>,
{
while let Some(_) = try!(access.next_entry::<IgnoredAny, IgnoredAny>()) {}
Ok(())
}
}
+8 -1
View File
@@ -469,10 +469,17 @@ nonzero_integers! {
NonZeroU16,
NonZeroU32,
NonZeroU64,
// FIXME: https://github.com/serde-rs/serde/issues/1136 NonZeroU128,
NonZeroUsize,
}
// Currently 128-bit integers do not work on Emscripten targets so we need an
// additional `#[cfg]`
serde_if_integer128! {
nonzero_integers! {
NonZeroU128,
}
}
impl<T> Serialize for Cell<T>
where
T: Serialize + Copy,
+3 -3
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_derive"
version = "1.0.72" # remember to update html_root_url
version = "1.0.77" # 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)]"
@@ -25,8 +25,8 @@ proc-macro = true
[dependencies]
proc-macro2 = "0.4"
quote = "0.6"
syn = { version = "0.14", features = ["visit"] }
quote = "0.6.3"
syn = { version = "0.15", features = ["visit"] }
[dev-dependencies]
serde = { version = "1.0", path = "../serde" }
+2 -1
View File
@@ -30,8 +30,9 @@ 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_{}", ident),
&format!("_IMPL_DESERIALIZE_FOR_{}", suffix),
Span::call_site(),
);
let body = Stmts(deserialize_body(&cont, &params));
+19 -15
View File
@@ -11,8 +11,8 @@ use proc_macro2::{Group, Span, TokenStream, TokenTree};
use std::collections::BTreeSet;
use std::str::FromStr;
use syn;
use syn::parse::{self, Parse, ParseStream};
use syn::punctuated::Punctuated;
use syn::synom::{ParseError, Synom};
use syn::Ident;
use syn::Meta::{List, NameValue, Word};
use syn::NestedMeta::{Literal, Meta};
@@ -90,6 +90,10 @@ pub struct Name {
deserialize: String,
}
fn unraw(ident: &Ident) -> String {
ident.to_string().trim_left_matches("r#").to_owned()
}
impl Name {
/// Return the container name for the container when serializing.
pub fn serialize_name(&self) -> String {
@@ -380,8 +384,8 @@ impl Container {
Container {
name: Name {
serialize: ser_name.get().unwrap_or_else(|| item.ident.to_string()),
deserialize: de_name.get().unwrap_or_else(|| item.ident.to_string()),
serialize: ser_name.get().unwrap_or_else(|| unraw(&item.ident)),
deserialize: de_name.get().unwrap_or_else(|| unraw(&item.ident)),
},
transparent: transparent.get(),
deny_unknown_fields: deny_unknown_fields.get(),
@@ -697,8 +701,8 @@ impl Variant {
let de_renamed = de_name.is_some();
Variant {
name: Name {
serialize: ser_name.unwrap_or_else(|| variant.ident.to_string()),
deserialize: de_name.unwrap_or_else(|| variant.ident.to_string()),
serialize: ser_name.unwrap_or_else(|| unraw(&variant.ident)),
deserialize: de_name.unwrap_or_else(|| unraw(&variant.ident)),
},
ser_renamed: ser_renamed,
de_renamed: de_renamed,
@@ -822,7 +826,7 @@ impl Field {
let mut flatten = BoolAttr::none(cx, "flatten");
let ident = match field.ident {
Some(ref ident) => ident.to_string(),
Some(ref ident) => unraw(ident),
None => index.to_string(),
};
@@ -1296,11 +1300,10 @@ fn parse_lit_into_lifetimes(
struct BorrowedLifetimes(Punctuated<syn::Lifetime, Token![+]>);
impl Synom for BorrowedLifetimes {
named!(parse -> Self, map!(
call!(Punctuated::parse_separated_nonempty),
BorrowedLifetimes
));
impl Parse for BorrowedLifetimes {
fn parse(input: ParseStream) -> parse::Result<Self> {
Punctuated::parse_separated_nonempty(input).map(BorrowedLifetimes)
}
}
if let Ok(BorrowedLifetimes(lifetimes)) = parse_lit_str(string) {
@@ -1509,7 +1512,8 @@ fn collect_lifetimes(ty: &syn::Type, out: &mut BTreeSet<syn::Lifetime>) {
syn::GenericArgument::Binding(ref binding) => {
collect_lifetimes(&binding.ty, out);
}
syn::GenericArgument::Const(_) => {}
syn::GenericArgument::Constraint(_)
| syn::GenericArgument::Const(_) => {}
}
}
}
@@ -1531,15 +1535,15 @@ fn collect_lifetimes(ty: &syn::Type, out: &mut BTreeSet<syn::Lifetime>) {
}
}
fn parse_lit_str<T>(s: &syn::LitStr) -> Result<T, ParseError>
fn parse_lit_str<T>(s: &syn::LitStr) -> parse::Result<T>
where
T: Synom,
T: Parse,
{
let tokens = try!(spanned_tokens(s));
syn::parse2(tokens)
}
fn spanned_tokens(s: &syn::LitStr) -> Result<TokenStream, ParseError> {
fn spanned_tokens(s: &syn::LitStr) -> parse::Result<TokenStream> {
let stream = try!(syn::parse_str(&s.value()));
Ok(respan_token_stream(stream, s.span()))
}
+3 -3
View File
@@ -22,7 +22,7 @@
//!
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.72")]
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.77")]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Whitelisted clippy lints
#![cfg_attr(
@@ -81,7 +81,7 @@ mod try;
#[proc_macro_derive(Serialize, attributes(serde))]
pub fn derive_serialize(input: TokenStream) -> TokenStream {
let input: DeriveInput = syn::parse(input).unwrap();
let input = parse_macro_input!(input as DeriveInput);
ser::expand_derive_serialize(&input)
.unwrap_or_else(compile_error)
.into()
@@ -89,7 +89,7 @@ pub fn derive_serialize(input: TokenStream) -> TokenStream {
#[proc_macro_derive(Deserialize, attributes(serde))]
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
let input: DeriveInput = syn::parse(input).unwrap();
let input = parse_macro_input!(input as DeriveInput);
de::expand_derive_deserialize(&input)
.unwrap_or_else(compile_error)
.into()
+5 -1
View File
@@ -26,7 +26,11 @@ 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 dummy_const = Ident::new(&format!("_IMPL_SERIALIZE_FOR_{}", ident), Span::call_site());
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() {
+1 -1
View File
@@ -16,7 +16,7 @@ path = "lib.rs"
[dependencies]
proc-macro2 = "0.4"
syn = { version = "0.14", default-features = false, features = ["derive", "parsing", "clone-impls"] }
syn = { version = "0.15", default-features = false, features = ["derive", "parsing", "clone-impls"] }
[badges]
travis-ci = { repository = "serde-rs/serde" }
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_test"
version = "1.0.72" # remember to update html_root_url
version = "1.0.77" # 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"
+1 -1
View File
@@ -161,7 +161,7 @@
//! # }
//! ```
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.72")]
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.77")]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Whitelisted clippy lints
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
+2 -2
View File
@@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(lang_items, start, panic_implementation)]
#![feature(lang_items, start, panic_handler)]
#![no_std]
extern crate libc;
@@ -20,7 +20,7 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}
#[panic_implementation]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe {
libc::abort();
@@ -20,7 +20,7 @@ mod remote {
#[serde(remote = "remote::S")]
struct S {
a: u8,
//~^^^^ ERROR: missing field `b` in initializer of `remote::S`
//~^^^ ERROR: missing field `b` in initializer of `remote::S`
}
fn main() {}
@@ -18,9 +18,9 @@ mod remote {
#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::S")]
struct S {
//~^^^ ERROR: struct `remote::S` has no field named `b`
b: u8,
//~^^^^^ ERROR: no field `b` on type `&remote::S`
//~^ ERROR: struct `remote::S` has no field named `b`
//~^^ ERROR: no field `b` on type `&remote::S`
}
fn main() {}
+65
View File
@@ -2246,3 +2246,68 @@ fn test_transparent_tuple_struct() {
assert_tokens(&Transparent(false, 1, false, PhantomData), &[Token::U32(1)]);
}
#[test]
fn test_internally_tagged_unit_enum_with_unknown_fields() {
#[derive(Deserialize, PartialEq, Debug)]
#[serde(tag = "t")]
enum Data {
A,
}
let data = Data::A;
assert_de_tokens(
&data,
&[
Token::Map { len: None },
Token::Str("t"),
Token::Str("A"),
Token::Str("b"),
Token::I32(0),
Token::MapEnd,
],
);
}
#[test]
fn test_flattened_internally_tagged_unit_enum_with_unknown_fields() {
#[derive(Deserialize, PartialEq, Debug)]
struct S {
#[serde(flatten)]
x: X,
#[serde(flatten)]
y: Y,
}
#[derive(Deserialize, PartialEq, Debug)]
#[serde(tag = "typeX")]
enum X {
A,
}
#[derive(Deserialize, PartialEq, Debug)]
#[serde(tag = "typeY")]
enum Y {
B { c: u32 },
}
let s = S {
x: X::A,
y: Y::B { c: 0 },
};
assert_de_tokens(
&s,
&[
Token::Map { len: None },
Token::Str("typeX"),
Token::Str("A"),
Token::Str("typeY"),
Token::Str("B"),
Token::Str("c"),
Token::I32(0),
Token::MapEnd,
],
);
}
+6 -1
View File
@@ -156,8 +156,12 @@ macro_rules! declare_tests {
)+
};
($($name:ident { $($value:expr => $tokens:expr,)+ })+) => {
($(
$(#[$cfg:meta])*
$name:ident { $($value:expr => $tokens:expr,)+ }
)+) => {
$(
$(#[$cfg])*
#[test]
fn $name() {
$(
@@ -260,6 +264,7 @@ declare_tests! {
0f32 => &[Token::F32(0.)],
0f64 => &[Token::F64(0.)],
}
#[cfg(not(target_arch = "wasm32"))]
test_small_int_to_128 {
1i128 => &[Token::I8(1)],
1i128 => &[Token::I16(1)],
+1
View File
@@ -618,6 +618,7 @@ fn test_enum_skipped() {
);
}
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_integer128() {
assert_ser_tokens_error(&1i128, &[], "i128 is not supported");
+26
View File
@@ -0,0 +1,26 @@
// Copyright 2018 Serde Developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![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]
// right here, the stable compiler would fail to parse those raw identifiers
// even if the cfg were not enabled.
#[cfg(feature = "unstable")]
mod unstable;
+1
View File
@@ -26,6 +26,7 @@ fn test_u32_to_enum() {
assert_eq!(E::B, e);
}
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_integer128() {
let de_u128 = IntoDeserializer::<value::Error>::into_deserializer(1u128);
+32
View File
@@ -0,0 +1,32 @@
// Copyright 2018 Serde Developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use serde_test::{assert_tokens, Token};
#[test]
fn test_raw_identifiers() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[allow(non_camel_case_types)]
enum r#type {
r#type { r#type: () },
}
assert_tokens(
&r#type::r#type { r#type: () },
&[
Token::StructVariant {
name: "type",
variant: "type",
len: 1,
},
Token::Str("type"),
Token::Unit,
Token::StructVariantEnd,
],
);
}
+13
View File
@@ -42,6 +42,18 @@ if [ -n "${CLIPPY}" ]; then
cd "$DIR/test_suite/no_std"
cargo clippy -- -Dclippy
elif [ -n "${EMSCRIPTEN}" ]; then
CARGO_WEB_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/koute/cargo-web/releases/latest)
CARGO_WEB_VERSION=$(echo "${CARGO_WEB_RELEASE}" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
CARGO_WEB_URL="https://github.com/koute/cargo-web/releases/download/${CARGO_WEB_VERSION}/cargo-web-x86_64-unknown-linux-gnu.gz"
mkdir -p ~/.cargo/bin
echo "Downloading cargo-web from: ${CARGO_WEB_URL}"
curl -L "${CARGO_WEB_URL}" | gzip -d > ~/.cargo/bin/cargo-web
chmod +x ~/.cargo/bin/cargo-web
cd "$DIR/test_suite"
cargo web test --target=wasm32-unknown-emscripten --nodejs
else
CHANNEL=nightly
cd "$DIR"
@@ -50,6 +62,7 @@ else
channel build
channel build --no-default-features
channel build --no-default-features --features alloc
channel build --no-default-features --features 'rc alloc'
channel test --features 'rc unstable'
cd "$DIR/test_suite/deps"
channel build