Make the LocalKey facade of thread_local! inlineable cross-crate.
This commit is contained in:
parent
a3beb8fe61
commit
4e2be14986
@ -159,8 +159,9 @@ macro_rules! thread_local {
|
|||||||
#[allow_internal_unstable]
|
#[allow_internal_unstable]
|
||||||
#[allow_internal_unsafe]
|
#[allow_internal_unsafe]
|
||||||
macro_rules! __thread_local_inner {
|
macro_rules! __thread_local_inner {
|
||||||
($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => {
|
(@key $(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => {
|
||||||
$(#[$attr])* $vis static $name: $crate::thread::LocalKey<$t> = {
|
{
|
||||||
|
#[inline]
|
||||||
fn __init() -> $t { $init }
|
fn __init() -> $t { $init }
|
||||||
|
|
||||||
unsafe fn __getit() -> $crate::option::Option<
|
unsafe fn __getit() -> $crate::option::Option<
|
||||||
@ -182,7 +183,16 @@ macro_rules! __thread_local_inner {
|
|||||||
unsafe {
|
unsafe {
|
||||||
$crate::thread::LocalKey::new(__getit, __init)
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,5 +16,5 @@ mod bar {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
bar::baz.with(|_| ());
|
bar::baz.with(|_| ());
|
||||||
//~^ ERROR static `baz` is private
|
//~^ ERROR `baz` is private
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user