Skip to content

Commit 1a18c65

Browse files
committed
Patch obscure soundness issue in the inline lazy impl.
1 parent 28cc070 commit 1a18c65

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/inline_lazy.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77

8-
extern crate std;
98
extern crate core;
9+
extern crate std;
1010

1111
use self::std::prelude::v1::*;
1212
use self::std::sync::Once;
1313
pub use self::std::sync::ONCE_INIT;
1414

15-
pub struct Lazy<T: Sync>(pub Option<T>, pub Once);
15+
pub struct Lazy<T: Sync>(Option<T>, Once);
1616

1717
impl<T: Sync> Lazy<T> {
18+
pub const INIT: Self = Lazy(None, ONCE_INIT);
19+
1820
#[inline(always)]
1921
pub fn get<F>(&'static mut self, f: F) -> &T
20-
where F: FnOnce() -> T
22+
where
23+
F: FnOnce() -> T,
2124
{
2225
{
2326
let r = &mut self.0;
@@ -40,6 +43,6 @@ unsafe impl<T: Sync> Sync for Lazy<T> {}
4043
#[doc(hidden)]
4144
macro_rules! __lazy_static_create {
4245
($NAME:ident, $T:ty) => {
43-
static mut $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy(None, $crate::lazy::ONCE_INIT);
44-
}
46+
static mut $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy::INIT;
47+
};
4548
}

0 commit comments

Comments
 (0)