@@ -50,7 +50,8 @@ use crate::fmt;
5050/// use std::cell::Cell;
5151/// use std::thread;
5252///
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) });
5455///
5556/// assert_eq!(FOO.get(), 1);
5657/// FOO.set(2);
@@ -138,7 +139,7 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
138139/// use std::cell::{Cell, RefCell};
139140///
140141/// thread_local! {
141- /// pub static FOO: Cell<u32> = Cell::new(1);
142+ /// pub static FOO: Cell<u32> = const { Cell::new(1) } ;
142143///
143144/// static BAR: RefCell<Vec<f32>> = RefCell::new(vec![1.0, 2.0]);
144145/// }
@@ -394,7 +395,7 @@ impl<T: 'static> LocalKey<Cell<T>> {
394395 /// use std::cell::Cell;
395396 ///
396397 /// thread_local! {
397- /// static X: Cell<i32> = Cell::new(1);
398+ /// static X: Cell<i32> = const { Cell::new(1) } ;
398399 /// }
399400 ///
400401 /// assert_eq!(X.get(), 1);
@@ -423,7 +424,7 @@ impl<T: 'static> LocalKey<Cell<T>> {
423424 /// use std::cell::Cell;
424425 ///
425426 /// thread_local! {
426- /// static X: Cell<Option<i32>> = Cell::new(Some(1));
427+ /// static X: Cell<Option<i32>> = const { Cell::new(Some(1)) } ;
427428 /// }
428429 ///
429430 /// assert_eq!(X.take(), Some(1));
@@ -453,7 +454,7 @@ impl<T: 'static> LocalKey<Cell<T>> {
453454 /// use std::cell::Cell;
454455 ///
455456 /// thread_local! {
456- /// static X: Cell<i32> = Cell::new(1);
457+ /// static X: Cell<i32> = const { Cell::new(1) } ;
457458 /// }
458459 ///
459460 /// assert_eq!(X.replace(2), 1);
0 commit comments