From 477dfc12b1f36824a9d355f2684c5491ce89517d Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Wed, 23 Jan 2019 17:04:46 -0500 Subject: [PATCH] allow specifying attributes --- src/lib.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 419ab65..ca4a2ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,10 +51,12 @@ use std::cell::Cell; use std::marker; use std::thread::LocalKey; +/// The macro. See the module level documentation for the description and examples. #[macro_export] #[cfg(not(feature = "nightly"))] macro_rules! scoped_thread_local { - (static $name:ident: $ty:ty) => ( + ($(#[$attrs:meta])* static $name:ident: $ty:ty) => ( + $(#[$attrs])* static $name: $crate::ScopedKey<$ty> = $crate::ScopedKey { inner: { thread_local!(static FOO: ::std::cell::Cell = { @@ -67,11 +69,13 @@ macro_rules! scoped_thread_local { ) } +/// The macro. See the module level documentation for the description and examples. #[macro_export] #[allow_internal_unstable] #[cfg(feature = "nightly")] macro_rules! scoped_thread_local { - ($vis:vis static $name:ident: $ty:ty) => ( + ($(#[$attrs:meta])* $vis:vis static $name:ident: $ty:ty) => ( + $(#[$attrs])* $vis static $name: $crate::ScopedKey<$ty> = $crate::ScopedKey { inner: { thread_local!(static FOO: ::std::cell::Cell = { @@ -266,4 +270,20 @@ mod tests { assert_eq!(rx.recv().unwrap(), 1); assert!(t.join().is_err()); } + + #[test] + fn attrs_allowed() { + scoped_thread_local!( + /// Docs + static BAZ: u32 + ); + + scoped_thread_local!( + #[allow(non_upper_case_globals)] + static quux: u32 + ); + + let _ = BAZ; + let _ = quux; + } }