@@ -192,7 +192,7 @@ macro_rules! __thread_local_inner {
192192 static __KEY: $crate:: thread:: __OsLocalKeyInner<$t> =
193193 $crate:: thread:: __OsLocalKeyInner:: new( ) ;
194194
195- unsafe fn __getit( ) -> & ' static Option <$t> { __KEY. get( ) }
195+ unsafe fn __getit( ) -> & ' static $crate :: option :: Option <$t> { __KEY. get( ) }
196196
197197 unsafe fn __get_state( ) -> $crate:: thread:: LocalKeyState { __KEY. get_state( ) }
198198
@@ -504,39 +504,33 @@ pub mod fast {
504504 }
505505 }
506506
507- pub fn get ( & self ) -> & ' static Option < T > {
508- unsafe { & * self . inner . get ( ) }
507+ pub unsafe fn get ( & self ) -> & ' static Option < T > {
508+ & * self . inner . get ( )
509509 }
510510
511- pub fn get_state ( & self ) -> LocalKeyState {
512- unsafe { * self . state . get ( ) }
511+ pub unsafe fn get_state ( & self ) -> LocalKeyState {
512+ * self . state . get ( )
513513 }
514514
515- pub fn pre_init ( & self ) {
516- unsafe {
517- // It's critical that we set the state to Initializing before
518- // registering destructors - if registering destructors causes
519- // allocation, and the global allocator uses TLS, then the
520- // allocator needs to be able to detect that the TLS is in
521- // the Initializing state and perform appropriate fallback
522- // logic rather than recursing infinitely.
523- * self . state . get ( ) = LocalKeyState :: Initializing ;
524- self . register_dtor ( ) ;
525- }
515+ pub unsafe fn pre_init ( & self ) {
516+ // It's critical that we set the state to Initializing before
517+ // registering destructors - if registering destructors causes
518+ // allocation, and the global allocator uses TLS, then the
519+ // allocator needs to be able to detect that the TLS is in
520+ // the Initializing state and perform appropriate fallback
521+ // logic rather than recursing infinitely.
522+ * self . state . get ( ) = LocalKeyState :: Initializing ;
523+ self . register_dtor ( ) ;
526524 }
527525
528- pub fn post_init ( & self , val : T ) {
529- unsafe {
530- * self . inner . get ( ) = Some ( val) ;
531- * self . state . get ( ) = LocalKeyState :: Valid ;
532- }
526+ pub unsafe fn post_init ( & self , val : T ) {
527+ * self . inner . get ( ) = Some ( val) ;
528+ * self . state . get ( ) = LocalKeyState :: Valid ;
533529 }
534530
535- pub fn rollback_init ( & self ) {
536- unsafe {
537- * self . inner . get ( ) = None ;
538- * self . state . get ( ) = LocalKeyState :: Uninitialized ;
539- }
531+ pub unsafe fn rollback_init ( & self ) {
532+ * self . inner . get ( ) = None ;
533+ * self . state . get ( ) = LocalKeyState :: Uninitialized ;
540534 }
541535
542536 unsafe fn register_dtor ( & self ) {
@@ -605,54 +599,46 @@ pub mod os {
605599 }
606600 }
607601
608- pub fn get ( & self ) -> & ' static Option < T > {
609- unsafe {
610- match * self . state . get ( ) {
611- LocalKeyState :: Valid => {
612- // Since the state is Valid, we know that os points to
613- // an allocated Value<T>.
614- let ptr = self . os . get ( ) as * mut Value < T > ;
615- debug_assert ! ( !ptr. is_null( ) ) ;
616- & * ( * ptr) . value . get ( )
617- }
618- _ => {
619- // The dummy_value is guaranteed to always be None. This
620- // allows us to avoid allocating if the state isn't Valid.
621- // This is critical because it means that an allocator can
622- // call try_with and detect that the key is in state
623- // Initializing without recursing infinitely.
624- & * self . dummy_value . get ( )
625- }
602+ pub unsafe fn get ( & self ) -> & ' static Option < T > {
603+ match * self . state . get ( ) {
604+ LocalKeyState :: Valid => {
605+ // Since the state is Valid, we know that os points to
606+ // an allocated Value<T>.
607+ let ptr = self . os . get ( ) as * mut Value < T > ;
608+ debug_assert ! ( !ptr. is_null( ) ) ;
609+ & * ( * ptr) . value . get ( )
610+ }
611+ _ => {
612+ // The dummy_value is guaranteed to always be None. This
613+ // allows us to avoid allocating if the state isn't Valid.
614+ // This is critical because it means that an allocator can
615+ // call try_with and detect that the key is in state
616+ // Initializing without recursing infinitely.
617+ & * self . dummy_value . get ( )
626618 }
627619 }
628620 }
629621
630- pub fn get_state ( & self ) -> LocalKeyState {
631- unsafe { * self . state . get ( ) }
622+ pub unsafe fn get_state ( & self ) -> LocalKeyState {
623+ * self . state . get ( )
632624 }
633625
634- pub fn pre_init ( & self ) {
635- unsafe {
636- * self . state . get ( ) = LocalKeyState :: Initializing ;
637- }
626+ pub unsafe fn pre_init ( & self ) {
627+ * self . state . get ( ) = LocalKeyState :: Initializing ;
638628 }
639629
640- pub fn rollback_init ( & self ) {
641- unsafe {
642- * self . state . get ( ) = LocalKeyState :: Uninitialized ;
643- }
630+ pub unsafe fn rollback_init ( & self ) {
631+ * self . state . get ( ) = LocalKeyState :: Uninitialized ;
644632 }
645633
646- pub fn post_init ( & self , val : T ) {
647- unsafe {
648- let ptr: Box < Value < T > > = box Value {
649- key : & * ( self as * const _ ) ,
650- value : UnsafeCell :: new ( Some ( val) ) ,
651- } ;
652- let ptr = Box :: into_raw ( ptr) ;
653- self . os . set ( ptr as * mut u8 ) ;
654- * self . state . get ( ) = LocalKeyState :: Valid ;
655- }
634+ pub unsafe fn post_init ( & self , val : T ) {
635+ let ptr: Box < Value < T > > = box Value {
636+ key : & * ( self as * const _ ) ,
637+ value : UnsafeCell :: new ( Some ( val) ) ,
638+ } ;
639+ let ptr = Box :: into_raw ( ptr) ;
640+ self . os . set ( ptr as * mut u8 ) ;
641+ * self . state . get ( ) = LocalKeyState :: Valid ;
656642 }
657643 }
658644
0 commit comments