Skip to content

Commit 22f7a02

Browse files
committed
Deprecate core::nonzero in favor of ptr::NonNull and num::NonZero*
1 parent 67f46ce commit 22f7a02

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/libcore/nonzero.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
//! Exposes the NonZero lang item which provides optimization hints.
1212
#![unstable(feature = "nonzero",
13-
reason = "needs an RFC to flesh out the design",
13+
reason = "deprecated",
1414
issue = "27730")]
15+
#![rustc_deprecated(reason = "use `std::ptr::NonNull` or `std::num::NonZero*` instead",
16+
since = "1.26.0")]
17+
#![allow(deprecated)]
1518

1619
use ops::CoerceUnsized;
1720

src/libcore/num/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use convert::{Infallible, TryFrom};
1616
use fmt;
1717
use intrinsics;
18-
use nonzero::NonZero;
18+
#[allow(deprecated)] use nonzero::NonZero;
1919
use ops;
2020
use str::FromStr;
2121

@@ -46,9 +46,11 @@ macro_rules! nonzero_integers {
4646
/// assert_eq!(size_of::<Option<std::num::NonZeroU32>>(), size_of::<u32>());
4747
/// ```
4848
#[$stability]
49+
#[allow(deprecated)]
4950
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
5051
pub struct $Ty(NonZero<$Int>);
5152

53+
#[allow(deprecated)]
5254
impl $Ty {
5355
/// Create a non-zero without checking the value.
5456
///

src/libcore/ptr.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use fmt;
2323
use hash;
2424
use marker::{PhantomData, Unsize};
2525
use mem;
26-
use nonzero::NonZero;
26+
#[allow(deprecated)] use nonzero::NonZero;
2727

2828
use cmp::Ordering::{self, Less, Equal, Greater};
2929

@@ -2285,6 +2285,7 @@ impl<T: ?Sized> PartialOrd for *mut T {
22852285
#[unstable(feature = "ptr_internals", issue = "0",
22862286
reason = "use NonNull instead and consider PhantomData<T> \
22872287
(if you also use #[may_dangle]), Send, and/or Sync")]
2288+
#[allow(deprecated)]
22882289
pub struct Unique<T: ?Sized> {
22892290
pointer: NonZero<*const T>,
22902291
// NOTE: this marker has no consequences for variance, but is necessary
@@ -2332,6 +2333,7 @@ impl<T: Sized> Unique<T> {
23322333
}
23332334

23342335
#[unstable(feature = "ptr_internals", issue = "0")]
2336+
#[allow(deprecated)]
23352337
impl<T: ?Sized> Unique<T> {
23362338
/// Creates a new `Unique`.
23372339
///
@@ -2392,13 +2394,15 @@ impl<T: ?Sized> fmt::Pointer for Unique<T> {
23922394
}
23932395

23942396
#[unstable(feature = "ptr_internals", issue = "0")]
2397+
#[allow(deprecated)]
23952398
impl<'a, T: ?Sized> From<&'a mut T> for Unique<T> {
23962399
fn from(reference: &'a mut T) -> Self {
23972400
Unique { pointer: NonZero::from(reference), _marker: PhantomData }
23982401
}
23992402
}
24002403

24012404
#[unstable(feature = "ptr_internals", issue = "0")]
2405+
#[allow(deprecated)]
24022406
impl<'a, T: ?Sized> From<&'a T> for Unique<T> {
24032407
fn from(reference: &'a T) -> Self {
24042408
Unique { pointer: NonZero::from(reference), _marker: PhantomData }
@@ -2436,7 +2440,7 @@ pub type Shared<T> = NonNull<T>;
24362440
/// provide a public API that follows the normal shared XOR mutable rules of Rust.
24372441
#[stable(feature = "nonnull", since = "1.25.0")]
24382442
pub struct NonNull<T: ?Sized> {
2439-
pointer: NonZero<*const T>,
2443+
#[allow(deprecated)] pointer: NonZero<*const T>,
24402444
}
24412445

24422446
/// `NonNull` pointers are not `Send` because the data they reference may be aliased.
@@ -2463,6 +2467,7 @@ impl<T: Sized> NonNull<T> {
24632467
}
24642468
}
24652469

2470+
#[allow(deprecated)]
24662471
impl<T: ?Sized> NonNull<T> {
24672472
/// Creates a new `NonNull`.
24682473
///
@@ -2581,13 +2586,15 @@ impl<T: ?Sized> From<Unique<T>> for NonNull<T> {
25812586
}
25822587

25832588
#[stable(feature = "nonnull", since = "1.25.0")]
2589+
#[allow(deprecated)]
25842590
impl<'a, T: ?Sized> From<&'a mut T> for NonNull<T> {
25852591
fn from(reference: &'a mut T) -> Self {
25862592
NonNull { pointer: NonZero::from(reference) }
25872593
}
25882594
}
25892595

25902596
#[stable(feature = "nonnull", since = "1.25.0")]
2597+
#[allow(deprecated)]
25912598
impl<'a, T: ?Sized> From<&'a T> for NonNull<T> {
25922599
fn from(reference: &'a T) -> Self {
25932600
NonNull { pointer: NonZero::from(reference) }

0 commit comments

Comments
 (0)