diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-08-23 23:58:35 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-23 23:58:35 -0400 |
| commit | d5340c26fa789a9dfe08c5ccc7d0539cd4f7a95c (patch) | |
| tree | fe944191aa2d0f12638dd23b0fd16985910c1125 /library/std/src/sync | |
| parent | 265503668d16f96e0656bc665073a7cd34177085 (diff) | |
| parent | 06eb782c4e727c33d8548a791998a0a2cbedceae (diff) | |
Rollup merge of #145307 - connortsui20:lazylock-poison-msg, r=Amanieu
Fix `LazyLock` poison panic message Fixes the issue raised in https://github.com/rust-lang/rust/pull/144872#issuecomment-3151100248 r? ```@Amanieu```
Diffstat (limited to 'library/std/src/sync')
| -rw-r--r-- | library/std/src/sync/lazy_lock.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/library/std/src/sync/lazy_lock.rs b/library/std/src/sync/lazy_lock.rs index a40e29a772a..3231125f7a1 100644 --- a/library/std/src/sync/lazy_lock.rs +++ b/library/std/src/sync/lazy_lock.rs @@ -244,7 +244,11 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> { #[inline] #[stable(feature = "lazy_cell", since = "1.80.0")] pub fn force(this: &LazyLock<T, F>) -> &T { - this.once.call_once(|| { + this.once.call_once_force(|state| { + if state.is_poisoned() { + panic_poisoned(); + } + // SAFETY: `call_once` only runs this closure once, ever. let data = unsafe { &mut *this.data.get() }; let f = unsafe { ManuallyDrop::take(&mut data.f) }; @@ -257,8 +261,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> { // * the closure was called and initialized `value`. // * the closure was called and panicked, so this point is never reached. // * the closure was not called, but a previous call initialized `value`. - // * the closure was not called because the Once is poisoned, so this point - // is never reached. + // * the closure was not called because the Once is poisoned, which we handled above. // So `value` has definitely been initialized and will not be modified again. unsafe { &*(*this.data.get()).value } } |
