diff options
| author | Steven Fackler <sfackler@gmail.com> | 2019-06-11 18:57:48 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2019-06-12 21:32:51 -0700 |
| commit | 72e99f57c5118430361d23ed8e8815c1dd7271a5 (patch) | |
| tree | 0682ccd73686fb8b24aad5ce2d6ba44d23227fa0 | |
| parent | 5f3656ce9a2212fad872605b7a4ee103a155e9f3 (diff) | |
| download | rust-72e99f57c5118430361d23ed8e8815c1dd7271a5.tar.gz rust-72e99f57c5118430361d23ed8e8815c1dd7271a5.zip | |
Deprecate ONCE_INIT
Once::new() has been a stable const fn for a while now. Closes #61746
| -rw-r--r-- | src/librustc_metadata/dynamic_lib.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sync/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sync/once.rs | 5 | ||||
| -rw-r--r-- | 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 9dd160c24c3..395270f5bb5 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<T, F>(f: F) -> Result<T, String> 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 @@ 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 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 arena() -> &'static ArenaSet<Vec<u8>> { ArenaSet(vec![], &Z) } unsafe { - use std::sync::{Once, ONCE_INIT}; + use std::sync::Once; fn require_sync<T: Sync>(_: &T) { } unsafe fn __stability() -> &'static ArenaSet<Vec<u8>> { use std::mem::transmute; static mut DATA: *const ArenaSet<Vec<u8>> = 0 as *const ArenaSet<Vec<u8>>; - static mut ONCE: Once = ONCE_INIT; + static mut ONCE: Once = Once::new(); ONCE.call_once(|| { DATA = transmute ::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>> |
