File tree 2 files changed +9
-4
lines changed
2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -1591,8 +1591,7 @@ impl<T> NonNull<[T]> {
1591
1591
#[ unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
1592
1592
#[ rustc_const_unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
1593
1593
pub const fn as_non_null_ptr ( self ) -> NonNull < T > {
1594
- // SAFETY: We know `self` is non-null.
1595
- unsafe { NonNull :: new_unchecked ( self . as_ptr ( ) . as_mut_ptr ( ) ) }
1594
+ self . cast ( )
1596
1595
}
1597
1596
1598
1597
/// Returns a raw pointer to the slice's buffer.
@@ -1828,8 +1827,7 @@ impl<T: ?Sized> hash::Hash for NonNull<T> {
1828
1827
impl < T : ?Sized > From < Unique < T > > for NonNull < T > {
1829
1828
#[ inline]
1830
1829
fn from ( unique : Unique < T > ) -> Self {
1831
- // SAFETY: A Unique pointer cannot be null.
1832
- unsafe { NonNull { pointer : unique. as_ptr ( ) } }
1830
+ unique. as_non_null_ptr ( )
1833
1831
}
1834
1832
}
1835
1833
Original file line number Diff line number Diff line change @@ -106,6 +106,13 @@ impl<T: ?Sized> Unique<T> {
106
106
self . pointer . as_ptr ( )
107
107
}
108
108
109
+ /// Acquires the underlying `*mut` pointer.
110
+ #[ must_use = "`self` will be dropped if the result is not used" ]
111
+ #[ inline]
112
+ pub const fn as_non_null_ptr ( self ) -> NonNull < T > {
113
+ self . pointer
114
+ }
115
+
109
116
/// Dereferences the content.
110
117
///
111
118
/// The resulting lifetime is bound to self so this behaves "as if"
You can’t perform that action at this time.
0 commit comments