Skip to content

Commit fb7309c

Browse files
authored
Rollup merge of #41995 - gamazeps:thread-localkey, r=frewsxcv
[Doc] Add links to the `thread::LocalKey` doc. Part of #29378 . I do not know exactly what should be done for the `cleanup` part, if you have any idea I'll gladly do it. r? @rust-lang/docs
2 parents 459a3af + f92bd3d commit fb7309c

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/libstd/thread/local.rs

+30-15
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ use mem;
1919
/// A thread local storage key which owns its contents.
2020
///
2121
/// This key uses the fastest possible implementation available to it for the
22-
/// target platform. It is instantiated with the `thread_local!` macro and the
23-
/// primary method is the `with` method.
22+
/// target platform. It is instantiated with the [`thread_local!`] macro and the
23+
/// primary method is the [`with`] method.
2424
///
25-
/// The `with` method yields a reference to the contained value which cannot be
25+
/// The [`with`] method yields a reference to the contained value which cannot be
2626
/// sent across threads or escape the given closure.
2727
///
2828
/// # Initialization and Destruction
2929
///
30-
/// Initialization is dynamically performed on the first call to `with()`
31-
/// within a thread, and values that implement `Drop` get destructed when a
30+
/// Initialization is dynamically performed on the first call to [`with`]
31+
/// within a thread, and values that implement [`Drop`] get destructed when a
3232
/// thread exits. Some caveats apply, which are explained below.
3333
///
3434
/// # Examples
@@ -77,6 +77,10 @@ use mem;
7777
/// 3. On macOS, initializing TLS during destruction of other TLS slots can
7878
/// sometimes cancel *all* destructors for the current thread, whether or not
7979
/// the slots have already had their destructors run or not.
80+
///
81+
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
82+
/// [`thread_local!`]: ../../std/macro.thread_local.html
83+
/// [`Drop`]: ../../std/ops/trait.Drop.html
8084
#[stable(feature = "rust1", since = "1.0.0")]
8185
pub struct LocalKey<T: 'static> {
8286
// This outer `LocalKey<T>` type is what's going to be stored in statics,
@@ -106,7 +110,7 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
106110
}
107111
}
108112

109-
/// Declare a new thread local storage key of type `std::thread::LocalKey`.
113+
/// Declare a new thread local storage key of type [`std::thread::LocalKey`].
110114
///
111115
/// # Syntax
112116
///
@@ -124,8 +128,10 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
124128
/// # fn main() {}
125129
/// ```
126130
///
127-
/// See [LocalKey documentation](thread/struct.LocalKey.html) for more
131+
/// See [LocalKey documentation][`std::thread::LocalKey`] for more
128132
/// information.
133+
///
134+
/// [`std::thread::LocalKey`]: ../std/thread/struct.LocalKey.html
129135
#[macro_export]
130136
#[stable(feature = "rust1", since = "1.0.0")]
131137
#[allow_internal_unstable]
@@ -195,11 +201,13 @@ macro_rules! __thread_local_inner {
195201
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
196202
pub enum LocalKeyState {
197203
/// All keys are in this state whenever a thread starts. Keys will
198-
/// transition to the `Valid` state once the first call to `with` happens
204+
/// transition to the `Valid` state once the first call to [`with`] happens
199205
/// and the initialization expression succeeds.
200206
///
201207
/// Keys in the `Uninitialized` state will yield a reference to the closure
202-
/// passed to `with` so long as the initialization routine does not panic.
208+
/// passed to [`with`] so long as the initialization routine does not panic.
209+
///
210+
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
203211
Uninitialized,
204212

205213
/// Once a key has been accessed successfully, it will enter the `Valid`
@@ -208,15 +216,19 @@ pub enum LocalKeyState {
208216
/// `Destroyed` state.
209217
///
210218
/// Keys in the `Valid` state will be guaranteed to yield a reference to the
211-
/// closure passed to `with`.
219+
/// closure passed to [`with`].
220+
///
221+
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
212222
Valid,
213223

214224
/// When a thread exits, the destructors for keys will be run (if
215225
/// necessary). While a destructor is running, and possibly after a
216226
/// destructor has run, a key is in the `Destroyed` state.
217227
///
218228
/// Keys in the `Destroyed` states will trigger a panic when accessed via
219-
/// `with`.
229+
/// [`with`].
230+
///
231+
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
220232
Destroyed,
221233
}
222234

@@ -283,23 +295,26 @@ impl<T: 'static> LocalKey<T> {
283295
/// Query the current state of this key.
284296
///
285297
/// A key is initially in the `Uninitialized` state whenever a thread
286-
/// starts. It will remain in this state up until the first call to `with`
298+
/// starts. It will remain in this state up until the first call to [`with`]
287299
/// within a thread has run the initialization expression successfully.
288300
///
289301
/// Once the initialization expression succeeds, the key transitions to the
290-
/// `Valid` state which will guarantee that future calls to `with` will
302+
/// `Valid` state which will guarantee that future calls to [`with`] will
291303
/// succeed within the thread.
292304
///
293305
/// When a thread exits, each key will be destroyed in turn, and as keys are
294306
/// destroyed they will enter the `Destroyed` state just before the
295307
/// destructor starts to run. Keys may remain in the `Destroyed` state after
296308
/// destruction has completed. Keys without destructors (e.g. with types
297-
/// that are `Copy`), may never enter the `Destroyed` state.
309+
/// that are [`Copy`]), may never enter the `Destroyed` state.
298310
///
299311
/// Keys in the `Uninitialized` state can be accessed so long as the
300312
/// initialization does not panic. Keys in the `Valid` state are guaranteed
301313
/// to be able to be accessed. Keys in the `Destroyed` state will panic on
302-
/// any call to `with`.
314+
/// any call to [`with`].
315+
///
316+
/// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
317+
/// [`Copy`]: ../../std/marker/trait.Copy.html
303318
#[unstable(feature = "thread_local_state",
304319
reason = "state querying was recently added",
305320
issue = "27716")]

0 commit comments

Comments
 (0)