Compare commits

...

8 Commits

Author SHA1 Message Date
David Tolnay 9c6f0c3a0e Release 1.0.114 2020-06-21 17:31:02 -07:00
David Tolnay a9f8ea0a1e Simplify search for packed repr attr 2020-06-21 17:22:07 -07:00
David Tolnay 04faac962a Remove error_on_line_overflow rustfmt setting
No longer seeing warnings on this from rustfmt.
2020-06-21 16:48:22 -07:00
Tanner Rogalsky 7e5701ad2b add alignment specific packed repr tests 2020-06-21 16:46:27 -07:00
Tanner Rogalsky 1cd10a7d09 Improved packed repr matching. 2020-06-21 16:46:27 -07:00
Tanner Rogalsky d5e6436b28 Add tests validating Serialize derivation for packed structs. 2020-06-21 16:46:27 -07:00
David Tolnay 8ff11dc234 Merge pull request #1841 from dtolnay/lenhint
Remove len hint specialization
2020-06-20 19:08:34 -07:00
David Tolnay 6b3777b617 Remove len hint specialization 2020-06-20 19:02:26 -07:00
11 changed files with 45 additions and 43 deletions
-1
View File
@@ -1 +0,0 @@
error_on_line_overflow = false
+2 -2
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde" name = "serde"
version = "1.0.113" # remember to update html_root_url and serde_derive dependency version = "1.0.114" # remember to update html_root_url and serde_derive dependency
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"] authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
description = "A generic serialization/deserialization framework" description = "A generic serialization/deserialization framework"
@@ -14,7 +14,7 @@ include = ["build.rs", "src/**/*.rs", "crates-io.md", "README.md", "LICENSE-APAC
build = "build.rs" build = "build.rs"
[dependencies] [dependencies]
serde_derive = { version = "=1.0.113", optional = true, path = "../serde_derive" } serde_derive = { version = "=1.0.114", optional = true, path = "../serde_derive" }
[dev-dependencies] [dev-dependencies]
serde_derive = { version = "1.0", path = "../serde_derive" } serde_derive = { version = "1.0", path = "../serde_derive" }
+2 -2
View File
@@ -82,14 +82,14 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here. // Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde/1.0.113")] #![doc(html_root_url = "https://docs.rs/serde/1.0.114")]
// Support using Serde without the standard library! // Support using Serde without the standard library!
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
// Unstable functionality only if the user asks for it. For tracking and // Unstable functionality only if the user asks for it. For tracking and
// discussion of these features please refer to this issue: // discussion of these features please refer to this issue:
// //
// https://github.com/serde-rs/serde/issues/812 // https://github.com/serde-rs/serde/issues/812
#![cfg_attr(feature = "unstable", feature(specialization, never_type))] #![cfg_attr(feature = "unstable", feature(never_type))]
#![allow(unknown_lints, bare_trait_objects, deprecated)] #![allow(unknown_lints, bare_trait_objects, deprecated)]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))] #![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))] #![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
+2 -31
View File
@@ -1278,7 +1278,7 @@ pub trait Serializer: Sized {
<I as IntoIterator>::Item: Serialize, <I as IntoIterator>::Item: Serialize,
{ {
let iter = iter.into_iter(); let iter = iter.into_iter();
let mut serializer = try!(self.serialize_seq(iter.len_hint())); let mut serializer = try!(self.serialize_seq(iterator_len_hint(&iter)));
for item in iter { for item in iter {
try!(serializer.serialize_element(&item)); try!(serializer.serialize_element(&item));
} }
@@ -1318,7 +1318,7 @@ pub trait Serializer: Sized {
I: IntoIterator<Item = (K, V)>, I: IntoIterator<Item = (K, V)>,
{ {
let iter = iter.into_iter(); let iter = iter.into_iter();
let mut serializer = try!(self.serialize_map(iter.len_hint())); let mut serializer = try!(self.serialize_map(iterator_len_hint(&iter)));
for (key, value) in iter { for (key, value) in iter {
try!(serializer.serialize_entry(&key, &value)); try!(serializer.serialize_entry(&key, &value));
} }
@@ -1953,35 +1953,6 @@ pub trait SerializeStructVariant {
fn end(self) -> Result<Self::Ok, Self::Error>; fn end(self) -> Result<Self::Ok, Self::Error>;
} }
trait LenHint: Iterator {
fn len_hint(&self) -> Option<usize>;
}
impl<I> LenHint for I
where
I: Iterator,
{
#[cfg(not(feature = "unstable"))]
fn len_hint(&self) -> Option<usize> {
iterator_len_hint(self)
}
#[cfg(feature = "unstable")]
default fn len_hint(&self) -> Option<usize> {
iterator_len_hint(self)
}
}
#[cfg(feature = "unstable")]
impl<I> LenHint for I
where
I: ExactSizeIterator,
{
fn len_hint(&self) -> Option<usize> {
Some(self.len())
}
}
fn iterator_len_hint<I>(iter: &I) -> Option<usize> fn iterator_len_hint<I>(iter: &I) -> Option<usize>
where where
I: Iterator, I: Iterator,
+2 -2
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde_derive" name = "serde_derive"
version = "1.0.113" # remember to update html_root_url version = "1.0.114" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"] authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]" description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]"
@@ -22,7 +22,7 @@ proc-macro = true
[dependencies] [dependencies]
proc-macro2 = "1.0" proc-macro2 = "1.0"
quote = "1.0" quote = "1.0"
syn = { version = "1.0", features = ["visit"] } syn = { version = "1.0.33", features = ["visit"] }
[dev-dependencies] [dev-dependencies]
serde = { version = "1.0", path = "../serde" } serde = { version = "1.0", path = "../serde" }
+5 -1
View File
@@ -597,7 +597,11 @@ impl Container {
for attr in &item.attrs { for attr in &item.attrs {
if attr.path.is_ident("repr") { if attr.path.is_ident("repr") {
let _ = attr.parse_args_with(|input: ParseStream| { let _ = attr.parse_args_with(|input: ParseStream| {
is_packed |= input.parse::<Ident>()? == "packed"; while let Some(token) = input.parse()? {
if let TokenTree::Ident(ident) = token {
is_packed |= ident == "packed";
}
}
Ok(()) Ok(())
}); });
} }
+1 -1
View File
@@ -13,7 +13,7 @@
//! //!
//! [https://serde.rs/derive.html]: https://serde.rs/derive.html //! [https://serde.rs/derive.html]: https://serde.rs/derive.html
#![doc(html_root_url = "https://docs.rs/serde_derive/1.0.113")] #![doc(html_root_url = "https://docs.rs/serde_derive/1.0.114")]
#![allow(unknown_lints, bare_trait_objects)] #![allow(unknown_lints, bare_trait_objects)]
#![deny(clippy::all, clippy::pedantic)] #![deny(clippy::all, clippy::pedantic)]
// Ignored clippy lints // Ignored clippy lints
+1 -1
View File
@@ -16,7 +16,7 @@ path = "lib.rs"
[dependencies] [dependencies]
proc-macro2 = "1.0" proc-macro2 = "1.0"
quote = "1.0" quote = "1.0"
syn = { version = "1.0", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] } syn = { version = "1.0.33", default-features = false, features = ["derive", "parsing", "printing", "clone-impls"] }
[package.metadata.docs.rs] [package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"] targets = ["x86_64-unknown-linux-gnu"]
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "serde_test" name = "serde_test"
version = "1.0.113" # remember to update html_root_url version = "1.0.114" # remember to update html_root_url
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"] authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
description = "Token De/Serializer for testing De/Serialize implementations" description = "Token De/Serializer for testing De/Serialize implementations"
+1 -1
View File
@@ -144,7 +144,7 @@
//! # } //! # }
//! ``` //! ```
#![doc(html_root_url = "https://docs.rs/serde_test/1.0.113")] #![doc(html_root_url = "https://docs.rs/serde_test/1.0.114")]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))] #![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))] #![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))]
// Ignored clippy lints // Ignored clippy lints
+28
View File
@@ -1878,3 +1878,31 @@ fn test_internally_tagged_newtype_variant_containing_unit_struct() {
], ],
); );
} }
#[deny(safe_packed_borrows)]
#[test]
fn test_packed_struct_can_derive_serialize() {
#[derive(Copy, Clone, Serialize)]
#[repr(packed, C)]
struct PackedC {
t: f32,
}
#[derive(Copy, Clone, Serialize)]
#[repr(C, packed)]
struct CPacked {
t: f32,
}
#[derive(Copy, Clone, Serialize)]
#[repr(C, packed(2))]
struct CPacked2 {
t: f32,
}
#[derive(Copy, Clone, Serialize)]
#[repr(packed(2), C)]
struct Packed2C {
t: f32,
}
}