Skip to content

Commit

Permalink
Rollup merge of rust-lang#116172 - joboet:recursive_tls_initializatio…
Browse files Browse the repository at this point in the history
…n, r=dtolnay

Broaden the consequences of recursive TLS initialization

This PR updates the documentation of `LocalKey` to clearly disallow the behaviour described in [this comment](rust-lang#110897 (comment)). This allows using `OnceCell` for the lazy initialization of TLS variables, which panics on reentrant initialization instead of updating the value like TLS variables currently do.

`@rustbot` label +T-libs-api
r? `@m-ou-se`
  • Loading branch information
matthiaskrgr committed Oct 15, 2023
2 parents 8a2877b + 559ec69 commit 8c1b136
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions library/std/src/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ use crate::fmt;
/// within a thread, and values that implement [`Drop`] get destructed when a
/// thread exits. Some caveats apply, which are explained below.
///
/// A `LocalKey`'s initializer cannot recursively depend on itself, and using
/// a `LocalKey` in this way will cause the initializer to infinitely recurse
/// on the first call to `with`.
/// A `LocalKey`'s initializer cannot recursively depend on itself. Using a
/// `LocalKey` in this way may cause panics, aborts or infinite recursion on
/// the first call to `with`.
///
/// # Examples
///
Expand Down

0 comments on commit 8c1b136

Please sign in to comment.