@@ -77,8 +77,12 @@ impl TaggedArcPtr {
77
77
}
78
78
79
79
/// Retrieves the tag.
80
+ ///
81
+ /// # Safety
82
+ ///
83
+ /// You can only drop the `Arc` if the instance is dropped.
80
84
#[ inline]
81
- pub ( crate ) fn try_as_arc_owned ( self ) -> Option < ManuallyDrop < Arc < Box < str > > > > {
85
+ pub ( crate ) unsafe fn try_as_arc_owned ( self ) -> Option < ManuallyDrop < Arc < Box < str > > > > {
82
86
// Unpack the tag from the alignment niche
83
87
let tag = Strict :: addr ( self . packed . as_ptr ( ) ) & Self :: BOOL_BITS ;
84
88
if tag != 0 {
@@ -245,16 +249,14 @@ impl Symbol {
245
249
}
246
250
}
247
251
248
- ManuallyDrop :: into_inner (
249
- match shard. raw_entry_mut ( ) . from_key_hashed_nocheck :: < str > ( hash, arc. as_ref ( ) ) {
250
- RawEntryMut :: Occupied ( occ) => occ. remove_entry ( ) ,
251
- RawEntryMut :: Vacant ( _) => unreachable ! ( ) ,
252
- }
253
- . 0
254
- . 0
255
- . try_as_arc_owned ( )
256
- . unwrap ( ) ,
257
- ) ;
252
+ let ptr = match shard. raw_entry_mut ( ) . from_key_hashed_nocheck :: < str > ( hash, arc. as_ref ( ) ) {
253
+ RawEntryMut :: Occupied ( occ) => occ. remove_entry ( ) ,
254
+ RawEntryMut :: Vacant ( _) => unreachable ! ( ) ,
255
+ }
256
+ . 0
257
+ . 0 ;
258
+ // SAFETY: We're dropping, we have ownership.
259
+ ManuallyDrop :: into_inner ( unsafe { ptr. try_as_arc_owned ( ) . unwrap ( ) } ) ;
258
260
debug_assert_eq ! ( Arc :: count( arc) , 1 ) ;
259
261
260
262
// Shrink the backing storage if the shard is less than 50% occupied.
@@ -267,7 +269,8 @@ impl Symbol {
267
269
impl Drop for Symbol {
268
270
#[ inline]
269
271
fn drop ( & mut self ) {
270
- let Some ( arc) = self . repr . try_as_arc_owned ( ) else {
272
+ // SAFETY: We're dropping, we have ownership.
273
+ let Some ( arc) = ( unsafe { self . repr . try_as_arc_owned ( ) } ) else {
271
274
return ;
272
275
} ;
273
276
// When the last `Ref` is dropped, remove the object from the global map.
@@ -288,7 +291,8 @@ impl Clone for Symbol {
288
291
}
289
292
290
293
fn increase_arc_refcount ( repr : TaggedArcPtr ) -> TaggedArcPtr {
291
- let Some ( arc) = repr. try_as_arc_owned ( ) else {
294
+ // SAFETY: We're not dropping the `Arc`.
295
+ let Some ( arc) = ( unsafe { repr. try_as_arc_owned ( ) } ) else {
292
296
return repr;
293
297
} ;
294
298
// increase the ref count
0 commit comments