Avoid shadowing user provided types or type aliases in thread_local!
· qinheping/verify-rust-std@a6e300e (original) (raw)
`@@ -49,20 +49,21 @@ pub use lazy::Storage as LazyStorage;
`
49
49
`#[unstable(feature = "thread_local_internals", issue = "none")]
`
50
50
`#[rustc_macro_transparency = "semitransparent"]
`
51
51
`pub macro thread_local_inner {
`
52
``
`` -
// used to generate the LocalKey
value for const-initialized thread locals
``
``
52
`` +
// NOTE: we cannot import LocalKey
, LazyStorage
or EagerStorage
with a use
because that
``
``
53
`+
// can shadow user provided type or type alias with a matching name. Please update the shadowing
`
``
54
`` +
// test in tests/thread.rs
if these types are renamed.
``
``
55
+
``
56
`` +
// Used to generate the LocalKey
value for const-initialized thread locals.
``
53
57
`(@key t:ty,constt:ty, const t:ty,constinit:expr) => {{
`
54
58
`const __INIT: t=t = t=init;
`
55
59
``
56
60
`unsafe {
`
57
``
`-
use $crate::mem::needs_drop;
`
58
``
`-
use $crate::thread::LocalKey;
`
59
``
`-
use $crate::thread::local_impl::EagerStorage;
`
60
``
-
61
``
`-
LocalKey::new(const {
`
62
``
`-
if needs_drop::<$t>() {
`
``
61
`+
$crate::thread::LocalKey::new(const {
`
``
62
`+
if crate::mem::needsdrop::<crate::mem::needs_drop::<crate::mem::needsdrop::<t>() {
`
63
63
` |_| {
`
64
64
`#[thread_local]
`
65
``
`-
static VAL: EagerStorage<$t> = EagerStorage::new(__INIT);
`
``
65
`+
static VAL: crate::thread::localimpl::EagerStorage<crate::thread::local_impl::EagerStorage<crate::thread::localimpl::EagerStorage<t>
`
``
66
`+
= $crate::thread::local_impl::EagerStorage::new(__INIT);
`
66
67
`VAL.get()
`
67
68
`}
`
68
69
`} else {
`
`@@ -84,21 +85,19 @@ pub macro thread_local_inner {
`
84
85
`}
`
85
86
``
86
87
`unsafe {
`
87
``
`-
use $crate::mem::needs_drop;
`
88
``
`-
use $crate::thread::LocalKey;
`
89
``
`-
use $crate::thread::local_impl::LazyStorage;
`
90
``
-
91
``
`-
LocalKey::new(const {
`
92
``
`-
if needs_drop::<$t>() {
`
``
88
`+
$crate::thread::LocalKey::new(const {
`
``
89
`+
if crate::mem::needsdrop::<crate::mem::needs_drop::<crate::mem::needsdrop::<t>() {
`
93
90
` |init| {
`
94
91
`#[thread_local]
`
95
``
`-
static VAL: LazyStorage<$t, ()> = LazyStorage::new();
`
``
92
`+
static VAL: crate::thread::localimpl::LazyStorage<crate::thread::local_impl::LazyStorage<crate::thread::localimpl::LazyStorage<t, ()>
`
``
93
`+
= $crate::thread::local_impl::LazyStorage::new();
`
96
94
`VAL.get_or_init(init, __init)
`
97
95
`}
`
98
96
`} else {
`
99
97
` |init| {
`
100
98
`#[thread_local]
`
101
``
`-
static VAL: LazyStorage<$t, !> = LazyStorage::new();
`
``
99
`+
static VAL: crate::thread::localimpl::LazyStorage<crate::thread::local_impl::LazyStorage<crate::thread::localimpl::LazyStorage<t, !>
`
``
100
`+
= $crate::thread::local_impl::LazyStorage::new();
`
102
101
`VAL.get_or_init(init, __init)
`
103
102
`}
`
104
103
`}
`