Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate ONCE_INIT in future 1.38 release #61757

Merged
merged 1 commit into from Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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