about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-11-28 00:51:37 +0000
committerbors <bors@rust-lang.org>2024-11-28 00:51:37 +0000
commiteddb717281a9031f645d88dd3b8323a7e25632cc (patch)
tree0a9df155daa91a5aa5720e39cad9fe79c2b51864 /library/std/src
parent66adeaf46b7a646daeed29518ef76235fcdb9726 (diff)
parent5fc4f85f60f9b1169bddf62d4f23340d81f14a0a (diff)
downloadrust-eddb717281a9031f645d88dd3b8323a7e25632cc.tar.gz
rust-eddb717281a9031f645d88dd3b8323a7e25632cc.zip
Auto merge of #133551 - matthiaskrgr:rollup-m0rr5oz, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #132410 (Some more refactorings towards removing driver queries)
 - #133418 (coverage: Store coverage source regions as `Span` until codegen)
 - #133498 (Add missing code examples on `LocalKey`)
 - #133518 (Structurally resolve before checking `!` in HIR typeck)
 - #133521 (Structurally resolve before matching on type of projection)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/thread/local.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs
index 9edb3fa4193..bc5f701e346 100644
--- a/library/std/src/thread/local.rs
+++ b/library/std/src/thread/local.rs
@@ -252,6 +252,19 @@ impl<T: 'static> LocalKey<T> {
     /// This function will `panic!()` if the key currently has its
     /// destructor running, and it **may** panic if the destructor has
     /// previously been run for this thread.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// thread_local! {
+    ///     pub static STATIC: String = String::from("I am");
+    /// }
+    ///
+    /// assert_eq!(
+    ///     STATIC.with(|original_value| format!("{original_value} initialized")),
+    ///     "I am initialized",
+    /// );
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn with<F, R>(&'static self, f: F) -> R
     where
@@ -273,6 +286,19 @@ impl<T: 'static> LocalKey<T> {
     ///
     /// This function will still `panic!()` if the key is uninitialized and the
     /// key's initializer panics.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// thread_local! {
+    ///     pub static STATIC: String = String::from("I am");
+    /// }
+    ///
+    /// assert_eq!(
+    ///     STATIC.try_with(|original_value| format!("{original_value} initialized")),
+    ///     Ok(String::from("I am initialized")),
+    /// );
+    /// ```
     #[stable(feature = "thread_local_try_with", since = "1.26.0")]
     #[inline]
     pub fn try_with<F, R>(&'static self, f: F) -> Result<R, AccessError>
@@ -452,7 +478,7 @@ impl<T: 'static> LocalKey<RefCell<T>> {
     /// Panics if the key currently has its destructor running,
     /// and it **may** panic if the destructor has previously been run for this thread.
     ///
-    /// # Example
+    /// # Examples
     ///
     /// ```
     /// use std::cell::RefCell;
@@ -483,7 +509,7 @@ impl<T: 'static> LocalKey<RefCell<T>> {
     /// Panics if the key currently has its destructor running,
     /// and it **may** panic if the destructor has previously been run for this thread.
     ///
-    /// # Example
+    /// # Examples
     ///
     /// ```
     /// use std::cell::RefCell;