about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJules Bertholet <julesbertholet@quoi.xyz>2025-09-27 15:47:06 -0400
committerJules Bertholet <julesbertholet@quoi.xyz>2025-09-27 17:05:39 -0400
commit4d32b9a1783343d42a9864fe3d2115daa2cb425e (patch)
tree508fe80b63530b51d3a6bfbe0a044ec4ac2a1627
parenta4e87e940620bc0e61caa7c42b1edc53c0aee7cb (diff)
downloadrust-4d32b9a1783343d42a9864fe3d2115daa2cb425e.tar.gz
rust-4d32b9a1783343d42a9864fe3d2115daa2cb425e.zip
Hoist non-platform-specific code out of `thread_local_inner!`
-rw-r--r--library/std/src/sys/thread_local/native/mod.rs4
-rw-r--r--library/std/src/sys/thread_local/no_threads.rs5
-rw-r--r--library/std/src/sys/thread_local/os.rs5
-rw-r--r--library/std/src/thread/local.rs8
-rw-r--r--tests/ui/macros/macro-local-data-key-priv.stderr2
-rw-r--r--tests/ui/thread-local/no-unstable.stderr6
6 files changed, 10 insertions, 20 deletions
diff --git a/library/std/src/sys/thread_local/native/mod.rs b/library/std/src/sys/thread_local/native/mod.rs
index 9544721b923..5dc14240804 100644
--- a/library/std/src/sys/thread_local/native/mod.rs
+++ b/library/std/src/sys/thread_local/native/mod.rs
@@ -108,10 +108,6 @@ pub macro thread_local_inner {
             })
         }
     }},
-    ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $(#[$align_attr:meta])*, $($init:tt)*) => {
-        $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> =
-            $crate::thread::local_impl::thread_local_inner!(@key $t, $(#[$align_attr])*, $($init)*);
-    },
 }
 
 #[rustc_macro_transparency = "semitransparent"]
diff --git a/library/std/src/sys/thread_local/no_threads.rs b/library/std/src/sys/thread_local/no_threads.rs
index 4d6a4464cfa..409dfb19518 100644
--- a/library/std/src/sys/thread_local/no_threads.rs
+++ b/library/std/src/sys/thread_local/no_threads.rs
@@ -39,11 +39,6 @@ pub macro thread_local_inner {
             })
         }
     }},
-
-    ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $(#[$align_attr:meta])*, $($init:tt)*) => {
-        $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> =
-            $crate::thread::local_impl::thread_local_inner!(@key $t, $(#[$align_attr])*, $($init)*);
-    },
 }
 
 #[allow(missing_debug_implementations)]
diff --git a/library/std/src/sys/thread_local/os.rs b/library/std/src/sys/thread_local/os.rs
index 77746b203a3..b488f12fe84 100644
--- a/library/std/src/sys/thread_local/os.rs
+++ b/library/std/src/sys/thread_local/os.rs
@@ -85,11 +85,6 @@ pub macro thread_local_inner {
 
         $($crate::thread::local_impl::thread_local_inner!(@align $final_align, $($attr_rest)+);)?
     },
-
-    ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $(#[$($align_attr:tt)*])*, $($init:tt)*) => {
-        $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> =
-            $crate::thread::local_impl::thread_local_inner!(@key $t, $(#[$($align_attr)*])*, $($init)*);
-    },
 }
 
 /// Use a regular global static to store this key; the state provided will then be
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs
index 70df7e724ca..4259a4d1f3b 100644
--- a/library/std/src/thread/local.rs
+++ b/library/std/src/thread/local.rs
@@ -327,13 +327,17 @@ pub macro thread_local_process_attrs {
 
     // process `const` declaration and recurse
     ([$($align_attrs:tt)*] [$($other_attrs:tt)*]; $vis:vis static $name:ident: $t:ty = const $init:block $(; $($($rest:tt)+)?)?) => (
-        $crate::thread::local_impl::thread_local_inner!($($other_attrs)* $vis $name, $t, $($align_attrs)*, const $init);
+        $($other_attrs)* $vis const $name: $crate::thread::LocalKey<$t> =
+            $crate::thread::local_impl::thread_local_inner!(@key $t, $($align_attrs)*, const $init);
+
         $($($crate::thread::local_impl::thread_local_process_attrs!([] []; $($rest)+);)?)?
     ),
 
     // process non-`const` declaration and recurse
     ([$($align_attrs:tt)*] [$($other_attrs:tt)*]; $vis:vis static $name:ident: $t:ty = $init:expr $(; $($($rest:tt)+)?)?) => (
-        $crate::thread::local_impl::thread_local_inner!($($other_attrs)* $vis $name, $t, $($align_attrs)*, $init);
+        $($other_attrs)* $vis const $name: $crate::thread::LocalKey<$t> =
+            $crate::thread::local_impl::thread_local_inner!(@key $t, $($align_attrs)*, $init);
+
         $($($crate::thread::local_impl::thread_local_process_attrs!([] []; $($rest)+);)?)?
     ),
 }
diff --git a/tests/ui/macros/macro-local-data-key-priv.stderr b/tests/ui/macros/macro-local-data-key-priv.stderr
index e93bd11046d..8df1aec140d 100644
--- a/tests/ui/macros/macro-local-data-key-priv.stderr
+++ b/tests/ui/macros/macro-local-data-key-priv.stderr
@@ -9,7 +9,7 @@ note: the constant `baz` is defined here
    |
 LL |     thread_local!(static baz: f64 = 0.0);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
+   = note: this error originates in the macro `$crate::thread::local_impl::thread_local_process_attrs` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/thread-local/no-unstable.stderr b/tests/ui/thread-local/no-unstable.stderr
index fc2541894e7..fbcd804d917 100644
--- a/tests/ui/thread-local/no-unstable.stderr
+++ b/tests/ui/thread-local/no-unstable.stderr
@@ -10,7 +10,7 @@ LL | | }
    = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
    = note: the `#[rustc_dummy]` attribute is an internal implementation detail that will never be stable
    = note: the `#[rustc_dummy]` attribute is used for rustc unit tests
-   = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
+   = note: this error originates in the macro `$crate::thread::local_impl::thread_local_process_attrs` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error[E0658]: use of an internal attribute
   --> $DIR/no-unstable.rs:1:1
@@ -38,7 +38,7 @@ LL | | }
    = note: see issue #93798 <https://github.com/rust-lang/rust/issues/93798> for more information
    = help: add `#![feature(used_with_arg)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-   = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
+   = note: this error originates in the macro `$crate::thread::local_impl::thread_local_process_attrs` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: `#[used]` attribute cannot be used on constants
   --> $DIR/no-unstable.rs:1:1
@@ -50,7 +50,7 @@ LL | | }
    | |_^
    |
    = help: `#[used]` can only be applied to statics
-   = note: this error originates in the macro `$crate::thread::local_impl::thread_local_inner` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
+   = note: this error originates in the macro `$crate::thread::local_impl::thread_local_process_attrs` which comes from the expansion of the macro `thread_local` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to 4 previous errors