@@ -132,6 +132,44 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
132
132
}
133
133
}
134
134
135
+ #[ doc( hidden) ]
136
+ #[ allow_internal_unstable( thread_local_internals) ]
137
+ #[ unstable( feature = "thread_local_internals" , issue = "none" ) ]
138
+ #[ rustc_macro_transparency = "semitransparent" ]
139
+ pub macro thread_local_process_attrs {
140
+ // separate attributes into `rustc_align_static` and everything else
141
+
142
+ ( [ $( $prev_align_attrs: tt) * ] [ $( $prev_other_attrs: tt) * ] #[ rustc_align_static $( $attr_rest: tt) * ] $( $tt: tt) * ) => (
143
+ $crate:: thread:: local_impl:: thread_local_process_attrs!( [ $( $prev_align_attrs) * #[ rustc_align_static $( $attr_rest) * ] ] [ $( $prev_other_attrs) * ] $( $tt) * ) ;
144
+ ) ,
145
+
146
+ ( [ $( $prev_align_attrs: tt) * ] [ $( $prev_other_attrs: tt) * ] #[ $attr: meta] $( $tt: tt) * ) => (
147
+ $crate:: thread:: local_impl:: thread_local_process_attrs!( [ $( $prev_align_attrs) * ] [ $( $prev_other_attrs) * #[ $attr] ] $( $tt) * ) ;
148
+ ) ,
149
+
150
+ // delegate to `thread_local_inner` once attributes are categorized
151
+
152
+ ( [ $( $align_attrs: tt) * ] [ $( $other_attrs: tt) * ] $vis: vis static $name: ident: $t: ty = const $init: block; $( $rest: tt) * ) => (
153
+ $crate:: thread:: local_impl:: thread_local_inner!( $( $other_attrs) * $vis $name, $t, $( $align_attrs) * , const $init) ;
154
+ $crate:: thread_local!( $( $rest) * ) ;
155
+ ) ,
156
+
157
+ ( [ $( $align_attrs: tt) * ] [ $( $other_attrs: tt) * ] $vis: vis static $name: ident: $t: ty = const $init: block) => (
158
+ $crate:: thread:: local_impl:: thread_local_inner!( $( $other_attrs) * $vis $name, $t, $( $align_attrs) * , const $init) ;
159
+ ) ,
160
+
161
+ // process multiple declarations
162
+ ( [ $( $align_attrs: tt) * ] [ $( $other_attrs: tt) * ] $vis: vis static $name: ident: $t: ty = $init: expr; $( $rest: tt) * ) => (
163
+ $crate:: thread:: local_impl:: thread_local_inner!( $( $other_attrs) * $vis $name, $t, $( $align_attrs) * , $init) ;
164
+ $crate:: thread_local!( $( $rest) * ) ;
165
+ ) ,
166
+
167
+ // handle a single declaration
168
+ ( [ $( $align_attrs: tt) * ] [ $( $other_attrs: tt) * ] $vis: vis static $name: ident: $t: ty = $init: expr) => (
169
+ $crate:: thread:: local_impl:: thread_local_inner!( $( $other_attrs) * $vis $name, $t, $( $align_attrs) * , $init) ;
170
+ ) ,
171
+ }
172
+
135
173
/// Declare a new thread local storage key of type [`std::thread::LocalKey`].
136
174
///
137
175
/// # Syntax
@@ -185,25 +223,9 @@ macro_rules! thread_local {
185
223
// empty (base case for the recursion)
186
224
( ) => { } ;
187
225
188
- ( $( #[ $attr: meta] ) * $vis: vis static $name: ident: $t: ty = const $init: block; $( $rest: tt) * ) => (
189
- $crate:: thread:: local_impl:: thread_local_inner!( $( #[ $attr] ) * $vis $name, $t, const $init) ;
190
- $crate:: thread_local!( $( $rest) * ) ;
191
- ) ;
192
-
193
- ( $( #[ $attr: meta] ) * $vis: vis static $name: ident: $t: ty = const $init: block) => (
194
- $crate:: thread:: local_impl:: thread_local_inner!( $( #[ $attr] ) * $vis $name, $t, const $init) ;
195
- ) ;
196
-
197
- // process multiple declarations
198
- ( $( #[ $attr: meta] ) * $vis: vis static $name: ident: $t: ty = $init: expr; $( $rest: tt) * ) => (
199
- $crate:: thread:: local_impl:: thread_local_inner!( $( #[ $attr] ) * $vis $name, $t, $init) ;
200
- $crate:: thread_local!( $( $rest) * ) ;
201
- ) ;
202
-
203
- // handle a single declaration
204
- ( $( #[ $attr: meta] ) * $vis: vis static $name: ident: $t: ty = $init: expr) => (
205
- $crate:: thread:: local_impl:: thread_local_inner!( $( #[ $attr] ) * $vis $name, $t, $init) ;
206
- ) ;
226
+ ( $( $tt: tt) * ) => {
227
+ $crate:: thread:: local_impl:: thread_local_process_attrs!( [ ] [ ] $( $tt) * ) ;
228
+ } ;
207
229
}
208
230
209
231
/// An error returned by [`LocalKey::try_with`](struct.LocalKey.html#method.try_with).
0 commit comments