Skip to content

Commit

Permalink
Rollup merge of #72288 - vorner:stabilize-weak-into-raw, r=dtolnay
Browse files Browse the repository at this point in the history
Stabilization of weak-into-raw

Closes #60728.

There are also two removals of `#![feature(weak_into_raw)]` in the `src/tools/miri` submodule. How should I synchronize the changes with there?

* I can ignore it for now and once this gets merged, update the tool, send a pull request to that one and then reference the changes to rustc.
* I could try submitting the changes to miri first, but then the build would fail there, because the attribute would still be needed.

I think the first one is the correct one, extrapolating from the contributing guidelines (even though they speak about breaking the tools and this should not break it, as extra feature should not hurt).
  • Loading branch information
JohnTitor authored May 29, 2020
2 parents ea5848d + ba0d0c2 commit d472f8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
16 changes: 4 additions & 12 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,6 @@ impl<T: ?Sized> Rc<T> {
/// # Examples
///
/// ```
/// #![feature(weak_into_raw)]
///
/// use std::rc::Rc;
///
/// let x = Rc::new("hello".to_owned());
Expand All @@ -590,7 +588,7 @@ impl<T: ?Sized> Rc<T> {
/// assert_eq!(x_ptr, Rc::as_ptr(&y));
/// assert_eq!(unsafe { &*x_ptr }, "hello");
/// ```
#[unstable(feature = "weak_into_raw", issue = "60728")]
#[stable(feature = "weak_into_raw", since = "1.45.0")]
pub fn as_ptr(this: &Self) -> *const T {
let ptr: *mut RcBox<T> = NonNull::as_ptr(this.ptr);
let fake_ptr = ptr as *mut T;
Expand Down Expand Up @@ -1681,8 +1679,6 @@ impl<T> Weak<T> {
/// # Examples
///
/// ```
/// #![feature(weak_into_raw)]
///
/// use std::rc::Rc;
/// use std::ptr;
///
Expand All @@ -1700,7 +1696,7 @@ impl<T> Weak<T> {
/// ```
///
/// [`null`]: ../../std/ptr/fn.null.html
#[unstable(feature = "weak_into_raw", issue = "60728")]
#[stable(feature = "weak_into_raw", since = "1.45.0")]
pub fn as_ptr(&self) -> *const T {
let offset = data_offset_sized::<T>();
let ptr = self.ptr.cast::<u8>().as_ptr().wrapping_offset(offset);
Expand All @@ -1718,8 +1714,6 @@ impl<T> Weak<T> {
/// # Examples
///
/// ```
/// #![feature(weak_into_raw)]
///
/// use std::rc::{Rc, Weak};
///
/// let strong = Rc::new("hello".to_owned());
Expand All @@ -1735,7 +1729,7 @@ impl<T> Weak<T> {
///
/// [`from_raw`]: struct.Weak.html#method.from_raw
/// [`as_ptr`]: struct.Weak.html#method.as_ptr
#[unstable(feature = "weak_into_raw", issue = "60728")]
#[stable(feature = "weak_into_raw", since = "1.45.0")]
pub fn into_raw(self) -> *const T {
let result = self.as_ptr();
mem::forget(self);
Expand All @@ -1762,8 +1756,6 @@ impl<T> Weak<T> {
/// # Examples
///
/// ```
/// #![feature(weak_into_raw)]
///
/// use std::rc::{Rc, Weak};
///
/// let strong = Rc::new("hello".to_owned());
Expand All @@ -1788,7 +1780,7 @@ impl<T> Weak<T> {
/// [`Weak`]: struct.Weak.html
/// [`new`]: struct.Weak.html#method.new
/// [`forget`]: ../../std/mem/fn.forget.html
#[unstable(feature = "weak_into_raw", issue = "60728")]
#[stable(feature = "weak_into_raw", since = "1.45.0")]
pub unsafe fn from_raw(ptr: *const T) -> Self {
if ptr.is_null() {
Self::new()
Expand Down
16 changes: 4 additions & 12 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,6 @@ impl<T: ?Sized> Arc<T> {
/// # Examples
///
/// ```
/// #![feature(weak_into_raw)]
///
/// use std::sync::Arc;
///
/// let x = Arc::new("hello".to_owned());
Expand All @@ -589,7 +587,7 @@ impl<T: ?Sized> Arc<T> {
/// assert_eq!(x_ptr, Arc::as_ptr(&y));
/// assert_eq!(unsafe { &*x_ptr }, "hello");
/// ```
#[unstable(feature = "weak_into_raw", issue = "60728")]
#[stable(feature = "weak_into_raw", since = "1.45.0")]
pub fn as_ptr(this: &Self) -> *const T {
let ptr: *mut ArcInner<T> = NonNull::as_ptr(this.ptr);
let fake_ptr = ptr as *mut T;
Expand Down Expand Up @@ -1449,8 +1447,6 @@ impl<T> Weak<T> {
/// # Examples
///
/// ```
/// #![feature(weak_into_raw)]
///
/// use std::sync::Arc;
/// use std::ptr;
///
Expand All @@ -1468,7 +1464,7 @@ impl<T> Weak<T> {
/// ```
///
/// [`null`]: ../../std/ptr/fn.null.html
#[unstable(feature = "weak_into_raw", issue = "60728")]
#[stable(feature = "weak_into_raw", since = "1.45.0")]
pub fn as_ptr(&self) -> *const T {
let offset = data_offset_sized::<T>();
let ptr = self.ptr.cast::<u8>().as_ptr().wrapping_offset(offset);
Expand All @@ -1486,8 +1482,6 @@ impl<T> Weak<T> {
/// # Examples
///
/// ```
/// #![feature(weak_into_raw)]
///
/// use std::sync::{Arc, Weak};
///
/// let strong = Arc::new("hello".to_owned());
Expand All @@ -1503,7 +1497,7 @@ impl<T> Weak<T> {
///
/// [`from_raw`]: struct.Weak.html#method.from_raw
/// [`as_ptr`]: struct.Weak.html#method.as_ptr
#[unstable(feature = "weak_into_raw", issue = "60728")]
#[stable(feature = "weak_into_raw", since = "1.45.0")]
pub fn into_raw(self) -> *const T {
let result = self.as_ptr();
mem::forget(self);
Expand Down Expand Up @@ -1531,8 +1525,6 @@ impl<T> Weak<T> {
/// # Examples
///
/// ```
/// #![feature(weak_into_raw)]
///
/// use std::sync::{Arc, Weak};
///
/// let strong = Arc::new("hello".to_owned());
Expand All @@ -1557,7 +1549,7 @@ impl<T> Weak<T> {
/// [`Weak`]: struct.Weak.html
/// [`Arc`]: struct.Arc.html
/// [`forget`]: ../../std/mem/fn.forget.html
#[unstable(feature = "weak_into_raw", issue = "60728")]
#[stable(feature = "weak_into_raw", since = "1.45.0")]
pub unsafe fn from_raw(ptr: *const T) -> Self {
if ptr.is_null() {
Self::new()
Expand Down

0 comments on commit d472f8e

Please sign in to comment.