Skip to content

Commit

Permalink
Rollup merge of rust-lang#61757 - sfackler:deprecate-once-init, r=ale…
Browse files Browse the repository at this point in the history
…xcrichton

Deprecate ONCE_INIT in future 1.38 release

Once::new() has been a stable const fn for a while now.

Closes rust-lang#61746
  • Loading branch information
Centril committed Jun 13, 2019
2 parents ca06f88 + 72e99f5 commit e45c83c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/librustc_metadata/dynamic_lib.rs
Expand Up @@ -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(|| {
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sync/mod.rs
Expand Up @@ -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};
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/sync/once.rs
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/issues/issue-39367.rs
Expand Up @@ -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>>>
Expand Down

0 comments on commit e45c83c

Please sign in to comment.