Skip to content

Commit c2d2c2d

Browse files
committed
Stabilize rc_raw feature, closes #37197
1 parent 52d9682 commit c2d2c2d

File tree

11 files changed

+54
-54
lines changed

11 files changed

+54
-54
lines changed

src/liballoc/arc.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,15 @@ impl<T> Arc<T> {
287287
/// # Examples
288288
///
289289
/// ```
290-
/// #![feature(rc_raw)]
291-
///
292290
/// use std::sync::Arc;
293291
///
294292
/// let x = Arc::new(10);
295293
/// let x_ptr = Arc::into_raw(x);
296294
/// assert_eq!(unsafe { *x_ptr }, 10);
297295
/// ```
298-
#[unstable(feature = "rc_raw", issue = "37197")]
299-
pub fn into_raw(this: Self) -> *mut T {
300-
let ptr = unsafe { &mut (**this.ptr).data as *mut _ };
296+
#[stable(feature = "rc_raw", since = "1.17.0")]
297+
pub fn into_raw(this: Self) -> *const T {
298+
let ptr = unsafe { &(**this.ptr).data as *const _ };
301299
mem::forget(this);
302300
ptr
303301
}
@@ -315,8 +313,6 @@ impl<T> Arc<T> {
315313
/// # Examples
316314
///
317315
/// ```
318-
/// #![feature(rc_raw)]
319-
///
320316
/// use std::sync::Arc;
321317
///
322318
/// let x = Arc::new(10);
@@ -332,11 +328,11 @@ impl<T> Arc<T> {
332328
///
333329
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
334330
/// ```
335-
#[unstable(feature = "rc_raw", issue = "37197")]
336-
pub unsafe fn from_raw(ptr: *mut T) -> Self {
331+
#[stable(feature = "rc_raw", since = "1.17.0")]
332+
pub unsafe fn from_raw(ptr: *const T) -> Self {
337333
// To find the corresponding pointer to the `ArcInner` we need to subtract the offset of the
338334
// `data` field from the pointer.
339-
Arc { ptr: Shared::new((ptr as *mut u8).offset(-offset_of!(ArcInner<T>, data)) as *mut _) }
335+
Arc { ptr: Shared::new((ptr as *const u8).offset(-offset_of!(ArcInner<T>, data)) as *const _) }
340336
}
341337
}
342338

@@ -448,7 +444,7 @@ impl<T: ?Sized> Arc<T> {
448444
// Non-inlined part of `drop`.
449445
#[inline(never)]
450446
unsafe fn drop_slow(&mut self) {
451-
let ptr = *self.ptr;
447+
let ptr = self.ptr.as_mut_ptr();
452448

453449
// Destroy the data at this time, even though we may not free the box
454450
// allocation itself (there may still be weak pointers lying around).
@@ -624,7 +620,7 @@ impl<T: Clone> Arc<T> {
624620
// As with `get_mut()`, the unsafety is ok because our reference was
625621
// either unique to begin with, or became one upon cloning the contents.
626622
unsafe {
627-
let inner = &mut **this.ptr;
623+
let inner = &mut *this.ptr.as_mut_ptr();
628624
&mut inner.data
629625
}
630626
}
@@ -667,7 +663,7 @@ impl<T: ?Sized> Arc<T> {
667663
// the Arc itself to be `mut`, so we're returning the only possible
668664
// reference to the inner data.
669665
unsafe {
670-
let inner = &mut **this.ptr;
666+
let inner = &mut *this.ptr.as_mut_ptr();
671667
Some(&mut inner.data)
672668
}
673669
} else {

src/liballoc/rc.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,15 @@ impl<T> Rc<T> {
364364
/// # Examples
365365
///
366366
/// ```
367-
/// #![feature(rc_raw)]
368-
///
369367
/// use std::rc::Rc;
370368
///
371369
/// let x = Rc::new(10);
372370
/// let x_ptr = Rc::into_raw(x);
373371
/// assert_eq!(unsafe { *x_ptr }, 10);
374372
/// ```
375-
#[unstable(feature = "rc_raw", issue = "37197")]
376-
pub fn into_raw(this: Self) -> *mut T {
377-
let ptr = unsafe { &mut (**this.ptr).value as *mut _ };
373+
#[stable(feature = "rc_raw", since = "1.17.0")]
374+
pub fn into_raw(this: Self) -> *const T {
375+
let ptr = unsafe { &mut (*this.ptr.as_mut_ptr()).value as *const _ };
378376
mem::forget(this);
379377
ptr
380378
}
@@ -392,8 +390,6 @@ impl<T> Rc<T> {
392390
/// # Examples
393391
///
394392
/// ```
395-
/// #![feature(rc_raw)]
396-
///
397393
/// use std::rc::Rc;
398394
///
399395
/// let x = Rc::new(10);
@@ -409,11 +405,11 @@ impl<T> Rc<T> {
409405
///
410406
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
411407
/// ```
412-
#[unstable(feature = "rc_raw", issue = "37197")]
413-
pub unsafe fn from_raw(ptr: *mut T) -> Self {
408+
#[stable(feature = "rc_raw", since = "1.17.0")]
409+
pub unsafe fn from_raw(ptr: *const T) -> Self {
414410
// To find the corresponding pointer to the `RcBox` we need to subtract the offset of the
415411
// `value` field from the pointer.
416-
Rc { ptr: Shared::new((ptr as *mut u8).offset(-offset_of!(RcBox<T>, value)) as *mut _) }
412+
Rc { ptr: Shared::new((ptr as *const u8).offset(-offset_of!(RcBox<T>, value)) as *const _) }
417413
}
418414
}
419415

@@ -543,7 +539,7 @@ impl<T: ?Sized> Rc<T> {
543539
#[stable(feature = "rc_unique", since = "1.4.0")]
544540
pub fn get_mut(this: &mut Self) -> Option<&mut T> {
545541
if Rc::is_unique(this) {
546-
let inner = unsafe { &mut **this.ptr };
542+
let inner = unsafe { &mut *this.ptr.as_mut_ptr() };
547543
Some(&mut inner.value)
548544
} else {
549545
None
@@ -627,7 +623,7 @@ impl<T: Clone> Rc<T> {
627623
// reference count is guaranteed to be 1 at this point, and we required
628624
// the `Rc<T>` itself to be `mut`, so we're returning the only possible
629625
// reference to the inner value.
630-
let inner = unsafe { &mut **this.ptr };
626+
let inner = unsafe { &mut *this.ptr.as_mut_ptr() };
631627
&mut inner.value
632628
}
633629
}
@@ -673,7 +669,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
673669
/// ```
674670
fn drop(&mut self) {
675671
unsafe {
676-
let ptr = *self.ptr;
672+
let ptr = self.ptr.as_mut_ptr();
677673

678674
self.dec_strong();
679675
if self.strong() == 0 {

src/libcollections/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,13 @@ mod std {
133133
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
134134
pub enum Bound<T> {
135135
/// An inclusive bound.
136+
#[stable(feature = "collections_bound", since = "1.17.0")]
136137
Included(T),
137138
/// An exclusive bound.
139+
#[stable(feature = "collections_bound", since = "1.17.0")]
138140
Excluded(T),
139141
/// An infinite endpoint. Indicates that there is no bound in this direction.
142+
#[stable(feature = "collections_bound", since = "1.17.0")]
140143
Unbounded,
141144
}
142145

src/libcollections/linked_list.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<T> LinkedList<T> {
142142

143143
match self.head {
144144
None => self.tail = node,
145-
Some(head) => (**head).prev = node,
145+
Some(head) => (*head.as_mut_ptr()).prev = node,
146146
}
147147

148148
self.head = node;
@@ -154,12 +154,12 @@ impl<T> LinkedList<T> {
154154
#[inline]
155155
fn pop_front_node(&mut self) -> Option<Box<Node<T>>> {
156156
self.head.map(|node| unsafe {
157-
let node = Box::from_raw(*node);
157+
let node = Box::from_raw(node.as_mut_ptr());
158158
self.head = node.next;
159159

160160
match self.head {
161161
None => self.tail = None,
162-
Some(head) => (**head).prev = None,
162+
Some(head) => (*head.as_mut_ptr()).prev = None,
163163
}
164164

165165
self.len -= 1;
@@ -177,7 +177,7 @@ impl<T> LinkedList<T> {
177177

178178
match self.tail {
179179
None => self.head = node,
180-
Some(tail) => (**tail).next = node,
180+
Some(tail) => (*tail.as_mut_ptr()).next = node,
181181
}
182182

183183
self.tail = node;
@@ -189,12 +189,12 @@ impl<T> LinkedList<T> {
189189
#[inline]
190190
fn pop_back_node(&mut self) -> Option<Box<Node<T>>> {
191191
self.tail.map(|node| unsafe {
192-
let node = Box::from_raw(*node);
192+
let node = Box::from_raw(node.as_mut_ptr());
193193
self.tail = node.prev;
194194

195195
match self.tail {
196196
None => self.head = None,
197-
Some(tail) => (**tail).next = None,
197+
Some(tail) => (*tail.as_mut_ptr()).next = None,
198198
}
199199

200200
self.len -= 1;
@@ -269,8 +269,8 @@ impl<T> LinkedList<T> {
269269
Some(tail) => {
270270
if let Some(other_head) = other.head.take() {
271271
unsafe {
272-
(**tail).next = Some(other_head);
273-
(**other_head).prev = Some(tail);
272+
(*tail.as_mut_ptr()).next = Some(other_head);
273+
(*other_head.as_mut_ptr()).prev = Some(tail);
274274
}
275275

276276
self.tail = other.tail.take();
@@ -484,7 +484,7 @@ impl<T> LinkedList<T> {
484484
#[inline]
485485
#[stable(feature = "rust1", since = "1.0.0")]
486486
pub fn front_mut(&mut self) -> Option<&mut T> {
487-
self.head.map(|node| unsafe { &mut (**node).element })
487+
self.head.map(|node| unsafe { &mut (*node.as_mut_ptr()).element })
488488
}
489489

490490
/// Provides a reference to the back element, or `None` if the list is
@@ -530,7 +530,7 @@ impl<T> LinkedList<T> {
530530
#[inline]
531531
#[stable(feature = "rust1", since = "1.0.0")]
532532
pub fn back_mut(&mut self) -> Option<&mut T> {
533-
self.tail.map(|node| unsafe { &mut (**node).element })
533+
self.tail.map(|node| unsafe { &mut (*node.as_mut_ptr()).element })
534534
}
535535

536536
/// Adds an element first in the list.
@@ -675,9 +675,9 @@ impl<T> LinkedList<T> {
675675
let second_part_head;
676676

677677
unsafe {
678-
second_part_head = (**split_node.unwrap()).next.take();
678+
second_part_head = (*split_node.unwrap().as_mut_ptr()).next.take();
679679
if let Some(head) = second_part_head {
680-
(**head).prev = None;
680+
(*head.as_mut_ptr()).prev = None;
681681
}
682682
}
683683

@@ -816,7 +816,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
816816
None
817817
} else {
818818
self.head.map(|node| unsafe {
819-
let node = &mut **node;
819+
let node = &mut *node.as_mut_ptr();
820820
self.len -= 1;
821821
self.head = node.next;
822822
&mut node.element
@@ -838,7 +838,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
838838
None
839839
} else {
840840
self.tail.map(|node| unsafe {
841-
let node = &mut **node;
841+
let node = &mut *node.as_mut_ptr();
842842
self.len -= 1;
843843
self.tail = node.prev;
844844
&mut node.element
@@ -896,8 +896,8 @@ impl<'a, T> IterMut<'a, T> {
896896
element: element,
897897
})));
898898

899-
(**prev).next = node;
900-
(**head).prev = node;
899+
(*prev.as_mut_ptr()).next = node;
900+
(*head.as_mut_ptr()).prev = node;
901901

902902
self.list.len += 1;
903903
},
@@ -929,7 +929,7 @@ impl<'a, T> IterMut<'a, T> {
929929
if self.len == 0 {
930930
None
931931
} else {
932-
self.head.map(|node| unsafe { &mut (**node).element })
932+
self.head.map(|node| unsafe { &mut (*node.as_mut_ptr()).element })
933933
}
934934
}
935935
}

src/libcollections/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,7 @@ unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {
21002100
for _x in self.by_ref() {}
21012101

21022102
// RawVec handles deallocation
2103-
let _ = unsafe { RawVec::from_raw_parts(*self.buf, self.cap) };
2103+
let _ = unsafe { RawVec::from_raw_parts(self.buf.as_mut_ptr(), self.cap) };
21042104
}
21052105
}
21062106

@@ -2165,7 +2165,7 @@ impl<'a, T> Drop for Drain<'a, T> {
21652165

21662166
if self.tail_len > 0 {
21672167
unsafe {
2168-
let source_vec = &mut **self.vec;
2168+
let source_vec = &mut *self.vec.as_mut_ptr();
21692169
// memmove back untouched tail, update to new length
21702170
let start = source_vec.len();
21712171
let tail = self.tail_start;

src/libcollections/vec_deque.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ impl<'a, T: 'a> Drop for Drain<'a, T> {
21252125
fn drop(&mut self) {
21262126
for _ in self.by_ref() {}
21272127

2128-
let source_deque = unsafe { &mut **self.deque };
2128+
let source_deque = unsafe { &mut *self.deque.as_mut_ptr() };
21292129

21302130
// T = source_deque_tail; H = source_deque_head; t = drain_tail; h = drain_head
21312131
//

src/libcore/ptr.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -966,11 +966,19 @@ impl<T: ?Sized> Shared<T> {
966966
/// # Safety
967967
///
968968
/// `ptr` must be non-null.
969-
pub unsafe fn new(ptr: *mut T) -> Self {
969+
pub unsafe fn new(ptr: *const T) -> Self {
970970
Shared { pointer: NonZero::new(ptr), _marker: PhantomData }
971971
}
972972
}
973973

974+
#[unstable(feature = "shared", issue = "27730")]
975+
impl<T: ?Sized> Shared<T> {
976+
/// Acquires the underlying pointer as a `*mut` pointer.
977+
pub unsafe fn as_mut_ptr(&self) -> *mut T {
978+
**self as _
979+
}
980+
}
981+
974982
#[unstable(feature = "shared", issue = "27730")]
975983
impl<T: ?Sized> Clone for Shared<T> {
976984
fn clone(&self) -> Self {
@@ -986,10 +994,10 @@ impl<T: ?Sized, U: ?Sized> CoerceUnsized<Shared<U>> for Shared<T> where T: Unsiz
986994

987995
#[unstable(feature = "shared", issue = "27730")]
988996
impl<T: ?Sized> Deref for Shared<T> {
989-
type Target = *mut T;
997+
type Target = *const T;
990998

991999
#[inline]
992-
fn deref(&self) -> &*mut T {
1000+
fn deref(&self) -> &*const T {
9931001
unsafe { mem::transmute(&*self.pointer) }
9941002
}
9951003
}

src/librustc_data_structures/array_vec.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'a, A: Array> Drop for Drain<'a, A> {
248248

249249
if self.tail_len > 0 {
250250
unsafe {
251-
let source_array_vec = &mut **self.array_vec;
251+
let source_array_vec = &mut *self.array_vec.as_mut_ptr();
252252
// memmove back untouched tail, update to new length
253253
let start = source_array_vec.len();
254254
let tail = self.tail_start;
@@ -317,4 +317,3 @@ impl<T> Default for ManuallyDrop<T> {
317317
ManuallyDrop::new()
318318
}
319319
}
320-

src/librustc_data_structures/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#![feature(shared)]
2929
#![feature(collections_range)]
30-
#![feature(collections_bound)]
3130
#![cfg_attr(stage0,feature(field_init_shorthand))]
3231
#![feature(nonzero)]
3332
#![feature(rustc_private)]

src/libstd/collections/hash/table.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ impl<'a, K, V> Iterator for Drain<'a, K, V> {
11541154
fn next(&mut self) -> Option<(SafeHash, K, V)> {
11551155
self.iter.next().map(|bucket| {
11561156
unsafe {
1157-
(**self.table).size -= 1;
1157+
(*self.table.as_mut_ptr()).size -= 1;
11581158
let (k, v) = ptr::read(bucket.pair);
11591159
(SafeHash { hash: ptr::replace(bucket.hash, EMPTY_BUCKET) }, k, v)
11601160
}

src/libstd/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@
245245
#![feature(char_escape_debug)]
246246
#![feature(char_internals)]
247247
#![feature(collections)]
248-
#![feature(collections_bound)]
249248
#![feature(collections_range)]
250249
#![feature(compiler_builtins_lib)]
251250
#![feature(const_fn)]

0 commit comments

Comments
 (0)