@@ -527,7 +527,8 @@ impl<T> MaybeUninit<T> {
527527 #[ inline( always) ]
528528 pub const fn as_ptr ( & self ) -> * const T {
529529 // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
530- self as * const _ as * const T
530+ // FIXME: consider `ptr::from_ref` once that's const-stable
531+ ptr:: addr_of!( * self ) . cast :: < T > ( )
531532 }
532533
533534 /// Gets a mutable pointer to the contained value. Reading from this pointer or turning it
@@ -566,7 +567,7 @@ impl<T> MaybeUninit<T> {
566567 #[ inline( always) ]
567568 pub const fn as_mut_ptr ( & mut self ) -> * mut T {
568569 // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
569- self as * mut _ as * mut T
570+ ptr :: from_mut ( self ) . cast :: < T > ( )
570571 }
571572
572573 /// Extracts the value from the `MaybeUninit<T>` container. This is a great way
@@ -947,7 +948,7 @@ impl<T> MaybeUninit<T> {
947948 // And thus the conversion is safe
948949 let ret = unsafe {
949950 intrinsics:: assert_inhabited :: < [ T ; N ] > ( ) ;
950- ( & array as * const _ as * const [ T ; N ] ) . read ( )
951+ ptr :: from_ref ( & array) . cast :: < [ T ; N ] > ( ) . read ( )
951952 } ;
952953
953954 // FIXME: required to avoid `~const Destruct` bound
@@ -1002,15 +1003,15 @@ impl<T> MaybeUninit<T> {
10021003 #[ rustc_const_unstable( feature = "maybe_uninit_slice" , issue = "63569" ) ]
10031004 #[ inline( always) ]
10041005 pub const fn slice_as_ptr ( this : & [ MaybeUninit < T > ] ) -> * const T {
1005- this. as_ptr ( ) as * const T
1006+ this. as_ptr ( ) . cast :: < T > ( )
10061007 }
10071008
10081009 /// Gets a mutable pointer to the first element of the array.
10091010 #[ unstable( feature = "maybe_uninit_slice" , issue = "63569" ) ]
10101011 #[ rustc_const_unstable( feature = "maybe_uninit_slice" , issue = "63569" ) ]
10111012 #[ inline( always) ]
10121013 pub const fn slice_as_mut_ptr ( this : & mut [ MaybeUninit < T > ] ) -> * mut T {
1013- this. as_mut_ptr ( ) as * mut T
1014+ this. as_mut_ptr ( ) . cast :: < T > ( )
10141015 }
10151016
10161017 /// Copies the elements from `src` to `this`, returning a mutable reference to the now initialized contents of `this`.
@@ -1182,7 +1183,7 @@ impl<T> MaybeUninit<T> {
11821183 pub fn as_bytes ( & self ) -> & [ MaybeUninit < u8 > ] {
11831184 // SAFETY: MaybeUninit<u8> is always valid, even for padding bytes
11841185 unsafe {
1185- slice:: from_raw_parts ( self . as_ptr ( ) as * const MaybeUninit < u8 > , mem:: size_of :: < T > ( ) )
1186+ slice:: from_raw_parts ( self . as_ptr ( ) . cast :: < MaybeUninit < u8 > > ( ) , mem:: size_of :: < T > ( ) )
11861187 }
11871188 }
11881189
@@ -1214,7 +1215,7 @@ impl<T> MaybeUninit<T> {
12141215 // SAFETY: MaybeUninit<u8> is always valid, even for padding bytes
12151216 unsafe {
12161217 slice:: from_raw_parts_mut (
1217- self . as_mut_ptr ( ) as * mut MaybeUninit < u8 > ,
1218+ self . as_mut_ptr ( ) . cast :: < MaybeUninit < u8 > > ( ) ,
12181219 mem:: size_of :: < T > ( ) ,
12191220 )
12201221 }
@@ -1244,7 +1245,7 @@ impl<T> MaybeUninit<T> {
12441245 // SAFETY: MaybeUninit<u8> is always valid, even for padding bytes
12451246 unsafe {
12461247 slice:: from_raw_parts (
1247- this. as_ptr ( ) as * const MaybeUninit < u8 > ,
1248+ this. as_ptr ( ) . cast :: < MaybeUninit < u8 > > ( ) ,
12481249 this. len ( ) * mem:: size_of :: < T > ( ) ,
12491250 )
12501251 }
@@ -1277,7 +1278,7 @@ impl<T> MaybeUninit<T> {
12771278 // SAFETY: MaybeUninit<u8> is always valid, even for padding bytes
12781279 unsafe {
12791280 slice:: from_raw_parts_mut (
1280- this. as_mut_ptr ( ) as * mut MaybeUninit < u8 > ,
1281+ this. as_mut_ptr ( ) . cast :: < MaybeUninit < u8 > > ( ) ,
12811282 this. len ( ) * mem:: size_of :: < T > ( ) ,
12821283 )
12831284 }
0 commit comments