292292// and will prevent the doc build from failing.
293293#![ cfg_attr( feature = "default" , warn( rustdoc:: broken_intra_doc_links) ) ]
294294#![ no_std]
295- #![ expect( unsafe_op_in_unsafe_fn, reason = "crate isn't migrated yet" ) ]
296295
297296#[ cfg( feature = "std" ) ]
298297#[ macro_use]
@@ -352,8 +351,10 @@ macro_rules! map_maybe_uninit {
352351pub trait MaybeUninitExt < T > {
353352 /// Maps `MaybeUninit<T>` to `MaybeUninit<U>` using the closure provided.
354353 ///
355- /// Note that this is `unsafe` as there is no guarantee that `U` comes from
356- /// `T`.
354+ /// # Safety
355+ ///
356+ /// Requires that `*mut U` is a field projection from `*mut T`. Use
357+ /// `map_maybe_uninit!` above instead.
357358 unsafe fn map < U > ( & mut self , f : impl FnOnce ( * mut T ) -> * mut U )
358359 -> & mut core:: mem:: MaybeUninit < U > ;
359360}
@@ -364,7 +365,10 @@ impl<T> MaybeUninitExt<T> for core::mem::MaybeUninit<T> {
364365 f : impl FnOnce ( * mut T ) -> * mut U ,
365366 ) -> & mut core:: mem:: MaybeUninit < U > {
366367 let new_ptr = f ( self . as_mut_ptr ( ) ) ;
367- core:: mem:: transmute :: < * mut U , & mut core:: mem:: MaybeUninit < U > > ( new_ptr)
368+ // SAFETY: the memory layout of these two types are the same, and
369+ // asserting that it's a safe reference with the same lifetime as `self`
370+ // is a requirement of this function itself.
371+ unsafe { core:: mem:: transmute :: < * mut U , & mut core:: mem:: MaybeUninit < U > > ( new_ptr) }
368372 }
369373}
370374
0 commit comments