File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,28 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
137137/// # fn main() {}
138138/// ```
139139///
140+ /// This macro also supports wrapping initializing expression in `const` block
141+ /// if it can be evaluated in const context:
142+ ///
143+ /// ```
144+ /// use std::cell::Cell;
145+ /// thread_local! {
146+ /// static INIT_FLAG: Cell<bool> = const { Cell::new(false) };
147+ /// }
148+ /// ```
149+ ///
150+ /// Doing so does not change the behavior, but might enable more efficient implementation
151+ /// of [`LocalKey`][`std::thread::LocalKey`] on supported platforms.
152+ ///
153+ /// If initializing expression can not be evaluated in const context, wrapping it in
154+ /// `const` block is a compile error.
155+ ///
156+ /// ```compile_fail
157+ /// thread_local! {
158+ /// static FOO: Vec<i32> = const { vec![0] };
159+ /// }
160+ /// ```
161+ ///
140162/// See [`LocalKey` documentation][`std::thread::LocalKey`] for more
141163/// information.
142164///
You can’t perform that action at this time.
0 commit comments