Skip to content

Commit 09b4945

Browse files
authored
Merge pull request #8 from euclio/docs
allow specifying attributes
2 parents 0bcd065 + 477dfc1 commit 09b4945

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/lib.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ use std::cell::Cell;
5151
use std::marker;
5252
use std::thread::LocalKey;
5353

54+
/// The macro. See the module level documentation for the description and examples.
5455
#[macro_export]
5556
#[cfg(not(feature = "nightly"))]
5657
macro_rules! scoped_thread_local {
57-
(static $name:ident: $ty:ty) => (
58+
($(#[$attrs:meta])* static $name:ident: $ty:ty) => (
59+
$(#[$attrs])*
5860
static $name: $crate::ScopedKey<$ty> = $crate::ScopedKey {
5961
inner: {
6062
thread_local!(static FOO: ::std::cell::Cell<usize> = {
@@ -67,11 +69,13 @@ macro_rules! scoped_thread_local {
6769
)
6870
}
6971

72+
/// The macro. See the module level documentation for the description and examples.
7073
#[macro_export]
7174
#[allow_internal_unstable]
7275
#[cfg(feature = "nightly")]
7376
macro_rules! scoped_thread_local {
74-
($vis:vis static $name:ident: $ty:ty) => (
77+
($(#[$attrs:meta])* $vis:vis static $name:ident: $ty:ty) => (
78+
$(#[$attrs])*
7579
$vis static $name: $crate::ScopedKey<$ty> = $crate::ScopedKey {
7680
inner: {
7781
thread_local!(static FOO: ::std::cell::Cell<usize> = {
@@ -266,4 +270,20 @@ mod tests {
266270
assert_eq!(rx.recv().unwrap(), 1);
267271
assert!(t.join().is_err());
268272
}
273+
274+
#[test]
275+
fn attrs_allowed() {
276+
scoped_thread_local!(
277+
/// Docs
278+
static BAZ: u32
279+
);
280+
281+
scoped_thread_local!(
282+
#[allow(non_upper_case_globals)]
283+
static quux: u32
284+
);
285+
286+
let _ = BAZ;
287+
let _ = quux;
288+
}
269289
}

0 commit comments

Comments
 (0)