Files
rust/library
Jonathan Brouwer c1d608bb7e Rollup merge of #158760 - kpeis695:fix/localkey-try-with-may-return, r=aapoalas
Clarify that `LocalKey::try_with` may return `AccessError`

The docs for `LocalKey::try_with` state that the function *will* return an `AccessError` when the key has been destroyed. That's not actually guaranteed:

- `LocalKey::with` uses `try_with` internally and its docs explicitly acknowledge that it does not always panic when the destructor has run. If `try_with` really did detect every destroyed thread-local, `with` could always panic.
- The top-level `LocalKey` docs already note: "On all platforms it's possible for TLS to re-initialize other TLS slots during destruction."

Change *will* to *may* to accurately reflect the best-effort nature of the destroyed-key check.

Closes rust-lang/rust#157889

@rustbot label +A-docs
2026-07-07 22:26:56 +02:00
..
2026-07-06 19:36:40 +10:00
2026-06-30 09:01:03 +00:00