Skip to content

Commit e0e598b

Browse files
authored
Rollup merge of #51056 - tbu-:pr_once_new, r=dtolnay
Mention and use `Once::new` instead of `ONCE_INIT`
2 parents 08b4170 + 2a900e2 commit e0e598b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/libstd/sync/once.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ use thread::{self, Thread};
7373
/// A synchronization primitive which can be used to run a one-time global
7474
/// initialization. Useful for one-time initialization for FFI or related
7575
/// functionality. This type can only be constructed with the [`ONCE_INIT`]
76-
/// value.
76+
/// value or the equivalent [`Once::new`] constructor.
7777
///
7878
/// [`ONCE_INIT`]: constant.ONCE_INIT.html
79+
/// [`Once::new`]: struct.Once.html#method.new
7980
///
8081
/// # Examples
8182
///
8283
/// ```
83-
/// use std::sync::{Once, ONCE_INIT};
84+
/// use std::sync::Once;
8485
///
85-
/// static START: Once = ONCE_INIT;
86+
/// static START: Once = Once::new();
8687
///
8788
/// START.call_once(|| {
8889
/// // run initialization here
@@ -180,10 +181,10 @@ impl Once {
180181
/// # Examples
181182
///
182183
/// ```
183-
/// use std::sync::{Once, ONCE_INIT};
184+
/// use std::sync::Once;
184185
///
185186
/// static mut VAL: usize = 0;
186-
/// static INIT: Once = ONCE_INIT;
187+
/// static INIT: Once = Once::new();
187188
///
188189
/// // Accessing a `static mut` is unsafe much of the time, but if we do so
189190
/// // in a synchronized fashion (e.g. write once or read all) then we're
@@ -248,10 +249,10 @@ impl Once {
248249
/// ```
249250
/// #![feature(once_poison)]
250251
///
251-
/// use std::sync::{Once, ONCE_INIT};
252+
/// use std::sync::Once;
252253
/// use std::thread;
253254
///
254-
/// static INIT: Once = ONCE_INIT;
255+
/// static INIT: Once = Once::new();
255256
///
256257
/// // poison the once
257258
/// let handle = thread::spawn(|| {
@@ -431,10 +432,10 @@ impl OnceState {
431432
/// ```
432433
/// #![feature(once_poison)]
433434
///
434-
/// use std::sync::{Once, ONCE_INIT};
435+
/// use std::sync::Once;
435436
/// use std::thread;
436437
///
437-
/// static INIT: Once = ONCE_INIT;
438+
/// static INIT: Once = Once::new();
438439
///
439440
/// // poison the once
440441
/// let handle = thread::spawn(|| {
@@ -452,9 +453,9 @@ impl OnceState {
452453
/// ```
453454
/// #![feature(once_poison)]
454455
///
455-
/// use std::sync::{Once, ONCE_INIT};
456+
/// use std::sync::Once;
456457
///
457-
/// static INIT: Once = ONCE_INIT;
458+
/// static INIT: Once = Once::new();
458459
///
459460
/// INIT.call_once_force(|state| {
460461
/// assert!(!state.poisoned());

0 commit comments

Comments
 (0)