@@ -69,7 +69,13 @@ The `Deref` implementation uses a hidden static variable that is guarded by a at
6969*/
7070
7171#![ cfg_attr( feature="nightly" , feature( const_fn, core_intrinsics) ) ]
72- #![ crate_type = "dylib" ]
72+
73+ #[ cfg( not( feature="nightly" ) ) ]
74+ pub mod lazy;
75+
76+ #[ cfg( feature="nightly" ) ]
77+ #[ path="nightly_lazy.rs" ]
78+ pub mod lazy;
7379
7480#[ macro_export]
7581macro_rules! lazy_static {
@@ -84,52 +90,15 @@ macro_rules! lazy_static {
8490 impl :: std:: ops:: Deref for $N {
8591 type Target = $T;
8692 fn deref<' a>( & ' a self ) -> & ' a $T {
87- #[ inline( always) ]
88- fn __static_ref_initialize( ) -> $T { $e }
89-
9093 unsafe {
91- use std:: sync:: { Once , ONCE_INIT } ;
92-
93- #[ inline( always) ]
94- fn require_sync<T : Sync >( _: & T ) { }
95-
9694 #[ inline( always) ]
97- #[ cfg( feature="nightly" ) ]
98- unsafe fn __stability( ) -> & ' static $T {
99- use std:: cell:: UnsafeCell ;
100-
101- struct SyncCell ( UnsafeCell <Option <$T>>) ;
102- unsafe impl Sync for SyncCell { }
103-
104- static DATA : SyncCell = SyncCell ( UnsafeCell :: new( None ) ) ;
105- static ONCE : Once = ONCE_INIT ;
106- ONCE . call_once( || {
107- * DATA . 0 . get( ) = Some ( __static_ref_initialize( ) ) ;
108- } ) ;
109- match * DATA . 0 . get( ) {
110- Some ( ref x) => x,
111- None => :: std:: intrinsics:: unreachable( ) ,
112- }
113- }
95+ fn __static_ref_initialize( ) -> $T { $e }
11496
115- #[ inline( always) ]
116- #[ cfg( not( feature="nightly" ) ) ]
11797 unsafe fn __stability( ) -> & ' static $T {
118- use std:: mem:: transmute;
119- use std:: boxed:: Box ;
120-
121- static mut DATA : * const $T = 0 as * const $T;
122- static mut ONCE : Once = ONCE_INIT ;
123- ONCE . call_once( || {
124- DATA = transmute:: <Box <$T>, * const $T>(
125- Box :: new( __static_ref_initialize( ) ) ) ;
126- } ) ;
127- & * DATA
98+ lazy_static_create!( LAZY , $T) ;
99+ LAZY . get( __static_ref_initialize)
128100 }
129-
130- let static_ref = __stability( ) ;
131- require_sync( static_ref) ;
132- static_ref
101+ __stability( )
133102 }
134103 }
135104 }
0 commit comments