diff options
| author | Nikolai Vazquez <hello@nikolaivazquez.com> | 2023-10-03 14:44:41 -0400 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2024-01-20 18:39:16 -0800 |
| commit | fc75a4e14607a9b6445fd0c6685fb6999fa69de8 (patch) | |
| tree | 8e8ff68007bf17ad1baf84a2895e927a46185077 /library/std/src/thread | |
| parent | 867d39cdf625e4db4b381faff993346582e598b4 (diff) | |
| download | rust-fc75a4e14607a9b6445fd0c6685fb6999fa69de8.tar.gz rust-fc75a4e14607a9b6445fd0c6685fb6999fa69de8.zip | |
Allow any expression blocks in `thread_local!`
Diffstat (limited to 'library/std/src/thread')
| -rw-r--r-- | library/std/src/thread/local.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs index 338567777f7..4c5e0e91394 100644 --- a/library/std/src/thread/local.rs +++ b/library/std/src/thread/local.rs @@ -166,7 +166,10 @@ impl<T: 'static> fmt::Debug for LocalKey<T> { /// ``` /// use std::cell::Cell; /// thread_local! { -/// pub static FOO: Cell<u32> = const { Cell::new(1) }; +/// pub static FOO: Cell<u32> = const { +/// let value = 1; +/// Cell::new(value) +/// }; /// } /// /// assert_eq!(FOO.get(), 1); @@ -186,12 +189,12 @@ macro_rules! thread_local { // empty (base case for the recursion) () => {}; - ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const { $init:expr }; $($rest:tt)*) => ( + ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const $init:block; $($rest:tt)*) => ( $crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init); $crate::thread_local!($($rest)*); ); - ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const { $init:expr }) => ( + ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = const $init:block) => ( $crate::thread::local_impl::thread_local_inner!($(#[$attr])* $vis $name, $t, const $init); ); |
