From 6fbf40b83c65ba2bfe9e94276482b13dd979ac63 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 24 Apr 2017 08:14:44 +0900 Subject: [PATCH] Remove usage of unstable core::num::Zero, which was removed upstream. https://github.com/rust-lang/rust/pull/41437 --- serde/Cargo.toml | 2 +- serde/src/de/impls.rs | 16 +++++++++------- serde/src/lib.rs | 9 +++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/serde/Cargo.toml b/serde/Cargo.toml index 683d075b..f89b4429 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde" -version = "1.0.0" # remember to update html_root_url +version = "1.0.1" # remember to update html_root_url authors = ["Erick Tryzelaar ", "David Tolnay "] license = "MIT/Apache-2.0" description = "A generic serialization/deserialization framework" diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index b73511bb..783eb562 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -1471,22 +1471,24 @@ where //////////////////////////////////////////////////////////////////////////////// #[cfg(feature = "unstable")] -#[allow(deprecated)] // num::Zero is deprecated but there is no replacement impl<'de, T> Deserialize<'de> for NonZero where - T: Deserialize<'de> + PartialEq + Zeroable + Zero, + T: Deserialize<'de> + Zeroable, { fn deserialize(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { let value = try!(Deserialize::deserialize(deserializer)); - if value == Zero::zero() { - return Err(Error::custom("expected a non-zero value")); + unsafe { + let ptr = &value as *const T as *const u8; + if slice::from_raw_parts(ptr, mem::size_of::()).iter().all(|&b| b == 0) { + return Err(Error::custom("expected a non-zero value")); + } + // Waiting for a safe way to construct NonZero: + // https://github.com/rust-lang/rust/issues/27730#issuecomment-269726075 + Ok(NonZero::new(value)) } - // Waiting for a safe way to construct NonZero: - // https://github.com/rust-lang/rust/issues/27730#issuecomment-269726075 - unsafe { Ok(NonZero::new(value)) } } } diff --git a/serde/src/lib.rs b/serde/src/lib.rs index 7fe587f5..2399c9fb 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -79,7 +79,7 @@ //////////////////////////////////////////////////////////////////////////////// // Serde types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/serde/1.0.0")] +#![doc(html_root_url = "https://docs.rs/serde/1.0.1")] // Support using Serde without the standard library! #![cfg_attr(not(feature = "std"), no_std)] @@ -88,7 +88,7 @@ // discussion of these features please refer to this issue: // // https://github.com/serde-rs/serde/issues/812 -#![cfg_attr(feature = "unstable", feature(nonzero, specialization, zero_one))] +#![cfg_attr(feature = "unstable", feature(nonzero, specialization))] #![cfg_attr(all(feature = "std", feature = "unstable"), feature(into_boxed_c_str))] #![cfg_attr(feature = "alloc", feature(alloc))] #![cfg_attr(feature = "collections", feature(collections))] @@ -124,7 +124,7 @@ mod lib { pub use core::*; } - pub use self::core::{cmp, iter, mem, ops, str}; + pub use self::core::{cmp, iter, mem, ops, slice, str}; pub use self::core::{i8, i16, i32, i64, isize}; pub use self::core::{u8, u16, u32, u64, usize}; pub use self::core::{f32, f64}; @@ -193,9 +193,6 @@ mod lib { #[cfg(feature = "unstable")] pub use core::nonzero::{NonZero, Zeroable}; - #[cfg(feature = "unstable")] - #[allow(deprecated)] // required for impl Deserialize for NonZero - pub use core::num::Zero; } ////////////////////////////////////////////////////////////////////////////////