Skip to content

Commit 38a2fdb

Browse files
committed
Fixed bug and written test for initialize()
1 parent 90abea9 commit 38a2fdb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ macro_rules! __lazy_static_internal {
132132
}
133133
impl $crate::LazyStatic for $N {
134134
fn initialize(lazy: &Self) {
135-
let _ = &*lazy;
135+
let _ = &**lazy;
136136
}
137137
}
138138
__lazy_static_internal!($($t)*);

tests/test.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,23 @@ lazy_static! {
127127
fn item_name_shadowing() {
128128
assert_eq!(*ITEM_NAME_TEST, X);
129129
}
130+
131+
use std::sync::atomic::AtomicBool;
132+
use std::sync::atomic::ATOMIC_BOOL_INIT;
133+
use std::sync::atomic::Ordering::SeqCst;
134+
135+
static PRE_INIT_FLAG: AtomicBool = ATOMIC_BOOL_INIT;
136+
137+
lazy_static! {
138+
static ref PRE_INIT: () = {
139+
PRE_INIT_FLAG.store(true, SeqCst);
140+
()
141+
};
142+
}
143+
144+
#[test]
145+
fn pre_init() {
146+
assert_eq!(PRE_INIT_FLAG.load(SeqCst), false);
147+
lazy_static::initialize(&PRE_INIT);
148+
assert_eq!(PRE_INIT_FLAG.load(SeqCst), true);
149+
}

0 commit comments

Comments
 (0)