@@ -2071,6 +2071,7 @@ impl<T> UnsafeCell<T> {
2071
2071
/// ```
2072
2072
#[ inline( always) ]
2073
2073
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2074
+ // When this is const stabilized, please remove `primitive_into_inner` below.
2074
2075
#[ rustc_const_unstable( feature = "const_cell_into_inner" , issue = "78729" ) ]
2075
2076
pub const fn into_inner ( self ) -> T {
2076
2077
self . value
@@ -2217,6 +2218,47 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
2217
2218
#[ unstable( feature = "dispatch_from_dyn" , issue = "none" ) ]
2218
2219
impl < T : DispatchFromDyn < U > , U > DispatchFromDyn < UnsafeCell < U > > for UnsafeCell < T > { }
2219
2220
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
+
2220
2262
/// [`UnsafeCell`], but [`Sync`].
2221
2263
///
2222
2264
/// This is just an `UnsafeCell`, except it implements `Sync`
0 commit comments