Stabilize rc_raw feature, closes #37197
This commit is contained in:
parent
48890d4971
commit
a8f4a1bd98
11 changed files with 54 additions and 54 deletions
|
@ -287,17 +287,15 @@ impl<T> Arc<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(rc_raw)]
|
||||
///
|
||||
/// use std::sync::Arc;
|
||||
///
|
||||
/// let x = Arc::new(10);
|
||||
/// let x_ptr = Arc::into_raw(x);
|
||||
/// assert_eq!(unsafe { *x_ptr }, 10);
|
||||
/// ```
|
||||
#[unstable(feature = "rc_raw", issue = "37197")]
|
||||
pub fn into_raw(this: Self) -> *mut T {
|
||||
let ptr = unsafe { &mut (**this.ptr).data as *mut _ };
|
||||
#[stable(feature = "rc_raw", since = "1.17.0")]
|
||||
pub fn into_raw(this: Self) -> *const T {
|
||||
let ptr = unsafe { &(**this.ptr).data as *const _ };
|
||||
mem::forget(this);
|
||||
ptr
|
||||
}
|
||||
|
@ -315,8 +313,6 @@ impl<T> Arc<T> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(rc_raw)]
|
||||
///
|
||||
/// use std::sync::Arc;
|
||||
///
|
||||
/// let x = Arc::new(10);
|
||||
|
@ -332,11 +328,11 @@ impl<T> Arc<T> {
|
|||
///
|
||||
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
|
||||
/// ```
|
||||
#[unstable(feature = "rc_raw", issue = "37197")]
|
||||
pub unsafe fn from_raw(ptr: *mut T) -> Self {
|
||||
#[stable(feature = "rc_raw", since = "1.17.0")]
|
||||
pub unsafe fn from_raw(ptr: *const T) -> Self {
|
||||
// To find the corresponding pointer to the `ArcInner` we need to subtract the offset of the
|
||||
// `data` field from the pointer.
|
||||
Arc { ptr: Shared::new((ptr as *mut u8).offset(-offset_of!(ArcInner<T>, data)) as *mut _) }
|
||||
Arc { ptr: Shared::new((ptr as *const u8).offset(-offset_of!(ArcInner<T>, data)) as *const _) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -448,7 +444,7 @@ impl<T: ?Sized> Arc<T> {
|
|||
// Non-inlined part of `drop`.
|
||||
#[inline(never)]
|
||||
unsafe fn drop_slow(&mut self) {
|
||||
let ptr = *self.ptr;
|
||||
let ptr = self.ptr.as_mut_ptr();
|
||||
|
||||
// Destroy the data at this time, even though we may not free the box
|
||||
// allocation itself (there may still be weak pointers lying around).
|
||||
|
@ -624,7 +620,7 @@ impl<T: Clone> Arc<T> {
|
|||
// As with `get_mut()`, the unsafety is ok because our reference was
|
||||
// either unique to begin with, or became one upon cloning the contents.
|
||||
unsafe {
|
||||
let inner = &mut **this.ptr;
|
||||
let inner = &mut *this.ptr.as_mut_ptr();
|
||||
&mut inner.data
|
||||
}
|
||||
}
|
||||
|
@ -667,7 +663,7 @@ impl<T: ?Sized> Arc<T> {
|
|||
// the Arc itself to be `mut`, so we're returning the only possible
|
||||
// reference to the inner data.
|
||||
unsafe {
|
||||
let inner = &mut **this.ptr;
|
||||
let inner = &mut *this.ptr.as_mut_ptr();
|
||||
Some(&mut inner.data)
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue