File tree 1 file changed +22
-0
lines changed
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> {
137
137
/// # fn main() {}
138
138
/// ```
139
139
///
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
+ ///
140
162
/// See [`LocalKey` documentation][`std::thread::LocalKey`] for more
141
163
/// information.
142
164
///
You can’t perform that action at this time.
0 commit comments