Replace deprecated ATOMIC_INIT consts

This commit is contained in:
Mark Rousskov 2019-01-26 09:14:49 -07:00
parent abe36c4741
commit 7a58c6d1de
27 changed files with 89 additions and 59 deletions

View file

@ -2,7 +2,7 @@ use std::cmp;
use std::collections::BinaryHeap;
use std::collections::binary_heap::{Drain, PeekMut};
use std::panic::{self, AssertUnwindSafe};
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
use rand::{thread_rng, seq::SliceRandom};
@ -283,7 +283,7 @@ fn assert_covariance() {
// Destructors must be called exactly once per element.
#[test]
fn panic_safe() {
static DROP_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
#[derive(Eq, PartialEq, Ord, Clone, Debug)]
struct PanicOrd<T>(T, bool);

View file

@ -5,7 +5,7 @@ use std::mem;
use std::panic;
use std::rc::Rc;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize};
use std::sync::atomic::AtomicUsize;
use std::thread;
use rand::{Rng, RngCore, thread_rng, seq::SliceRandom};
@ -1500,7 +1500,7 @@ static DROP_COUNTS: [AtomicUsize; MAX_LEN] = [
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
];
static VERSIONS: AtomicUsize = ATOMIC_USIZE_INIT;
static VERSIONS: AtomicUsize = AtomicUsize::new(0);
#[derive(Clone, Eq)]
struct DropCounter {

View file

@ -2413,12 +2413,11 @@ pub fn fence(order: Ordering) {
///
/// ```
/// use std::sync::atomic::{AtomicBool, AtomicUsize};
/// use std::sync::atomic::{ATOMIC_BOOL_INIT, ATOMIC_USIZE_INIT};
/// use std::sync::atomic::Ordering;
/// use std::sync::atomic::compiler_fence;
///
/// static IMPORTANT_VARIABLE: AtomicUsize = ATOMIC_USIZE_INIT;
/// static IS_READY: AtomicBool = ATOMIC_BOOL_INIT;
/// static IMPORTANT_VARIABLE: AtomicUsize = AtomicUsize::new(0);
/// static IS_READY: AtomicBool = AtomicBool::new(false);
///
/// fn main() {
/// IMPORTANT_VARIABLE.store(42, Ordering::Relaxed);

View file

@ -91,7 +91,7 @@ use std::panic;
use std::path::{PathBuf, Path};
use std::process::{self, Command, Stdio};
use std::str;
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Once, ONCE_INIT};
use std::thread;
@ -254,7 +254,7 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
// general this assertion never trips due to the once guard in `get_codegen_backend`,
// but there's a few manual calls to this function in this file we protect
// against.
static LOADED: AtomicBool = ATOMIC_BOOL_INIT;
static LOADED: AtomicBool = AtomicBool::new(false);
assert!(!LOADED.fetch_or(true, Ordering::SeqCst),
"cannot load the default codegen backend twice");

View file

@ -1127,9 +1127,9 @@ A borrow of a constant containing interior mutability was attempted. Erroneous
code example:
```compile_fail,E0492
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
use std::sync::atomic::AtomicUsize;
const A: AtomicUsize = ATOMIC_USIZE_INIT;
const A: AtomicUsize = AtomicUsize::new(0);
static B: &'static AtomicUsize = &A;
// error: cannot borrow a constant which may contain interior mutability,
// create a static instead
@ -1145,9 +1145,9 @@ explicitly a single memory location, which can be mutated at will.
So, in order to solve this error, either use statics which are `Sync`:
```
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
use std::sync::atomic::AtomicUsize;
static A: AtomicUsize = ATOMIC_USIZE_INIT;
static A: AtomicUsize = AtomicUsize::new(0);
static B: &'static AtomicUsize = &A; // ok!
```

View file

@ -95,11 +95,11 @@ pub use alloc_crate::alloc::*;
///
/// ```rust
/// use std::alloc::{System, GlobalAlloc, Layout};
/// use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering::SeqCst};
/// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
///
/// struct Counter;
///
/// static ALLOCATED: AtomicUsize = ATOMIC_USIZE_INIT;
/// static ALLOCATED: AtomicUsize = AtomicUsize::new(0);
///
/// unsafe impl GlobalAlloc for Counter {
/// unsafe fn alloc(&self, layout: Layout) -> *mut u8 {

View file

@ -2,13 +2,13 @@
use collections::BTreeMap;
use ptr;
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use sync::atomic::{AtomicUsize, Ordering};
pub type Key = usize;
type Dtor = unsafe extern fn(*mut u8);
static NEXT_KEY: AtomicUsize = ATOMIC_USIZE_INIT;
static NEXT_KEY: AtomicUsize = AtomicUsize::new(0);
static mut KEYS: *mut BTreeMap<Key, Option<Dtor>> = ptr::null_mut();

View file

@ -1,4 +1,4 @@
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use sync::atomic::{AtomicUsize, Ordering};
use ptr;
use mem;
use cell::Cell;
@ -15,7 +15,40 @@ macro_rules! dup {
((* $($exp:tt)*) $($val:tt)*) => (dup!( ($($exp)*) $($val)* $($val)* ));
(() $($val:tt)*) => ([$($val),*])
}
static TLS_DESTRUCTOR: [AtomicUsize; TLS_KEYS] = dup!((* * * * * * *) ATOMIC_USIZE_INIT);
static TLS_DESTRUCTOR: [AtomicUsize; TLS_KEYS] = [
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
];
extern "C" {
fn get_tls_ptr() -> *const u8;
@ -119,7 +152,7 @@ impl Tls {
}
mod sync_bitset {
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use sync::atomic::{AtomicUsize, Ordering};
use iter::{Enumerate, Peekable};
use slice::Iter;
use super::{TLS_KEYS_BITSET_SIZE, USIZE_BITS};
@ -128,7 +161,7 @@ mod sync_bitset {
pub(super) struct SyncBitset([AtomicUsize; TLS_KEYS_BITSET_SIZE]);
pub(super) const SYNC_BITSET_INIT: SyncBitset =
SyncBitset([ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT]);
SyncBitset([AtomicUsize::new(0), AtomicUsize::new(0)]);
impl SyncBitset {
pub fn get(&self, index: usize) -> bool {

View file

@ -1,7 +1,7 @@
use io;
use libc::{self, c_int};
use mem;
use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
use sync::atomic::{AtomicBool, Ordering};
use sys::fd::FileDesc;
use sys::{cvt, cvt_r};
@ -13,7 +13,7 @@ pub struct AnonPipe(FileDesc);
pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
syscall! { fn pipe2(fds: *mut c_int, flags: c_int) -> c_int }
static INVALID: AtomicBool = ATOMIC_BOOL_INIT;
static INVALID: AtomicBool = AtomicBool::new(false);
let mut fds = [0; 2];

View file

@ -7,7 +7,7 @@ use path::Path;
use ptr;
use slice;
use sync::atomic::Ordering::SeqCst;
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
use sync::atomic::AtomicUsize;
use sys::c;
use sys::fs::{File, OpenOptions};
use sys::handle::Handle;
@ -148,7 +148,7 @@ pub fn anon_pipe(ours_readable: bool) -> io::Result<Pipes> {
}
fn random_number() -> usize {
static N: AtomicUsize = ATOMIC_USIZE_INIT;
static N: AtomicUsize = AtomicUsize::new(0);
loop {
if N.load(SeqCst) != 0 {
return N.fetch_add(1, SeqCst)

View file

@ -4,12 +4,12 @@
extern crate custom;
use std::sync::atomic::{ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
use custom::A;
#[global_allocator]
static ALLOCATOR: A = A(ATOMIC_USIZE_INIT);
static ALLOCATOR: A = A(AtomicUsize::new(0));
pub fn get() -> usize {
ALLOCATOR.0.load(Ordering::SeqCst)

View file

@ -8,9 +8,9 @@
extern crate helper;
use std::alloc::{self, Global, Alloc, System, Layout};
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use std::sync::atomic::{AtomicUsize, Ordering};
static HITS: AtomicUsize = ATOMIC_USIZE_INIT;
static HITS: AtomicUsize = AtomicUsize::new(0);
struct A;

View file

@ -10,10 +10,10 @@ extern crate custom;
extern crate helper;
use std::alloc::{Global, Alloc, System, Layout};
use std::sync::atomic::{Ordering, ATOMIC_USIZE_INIT};
use std::sync::atomic::{Ordering, AtomicUsize};
#[global_allocator]
static GLOBAL: custom::A = custom::A(ATOMIC_USIZE_INIT);
static GLOBAL: custom::A = custom::A(AtomicUsize::new(0));
fn main() {
unsafe {

View file

@ -12,9 +12,9 @@ extern crate custom_as_global;
extern crate helper;
use std::alloc::{alloc, dealloc, GlobalAlloc, System, Layout};
use std::sync::atomic::{Ordering, ATOMIC_USIZE_INIT};
use std::sync::atomic::{AtomicUsize, Ordering};
static GLOBAL: custom::A = custom::A(ATOMIC_USIZE_INIT);
static GLOBAL: custom::A = custom::A(AtomicUsize::new(0));
fn main() {
unsafe {
@ -45,4 +45,3 @@ fn main() {
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 2);
}
}

View file

@ -1,9 +1,9 @@
#![allow(stable_features)]
#![feature(atomic_access)]
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT};
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::*;
static mut ATOMIC: AtomicBool = ATOMIC_BOOL_INIT;
static mut ATOMIC: AtomicBool = AtomicBool::new(false);
fn main() {
unsafe {

View file

@ -1,10 +1,10 @@
#![allow(stable_features)]
#![feature(extended_compare_and_swap)]
use std::sync::atomic::{AtomicIsize, ATOMIC_ISIZE_INIT};
use std::sync::atomic::AtomicIsize;
use std::sync::atomic::Ordering::*;
static ATOMIC: AtomicIsize = ATOMIC_ISIZE_INIT;
static ATOMIC: AtomicIsize = AtomicIsize::new(0);
fn main() {
// Make sure codegen can emit all the intrinsics correctly

View file

@ -2,7 +2,7 @@
//! Test that #[derive(Copy, Clone)] produces a shallow copy
//! even when a member violates RFC 1521
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
use std::sync::atomic::{AtomicBool, Ordering};
/// A struct that pretends to be Copy, but actually does something
/// in its Clone impl
@ -10,7 +10,7 @@ use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
struct Liar;
/// Static cooperating with the rogue Clone impl
static CLONED: AtomicBool = ATOMIC_BOOL_INIT;
static CLONED: AtomicBool = AtomicBool::new(false);
impl Clone for Liar {
fn clone(&self) -> Self {
@ -36,4 +36,3 @@ fn main() {
// if Innocent was byte-for-byte copied, CLONED will still be false
assert!(!CLONED.load(Ordering::SeqCst));
}

View file

@ -3,9 +3,9 @@
#![feature(generators, generator_trait)]
use std::ops::Generator;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static A: AtomicUsize = ATOMIC_USIZE_INIT;
static A: AtomicUsize = AtomicUsize::new(0);
struct B;

View file

@ -3,9 +3,9 @@
#![feature(generators, generator_trait)]
use std::ops::Generator;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static A: AtomicUsize = ATOMIC_USIZE_INIT;
static A: AtomicUsize = AtomicUsize::new(0);
struct B;

View file

@ -6,9 +6,9 @@
use std::ops::Generator;
use std::panic;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static A: AtomicUsize = ATOMIC_USIZE_INIT;
static A: AtomicUsize = AtomicUsize::new(0);
struct B;

View file

@ -1,7 +1,7 @@
// run-pass
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static DROP_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
struct A(i32);

View file

@ -10,7 +10,7 @@
use std::sync::atomic;
use std::sync::atomic::Ordering::SeqCst;
static COUNTER: atomic::AtomicUsize = atomic::ATOMIC_USIZE_INIT;
static COUNTER: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
struct DropMe {
}

View file

@ -1,11 +1,11 @@
// run-pass
// ignore-emscripten no threads support
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::panic;
use std::thread;
static A: AtomicUsize = ATOMIC_USIZE_INIT;
static A: AtomicUsize = AtomicUsize::new(0);
fn main() {
panic::set_hook(Box::new(|_| {

View file

@ -6,13 +6,13 @@
#![feature(thread_local_try_with)]
use std::thread;
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use std::sync::atomic::{AtomicUsize, Ordering};
struct Foo { cnt: usize }
thread_local!(static FOO: Foo = Foo::init());
static CNT: AtomicUsize = ATOMIC_USIZE_INIT;
static CNT: AtomicUsize = AtomicUsize::new(0);
impl Foo {
fn init() -> Foo {

View file

@ -10,7 +10,7 @@
#![feature(thread_local)]
#[thread_local]
static mut X: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
static mut X: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsize::new(0);
fn main() {
unsafe {

View file

@ -1,6 +1,6 @@
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
use std::sync::atomic::AtomicUsize;
const A: AtomicUsize = ATOMIC_USIZE_INIT;
const A: AtomicUsize = AtomicUsize::new(0);
static B: &'static AtomicUsize = &A; //~ ERROR E0492
fn main() {

View file

@ -20,7 +20,7 @@ use std::os::unix::prelude::*;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::str;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use std::thread;
@ -31,7 +31,7 @@ macro_rules! t {
})
}
static TEST: AtomicUsize = ATOMIC_USIZE_INIT;
static TEST: AtomicUsize = AtomicUsize::new(0);
struct Config {
pub remote: bool,