Remove usage of unstable core::num::Zero, which was removed upstream.

https://github.com/rust-lang/rust/pull/41437
This commit is contained in:
Simon Sapin 2017-04-24 08:14:44 +09:00
parent d7ccef0cac
commit 6fbf40b83c
3 changed files with 13 additions and 14 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "serde" 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 <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"] authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"]
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
description = "A generic serialization/deserialization framework" description = "A generic serialization/deserialization framework"

View File

@ -1471,22 +1471,24 @@ where
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
#[allow(deprecated)] // num::Zero is deprecated but there is no replacement
impl<'de, T> Deserialize<'de> for NonZero<T> impl<'de, T> Deserialize<'de> for NonZero<T>
where where
T: Deserialize<'de> + PartialEq + Zeroable + Zero, T: Deserialize<'de> + Zeroable,
{ {
fn deserialize<D>(deserializer: D) -> Result<NonZero<T>, D::Error> fn deserialize<D>(deserializer: D) -> Result<NonZero<T>, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
let value = try!(Deserialize::deserialize(deserializer)); let value = try!(Deserialize::deserialize(deserializer));
if value == Zero::zero() { unsafe {
return Err(Error::custom("expected a non-zero value")); let ptr = &value as *const T as *const u8;
if slice::from_raw_parts(ptr, mem::size_of::<T>()).iter().all(|&b| b == 0) {
return Err(Error::custom("expected a non-zero value"));
}
// Waiting for a safe way to construct NonZero<T>:
// https://github.com/rust-lang/rust/issues/27730#issuecomment-269726075
Ok(NonZero::new(value))
} }
// Waiting for a safe way to construct NonZero<T>:
// https://github.com/rust-lang/rust/issues/27730#issuecomment-269726075
unsafe { Ok(NonZero::new(value)) }
} }
} }

View File

@ -79,7 +79,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Serde types in rustdoc of other crates get linked to here. // Serde types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/serde/1.0.0")] #![doc(html_root_url = "https://docs.rs/serde/1.0.1")]
// 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)]
@ -88,7 +88,7 @@
// 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(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(all(feature = "std", feature = "unstable"), feature(into_boxed_c_str))]
#![cfg_attr(feature = "alloc", feature(alloc))] #![cfg_attr(feature = "alloc", feature(alloc))]
#![cfg_attr(feature = "collections", feature(collections))] #![cfg_attr(feature = "collections", feature(collections))]
@ -124,7 +124,7 @@ mod lib {
pub use core::*; 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::{i8, i16, i32, i64, isize};
pub use self::core::{u8, u16, u32, u64, usize}; pub use self::core::{u8, u16, u32, u64, usize};
pub use self::core::{f32, f64}; pub use self::core::{f32, f64};
@ -193,9 +193,6 @@ mod lib {
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
pub use core::nonzero::{NonZero, Zeroable}; pub use core::nonzero::{NonZero, Zeroable};
#[cfg(feature = "unstable")]
#[allow(deprecated)] // required for impl Deserialize for NonZero<T>
pub use core::num::Zero;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////