diff options
| author | bors <bors@rust-lang.org> | 2019-01-31 03:47:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-01-31 03:47:17 +0000 |
| commit | f40aaa68278ef0879af5fe7ce077c64c6515ea05 (patch) | |
| tree | 4e07acbdc12409c4e340f11584f410286872197e /src/liballoc | |
| parent | 147311c5fc62537da8eb9c6f69536bec6719d534 (diff) | |
| parent | 877dee7c67d3300074d485e3ef48984732aa907d (diff) | |
| download | rust-f40aaa68278ef0879af5fe7ce077c64c6515ea05.tar.gz rust-f40aaa68278ef0879af5fe7ce077c64c6515ea05.zip | |
Auto merge of #58016 - Centril:rollup, r=Centril
Rollup of 12 pull requests Successful merges: - #57008 (suggest `|` when `,` founds in invalid match value) - #57106 (Mark str::trim.* functions as #[must_use].) - #57920 (use `SOURCE_DATE_EPOCH` for man page time if set) - #57934 (Introduce into_raw_non_null on Rc and Arc) - #57971 (SGX target: improve panic & exit handling) - #57980 (Add the edition guide to the bookshelf) - #57984 (Improve bug message in check_ty) - #57999 (Add MOVBE x86 CPU feature) - #58000 (Fixes and cleanups) - #58005 (update docs for fix_start/end_matches) - #58007 (Don't panic when accessing enum variant ctor using `Self` in match) - #58008 (Pass correct arguments to places_conflict) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/rc.rs | 21 | ||||
| -rw-r--r-- | src/liballoc/sync.rs | 21 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index c0dc010fe59..5efb74bc120 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -433,6 +433,27 @@ impl<T: ?Sized> Rc<T> { } } + /// Consumes the `Rc`, returning the wrapped pointer as `NonNull<T>`. + /// + /// # Examples + /// + /// ``` + /// #![feature(rc_into_raw_non_null)] + /// + /// use std::rc::Rc; + /// + /// let x = Rc::new(10); + /// let ptr = Rc::into_raw_non_null(x); + /// let deref = unsafe { *ptr.as_ref() }; + /// assert_eq!(deref, 10); + /// ``` + #[unstable(feature = "rc_into_raw_non_null", issue = "47336")] + #[inline] + pub fn into_raw_non_null(this: Self) -> NonNull<T> { + // safe because Rc guarantees its pointer is non-null + unsafe { NonNull::new_unchecked(Rc::into_raw(this) as *mut _) } + } + /// Creates a new [`Weak`][weak] pointer to this value. /// /// [weak]: struct.Weak.html diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 390a0791650..5cffa93db11 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -413,6 +413,27 @@ impl<T: ?Sized> Arc<T> { } } + /// Consumes the `Arc`, returning the wrapped pointer as `NonNull<T>`. + /// + /// # Examples + /// + /// ``` + /// #![feature(rc_into_raw_non_null)] + /// + /// use std::sync::Arc; + /// + /// let x = Arc::new(10); + /// let ptr = Arc::into_raw_non_null(x); + /// let deref = unsafe { *ptr.as_ref() }; + /// assert_eq!(deref, 10); + /// ``` + #[unstable(feature = "rc_into_raw_non_null", issue = "47336")] + #[inline] + pub fn into_raw_non_null(this: Self) -> NonNull<T> { + // safe because Arc guarantees its pointer is non-null + unsafe { NonNull::new_unchecked(Arc::into_raw(this) as *mut _) } + } + /// Creates a new [`Weak`][weak] pointer to this value. /// /// [weak]: struct.Weak.html |
