diff options
Diffstat (limited to 'library/std/src/thread/local.rs')
| -rw-r--r-- | library/std/src/thread/local.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs index ca04aa4ada4..d5a5d10205d 100644 --- a/library/std/src/thread/local.rs +++ b/library/std/src/thread/local.rs @@ -50,7 +50,8 @@ use crate::fmt; /// use std::cell::Cell; /// use std::thread; /// -/// thread_local!(static FOO: Cell<u32> = Cell::new(1)); +/// // explicit `const {}` block enables more efficient initialization +/// thread_local!(static FOO: Cell<u32> = const { Cell::new(1) }); /// /// assert_eq!(FOO.get(), 1); /// FOO.set(2); @@ -138,7 +139,7 @@ impl<T: 'static> fmt::Debug for LocalKey<T> { /// use std::cell::{Cell, RefCell}; /// /// thread_local! { -/// pub static FOO: Cell<u32> = Cell::new(1); +/// pub static FOO: Cell<u32> = const { Cell::new(1) }; /// /// static BAR: RefCell<Vec<f32>> = RefCell::new(vec![1.0, 2.0]); /// } @@ -394,7 +395,7 @@ impl<T: 'static> LocalKey<Cell<T>> { /// use std::cell::Cell; /// /// thread_local! { - /// static X: Cell<i32> = Cell::new(1); + /// static X: Cell<i32> = const { Cell::new(1) }; /// } /// /// assert_eq!(X.get(), 1); @@ -423,7 +424,7 @@ impl<T: 'static> LocalKey<Cell<T>> { /// use std::cell::Cell; /// /// thread_local! { - /// static X: Cell<Option<i32>> = Cell::new(Some(1)); + /// static X: Cell<Option<i32>> = const { Cell::new(Some(1)) }; /// } /// /// assert_eq!(X.take(), Some(1)); @@ -453,7 +454,7 @@ impl<T: 'static> LocalKey<Cell<T>> { /// use std::cell::Cell; /// /// thread_local! { - /// static X: Cell<i32> = Cell::new(1); + /// static X: Cell<i32> = const { Cell::new(1) }; /// } /// /// assert_eq!(X.replace(2), 1); |
