File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 88extern crate std;
99
1010use self :: std:: prelude:: v1:: * ;
11- use self :: std:: cell:: UnsafeCell ;
1211use self :: std:: sync:: { Once , ONCE_INIT } ;
1312
14- pub struct Lazy < T : Sync > ( UnsafeCell < Option < T > > , Once ) ;
13+ pub struct Lazy < T : Sync > ( Option < T > , Once ) ;
1514
1615impl < T : Sync > Lazy < T > {
1716 #[ inline( always) ]
1817 pub const fn new ( ) -> Self {
19- Lazy ( UnsafeCell :: new ( None ) , ONCE_INIT )
18+ Lazy ( None , ONCE_INIT )
2019 }
2120
2221 #[ inline( always) ]
23- pub fn get < F > ( & ' static self , f : F ) -> & T
22+ pub fn get < F > ( & ' static mut self , f : F ) -> & T
2423 where F : FnOnce ( ) -> T
2524 {
26- unsafe {
25+ {
26+ let r = & mut self . 0 ;
2727 self . 1 . call_once ( || {
28- * self . 0 . get ( ) = Some ( f ( ) ) ;
28+ * r = Some ( f ( ) ) ;
2929 } ) ;
30-
31- match * self . 0 . get ( ) {
30+ }
31+ unsafe {
32+ match self . 0 {
3233 Some ( ref x) => x,
3334 None => std:: intrinsics:: unreachable ( ) ,
3435 }
@@ -43,6 +44,6 @@ unsafe impl<T: Sync> Sync for Lazy<T> {}
4344#[ doc( hidden) ]
4445macro_rules! __lazy_static_create {
4546 ( $NAME: ident, $T: ty) => {
46- static $NAME: $crate:: lazy:: Lazy <$T> = $crate:: lazy:: Lazy :: new( ) ;
47+ static mut $NAME: $crate:: lazy:: Lazy <$T> = $crate:: lazy:: Lazy :: new( ) ;
4748 }
4849}
You can’t perform that action at this time.
0 commit comments