1
1
use core:: fmt;
2
+ use core:: mem;
2
3
use core:: pin:: Pin ;
3
- use core:: ptr:: addr_of_mut;
4
4
use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
5
5
use core:: task:: Poll ;
6
6
@@ -342,7 +342,7 @@ impl SemaphoreGuard<'_> {
342
342
/// Drops the guard _without_ releasing the acquired permit.
343
343
#[ inline]
344
344
pub fn forget ( self ) {
345
- core :: mem:: forget ( self ) ;
345
+ mem:: forget ( self ) ;
346
346
}
347
347
}
348
348
@@ -356,24 +356,24 @@ impl Drop for SemaphoreGuard<'_> {
356
356
/// An owned guard that releases the acquired permit.
357
357
#[ clippy:: has_significant_drop]
358
358
#[ derive( Debug ) ]
359
- pub struct SemaphoreGuardArc ( Arc < Semaphore > ) ;
359
+ pub struct SemaphoreGuardArc ( Option < Arc < Semaphore > > ) ;
360
360
361
361
impl SemaphoreGuardArc {
362
362
/// Drops the guard _without_ releasing the acquired permit.
363
363
/// (Will still decrement the `Arc` reference count.)
364
364
#[ inline]
365
- pub fn forget ( self ) {
366
- let mut manual = core:: mem:: ManuallyDrop :: new ( self ) ;
367
-
365
+ pub fn forget ( mut self ) {
368
366
// Drop the inner `Arc` in order to decrement the reference count.
369
- // SAFETY: `manual` not used after this
370
- let _arc = unsafe { addr_of_mut ! ( manual. 0 ) . read ( ) } ;
367
+ // FIXME: get rid of the `Option` once RFC 3466 or equivalent is merged.
368
+ drop ( self . 0 . take ( ) ) ;
369
+ mem:: forget ( self ) ;
371
370
}
372
371
}
373
372
374
373
impl Drop for SemaphoreGuardArc {
375
374
fn drop ( & mut self ) {
376
- self . 0 . count . fetch_add ( 1 , Ordering :: AcqRel ) ;
377
- self . 0 . event . notify ( 1 ) ;
375
+ let opt = self . 0 . take ( ) . unwrap ( ) ;
376
+ opt. count . fetch_add ( 1 , Ordering :: AcqRel ) ;
377
+ opt. event . notify ( 1 ) ;
378
378
}
379
379
}
0 commit comments