Skip to content

Commit 462f63e

Browse files
committed
Rollup merge of rust-lang#55597 - alexcrichton:thread-local-inner, r=KodrAus
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.
2 parents 1525b0e + ff5226c commit 462f63e

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
@@ -146,13 +146,13 @@ macro_rules! thread_local {
146146

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

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

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

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)