Skip to content

Commit

Permalink
Merge pull request #8 from euclio/docs
Browse files Browse the repository at this point in the history
allow specifying attributes
  • Loading branch information
alexcrichton authored Jan 24, 2019
2 parents 0bcd065 + 477dfc1 commit 09b4945
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> = {
Expand All @@ -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<usize> = {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 09b4945

Please sign in to comment.