Skip to content

Commit

Permalink
Rollup merge of #116172 - joboet:recursive_tls_initialization, r=dtolnay
Browse files Browse the repository at this point in the history
Broaden the consequences of recursive TLS initialization

This PR updates the documentation of `LocalKey` to clearly disallow the behaviour described in [this comment](#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 authored Oct 15, 2023
2 parents 64368d0 + 559ec69 commit e063d8a
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 e063d8a

Please sign in to comment.