1
Fork 0

Mark Unique as perma-unstable, with the feature renamed to ptr_internals.

This commit is contained in:
Simon Sapin 2017-12-22 19:29:16 +01:00
parent a2f878a084
commit c97c1f7dc3
8 changed files with 25 additions and 25 deletions

@ -1 +1 @@
Subproject commit 2f7b05fd5939aa49d52c4ab309b9a47776ba7bd8 Subproject commit fec3182d0b0a3cf8122e192b3270064a5b19be5b

View file

@ -110,6 +110,7 @@
#![feature(pattern)] #![feature(pattern)]
#![feature(placement_in_syntax)] #![feature(placement_in_syntax)]
#![feature(placement_new_protocol)] #![feature(placement_new_protocol)]
#![feature(ptr_internals)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![feature(slice_get_slice)] #![feature(slice_get_slice)]
#![feature(slice_patterns)] #![feature(slice_patterns)]
@ -120,7 +121,6 @@
#![feature(trusted_len)] #![feature(trusted_len)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(unicode)] #![feature(unicode)]
#![feature(unique)]
#![feature(unsize)] #![feature(unsize)]
#![feature(allocator_internals)] #![feature(allocator_internals)]
#![feature(on_unimplemented)] #![feature(on_unimplemented)]

View file

@ -2330,8 +2330,9 @@ impl<T: ?Sized> PartialOrd for *mut T {
/// ///
/// Unlike `*mut T`, `Unique<T>` is covariant over `T`. This should always be correct /// Unlike `*mut T`, `Unique<T>` is covariant over `T`. This should always be correct
/// for any type which upholds Unique's aliasing requirements. /// for any type which upholds Unique's aliasing requirements.
#[unstable(feature = "unique", reason = "needs an RFC to flesh out design", #[unstable(feature = "ptr_internals", issue = "0",
issue = "27730")] reason = "use NonNull instead and consider PhantomData<T> \
(if you also use #[may_dangle]), Send, and/or Sync")]
pub struct Unique<T: ?Sized> { pub struct Unique<T: ?Sized> {
pointer: NonZero<*const T>, pointer: NonZero<*const T>,
// NOTE: this marker has no consequences for variance, but is necessary // NOTE: this marker has no consequences for variance, but is necessary
@ -2342,7 +2343,7 @@ pub struct Unique<T: ?Sized> {
_marker: PhantomData<T>, _marker: PhantomData<T>,
} }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<T: ?Sized> fmt::Debug for Unique<T> { impl<T: ?Sized> fmt::Debug for Unique<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:p}", self.as_ptr()) write!(f, "{:p}", self.as_ptr())
@ -2353,17 +2354,17 @@ impl<T: ?Sized> fmt::Debug for Unique<T> {
/// reference is unaliased. Note that this aliasing invariant is /// reference is unaliased. Note that this aliasing invariant is
/// unenforced by the type system; the abstraction using the /// unenforced by the type system; the abstraction using the
/// `Unique` must enforce it. /// `Unique` must enforce it.
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
unsafe impl<T: Send + ?Sized> Send for Unique<T> { } unsafe impl<T: Send + ?Sized> Send for Unique<T> { }
/// `Unique` pointers are `Sync` if `T` is `Sync` because the data they /// `Unique` pointers are `Sync` if `T` is `Sync` because the data they
/// reference is unaliased. Note that this aliasing invariant is /// reference is unaliased. Note that this aliasing invariant is
/// unenforced by the type system; the abstraction using the /// unenforced by the type system; the abstraction using the
/// `Unique` must enforce it. /// `Unique` must enforce it.
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
unsafe impl<T: Sync + ?Sized> Sync for Unique<T> { } unsafe impl<T: Sync + ?Sized> Sync for Unique<T> { }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<T: Sized> Unique<T> { impl<T: Sized> Unique<T> {
/// Creates a new `Unique` that is dangling, but well-aligned. /// Creates a new `Unique` that is dangling, but well-aligned.
/// ///
@ -2377,14 +2378,13 @@ impl<T: Sized> Unique<T> {
} }
} }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<T: ?Sized> Unique<T> { impl<T: ?Sized> Unique<T> {
/// Creates a new `Unique`. /// Creates a new `Unique`.
/// ///
/// # Safety /// # Safety
/// ///
/// `ptr` must be non-null. /// `ptr` must be non-null.
#[unstable(feature = "unique", issue = "27730")]
pub const unsafe fn new_unchecked(ptr: *mut T) -> Self { pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
Unique { pointer: NonZero::new_unchecked(ptr), _marker: PhantomData } Unique { pointer: NonZero::new_unchecked(ptr), _marker: PhantomData }
} }
@ -2418,41 +2418,41 @@ impl<T: ?Sized> Unique<T> {
} }
} }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<T: ?Sized> Clone for Unique<T> { impl<T: ?Sized> Clone for Unique<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
*self *self
} }
} }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<T: ?Sized> Copy for Unique<T> { } impl<T: ?Sized> Copy for Unique<T> { }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> { } impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> { }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<T: ?Sized> fmt::Pointer for Unique<T> { impl<T: ?Sized> fmt::Pointer for Unique<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Pointer::fmt(&self.as_ptr(), f) fmt::Pointer::fmt(&self.as_ptr(), f)
} }
} }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<'a, T: ?Sized> From<&'a mut T> for Unique<T> { impl<'a, T: ?Sized> From<&'a mut T> for Unique<T> {
fn from(reference: &'a mut T) -> Self { fn from(reference: &'a mut T) -> Self {
Unique { pointer: NonZero::from(reference), _marker: PhantomData } Unique { pointer: NonZero::from(reference), _marker: PhantomData }
} }
} }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<'a, T: ?Sized> From<&'a T> for Unique<T> { impl<'a, T: ?Sized> From<&'a T> for Unique<T> {
fn from(reference: &'a T) -> Self { fn from(reference: &'a T) -> Self {
Unique { pointer: NonZero::from(reference), _marker: PhantomData } Unique { pointer: NonZero::from(reference), _marker: PhantomData }
} }
} }
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<'a, T: ?Sized> From<NonNull<T>> for Unique<T> { impl<'a, T: ?Sized> From<NonNull<T>> for Unique<T> {
fn from(p: NonNull<T>) -> Self { fn from(p: NonNull<T>) -> Self {
Unique { pointer: p.pointer, _marker: PhantomData } Unique { pointer: p.pointer, _marker: PhantomData }

View file

@ -27,6 +27,7 @@
#![feature(iterator_try_fold)] #![feature(iterator_try_fold)]
#![feature(iter_rfind)] #![feature(iter_rfind)]
#![feature(iter_rfold)] #![feature(iter_rfold)]
#![feature(nonnull)]
#![feature(nonzero)] #![feature(nonzero)]
#![feature(pattern)] #![feature(pattern)]
#![feature(raw)] #![feature(raw)]
@ -41,7 +42,6 @@
#![feature(trusted_len)] #![feature(trusted_len)]
#![feature(try_from)] #![feature(try_from)]
#![feature(try_trait)] #![feature(try_trait)]
#![feature(unique)]
#![feature(exact_chunks)] #![feature(exact_chunks)]
extern crate core; extern crate core;

View file

@ -249,9 +249,9 @@ fn test_set_memory() {
} }
#[test] #[test]
fn test_unsized_unique() { fn test_unsized_nonnull() {
let xs: &[i32] = &[1, 2, 3]; let xs: &[i32] = &[1, 2, 3];
let ptr = unsafe { Unique::new_unchecked(xs as *const [i32] as *mut [i32]) }; let ptr = unsafe { NonNull::new_unchecked(xs as *const [i32] as *mut [i32]) };
let ys = unsafe { ptr.as_ref() }; let ys = unsafe { ptr.as_ref() };
let zs: &[i32] = &[1, 2, 3]; let zs: &[i32] = &[1, 2, 3];
assert!(ys == zs); assert!(ys == zs);

View file

@ -294,6 +294,7 @@
#![feature(placement_in_syntax)] #![feature(placement_in_syntax)]
#![feature(placement_new_protocol)] #![feature(placement_new_protocol)]
#![feature(prelude_import)] #![feature(prelude_import)]
#![feature(ptr_internals)]
#![feature(rand)] #![feature(rand)]
#![feature(raw)] #![feature(raw)]
#![feature(repr_align)] #![feature(repr_align)]
@ -315,7 +316,6 @@
#![feature(try_from)] #![feature(try_from)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(unicode)] #![feature(unicode)]
#![feature(unique)]
#![feature(untagged_unions)] #![feature(untagged_unions)]
#![feature(unwind_attributes)] #![feature(unwind_attributes)]
#![feature(vec_push_all)] #![feature(vec_push_all)]

View file

@ -196,7 +196,7 @@ impl<'a, T: RefUnwindSafe + ?Sized> UnwindSafe for &'a T {}
impl<T: RefUnwindSafe + ?Sized> UnwindSafe for *const T {} impl<T: RefUnwindSafe + ?Sized> UnwindSafe for *const T {}
#[stable(feature = "catch_unwind", since = "1.9.0")] #[stable(feature = "catch_unwind", since = "1.9.0")]
impl<T: RefUnwindSafe + ?Sized> UnwindSafe for *mut T {} impl<T: RefUnwindSafe + ?Sized> UnwindSafe for *mut T {}
#[unstable(feature = "unique", issue = "27730")] #[unstable(feature = "ptr_internals", issue = "0")]
impl<T: UnwindSafe + ?Sized> UnwindSafe for Unique<T> {} impl<T: UnwindSafe + ?Sized> UnwindSafe for Unique<T> {}
#[unstable(feature = "nonnull", issue = "27730")] #[unstable(feature = "nonnull", issue = "27730")]
impl<T: RefUnwindSafe + ?Sized> UnwindSafe for NonNull<T> {} impl<T: RefUnwindSafe + ?Sized> UnwindSafe for NonNull<T> {}

View file

@ -10,13 +10,13 @@
// Don't fail if we encounter a NonZero<*T> where T is an unsized type // Don't fail if we encounter a NonZero<*T> where T is an unsized type
#![feature(unique)] #![feature(nonnull)]
use std::ptr::Unique; use std::ptr::NonNull;
fn main() { fn main() {
let mut a = [0u8; 5]; let mut a = [0u8; 5];
let b: Option<Unique<[u8]>> = Some(Unique::from(&mut a)); let b: Option<NonNull<[u8]>> = Some(NonNull::from(&mut a));
match b { match b {
Some(_) => println!("Got `Some`"), Some(_) => println!("Got `Some`"),
None => panic!("Unexpected `None`"), None => panic!("Unexpected `None`"),