@@ -2071,6 +2071,7 @@ impl<T> UnsafeCell<T> {
20712071 /// ```
20722072 #[ inline( always) ]
20732073 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2074+ // When this is const stabilized, please remove `primitive_into_inner` below.
20742075 #[ rustc_const_unstable( feature = "const_cell_into_inner" , issue = "78729" ) ]
20752076 pub const fn into_inner ( self ) -> T {
20762077 self . value
@@ -2217,6 +2218,47 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
22172218#[ unstable( feature = "dispatch_from_dyn" , issue = "none" ) ]
22182219impl < T : DispatchFromDyn < U > , U > DispatchFromDyn < UnsafeCell < U > > for UnsafeCell < T > { }
22192220
2221+ // Special cases of UnsafeCell::into_inner where T is a primitive. These are
2222+ // used by Atomic*::into_inner.
2223+ //
2224+ // The real UnsafeCell::into_inner cannot be used yet in a stable const function.
2225+ // That is blocked on a "precise drop analysis" unstable const feature.
2226+ // https://github.com/rust-lang/rust/issues/73255
2227+ macro_rules! unsafe_cell_primitive_into_inner {
2228+ ( $( $primitive: ident $atomic: literal) * ) => {
2229+ $(
2230+ #[ cfg( target_has_atomic_load_store = $atomic) ]
2231+ impl UnsafeCell <$primitive> {
2232+ pub ( crate ) const fn primitive_into_inner( self ) -> $primitive {
2233+ self . value
2234+ }
2235+ }
2236+ ) *
2237+ } ;
2238+ }
2239+
2240+ unsafe_cell_primitive_into_inner ! {
2241+ i8 "8"
2242+ u8 "8"
2243+ i16 "16"
2244+ u16 "16"
2245+ i32 "32"
2246+ u32 "32"
2247+ i64 "64"
2248+ u64 "64"
2249+ i128 "128"
2250+ u128 "128"
2251+ isize "ptr"
2252+ usize "ptr"
2253+ }
2254+
2255+ #[ cfg( target_has_atomic_load_store = "ptr" ) ]
2256+ impl < T > UnsafeCell < * mut T > {
2257+ pub ( crate ) const fn primitive_into_inner ( self ) -> * mut T {
2258+ self . value
2259+ }
2260+ }
2261+
22202262/// [`UnsafeCell`], but [`Sync`].
22212263///
22222264/// This is just an `UnsafeCell`, except it implements `Sync`
0 commit comments