diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-11-14 09:18:10 -0800 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2014-12-18 12:09:07 -0500 |
| commit | ddb2466f6a1bb66f22824334022a4cee61c73bdc (patch) | |
| tree | 9cb97d3e4c4521b56d0776e5f7bda81e62135be4 /src/libstd/thread_local | |
| parent | c0b2885ee12b79c99ac8245edb6eebaaa8e7fef1 (diff) | |
| download | rust-ddb2466f6a1bb66f22824334022a4cee61c73bdc.tar.gz rust-ddb2466f6a1bb66f22824334022a4cee61c73bdc.zip | |
librustc: Always parse `macro!()`/`macro![]` as expressions if not
followed by a semicolon.
This allows code like `vec![1i, 2, 3].len();` to work.
This breaks code that uses macros as statements without putting
semicolons after them, such as:
fn main() {
...
assert!(a == b)
assert!(c == d)
println(...);
}
It also breaks code that uses macros as items without semicolons:
local_data_key!(foo)
fn main() {
println("hello world")
}
Add semicolons to fix this code. Those two examples can be fixed as
follows:
fn main() {
...
assert!(a == b);
assert!(c == d);
println(...);
}
local_data_key!(foo);
fn main() {
println("hello world")
}
RFC #378.
Closes #18635.
[breaking-change]
Diffstat (limited to 'src/libstd/thread_local')
| -rw-r--r-- | src/libstd/thread_local/mod.rs | 32 | ||||
| -rw-r--r-- | src/libstd/thread_local/scoped.rs | 18 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 76fb703514b..1268ab8e0cf 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -109,7 +109,7 @@ pub struct Key<T> { /// Declare a new thread local storage key of type `std::thread_local::Key`. #[macro_export] #[doc(hidden)] -macro_rules! thread_local( +macro_rules! thread_local { (static $name:ident: $t:ty = $init:expr) => ( static $name: ::std::thread_local::Key<$t> = { use std::cell::UnsafeCell as __UnsafeCell; @@ -119,7 +119,7 @@ macro_rules! thread_local( __thread_local_inner!(static __KEY: __UnsafeCell<__Option<$t>> = { __UnsafeCell { value: __None } - }) + }); fn __init() -> $t { $init } fn __getit() -> &'static __KeyInner<__UnsafeCell<__Option<$t>>> { &__KEY @@ -136,7 +136,7 @@ macro_rules! thread_local( __thread_local_inner!(static __KEY: __UnsafeCell<__Option<$t>> = { __UnsafeCell { value: __None } - }) + }); fn __init() -> $t { $init } fn __getit() -> &'static __KeyInner<__UnsafeCell<__Option<$t>>> { &__KEY @@ -144,7 +144,7 @@ macro_rules! thread_local( ::std::thread_local::Key { inner: __getit, init: __init } }; ); -) +} // Macro pain #4586: // @@ -167,7 +167,7 @@ macro_rules! thread_local( // itself. Woohoo. #[macro_export] -macro_rules! __thread_local_inner( +macro_rules! __thread_local_inner { (static $name:ident: $t:ty = $init:expr) => ( #[cfg_attr(any(target_os = "macos", target_os = "linux"), thread_local)] static $name: ::std::thread_local::KeyInner<$t> = @@ -204,7 +204,7 @@ macro_rules! __thread_local_inner( INIT }); -) +} impl<T: 'static> Key<T> { /// Acquire a reference to the value in this TLS key. @@ -459,7 +459,7 @@ mod tests { #[test] fn smoke_no_dtor() { - thread_local!(static FOO: UnsafeCell<int> = UnsafeCell { value: 1 }) + thread_local!(static FOO: UnsafeCell<int> = UnsafeCell { value: 1 }); FOO.with(|f| unsafe { assert_eq!(*f.get(), 1); @@ -483,7 +483,7 @@ mod tests { fn smoke_dtor() { thread_local!(static FOO: UnsafeCell<Option<Foo>> = UnsafeCell { value: None - }) + }); let (tx, rx) = channel(); spawn(move|| unsafe { @@ -501,10 +501,10 @@ mod tests { struct S2; thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell { value: None - }) + }); thread_local!(static K2: UnsafeCell<Option<S2>> = UnsafeCell { value: None - }) + }); static mut HITS: uint = 0; impl Drop for S1 { @@ -544,7 +544,7 @@ mod tests { struct S1; thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell { value: None - }) + }); impl Drop for S1 { fn drop(&mut self) { @@ -562,10 +562,10 @@ mod tests { struct S1(Sender<()>); thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell { value: None - }) + }); thread_local!(static K2: UnsafeCell<Option<Foo>> = UnsafeCell { value: None - }) + }); impl Drop for S1 { fn drop(&mut self) { @@ -597,7 +597,7 @@ mod dynamic_tests { #[test] fn smoke() { fn square(i: int) -> int { i * i } - thread_local!(static FOO: int = square(3)) + thread_local!(static FOO: int = square(3)); FOO.with(|f| { assert_eq!(*f, 9); @@ -611,7 +611,7 @@ mod dynamic_tests { m.insert(1, 2); RefCell::new(m) } - thread_local!(static FOO: RefCell<HashMap<int, int>> = map()) + thread_local!(static FOO: RefCell<HashMap<int, int>> = map()); FOO.with(|map| { assert_eq!(map.borrow()[1], 2); @@ -620,7 +620,7 @@ mod dynamic_tests { #[test] fn refcell_vec() { - thread_local!(static FOO: RefCell<Vec<uint>> = RefCell::new(vec![1, 2, 3])) + thread_local!(static FOO: RefCell<Vec<uint>> = RefCell::new(vec![1, 2, 3])); FOO.with(|vec| { assert_eq!(vec.borrow().len(), 3); diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs index ee742ab8375..7762d225b9a 100644 --- a/src/libstd/thread_local/scoped.rs +++ b/src/libstd/thread_local/scoped.rs @@ -24,7 +24,7 @@ //! # Example //! //! ``` -//! scoped_thread_local!(static FOO: uint) +//! scoped_thread_local!(static FOO: uint); //! //! // Initially each scoped slot is empty. //! assert!(!FOO.is_set()); @@ -60,18 +60,18 @@ pub struct Key<T> { #[doc(hidden)] pub inner: KeyInner<T> } /// This macro declares a `static` item on which methods are used to get and /// set the value stored within. #[macro_export] -macro_rules! scoped_thread_local( +macro_rules! scoped_thread_local { (static $name:ident: $t:ty) => ( __scoped_thread_local_inner!(static $name: $t) ); (pub static $name:ident: $t:ty) => ( __scoped_thread_local_inner!(pub static $name: $t) ); -) +} #[macro_export] #[doc(hidden)] -macro_rules! __scoped_thread_local_inner( +macro_rules! __scoped_thread_local_inner { (static $name:ident: $t:ty) => ( #[cfg_attr(not(any(windows, target_os = "android", target_os = "ios")), thread_local)] @@ -104,7 +104,7 @@ macro_rules! __scoped_thread_local_inner( INIT }) -) +} impl<T> Key<T> { /// Insert a value into this scoped thread local storage slot for a @@ -119,7 +119,7 @@ impl<T> Key<T> { /// # Example /// /// ``` - /// scoped_thread_local!(static FOO: uint) + /// scoped_thread_local!(static FOO: uint); /// /// FOO.set(&100, || { /// let val = FOO.with(|v| *v); @@ -171,7 +171,7 @@ impl<T> Key<T> { /// # Example /// /// ```no_run - /// scoped_thread_local!(static FOO: uint) + /// scoped_thread_local!(static FOO: uint); /// /// FOO.with(|slot| { /// // work with `slot` @@ -239,7 +239,7 @@ mod tests { #[test] fn smoke() { - scoped_thread_local!(static BAR: uint) + scoped_thread_local!(static BAR: uint); assert!(!BAR.is_set()); BAR.set(&1, || { @@ -253,7 +253,7 @@ mod tests { #[test] fn cell_allowed() { - scoped_thread_local!(static BAR: Cell<uint>) + scoped_thread_local!(static BAR: Cell<uint>); BAR.set(&Cell::new(1), || { BAR.with(|slot| { |
