@@ -50,7 +50,8 @@ use crate::fmt;
50
50
/// use std::cell::Cell;
51
51
/// use std::thread;
52
52
///
53
- /// thread_local!(static FOO: Cell<u32> = Cell::new(1));
53
+ /// // explicit `const {}` block enables more efficient initialization
54
+ /// thread_local!(static FOO: Cell<u32> = const { Cell::new(1) });
54
55
///
55
56
/// assert_eq!(FOO.get(), 1);
56
57
/// FOO.set(2);
@@ -138,7 +139,7 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
138
139
/// use std::cell::{Cell, RefCell};
139
140
///
140
141
/// thread_local! {
141
- /// pub static FOO: Cell<u32> = Cell::new(1);
142
+ /// pub static FOO: Cell<u32> = const { Cell::new(1) } ;
142
143
///
143
144
/// static BAR: RefCell<Vec<f32>> = RefCell::new(vec![1.0, 2.0]);
144
145
/// }
@@ -394,7 +395,7 @@ impl<T: 'static> LocalKey<Cell<T>> {
394
395
/// use std::cell::Cell;
395
396
///
396
397
/// thread_local! {
397
- /// static X: Cell<i32> = Cell::new(1);
398
+ /// static X: Cell<i32> = const { Cell::new(1) } ;
398
399
/// }
399
400
///
400
401
/// assert_eq!(X.get(), 1);
@@ -423,7 +424,7 @@ impl<T: 'static> LocalKey<Cell<T>> {
423
424
/// use std::cell::Cell;
424
425
///
425
426
/// thread_local! {
426
- /// static X: Cell<Option<i32>> = Cell::new(Some(1));
427
+ /// static X: Cell<Option<i32>> = const { Cell::new(Some(1)) } ;
427
428
/// }
428
429
///
429
430
/// assert_eq!(X.take(), Some(1));
@@ -453,7 +454,7 @@ impl<T: 'static> LocalKey<Cell<T>> {
453
454
/// use std::cell::Cell;
454
455
///
455
456
/// thread_local! {
456
- /// static X: Cell<i32> = Cell::new(1);
457
+ /// static X: Cell<i32> = const { Cell::new(1) } ;
457
458
/// }
458
459
///
459
460
/// assert_eq!(X.replace(2), 1);
0 commit comments