From 72e99f57c5118430361d23ed8e8815c1dd7271a5 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 11 Jun 2019 18:57:48 -0700 Subject: [PATCH] Deprecate ONCE_INIT Once::new() has been a stable const fn for a while now. Closes #61746 --- src/librustc_metadata/dynamic_lib.rs | 4 ++-- src/libstd/sync/mod.rs | 1 + src/libstd/sync/once.rs | 5 +++++ src/test/run-pass/issues/issue-39367.rs | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librustc_metadata/dynamic_lib.rs b/src/librustc_metadata/dynamic_lib.rs index 9dd160c24c373..395270f5bb53a 100644 --- a/src/librustc_metadata/dynamic_lib.rs +++ b/src/librustc_metadata/dynamic_lib.rs @@ -161,8 +161,8 @@ mod dl { 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 809ee8826981b..fd6e46fd61dc5 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -163,6 +163,7 @@ pub use self::condvar::{Condvar, WaitTimeoutResult}; #[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 0c91249402417..e529b8c4227fa 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 484cd782a09df..2e2b480e06602 100644 --- a/src/test/run-pass/issues/issue-39367.rs +++ b/src/test/run-pass/issues/issue-39367.rs @@ -11,13 +11,13 @@ fn arena() -> &'static 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>>