Skip to content

Commit f19baf0

Browse files
committed
Rename std::ptr::Shared to NonNull
`Shared` is now a deprecated `type` alias. CC rust-lang#27730 (comment)
1 parent ba5d7a6 commit f19baf0

File tree

13 files changed

+100
-95
lines changed

13 files changed

+100
-95
lines changed

src/liballoc/arc.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use core::intrinsics::abort;
2525
use core::mem::{self, align_of_val, size_of_val, uninitialized};
2626
use core::ops::Deref;
2727
use core::ops::CoerceUnsized;
28-
use core::ptr::{self, Shared};
28+
use core::ptr::{self, NonNull};
2929
use core::marker::{Unsize, PhantomData};
3030
use core::hash::{Hash, Hasher};
3131
use core::{isize, usize};
@@ -197,7 +197,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
197197
/// [rc_examples]: ../../std/rc/index.html#examples
198198
#[stable(feature = "rust1", since = "1.0.0")]
199199
pub struct Arc<T: ?Sized> {
200-
ptr: Shared<ArcInner<T>>,
200+
ptr: NonNull<ArcInner<T>>,
201201
phantom: PhantomData<T>,
202202
}
203203

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

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

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

399399
Arc {
400-
ptr: Shared::new_unchecked(arc_ptr),
400+
ptr: NonNull::new_unchecked(arc_ptr),
401401
phantom: PhantomData,
402402
}
403403
}
@@ -582,7 +582,7 @@ impl<T: ?Sized> Arc<T> {
582582
// Free the allocation without dropping its contents
583583
box_free(bptr);
584584

585-
Arc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
585+
Arc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
586586
}
587587
}
588588
}
@@ -609,7 +609,7 @@ impl<T> Arc<[T]> {
609609
&mut (*ptr).data as *mut [T] as *mut T,
610610
v.len());
611611

612-
Arc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
612+
Arc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
613613
}
614614
}
615615

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

672-
Arc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
672+
Arc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
673673
}
674674
}
675675
}
@@ -991,7 +991,7 @@ impl<T> Weak<T> {
991991
pub fn new() -> Weak<T> {
992992
unsafe {
993993
Weak {
994-
ptr: Shared::from(Box::into_unique(box ArcInner {
994+
ptr: NonNull::from(Box::into_unique(box ArcInner {
995995
strong: atomic::AtomicUsize::new(0),
996996
weak: atomic::AtomicUsize::new(1),
997997
data: uninitialized(),

src/liballoc/heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ unsafe impl Alloc for Heap {
232232
///
233233
/// This preserves the non-null invariant for types like `Box<T>`. The address
234234
/// may overlap with non-zero-size memory allocations.
235-
#[rustc_deprecated(since = "1.19", reason = "Use Unique/Shared::empty() instead")]
235+
#[rustc_deprecated(since = "1.19", reason = "Use Unique/NonNull::empty() instead")]
236236
#[unstable(feature = "heap_api", issue = "27700")]
237237
pub const EMPTY: *mut () = 1 as *mut ();
238238

src/liballoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@
103103
#![feature(iter_rfold)]
104104
#![feature(lang_items)]
105105
#![feature(needs_allocator)]
106+
#![feature(nonnull)]
106107
#![feature(nonzero)]
107108
#![feature(offset_to)]
108109
#![feature(optin_builtin_traits)]
109110
#![feature(pattern)]
110111
#![feature(placement_in_syntax)]
111112
#![feature(placement_new_protocol)]
112113
#![feature(rustc_attrs)]
113-
#![feature(shared)]
114114
#![feature(slice_get_slice)]
115115
#![feature(slice_patterns)]
116116
#![feature(slice_rsplit)]

src/liballoc/linked_list.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use core::iter::{FromIterator, FusedIterator};
2929
use core::marker::PhantomData;
3030
use core::mem;
3131
use core::ops::{BoxPlace, InPlace, Place, Placer};
32-
use core::ptr::{self, Shared};
32+
use core::ptr::{self, NonNull};
3333

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

5353
struct Node<T> {
54-
next: Option<Shared<Node<T>>>,
55-
prev: Option<Shared<Node<T>>>,
54+
next: Option<NonNull<Node<T>>>,
55+
prev: Option<NonNull<Node<T>>>,
5656
element: T,
5757
}
5858

@@ -65,8 +65,8 @@ struct Node<T> {
6565
/// [`LinkedList`]: struct.LinkedList.html
6666
#[stable(feature = "rust1", since = "1.0.0")]
6767
pub struct Iter<'a, T: 'a> {
68-
head: Option<Shared<Node<T>>>,
69-
tail: Option<Shared<Node<T>>>,
68+
head: Option<NonNull<Node<T>>>,
69+
tail: Option<NonNull<Node<T>>>,
7070
len: usize,
7171
marker: PhantomData<&'a Node<T>>,
7272
}
@@ -98,8 +98,8 @@ impl<'a, T> Clone for Iter<'a, T> {
9898
#[stable(feature = "rust1", since = "1.0.0")]
9999
pub struct IterMut<'a, T: 'a> {
100100
list: &'a mut LinkedList<T>,
101-
head: Option<Shared<Node<T>>>,
102-
tail: Option<Shared<Node<T>>>,
101+
head: Option<NonNull<Node<T>>>,
102+
tail: Option<NonNull<Node<T>>>,
103103
len: usize,
104104
}
105105

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

162162
match self.head {
163163
None => self.tail = node,
@@ -192,7 +192,7 @@ impl<T> LinkedList<T> {
192192
unsafe {
193193
node.next = None;
194194
node.prev = self.tail;
195-
let node = Some(Shared::from(Box::into_unique(node)));
195+
let node = Some(NonNull::from(Box::into_unique(node)));
196196

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

231231
match node.prev {
@@ -986,7 +986,7 @@ impl<'a, T> IterMut<'a, T> {
986986
Some(prev) => prev,
987987
};
988988

989-
let node = Some(Shared::from(Box::into_unique(box Node {
989+
let node = Some(NonNull::from(Box::into_unique(box Node {
990990
next: Some(head),
991991
prev: Some(prev),
992992
element,
@@ -1038,7 +1038,7 @@ pub struct DrainFilter<'a, T: 'a, F: 'a>
10381038
where F: FnMut(&mut T) -> bool,
10391039
{
10401040
list: &'a mut LinkedList<T>,
1041-
it: Option<Shared<Node<T>>>,
1041+
it: Option<NonNull<Node<T>>>,
10421042
pred: F,
10431043
idx: usize,
10441044
old_len: usize,

src/liballoc/rc.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ use core::marker::{Unsize, PhantomData};
256256
use core::mem::{self, align_of_val, forget, size_of_val, uninitialized};
257257
use core::ops::Deref;
258258
use core::ops::CoerceUnsized;
259-
use core::ptr::{self, Shared};
259+
use core::ptr::{self, NonNull};
260260
use core::convert::From;
261261

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

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

430430
Rc {
431-
ptr: Shared::new_unchecked(rc_ptr),
431+
ptr: NonNull::new_unchecked(rc_ptr),
432432
phantom: PhantomData,
433433
}
434434
}
@@ -649,7 +649,7 @@ impl Rc<Any> {
649649
let raw: *const RcBox<Any> = self.ptr.as_ptr();
650650
forget(self);
651651
Ok(Rc {
652-
ptr: Shared::new_unchecked(raw as *const RcBox<T> as *mut _),
652+
ptr: NonNull::new_unchecked(raw as *const RcBox<T> as *mut _),
653653
phantom: PhantomData,
654654
})
655655
}
@@ -695,7 +695,7 @@ impl<T: ?Sized> Rc<T> {
695695
// Free the allocation without dropping its contents
696696
box_free(bptr);
697697

698-
Rc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
698+
Rc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
699699
}
700700
}
701701
}
@@ -722,7 +722,7 @@ impl<T> Rc<[T]> {
722722
&mut (*ptr).value as *mut [T] as *mut T,
723723
v.len());
724724

725-
Rc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
725+
Rc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
726726
}
727727
}
728728

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

784-
Rc { ptr: Shared::new_unchecked(ptr), phantom: PhantomData }
784+
Rc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData }
785785
}
786786
}
787787
}
@@ -1160,7 +1160,7 @@ impl<T> From<Vec<T>> for Rc<[T]> {
11601160
/// [`None`]: ../../std/option/enum.Option.html#variant.None
11611161
#[stable(feature = "rc_weak", since = "1.4.0")]
11621162
pub struct Weak<T: ?Sized> {
1163-
ptr: Shared<RcBox<T>>,
1163+
ptr: NonNull<RcBox<T>>,
11641164
}
11651165

11661166
#[stable(feature = "rc_weak", since = "1.4.0")]
@@ -1190,7 +1190,7 @@ impl<T> Weak<T> {
11901190
pub fn new() -> Weak<T> {
11911191
unsafe {
11921192
Weak {
1193-
ptr: Shared::from(Box::into_unique(box RcBox {
1193+
ptr: NonNull::from(Box::into_unique(box RcBox {
11941194
strong: Cell::new(0),
11951195
weak: Cell::new(1),
11961196
value: uninitialized(),

src/liballoc/vec.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use core::num::Float;
7878
use core::ops::{InPlace, Index, IndexMut, Place, Placer};
7979
use core::ops;
8080
use core::ptr;
81-
use core::ptr::Shared;
81+
use core::ptr::NonNull;
8282
use core::slice;
8383

8484
use borrow::ToOwned;
@@ -1124,7 +1124,7 @@ impl<T> Vec<T> {
11241124
tail_start: end,
11251125
tail_len: len - end,
11261126
iter: range_slice.iter(),
1127-
vec: Shared::from(self),
1127+
vec: NonNull::from(self),
11281128
}
11291129
}
11301130
}
@@ -1745,7 +1745,7 @@ impl<T> IntoIterator for Vec<T> {
17451745
let cap = self.buf.cap();
17461746
mem::forget(self);
17471747
IntoIter {
1748-
buf: Shared::new_unchecked(begin),
1748+
buf: NonNull::new_unchecked(begin),
17491749
phantom: PhantomData,
17501750
cap,
17511751
ptr: begin,
@@ -2267,7 +2267,7 @@ impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
22672267
/// [`IntoIterator`]: ../../std/iter/trait.IntoIterator.html
22682268
#[stable(feature = "rust1", since = "1.0.0")]
22692269
pub struct IntoIter<T> {
2270-
buf: Shared<T>,
2270+
buf: NonNull<T>,
22712271
phantom: PhantomData<T>,
22722272
cap: usize,
22732273
ptr: *const T,
@@ -2442,7 +2442,7 @@ pub struct Drain<'a, T: 'a> {
24422442
tail_len: usize,
24432443
/// Current remaining range to remove
24442444
iter: slice::Iter<'a, T>,
2445-
vec: Shared<Vec<T>>,
2445+
vec: NonNull<Vec<T>>,
24462446
}
24472447

24482448
#[stable(feature = "collection_debug", since = "1.17.0")]

src/liballoc/vec_deque.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use core::iter::{repeat, FromIterator, FusedIterator};
2323
use core::mem;
2424
use core::ops::{Index, IndexMut, Place, Placer, InPlace};
2525
use core::ptr;
26-
use core::ptr::Shared;
26+
use core::ptr::NonNull;
2727
use core::slice;
2828

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

897897
Drain {
898-
deque: Shared::from(&mut *self),
898+
deque: NonNull::from(&mut *self),
899899
after_tail: drain_head,
900900
after_head: head,
901901
iter: Iter {
@@ -2154,7 +2154,7 @@ pub struct Drain<'a, T: 'a> {
21542154
after_tail: usize,
21552155
after_head: usize,
21562156
iter: Iter<'a, T>,
2157-
deque: Shared<VecDeque<T>>,
2157+
deque: NonNull<VecDeque<T>>,
21582158
}
21592159

21602160
#[stable(feature = "collection_debug", since = "1.17.0")]

0 commit comments

Comments
 (0)