diff --git a/src/librustc_metadata/dynamic_lib.rs b/src/librustc_metadata/dynamic_lib.rs index 9dd160c24c3..395270f5bb5 100644 --- a/src/librustc_metadata/dynamic_lib.rs +++ b/src/librustc_metadata/dynamic_lib.rs @@ -161,8 +161,8 @@ unsafe fn open_internal() -> *mut u8 { pub fn check_for_errors_in(f: F) -> Result where F: FnOnce() -> T, { - use std::sync::{Mutex, Once, ONCE_INIT}; - static INIT: Once = ONCE_INIT; + use std::sync::{Mutex, Once}; + static INIT: Once = Once::new(); static mut LOCK: *mut Mutex<()> = 0 as *mut _; unsafe { INIT.call_once(|| { diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index 809ee882698..fd6e46fd61d 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -163,6 +163,7 @@ #[stable(feature = "rust1", since = "1.0.0")] pub use self::mutex::{Mutex, MutexGuard}; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated)] pub use self::once::{Once, OnceState, ONCE_INIT}; #[stable(feature = "rust1", since = "1.0.0")] pub use crate::sys_common::poison::{PoisonError, TryLockError, TryLockResult, LockResult}; diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 0c912494024..e529b8c4227 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -115,6 +115,11 @@ pub struct OnceState { /// static START: Once = ONCE_INIT; /// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated( + since = "1.38.0", + reason = "the `new` function is now preferred", + suggestion = "Once::new()", +)] pub const ONCE_INIT: Once = Once::new(); // Four states that a Once can be in, encoded into the lower bits of `state` in diff --git a/src/test/run-pass/issues/issue-39367.rs b/src/test/run-pass/issues/issue-39367.rs index 484cd782a09..2e2b480e066 100644 --- a/src/test/run-pass/issues/issue-39367.rs +++ b/src/test/run-pass/issues/issue-39367.rs @@ -11,13 +11,13 @@ fn __static_ref_initialize() -> ArenaSet> { ArenaSet(vec![], &Z) } unsafe { - use std::sync::{Once, ONCE_INIT}; + use std::sync::Once; fn require_sync(_: &T) { } unsafe fn __stability() -> &'static ArenaSet> { use std::mem::transmute; static mut DATA: *const ArenaSet> = 0 as *const ArenaSet>; - static mut ONCE: Once = ONCE_INIT; + static mut ONCE: Once = Once::new(); ONCE.call_once(|| { DATA = transmute ::>>, *const ArenaSet>>