Skip to content

Commit

Permalink
Rename std::ptr::Shared to NonNull
Browse files Browse the repository at this point in the history
`Shared` is now a deprecated `type` alias.

CC rust-lang#27730 (comment)
  • Loading branch information
SimonSapin committed Jan 20, 2018
1 parent ba5d7a6 commit f19baf0
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 95 deletions.
18 changes: 9 additions & 9 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use core::intrinsics::abort;
use core::mem::{self, align_of_val, size_of_val, uninitialized};
use core::ops::Deref;
use core::ops::CoerceUnsized;
use core::ptr::{self, Shared};
use core::ptr::{self, NonNull};
use core::marker::{Unsize, PhantomData};
use core::hash::{Hash, Hasher};
use core::{isize, usize};
Expand Down Expand Up @@ -197,7 +197,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
/// [rc_examples]: ../../std/rc/index.html#examples
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Arc<T: ?Sized> {
ptr: Shared<ArcInner<T>>,
ptr: NonNull<ArcInner<T>>,
phantom: PhantomData<T>,
}

Expand Down Expand Up @@ -234,7 +234,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
/// [`None`]: ../../std/option/enum.Option.html#variant.None
#[stable(feature = "arc_weak", since = "1.4.0")]
pub struct Weak<T: ?Sized> {
ptr: Shared<ArcInner<T>>,
ptr: NonNull<ArcInner<T>>,
}

#[stable(feature = "arc_weak", since = "1.4.0")]
Expand Down Expand Up @@ -286,7 +286,7 @@ impl<T> Arc<T> {
weak: atomic::AtomicUsize::new(1),
data,
};
Arc { ptr: Shared::from(Box::into_unique(x)), phantom: PhantomData }
Arc { ptr: NonNull::from(Box::into_unique(x)), phantom: PhantomData }
}

/// Returns the contained value, if the `Arc` has exactly one strong reference.
Expand Down Expand Up @@ -397,7 +397,7 @@ impl<T: ?Sized> Arc<T> {
let arc_ptr = set_data_ptr(fake_ptr, (ptr as *mut u8).offset(-offset));

Arc {
ptr: Shared::new_unchecked(arc_ptr),
ptr: NonNull::new_unchecked(arc_ptr),
phantom: PhantomData,
}
}
Expand Down Expand Up @@ -582,7 +582,7 @@ impl<T: ?Sized> Arc<T> {
// Free the allocation without dropping its contents
box_free(bptr);

Arc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
Arc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
}
}
}
Expand All @@ -609,7 +609,7 @@ impl<T> Arc<[T]> {
&mut (*ptr).data as *mut [T] as *mut T,
v.len());

Arc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
Arc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
}
}

Expand Down Expand Up @@ -669,7 +669,7 @@ impl<T: Clone> ArcFromSlice<T> for Arc<[T]> {
// All clear. Forget the guard so it doesn't free the new ArcInner.
mem::forget(guard);

Arc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
Arc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
}
}
}
Expand Down Expand Up @@ -991,7 +991,7 @@ impl<T> Weak<T> {
pub fn new() -> Weak<T> {
unsafe {
Weak {
ptr: Shared::from(Box::into_unique(box ArcInner {
ptr: NonNull::from(Box::into_unique(box ArcInner {
strong: atomic::AtomicUsize::new(0),
weak: atomic::AtomicUsize::new(1),
data: uninitialized(),
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ unsafe impl Alloc for Heap {
///
/// This preserves the non-null invariant for types like `Box<T>`. The address
/// may overlap with non-zero-size memory allocations.
#[rustc_deprecated(since = "1.19", reason = "Use Unique/Shared::empty() instead")]
#[rustc_deprecated(since = "1.19", reason = "Use Unique/NonNull::empty() instead")]
#[unstable(feature = "heap_api", issue = "27700")]
pub const EMPTY: *mut () = 1 as *mut ();

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@
#![feature(iter_rfold)]
#![feature(lang_items)]
#![feature(needs_allocator)]
#![feature(nonnull)]
#![feature(nonzero)]
#![feature(offset_to)]
#![feature(optin_builtin_traits)]
#![feature(pattern)]
#![feature(placement_in_syntax)]
#![feature(placement_new_protocol)]
#![feature(rustc_attrs)]
#![feature(shared)]
#![feature(slice_get_slice)]
#![feature(slice_patterns)]
#![feature(slice_rsplit)]
Expand Down
28 changes: 14 additions & 14 deletions src/liballoc/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use core::iter::{FromIterator, FusedIterator};
use core::marker::PhantomData;
use core::mem;
use core::ops::{BoxPlace, InPlace, Place, Placer};
use core::ptr::{self, Shared};
use core::ptr::{self, NonNull};

use boxed::{Box, IntermediateBox};
use super::SpecExtend;
Expand All @@ -44,15 +44,15 @@ use super::SpecExtend;
/// more memory efficient and make better use of CPU cache.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LinkedList<T> {
head: Option<Shared<Node<T>>>,
tail: Option<Shared<Node<T>>>,
head: Option<NonNull<Node<T>>>,
tail: Option<NonNull<Node<T>>>,
len: usize,
marker: PhantomData<Box<Node<T>>>,
}

struct Node<T> {
next: Option<Shared<Node<T>>>,
prev: Option<Shared<Node<T>>>,
next: Option<NonNull<Node<T>>>,
prev: Option<NonNull<Node<T>>>,
element: T,
}

Expand All @@ -65,8 +65,8 @@ struct Node<T> {
/// [`LinkedList`]: struct.LinkedList.html
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T: 'a> {
head: Option<Shared<Node<T>>>,
tail: Option<Shared<Node<T>>>,
head: Option<NonNull<Node<T>>>,
tail: Option<NonNull<Node<T>>>,
len: usize,
marker: PhantomData<&'a Node<T>>,
}
Expand Down Expand Up @@ -98,8 +98,8 @@ impl<'a, T> Clone for Iter<'a, T> {
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T: 'a> {
list: &'a mut LinkedList<T>,
head: Option<Shared<Node<T>>>,
tail: Option<Shared<Node<T>>>,
head: Option<NonNull<Node<T>>>,
tail: Option<NonNull<Node<T>>>,
len: usize,
}

Expand Down Expand Up @@ -157,7 +157,7 @@ impl<T> LinkedList<T> {
unsafe {
node.next = self.head;
node.prev = None;
let node = Some(Shared::from(Box::into_unique(node)));
let node = Some(NonNull::from(Box::into_unique(node)));

match self.head {
None => self.tail = node,
Expand Down Expand Up @@ -192,7 +192,7 @@ impl<T> LinkedList<T> {
unsafe {
node.next = None;
node.prev = self.tail;
let node = Some(Shared::from(Box::into_unique(node)));
let node = Some(NonNull::from(Box::into_unique(node)));

match self.tail {
None => self.head = node,
Expand Down Expand Up @@ -225,7 +225,7 @@ impl<T> LinkedList<T> {
///
/// Warning: this will not check that the provided node belongs to the current list.
#[inline]
unsafe fn unlink_node(&mut self, mut node: Shared<Node<T>>) {
unsafe fn unlink_node(&mut self, mut node: NonNull<Node<T>>) {
let node = node.as_mut();

match node.prev {
Expand Down Expand Up @@ -986,7 +986,7 @@ impl<'a, T> IterMut<'a, T> {
Some(prev) => prev,
};

let node = Some(Shared::from(Box::into_unique(box Node {
let node = Some(NonNull::from(Box::into_unique(box Node {
next: Some(head),
prev: Some(prev),
element,
Expand Down Expand Up @@ -1038,7 +1038,7 @@ pub struct DrainFilter<'a, T: 'a, F: 'a>
where F: FnMut(&mut T) -> bool,
{
list: &'a mut LinkedList<T>,
it: Option<Shared<Node<T>>>,
it: Option<NonNull<Node<T>>>,
pred: F,
idx: usize,
old_len: usize,
Expand Down
20 changes: 10 additions & 10 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ use core::marker::{Unsize, PhantomData};
use core::mem::{self, align_of_val, forget, size_of_val, uninitialized};
use core::ops::Deref;
use core::ops::CoerceUnsized;
use core::ptr::{self, Shared};
use core::ptr::{self, NonNull};
use core::convert::From;

use heap::{Heap, Alloc, Layout, box_free};
Expand All @@ -282,7 +282,7 @@ struct RcBox<T: ?Sized> {
/// [get_mut]: #method.get_mut
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Rc<T: ?Sized> {
ptr: Shared<RcBox<T>>,
ptr: NonNull<RcBox<T>>,
phantom: PhantomData<T>,
}

Expand Down Expand Up @@ -311,7 +311,7 @@ impl<T> Rc<T> {
// pointers, which ensures that the weak destructor never frees
// the allocation while the strong destructor is running, even
// if the weak pointer is stored inside the strong one.
ptr: Shared::from(Box::into_unique(box RcBox {
ptr: NonNull::from(Box::into_unique(box RcBox {
strong: Cell::new(1),
weak: Cell::new(1),
value,
Expand Down Expand Up @@ -428,7 +428,7 @@ impl<T: ?Sized> Rc<T> {
let rc_ptr = set_data_ptr(fake_ptr, (ptr as *mut u8).offset(-offset));

Rc {
ptr: Shared::new_unchecked(rc_ptr),
ptr: NonNull::new_unchecked(rc_ptr),
phantom: PhantomData,
}
}
Expand Down Expand Up @@ -649,7 +649,7 @@ impl Rc<Any> {
let raw: *const RcBox<Any> = self.ptr.as_ptr();
forget(self);
Ok(Rc {
ptr: Shared::new_unchecked(raw as *const RcBox<T> as *mut _),
ptr: NonNull::new_unchecked(raw as *const RcBox<T> as *mut _),
phantom: PhantomData,
})
}
Expand Down Expand Up @@ -695,7 +695,7 @@ impl<T: ?Sized> Rc<T> {
// Free the allocation without dropping its contents
box_free(bptr);

Rc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
Rc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
}
}
}
Expand All @@ -722,7 +722,7 @@ impl<T> Rc<[T]> {
&mut (*ptr).value as *mut [T] as *mut T,
v.len());

Rc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
Rc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
}
}

Expand Down Expand Up @@ -781,7 +781,7 @@ impl<T: Clone> RcFromSlice<T> for Rc<[T]> {
// All clear. Forget the guard so it doesn't free the new RcBox.
forget(guard);

Rc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
Rc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
}
}
}
Expand Down Expand Up @@ -1160,7 +1160,7 @@ impl<T> From<Vec<T>> for Rc<[T]> {
/// [`None`]: ../../std/option/enum.Option.html#variant.None
#[stable(feature = "rc_weak", since = "1.4.0")]
pub struct Weak<T: ?Sized> {
ptr: Shared<RcBox<T>>,
ptr: NonNull<RcBox<T>>,
}

#[stable(feature = "rc_weak", since = "1.4.0")]
Expand Down Expand Up @@ -1190,7 +1190,7 @@ impl<T> Weak<T> {
pub fn new() -> Weak<T> {
unsafe {
Weak {
ptr: Shared::from(Box::into_unique(box RcBox {
ptr: NonNull::from(Box::into_unique(box RcBox {
strong: Cell::new(0),
weak: Cell::new(1),
value: uninitialized(),
Expand Down
10 changes: 5 additions & 5 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use core::num::Float;
use core::ops::{InPlace, Index, IndexMut, Place, Placer};
use core::ops;
use core::ptr;
use core::ptr::Shared;
use core::ptr::NonNull;
use core::slice;

use borrow::ToOwned;
Expand Down Expand Up @@ -1124,7 +1124,7 @@ impl<T> Vec<T> {
tail_start: end,
tail_len: len - end,
iter: range_slice.iter(),
vec: Shared::from(self),
vec: NonNull::from(self),
}
}
}
Expand Down Expand Up @@ -1745,7 +1745,7 @@ impl<T> IntoIterator for Vec<T> {
let cap = self.buf.cap();
mem::forget(self);
IntoIter {
buf: Shared::new_unchecked(begin),
buf: NonNull::new_unchecked(begin),
phantom: PhantomData,
cap,
ptr: begin,
Expand Down Expand Up @@ -2267,7 +2267,7 @@ impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
/// [`IntoIterator`]: ../../std/iter/trait.IntoIterator.html
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
buf: Shared<T>,
buf: NonNull<T>,
phantom: PhantomData<T>,
cap: usize,
ptr: *const T,
Expand Down Expand Up @@ -2442,7 +2442,7 @@ pub struct Drain<'a, T: 'a> {
tail_len: usize,
/// Current remaining range to remove
iter: slice::Iter<'a, T>,
vec: Shared<Vec<T>>,
vec: NonNull<Vec<T>>,
}

#[stable(feature = "collection_debug", since = "1.17.0")]
Expand Down
6 changes: 3 additions & 3 deletions src/liballoc/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use core::iter::{repeat, FromIterator, FusedIterator};
use core::mem;
use core::ops::{Index, IndexMut, Place, Placer, InPlace};
use core::ptr;
use core::ptr::Shared;
use core::ptr::NonNull;
use core::slice;

use core::hash::{Hash, Hasher};
Expand Down Expand Up @@ -895,7 +895,7 @@ impl<T> VecDeque<T> {
self.head = drain_tail;

Drain {
deque: Shared::from(&mut *self),
deque: NonNull::from(&mut *self),
after_tail: drain_head,
after_head: head,
iter: Iter {
Expand Down Expand Up @@ -2154,7 +2154,7 @@ pub struct Drain<'a, T: 'a> {
after_tail: usize,
after_head: usize,
iter: Iter<'a, T>,
deque: Shared<VecDeque<T>>,
deque: NonNull<VecDeque<T>>,
}

#[stable(feature = "collection_debug", since = "1.17.0")]
Expand Down
Loading

0 comments on commit f19baf0

Please sign in to comment.