Skip to content

Commit 6fbf40b

Browse files
committed
Remove usage of unstable core::num::Zero, which was removed upstream.
rust-lang/rust#41437
1 parent d7ccef0 commit 6fbf40b

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

serde/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "serde"
3-
version = "1.0.0" # remember to update html_root_url
3+
version = "1.0.1" # remember to update html_root_url
44
authors = ["Erick Tryzelaar <[email protected]>", "David Tolnay <[email protected]>"]
55
license = "MIT/Apache-2.0"
66
description = "A generic serialization/deserialization framework"

serde/src/de/impls.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,22 +1471,24 @@ where
14711471
////////////////////////////////////////////////////////////////////////////////
14721472

14731473
#[cfg(feature = "unstable")]
1474-
#[allow(deprecated)] // num::Zero is deprecated but there is no replacement
14751474
impl<'de, T> Deserialize<'de> for NonZero<T>
14761475
where
1477-
T: Deserialize<'de> + PartialEq + Zeroable + Zero,
1476+
T: Deserialize<'de> + Zeroable,
14781477
{
14791478
fn deserialize<D>(deserializer: D) -> Result<NonZero<T>, D::Error>
14801479
where
14811480
D: Deserializer<'de>,
14821481
{
14831482
let value = try!(Deserialize::deserialize(deserializer));
1484-
if value == Zero::zero() {
1485-
return Err(Error::custom("expected a non-zero value"));
1483+
unsafe {
1484+
let ptr = &value as *const T as *const u8;
1485+
if slice::from_raw_parts(ptr, mem::size_of::<T>()).iter().all(|&b| b == 0) {
1486+
return Err(Error::custom("expected a non-zero value"));
1487+
}
1488+
// Waiting for a safe way to construct NonZero<T>:
1489+
// https://github.com/rust-lang/rust/issues/27730#issuecomment-269726075
1490+
Ok(NonZero::new(value))
14861491
}
1487-
// Waiting for a safe way to construct NonZero<T>:
1488-
// https://github.com/rust-lang/rust/issues/27730#issuecomment-269726075
1489-
unsafe { Ok(NonZero::new(value)) }
14901492
}
14911493
}
14921494

serde/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
////////////////////////////////////////////////////////////////////////////////
8080

8181
// Serde types in rustdoc of other crates get linked to here.
82-
#![doc(html_root_url = "https://docs.rs/serde/1.0.0")]
82+
#![doc(html_root_url = "https://docs.rs/serde/1.0.1")]
8383

8484
// Support using Serde without the standard library!
8585
#![cfg_attr(not(feature = "std"), no_std)]
@@ -88,7 +88,7 @@
8888
// discussion of these features please refer to this issue:
8989
//
9090
// https://github.com/serde-rs/serde/issues/812
91-
#![cfg_attr(feature = "unstable", feature(nonzero, specialization, zero_one))]
91+
#![cfg_attr(feature = "unstable", feature(nonzero, specialization))]
9292
#![cfg_attr(all(feature = "std", feature = "unstable"), feature(into_boxed_c_str))]
9393
#![cfg_attr(feature = "alloc", feature(alloc))]
9494
#![cfg_attr(feature = "collections", feature(collections))]
@@ -124,7 +124,7 @@ mod lib {
124124
pub use core::*;
125125
}
126126

127-
pub use self::core::{cmp, iter, mem, ops, str};
127+
pub use self::core::{cmp, iter, mem, ops, slice, str};
128128
pub use self::core::{i8, i16, i32, i64, isize};
129129
pub use self::core::{u8, u16, u32, u64, usize};
130130
pub use self::core::{f32, f64};
@@ -193,9 +193,6 @@ mod lib {
193193

194194
#[cfg(feature = "unstable")]
195195
pub use core::nonzero::{NonZero, Zeroable};
196-
#[cfg(feature = "unstable")]
197-
#[allow(deprecated)] // required for impl Deserialize for NonZero<T>
198-
pub use core::num::Zero;
199196
}
200197

201198
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)