about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libstd/thread/local.rs16
-rw-r--r--src/test/compile-fail/macro-local-data-key-priv.rs2
2 files changed, 14 insertions, 4 deletions
diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs
index 02347bf4906..4ee8132f55c 100644
--- a/src/libstd/thread/local.rs
+++ b/src/libstd/thread/local.rs
@@ -159,8 +159,9 @@ macro_rules! thread_local {
 #[allow_internal_unstable]
 #[allow_internal_unsafe]
 macro_rules! __thread_local_inner {
-    ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => {
-        $(#[$attr])* $vis static $name: $crate::thread::LocalKey<$t> = {
+    (@key $(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => {
+        {
+            #[inline]
             fn __init() -> $t { $init }
 
             unsafe fn __getit() -> $crate::option::Option<
@@ -182,7 +183,16 @@ macro_rules! __thread_local_inner {
             unsafe {
                 $crate::thread::LocalKey::new(__getit, __init)
             }
-        };
+        }
+    };
+    ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => {
+        #[cfg(stage0)]
+        $(#[$attr])* $vis static $name: $crate::thread::LocalKey<$t> =
+            __thread_local_inner!(@key $(#[$attr])* $vis $name, $t, $init);
+
+        #[cfg(not(stage0))]
+        $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> =
+            __thread_local_inner!(@key $(#[$attr])* $vis $name, $t, $init);
     }
 }
 
diff --git a/src/test/compile-fail/macro-local-data-key-priv.rs b/src/test/compile-fail/macro-local-data-key-priv.rs
index 3818c8f7754..3ae629cd895 100644
--- a/src/test/compile-fail/macro-local-data-key-priv.rs
+++ b/src/test/compile-fail/macro-local-data-key-priv.rs
@@ -16,5 +16,5 @@ mod bar {
 
 fn main() {
     bar::baz.with(|_| ());
-    //~^ ERROR static `baz` is private
+    //~^ ERROR `baz` is private
 }