diff options
| author | Josh Stone <jistone@redhat.com> | 2025-09-19 17:16:05 -0700 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2025-09-22 14:04:04 -0700 |
| commit | 389a502ade65e82d8a0c4d323118121c1c09c4f8 (patch) | |
| tree | 41236a3dd94c8091344705c6e07f1443fce8a170 /compiler | |
| parent | e10aa8891182378de002bd71bf4d04181fb8231d (diff) | |
| download | rust-389a502ade65e82d8a0c4d323118121c1c09c4f8.tar.gz rust-389a502ade65e82d8a0c4d323118121c1c09c4f8.zip | |
Fix a dangling reference in `rustc_thread_pool`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_thread_pool/src/latch.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/rustc_thread_pool/src/latch.rs b/compiler/rustc_thread_pool/src/latch.rs index 18d654d9f78..58dabaf35c0 100644 --- a/compiler/rustc_thread_pool/src/latch.rs +++ b/compiler/rustc_thread_pool/src/latch.rs @@ -388,13 +388,17 @@ impl Latch for CountLatch { #[inline] unsafe fn set(this: *const Self) { if unsafe { (*this).counter.fetch_sub(1, Ordering::SeqCst) == 1 } { - // NOTE: Once we call `set` on the internal `latch`, + // SAFETY: Once we call `set` on the internal `latch`, // the target may proceed and invalidate `this`! match unsafe { &(*this).kind } { CountLatchKind::Stealing { latch, registry, worker_index } => { let registry = Arc::clone(registry); + let worker_index = *worker_index; + // SAFETY: We don't use any references from `this` after this call. if unsafe { CoreLatch::set(latch) } { - registry.notify_worker_latch_is_set(*worker_index); + // We **must not** access any part of `this` anymore, which + // is why we read and shadowed these fields beforehand. + registry.notify_worker_latch_is_set(worker_index); } } CountLatchKind::Blocking { latch } => unsafe { LockLatch::set(latch) }, |
