Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion serde/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "David Tolnay <[email protected]>"]
license = "MIT/Apache-2.0"
description = "A generic serialization/deserialization framework"
Expand Down
16 changes: 9 additions & 7 deletions serde/src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
where
T: Deserialize<'de> + PartialEq + Zeroable + Zero,
T: Deserialize<'de> + Zeroable,
{
fn deserialize<D>(deserializer: D) -> Result<NonZero<T>, 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::<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)) }
}
}

Expand Down
9 changes: 3 additions & 6 deletions serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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))]
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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<T>
pub use core::num::Zero;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down