File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
compiler/rustc_thread_pool/src Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -388,13 +388,17 @@ impl Latch for CountLatch {
388
388
#[ inline]
389
389
unsafe fn set ( this : * const Self ) {
390
390
if unsafe { ( * this) . counter . fetch_sub ( 1 , Ordering :: SeqCst ) == 1 } {
391
- // NOTE : Once we call `set` on the internal `latch`,
391
+ // SAFETY : Once we call `set` on the internal `latch`,
392
392
// the target may proceed and invalidate `this`!
393
393
match unsafe { & ( * this) . kind } {
394
394
CountLatchKind :: Stealing { latch, registry, worker_index } => {
395
395
let registry = Arc :: clone ( registry) ;
396
+ let worker_index = * worker_index;
397
+ // SAFETY: We don't use any references from `this` after this call.
396
398
if unsafe { CoreLatch :: set ( latch) } {
397
- registry. notify_worker_latch_is_set ( * worker_index) ;
399
+ // We **must not** access any part of `this` anymore, which
400
+ // is why we read and shadowed these fields beforehand.
401
+ registry. notify_worker_latch_is_set ( worker_index) ;
398
402
}
399
403
}
400
404
CountLatchKind :: Blocking { latch } => unsafe { LockLatch :: set ( latch) } ,
You can’t perform that action at this time.
0 commit comments