mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-01 01:26:32 +00:00
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
This commit is contained in:
@@ -434,7 +434,7 @@ impl<T: 'static> LocalKey<T> {
|
||||
///
|
||||
/// This will lazily initialize the value if this thread has not referenced
|
||||
/// this key yet. If the key has been destroyed (which may happen if this is called
|
||||
/// in a destructor), this function will return an [`AccessError`].
|
||||
/// in a destructor), this function may return an [`AccessError`].
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user