Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace deprecated ATOMIC_INIT consts
  • Loading branch information
Mark-Simulacrum committed Jan 26, 2019
1 parent abe36c4 commit 7a58c6d
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/liballoc/tests/binary_heap.rs
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/tests/slice.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions src/libcore/sync/atomic.rs
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/lib.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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");

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/diagnostics.rs
Expand Up @@ -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
Expand All @@ -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!
```
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/alloc.rs
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/redox/thread_local.rs
Expand Up @@ -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();

Expand Down
41 changes: 37 additions & 4 deletions src/libstd/sys/sgx/abi/tls.rs
@@ -1,4 +1,4 @@
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use sync::atomic::{AtomicUsize, Ordering};
use ptr;
use mem;
use cell::Cell;
Expand All @@ -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;
Expand Down Expand Up @@ -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};
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/unix/pipe.rs
@@ -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};

Expand All @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/windows/pipe.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/allocator/auxiliary/custom-as-global.rs
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/allocator/custom.rs
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/allocator/xcrate-use.rs
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions src/test/run-pass/allocator/xcrate-use2.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -45,4 +45,3 @@ fn main() {
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 2);
}
}

4 changes: 2 additions & 2 deletions src/test/run-pass/atomic-access-bool.rs
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/atomic-compare_exchange.rs
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/test/run-pass/deriving/deriving-copyclone.rs
Expand Up @@ -2,15 +2,15 @@
//! 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
#[derive(Copy)]
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 {
Expand All @@ -36,4 +36,3 @@ fn main() {
// if Innocent was byte-for-byte copied, CLONED will still be false
assert!(!CLONED.load(Ordering::SeqCst));
}

4 changes: 2 additions & 2 deletions src/test/run-pass/generator/conditional-drop.rs
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/generator/drop-env.rs
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/generator/panic-drops.rs
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/issues/issue-34053.rs
@@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/mir/mir_fat_ptr_drop.rs
Expand Up @@ -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 {
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/panics/panic-recover-propagate.rs
@@ -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(|_| {
Expand Down

0 comments on commit 7a58c6d

Please sign in to comment.