Skip to content

Commit 7a58c6d

Browse files
Replace deprecated ATOMIC_INIT consts
1 parent abe36c4 commit 7a58c6d

File tree

27 files changed

+89
-59
lines changed

27 files changed

+89
-59
lines changed

src/liballoc/tests/binary_heap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cmp;
22
use std::collections::BinaryHeap;
33
use std::collections::binary_heap::{Drain, PeekMut};
44
use std::panic::{self, AssertUnwindSafe};
5-
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
5+
use std::sync::atomic::{AtomicUsize, Ordering};
66

77
use rand::{thread_rng, seq::SliceRandom};
88

@@ -283,7 +283,7 @@ fn assert_covariance() {
283283
// Destructors must be called exactly once per element.
284284
#[test]
285285
fn panic_safe() {
286-
static DROP_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
286+
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
287287

288288
#[derive(Eq, PartialEq, Ord, Clone, Debug)]
289289
struct PanicOrd<T>(T, bool);

src/liballoc/tests/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::mem;
55
use std::panic;
66
use std::rc::Rc;
77
use std::sync::atomic::Ordering::Relaxed;
8-
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize};
8+
use std::sync::atomic::AtomicUsize;
99
use std::thread;
1010

1111
use rand::{Rng, RngCore, thread_rng, seq::SliceRandom};
@@ -1500,7 +1500,7 @@ static DROP_COUNTS: [AtomicUsize; MAX_LEN] = [
15001500
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
15011501
];
15021502

1503-
static VERSIONS: AtomicUsize = ATOMIC_USIZE_INIT;
1503+
static VERSIONS: AtomicUsize = AtomicUsize::new(0);
15041504

15051505
#[derive(Clone, Eq)]
15061506
struct DropCounter {

src/libcore/sync/atomic.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2413,12 +2413,11 @@ pub fn fence(order: Ordering) {
24132413
///
24142414
/// ```
24152415
/// use std::sync::atomic::{AtomicBool, AtomicUsize};
2416-
/// use std::sync::atomic::{ATOMIC_BOOL_INIT, ATOMIC_USIZE_INIT};
24172416
/// use std::sync::atomic::Ordering;
24182417
/// use std::sync::atomic::compiler_fence;
24192418
///
2420-
/// static IMPORTANT_VARIABLE: AtomicUsize = ATOMIC_USIZE_INIT;
2421-
/// static IS_READY: AtomicBool = ATOMIC_BOOL_INIT;
2419+
/// static IMPORTANT_VARIABLE: AtomicUsize = AtomicUsize::new(0);
2420+
/// static IS_READY: AtomicBool = AtomicBool::new(false);
24222421
///
24232422
/// fn main() {
24242423
/// IMPORTANT_VARIABLE.store(42, Ordering::Relaxed);

src/librustc_driver/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ use std::panic;
9191
use std::path::{PathBuf, Path};
9292
use std::process::{self, Command, Stdio};
9393
use std::str;
94-
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
94+
use std::sync::atomic::{AtomicBool, Ordering};
9595
use std::sync::{Once, ONCE_INIT};
9696
use std::thread;
9797

@@ -254,7 +254,7 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
254254
// general this assertion never trips due to the once guard in `get_codegen_backend`,
255255
// but there's a few manual calls to this function in this file we protect
256256
// against.
257-
static LOADED: AtomicBool = ATOMIC_BOOL_INIT;
257+
static LOADED: AtomicBool = AtomicBool::new(false);
258258
assert!(!LOADED.fetch_or(true, Ordering::SeqCst),
259259
"cannot load the default codegen backend twice");
260260

src/librustc_mir/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1127,9 +1127,9 @@ A borrow of a constant containing interior mutability was attempted. Erroneous
11271127
code example:
11281128
11291129
```compile_fail,E0492
1130-
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
1130+
use std::sync::atomic::AtomicUsize;
11311131
1132-
const A: AtomicUsize = ATOMIC_USIZE_INIT;
1132+
const A: AtomicUsize = AtomicUsize::new(0);
11331133
static B: &'static AtomicUsize = &A;
11341134
// error: cannot borrow a constant which may contain interior mutability,
11351135
// create a static instead
@@ -1145,9 +1145,9 @@ explicitly a single memory location, which can be mutated at will.
11451145
So, in order to solve this error, either use statics which are `Sync`:
11461146
11471147
```
1148-
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
1148+
use std::sync::atomic::AtomicUsize;
11491149
1150-
static A: AtomicUsize = ATOMIC_USIZE_INIT;
1150+
static A: AtomicUsize = AtomicUsize::new(0);
11511151
static B: &'static AtomicUsize = &A; // ok!
11521152
```
11531153

src/libstd/alloc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ pub use alloc_crate::alloc::*;
9595
///
9696
/// ```rust
9797
/// use std::alloc::{System, GlobalAlloc, Layout};
98-
/// use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering::SeqCst};
98+
/// use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
9999
///
100100
/// struct Counter;
101101
///
102-
/// static ALLOCATED: AtomicUsize = ATOMIC_USIZE_INIT;
102+
/// static ALLOCATED: AtomicUsize = AtomicUsize::new(0);
103103
///
104104
/// unsafe impl GlobalAlloc for Counter {
105105
/// unsafe fn alloc(&self, layout: Layout) -> *mut u8 {

src/libstd/sys/redox/thread_local.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
use collections::BTreeMap;
44
use ptr;
5-
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
5+
use sync::atomic::{AtomicUsize, Ordering};
66

77
pub type Key = usize;
88

99
type Dtor = unsafe extern fn(*mut u8);
1010

11-
static NEXT_KEY: AtomicUsize = ATOMIC_USIZE_INIT;
11+
static NEXT_KEY: AtomicUsize = AtomicUsize::new(0);
1212

1313
static mut KEYS: *mut BTreeMap<Key, Option<Dtor>> = ptr::null_mut();
1414

src/libstd/sys/sgx/abi/tls.rs

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
1+
use sync::atomic::{AtomicUsize, Ordering};
22
use ptr;
33
use mem;
44
use cell::Cell;
@@ -15,7 +15,40 @@ macro_rules! dup {
1515
((* $($exp:tt)*) $($val:tt)*) => (dup!( ($($exp)*) $($val)* $($val)* ));
1616
(() $($val:tt)*) => ([$($val),*])
1717
}
18-
static TLS_DESTRUCTOR: [AtomicUsize; TLS_KEYS] = dup!((* * * * * * *) ATOMIC_USIZE_INIT);
18+
static TLS_DESTRUCTOR: [AtomicUsize; TLS_KEYS] = [
19+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
20+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
21+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
22+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
23+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
24+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
25+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
26+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
27+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
28+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
29+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
30+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
31+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
32+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
33+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
34+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
35+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
36+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
37+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
38+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
39+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
40+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
41+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
42+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
43+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
44+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
45+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
46+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
47+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
48+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
49+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
50+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
51+
];
1952

2053
extern "C" {
2154
fn get_tls_ptr() -> *const u8;
@@ -119,7 +152,7 @@ impl Tls {
119152
}
120153

121154
mod sync_bitset {
122-
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
155+
use sync::atomic::{AtomicUsize, Ordering};
123156
use iter::{Enumerate, Peekable};
124157
use slice::Iter;
125158
use super::{TLS_KEYS_BITSET_SIZE, USIZE_BITS};
@@ -128,7 +161,7 @@ mod sync_bitset {
128161
pub(super) struct SyncBitset([AtomicUsize; TLS_KEYS_BITSET_SIZE]);
129162

130163
pub(super) const SYNC_BITSET_INIT: SyncBitset =
131-
SyncBitset([ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT]);
164+
SyncBitset([AtomicUsize::new(0), AtomicUsize::new(0)]);
132165

133166
impl SyncBitset {
134167
pub fn get(&self, index: usize) -> bool {

src/libstd/sys/unix/pipe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use io;
22
use libc::{self, c_int};
33
use mem;
4-
use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
4+
use sync::atomic::{AtomicBool, Ordering};
55
use sys::fd::FileDesc;
66
use sys::{cvt, cvt_r};
77

@@ -13,7 +13,7 @@ pub struct AnonPipe(FileDesc);
1313

1414
pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
1515
syscall! { fn pipe2(fds: *mut c_int, flags: c_int) -> c_int }
16-
static INVALID: AtomicBool = ATOMIC_BOOL_INIT;
16+
static INVALID: AtomicBool = AtomicBool::new(false);
1717

1818
let mut fds = [0; 2];
1919

src/libstd/sys/windows/pipe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use path::Path;
77
use ptr;
88
use slice;
99
use sync::atomic::Ordering::SeqCst;
10-
use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
10+
use sync::atomic::AtomicUsize;
1111
use sys::c;
1212
use sys::fs::{File, OpenOptions};
1313
use sys::handle::Handle;
@@ -148,7 +148,7 @@ pub fn anon_pipe(ours_readable: bool) -> io::Result<Pipes> {
148148
}
149149

150150
fn random_number() -> usize {
151-
static N: AtomicUsize = ATOMIC_USIZE_INIT;
151+
static N: AtomicUsize = AtomicUsize::new(0);
152152
loop {
153153
if N.load(SeqCst) != 0 {
154154
return N.fetch_add(1, SeqCst)

src/test/run-pass/allocator/auxiliary/custom-as-global.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
extern crate custom;
66

7-
use std::sync::atomic::{ATOMIC_USIZE_INIT, Ordering};
7+
use std::sync::atomic::{AtomicUsize, Ordering};
88

99
use custom::A;
1010

1111
#[global_allocator]
12-
static ALLOCATOR: A = A(ATOMIC_USIZE_INIT);
12+
static ALLOCATOR: A = A(AtomicUsize::new(0));
1313

1414
pub fn get() -> usize {
1515
ALLOCATOR.0.load(Ordering::SeqCst)

src/test/run-pass/allocator/custom.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
extern crate helper;
99

1010
use std::alloc::{self, Global, Alloc, System, Layout};
11-
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
11+
use std::sync::atomic::{AtomicUsize, Ordering};
1212

13-
static HITS: AtomicUsize = ATOMIC_USIZE_INIT;
13+
static HITS: AtomicUsize = AtomicUsize::new(0);
1414

1515
struct A;
1616

src/test/run-pass/allocator/xcrate-use.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ extern crate custom;
1010
extern crate helper;
1111

1212
use std::alloc::{Global, Alloc, System, Layout};
13-
use std::sync::atomic::{Ordering, ATOMIC_USIZE_INIT};
13+
use std::sync::atomic::{Ordering, AtomicUsize};
1414

1515
#[global_allocator]
16-
static GLOBAL: custom::A = custom::A(ATOMIC_USIZE_INIT);
16+
static GLOBAL: custom::A = custom::A(AtomicUsize::new(0));
1717

1818
fn main() {
1919
unsafe {

src/test/run-pass/allocator/xcrate-use2.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ extern crate custom_as_global;
1212
extern crate helper;
1313

1414
use std::alloc::{alloc, dealloc, GlobalAlloc, System, Layout};
15-
use std::sync::atomic::{Ordering, ATOMIC_USIZE_INIT};
15+
use std::sync::atomic::{AtomicUsize, Ordering};
1616

17-
static GLOBAL: custom::A = custom::A(ATOMIC_USIZE_INIT);
17+
static GLOBAL: custom::A = custom::A(AtomicUsize::new(0));
1818

1919
fn main() {
2020
unsafe {
@@ -45,4 +45,3 @@ fn main() {
4545
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 2);
4646
}
4747
}
48-

src/test/run-pass/atomic-access-bool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![allow(stable_features)]
22
#![feature(atomic_access)]
3-
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT};
3+
use std::sync::atomic::AtomicBool;
44
use std::sync::atomic::Ordering::*;
55

6-
static mut ATOMIC: AtomicBool = ATOMIC_BOOL_INIT;
6+
static mut ATOMIC: AtomicBool = AtomicBool::new(false);
77

88
fn main() {
99
unsafe {

src/test/run-pass/atomic-compare_exchange.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![allow(stable_features)]
22

33
#![feature(extended_compare_and_swap)]
4-
use std::sync::atomic::{AtomicIsize, ATOMIC_ISIZE_INIT};
4+
use std::sync::atomic::AtomicIsize;
55
use std::sync::atomic::Ordering::*;
66

7-
static ATOMIC: AtomicIsize = ATOMIC_ISIZE_INIT;
7+
static ATOMIC: AtomicIsize = AtomicIsize::new(0);
88

99
fn main() {
1010
// Make sure codegen can emit all the intrinsics correctly

src/test/run-pass/deriving/deriving-copyclone.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
//! Test that #[derive(Copy, Clone)] produces a shallow copy
33
//! even when a member violates RFC 1521
44
5-
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
5+
use std::sync::atomic::{AtomicBool, Ordering};
66

77
/// A struct that pretends to be Copy, but actually does something
88
/// in its Clone impl
99
#[derive(Copy)]
1010
struct Liar;
1111

1212
/// Static cooperating with the rogue Clone impl
13-
static CLONED: AtomicBool = ATOMIC_BOOL_INIT;
13+
static CLONED: AtomicBool = AtomicBool::new(false);
1414

1515
impl Clone for Liar {
1616
fn clone(&self) -> Self {
@@ -36,4 +36,3 @@ fn main() {
3636
// if Innocent was byte-for-byte copied, CLONED will still be false
3737
assert!(!CLONED.load(Ordering::SeqCst));
3838
}
39-

src/test/run-pass/generator/conditional-drop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#![feature(generators, generator_trait)]
44

55
use std::ops::Generator;
6-
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
6+
use std::sync::atomic::{AtomicUsize, Ordering};
77

8-
static A: AtomicUsize = ATOMIC_USIZE_INIT;
8+
static A: AtomicUsize = AtomicUsize::new(0);
99

1010
struct B;
1111

src/test/run-pass/generator/drop-env.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#![feature(generators, generator_trait)]
44

55
use std::ops::Generator;
6-
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
6+
use std::sync::atomic::{AtomicUsize, Ordering};
77

8-
static A: AtomicUsize = ATOMIC_USIZE_INIT;
8+
static A: AtomicUsize = AtomicUsize::new(0);
99

1010
struct B;
1111

src/test/run-pass/generator/panic-drops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use std::ops::Generator;
88
use std::panic;
9-
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
9+
use std::sync::atomic::{AtomicUsize, Ordering};
1010

11-
static A: AtomicUsize = ATOMIC_USIZE_INIT;
11+
static A: AtomicUsize = AtomicUsize::new(0);
1212

1313
struct B;
1414

src/test/run-pass/issues/issue-34053.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// run-pass
2-
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
2+
use std::sync::atomic::{AtomicUsize, Ordering};
33

4-
static DROP_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
4+
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
55

66
struct A(i32);
77

src/test/run-pass/mir/mir_fat_ptr_drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use std::sync::atomic;
1111
use std::sync::atomic::Ordering::SeqCst;
1212

13-
static COUNTER: atomic::AtomicUsize = atomic::ATOMIC_USIZE_INIT;
13+
static COUNTER: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
1414

1515
struct DropMe {
1616
}

src/test/run-pass/panics/panic-recover-propagate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// run-pass
22
// ignore-emscripten no threads support
33

4-
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
4+
use std::sync::atomic::{AtomicUsize, Ordering};
55
use std::panic;
66
use std::thread;
77

8-
static A: AtomicUsize = ATOMIC_USIZE_INIT;
8+
static A: AtomicUsize = AtomicUsize::new(0);
99

1010
fn main() {
1111
panic::set_hook(Box::new(|_| {

0 commit comments

Comments
 (0)