@@ -60,7 +60,7 @@ pub mod __impl {
60
60
#[ unstable( feature = "scoped_tls" ,
61
61
reason = "scoped TLS has yet to have wide enough use to fully consider \
62
62
stabilizing its interface") ]
63
- pub struct ScopedKey < T > { #[ doc( hidden) ] pub inner : __impl:: KeyInner < T > }
63
+ pub struct ScopedKey < T : ? Sized > { #[ doc( hidden) ] pub inner : __impl:: KeyInner < * const T > }
64
64
65
65
/// Declare a new scoped thread local storage key.
66
66
///
@@ -123,7 +123,7 @@ macro_rules! __scoped_thread_local_inner {
123
123
const _INIT: __Key<$t> = __Key {
124
124
inner: :: std:: thread:: __scoped:: KeyInner {
125
125
inner: :: std:: thread:: __scoped:: OS_INIT ,
126
- marker: :: std:: marker:: PhantomData :: <:: std:: cell:: Cell < $t>>,
126
+ marker: :: std:: marker:: PhantomData :: <:: std:: cell:: UnsafeCell < * const $t>>,
127
127
}
128
128
} ;
129
129
@@ -134,7 +134,7 @@ macro_rules! __scoped_thread_local_inner {
134
134
#[ unstable( feature = "scoped_tls" ,
135
135
reason = "scoped TLS has yet to have wide enough use to fully consider \
136
136
stabilizing its interface") ]
137
- impl < T > ScopedKey < T > {
137
+ impl < T : ? Sized > ScopedKey < T > {
138
138
/// Inserts a value into this scoped thread local storage slot for a
139
139
/// duration of a closure.
140
140
///
@@ -167,19 +167,20 @@ impl<T> ScopedKey<T> {
167
167
pub fn set < R , F > ( & ' static self , t : & T , cb : F ) -> R where
168
168
F : FnOnce ( ) -> R ,
169
169
{
170
- struct Reset < ' a , T : ' a > {
171
- key : & ' a __impl:: KeyInner < T > ,
172
- val : * mut T ,
170
+ struct Reset < ' a , T : ' a + ? Sized > {
171
+ key : & ' a __impl:: KeyInner < * const T > ,
172
+ val : * mut * const T ,
173
173
}
174
- impl < ' a , T > Drop for Reset < ' a , T > {
174
+ impl < ' a , T : ? Sized > Drop for Reset < ' a , T > {
175
175
fn drop ( & mut self ) {
176
176
unsafe { self . key . set ( self . val ) }
177
177
}
178
178
}
179
179
180
+ let mut pt = t as * const _ ;
180
181
let prev = unsafe {
181
182
let prev = self . inner . get ( ) ;
182
- self . inner . set ( t as * const T as * mut T ) ;
183
+ self . inner . set ( & mut pt ) ;
183
184
prev
184
185
} ;
185
186
@@ -213,7 +214,7 @@ impl<T> ScopedKey<T> {
213
214
let ptr = self . inner . get ( ) ;
214
215
assert ! ( !ptr. is_null( ) , "cannot access a scoped thread local \
215
216
variable without calling `set` first") ;
216
- cb ( & * ptr)
217
+ cb ( & * * ptr)
217
218
}
218
219
}
219
220
@@ -252,13 +253,13 @@ mod imp {
252
253
target_arch = "aarch64" ) ) ]
253
254
mod imp {
254
255
use marker;
255
- use std:: cell:: Cell ;
256
+ use std:: cell:: UnsafeCell ;
256
257
use sys_common:: thread_local:: StaticKey as OsStaticKey ;
257
258
258
259
#[ doc( hidden) ]
259
260
pub struct KeyInner < T > {
260
261
pub inner : OsStaticKey ,
261
- pub marker : marker:: PhantomData < Cell < T > > ,
262
+ pub marker : marker:: PhantomData < UnsafeCell < T > > ,
262
263
}
263
264
264
265
unsafe impl < T > :: marker:: Sync for KeyInner < T > { }
0 commit comments