Skip to content

Commit 4bcf433

Browse files
authored
Rollup merge of rust-lang#61757 - sfackler:deprecate-once-init, r=alexcrichton
Deprecate ONCE_INIT Once::new() has been a stable const fn for a while now. Closes rust-lang#61746
2 parents d61e2f2 + d5df2a8 commit 4bcf433

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

src/librustc_metadata/dynamic_lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ mod dl {
161161
pub fn check_for_errors_in<T, F>(f: F) -> Result<T, String> where
162162
F: FnOnce() -> T,
163163
{
164-
use std::sync::{Mutex, Once, ONCE_INIT};
165-
static INIT: Once = ONCE_INIT;
164+
use std::sync::{Mutex, Once};
165+
static INIT: Once = Once::new();
166166
static mut LOCK: *mut Mutex<()> = 0 as *mut _;
167167
unsafe {
168168
INIT.call_once(|| {

src/libstd/sync/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ pub use self::condvar::{Condvar, WaitTimeoutResult};
163163
#[stable(feature = "rust1", since = "1.0.0")]
164164
pub use self::mutex::{Mutex, MutexGuard};
165165
#[stable(feature = "rust1", since = "1.0.0")]
166+
#[allow(deprecated)]
166167
pub use self::once::{Once, OnceState, ONCE_INIT};
167168
#[stable(feature = "rust1", since = "1.0.0")]
168169
pub use crate::sys_common::poison::{PoisonError, TryLockError, TryLockResult, LockResult};

src/libstd/sync/once.rs

+5
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ pub struct OnceState {
115115
/// static START: Once = ONCE_INIT;
116116
/// ```
117117
#[stable(feature = "rust1", since = "1.0.0")]
118+
#[rustc_deprecated(
119+
since = "1.37.0",
120+
reason = "the `new` function is now preferred",
121+
suggestion = "Once::new()",
122+
)]
118123
pub const ONCE_INIT: Once = Once::new();
119124

120125
// Four states that a Once can be in, encoded into the lower bits of `state` in

src/test/run-pass/issues/issue-39367.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ fn arena() -> &'static ArenaSet<Vec<u8>> {
1111
ArenaSet(vec![], &Z)
1212
}
1313
unsafe {
14-
use std::sync::{Once, ONCE_INIT};
14+
use std::sync::Once;
1515
fn require_sync<T: Sync>(_: &T) { }
1616
unsafe fn __stability() -> &'static ArenaSet<Vec<u8>> {
1717
use std::mem::transmute;
1818
static mut DATA: *const ArenaSet<Vec<u8>> = 0 as *const ArenaSet<Vec<u8>>;
1919

20-
static mut ONCE: Once = ONCE_INIT;
20+
static mut ONCE: Once = Once::new();
2121
ONCE.call_once(|| {
2222
DATA = transmute
2323
::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>

0 commit comments

Comments
 (0)