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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 37 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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)

0 commit comments

Comments
 (0)