Skip to content

Commit ff5226c

Browse files
committed
std: Enable usage of thread_local! through imports
The `thread_local!` macro delegated to an internal macro but it didn't do so in a macros-and-the-module-system compatible fashion, meaning if a `#![no_std]` crate imported `std` and tried to use `thread_local!` it would fail due to missing a lookup of an internal macro. This commit switches the macro to instead use `$crate` to invoke other macros, ensuring that it'll work when `thread_local!` is imported alone.
1 parent f6e9a6e commit ff5226c

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/libstd/thread/local.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ macro_rules! thread_local {
145145

146146
// process multiple declarations
147147
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => (
148-
__thread_local_inner!($(#[$attr])* $vis $name, $t, $init);
149-
thread_local!($($rest)*);
148+
$crate::__thread_local_inner!($(#[$attr])* $vis $name, $t, $init);
149+
$crate::thread_local!($($rest)*);
150150
);
151151

152152
// handle a single declaration
153153
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => (
154-
__thread_local_inner!($(#[$attr])* $vis $name, $t, $init);
154+
$crate::__thread_local_inner!($(#[$attr])* $vis $name, $t, $init);
155155
);
156156
}
157157

@@ -201,7 +201,7 @@ macro_rules! __thread_local_inner {
201201
};
202202
($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => {
203203
$(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> =
204-
__thread_local_inner!(@key $(#[$attr])* $vis $name, $t, $init);
204+
$crate::__thread_local_inner!(@key $(#[$attr])* $vis $name, $t, $init);
205205
}
206206
}
207207

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![no_std]
12+
13+
extern crate std;
14+
15+
std::thread_local!(static A: usize = 30);
16+
17+
fn main() {
18+
}

0 commit comments

Comments
 (0)