@@ -92,7 +92,7 @@ pub struct LocalKey<T: 'static> {
92
92
// trivially devirtualizable by LLVM because the value of `inner` never
93
93
// changes and the constant should be readonly within a crate. This mainly
94
94
// only runs into problems when TLS statics are exported across crates.
95
- inner : unsafe fn ( ) -> Option < & ' static UnsafeCell < Option < T > > > ,
95
+ inner : fn ( ) -> Option < & ' static UnsafeCell < Option < T > > > ,
96
96
97
97
// initialization routine to invoke to create a value
98
98
init : fn ( ) -> T ,
@@ -126,7 +126,7 @@ macro_rules! __thread_local_inner {
126
126
( $t: ty, $init: expr) => { {
127
127
fn __init( ) -> $t { $init }
128
128
129
- unsafe fn __getit( ) -> $crate:: option:: Option <
129
+ fn __getit( ) -> $crate:: option:: Option <
130
130
& ' static $crate:: cell:: UnsafeCell <
131
131
$crate:: option:: Option <$t>>>
132
132
{
@@ -183,7 +183,7 @@ impl<T: 'static> LocalKey<T> {
183
183
#[ unstable( feature = "thread_local_internals" ,
184
184
reason = "recently added to create a key" ,
185
185
issue = "0" ) ]
186
- pub const fn new ( inner : unsafe fn ( ) -> Option < & ' static UnsafeCell < Option < T > > > ,
186
+ pub const fn new ( inner : fn ( ) -> Option < & ' static UnsafeCell < Option < T > > > ,
187
187
init : fn ( ) -> T ) -> LocalKey < T > {
188
188
LocalKey {
189
189
inner : inner,
@@ -303,11 +303,13 @@ pub mod elf {
303
303
}
304
304
}
305
305
306
- pub unsafe fn get ( & ' static self ) -> Option < & ' static UnsafeCell < Option < T > > > {
307
- if intrinsics:: needs_drop :: < T > ( ) && self . dtor_running . get ( ) {
308
- return None
306
+ pub fn get ( & ' static self ) -> Option < & ' static UnsafeCell < Option < T > > > {
307
+ unsafe {
308
+ if intrinsics:: needs_drop :: < T > ( ) && self . dtor_running . get ( ) {
309
+ return None
310
+ }
311
+ self . register_dtor ( ) ;
309
312
}
310
- self . register_dtor ( ) ;
311
313
Some ( & self . inner )
312
314
}
313
315
@@ -452,24 +454,26 @@ pub mod os {
452
454
}
453
455
}
454
456
455
- pub unsafe fn get ( & ' static self ) -> Option < & ' static UnsafeCell < Option < T > > > {
456
- let ptr = self . os . get ( ) as * mut Value < T > ;
457
- if !ptr. is_null ( ) {
458
- if ptr as usize == 1 {
459
- return None
457
+ pub fn get ( & ' static self ) -> Option < & ' static UnsafeCell < Option < T > > > {
458
+ unsafe {
459
+ let ptr = self . os . get ( ) as * mut Value < T > ;
460
+ if !ptr. is_null ( ) {
461
+ if ptr as usize == 1 {
462
+ return None
463
+ }
464
+ return Some ( & ( * ptr) . value ) ;
460
465
}
461
- return Some ( & ( * ptr) . value ) ;
462
- }
463
466
464
- // If the lookup returned null, we haven't initialized our own local
465
- // copy, so do that now.
466
- let ptr: Box < Value < T > > = box Value {
467
- key : self ,
468
- value : UnsafeCell :: new ( None ) ,
469
- } ;
470
- let ptr = Box :: into_raw ( ptr) ;
471
- self . os . set ( ptr as * mut u8 ) ;
472
- Some ( & ( * ptr) . value )
467
+ // If the lookup returned null, we haven't initialized our own local
468
+ // copy, so do that now.
469
+ let ptr: Box < Value < T > > = box Value {
470
+ key : self ,
471
+ value : UnsafeCell :: new ( None ) ,
472
+ } ;
473
+ let ptr = Box :: into_raw ( ptr) ;
474
+ self . os . set ( ptr as * mut u8 ) ;
475
+ Some ( & ( * ptr) . value )
476
+ }
473
477
}
474
478
}
475
479
0 commit comments