File tree 1 file changed +10
-9
lines changed
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 8
8
extern crate std;
9
9
10
10
use self :: std:: prelude:: v1:: * ;
11
- use self :: std:: cell:: UnsafeCell ;
12
11
use self :: std:: sync:: { Once , ONCE_INIT } ;
13
12
14
- pub struct Lazy < T : Sync > ( UnsafeCell < Option < T > > , Once ) ;
13
+ pub struct Lazy < T : Sync > ( Option < T > , Once ) ;
15
14
16
15
impl < T : Sync > Lazy < T > {
17
16
#[ inline( always) ]
18
17
pub const fn new ( ) -> Self {
19
- Lazy ( UnsafeCell :: new ( None ) , ONCE_INIT )
18
+ Lazy ( None , ONCE_INIT )
20
19
}
21
20
22
21
#[ inline( always) ]
23
- pub fn get < F > ( & ' static self , f : F ) -> & T
22
+ pub fn get < F > ( & ' static mut self , f : F ) -> & T
24
23
where F : FnOnce ( ) -> T
25
24
{
26
- unsafe {
25
+ {
26
+ let r = & mut self . 0 ;
27
27
self . 1 . call_once ( || {
28
- * self . 0 . get ( ) = Some ( f ( ) ) ;
28
+ * r = Some ( f ( ) ) ;
29
29
} ) ;
30
-
31
- match * self . 0 . get ( ) {
30
+ }
31
+ unsafe {
32
+ match self . 0 {
32
33
Some ( ref x) => x,
33
34
None => std:: intrinsics:: unreachable ( ) ,
34
35
}
@@ -43,6 +44,6 @@ unsafe impl<T: Sync> Sync for Lazy<T> {}
43
44
#[ doc( hidden) ]
44
45
macro_rules! __lazy_static_create {
45
46
( $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( ) ;
47
48
}
48
49
}
You can’t perform that action at this time.
0 commit comments