Skip to content

Commit fc75a4e

Browse files
nvzqzdtolnay
authored andcommitted
Allow any expression blocks in thread_local!
1 parent 867d39c commit fc75a4e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Diff for: library/std/src/thread/local.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
166166
/// ```
167167
/// use std::cell::Cell;
168168
/// thread_local! {
169-
/// pub static FOO: Cell<u32> = const { Cell::new(1) };
169+
/// pub static FOO: Cell<u32> = const {
170+
/// let value = 1;
171+
/// Cell::new(value)
172+
/// };
170173
/// }
171174
///
172175
/// assert_eq!(FOO.get(), 1);
@@ -186,12 +189,12 @@ macro_rules! thread_local {
186189
// empty (base case for the recursion)
187190
() => {};
188191

189-
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const { $init:expr }; $($rest:tt)*) => (
192+
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const $init:block; $($rest:tt)*) => (
190193
$crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init);
191194
$crate::thread_local!($($rest)*);
192195
);
193196

194-
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const { $init:expr }) => (
197+
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const $init:block) => (
195198
$crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init);
196199
);
197200

0 commit comments

Comments
 (0)