@@ -49,20 +49,21 @@ pub use lazy::Storage as LazyStorage;
4949#[ unstable( feature = "thread_local_internals" , issue = "none" ) ]
5050#[ rustc_macro_transparency = "semitransparent" ]
5151pub 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.
5357 ( @key $t: ty, const $init: expr) => { {
5458 const __INIT: $t = $init;
5559
5660 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:: needs_drop :: < $t> ( ) {
6363 |_| {
6464 #[ thread_local]
65- static VAL : EagerStorage < $t> = EagerStorage :: new ( __INIT) ;
65+ static VAL : $crate:: thread:: local_impl:: EagerStorage < $t>
66+ = $crate:: thread:: local_impl:: EagerStorage :: new ( __INIT) ;
6667 VAL . get ( )
6768 }
6869 } else {
@@ -84,21 +85,19 @@ pub macro thread_local_inner {
8485 }
8586
8687 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:: needs_drop :: < $t> ( ) {
9390 |init| {
9491 #[ thread_local]
95- static VAL : LazyStorage < $t, ( ) > = LazyStorage :: new ( ) ;
92+ static VAL : $crate:: thread:: local_impl:: LazyStorage < $t, ( ) >
93+ = $crate:: thread:: local_impl:: LazyStorage :: new ( ) ;
9694 VAL . get_or_init ( init, __init)
9795 }
9896 } else {
9997 |init| {
10098 #[ thread_local]
101- static VAL : LazyStorage < $t, !> = LazyStorage :: new ( ) ;
99+ static VAL : $crate:: thread:: local_impl:: LazyStorage < $t, !>
100+ = $crate:: thread:: local_impl:: LazyStorage :: new ( ) ;
102101 VAL . get_or_init ( init, __init)
103102 }
104103 }
0 commit comments