Rollup merge of #61757 - sfackler:deprecate-once-init, r=alexcrichton

Deprecate ONCE_INIT in future 1.38 release

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

Closes #61746
This commit is contained in:
Mazdak Farrokhzad 2019-06-13 14:51:57 +02:00 committed by GitHub
commit e45c83ca23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 4 deletions

View File

@ -161,8 +161,8 @@ unsafe fn open_internal() -> *mut u8 {
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(|| {

View File

@ -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};

View File

@ -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

View File

@ -11,13 +11,13 @@ fn __static_ref_initialize() -> 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>>>