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 1
1
extern crate std;
2
2
3
3
use self :: std:: prelude:: v1:: * ;
4
- use self :: std:: cell:: UnsafeCell ;
5
4
use self :: std:: sync:: { Once , ONCE_INIT } ;
6
5
7
- pub struct Lazy < T : Sync > ( UnsafeCell < Option < T > > , Once ) ;
6
+ pub struct Lazy < T : Sync > ( Option < T > , Once ) ;
8
7
9
8
impl < T : Sync > Lazy < T > {
10
9
#[ inline( always) ]
11
10
pub const fn new ( ) -> Self {
12
- Lazy ( UnsafeCell :: new ( None ) , ONCE_INIT )
11
+ Lazy ( None , ONCE_INIT )
13
12
}
14
13
15
14
#[ inline( always) ]
16
- pub fn get < F > ( & ' static self , f : F ) -> & T
15
+ pub fn get < F > ( & ' static mut self , f : F ) -> & T
17
16
where F : FnOnce ( ) -> T
18
17
{
19
- unsafe {
18
+ {
19
+ let r = & mut self . 0 ;
20
20
self . 1 . call_once ( || {
21
- * self . 0 . get ( ) = Some ( f ( ) ) ;
21
+ * r = Some ( f ( ) ) ;
22
22
} ) ;
23
-
24
- match * self . 0 . get ( ) {
23
+ }
24
+ unsafe {
25
+ match self . 0 {
25
26
Some ( ref x) => x,
26
27
None => std:: intrinsics:: unreachable ( ) ,
27
28
}
@@ -35,6 +36,6 @@ unsafe impl<T: Sync> Sync for Lazy<T> {}
35
36
#[ allow_internal_unstable]
36
37
macro_rules! __lazy_static_create {
37
38
( $NAME: ident, $T: ty) => {
38
- static $NAME: $crate:: lazy:: Lazy <$T> = $crate:: lazy:: Lazy :: new( ) ;
39
+ static mut $NAME: $crate:: lazy:: Lazy <$T> = $crate:: lazy:: Lazy :: new( ) ;
39
40
}
40
41
}
You can’t perform that action at this time.
0 commit comments