Use const fn to abstract away the contents of UnsafeCell & friends.

This commit is contained in:
Eduard Burtescu 2015-05-27 11:18:36 +03:00
parent 6e8e4f847c
commit 377b0900ae
76 changed files with 417 additions and 525 deletions

View file

@ -13,10 +13,10 @@
// `T`. Issue #20300.
use std::marker::{PhantomData};
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
use std::sync::atomic::{AtomicUsize};
use std::sync::atomic::Ordering::SeqCst;
static COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
static COUNTER: AtomicUsize = AtomicUsize::new(0);
// Preamble.
trait Trait { type Item; }

View file

@ -12,9 +12,9 @@
// destructor.
use std::thread;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
static LOG: AtomicUsize = AtomicUsize::new(0);
struct D(u8);

View file

@ -12,9 +12,9 @@
// destructor.
use std::thread;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
static LOG: AtomicUsize = AtomicUsize::new(0);
struct D(u8);

View file

@ -38,8 +38,8 @@ unsafe impl<T: Send> Sync for UnsafeEnum<T> {}
static STATIC1: UnsafeEnum<isize> = UnsafeEnum::VariantSafe;
static STATIC2: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell { value: 1 });
const CONST: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell { value: 1 });
static STATIC2: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
const CONST: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
static STATIC3: MyUnsafe<isize> = MyUnsafe{value: CONST};
static STATIC4: &'static MyUnsafePack<isize> = &STATIC2;
@ -50,7 +50,7 @@ struct Wrap<T> {
unsafe impl<T: Send> Sync for Wrap<T> {}
static UNSAFE: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell{value: 2});
static UNSAFE: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(2));
static WRAPPED_UNSAFE: Wrap<&'static MyUnsafePack<isize>> = Wrap { value: &UNSAFE };
fn main() {

View file

@ -15,10 +15,10 @@
extern crate issue_17718 as other;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
const C1: usize = 1;
const C2: AtomicUsize = ATOMIC_USIZE_INIT;
const C2: AtomicUsize = AtomicUsize::new(0);
const C3: fn() = foo;
const C4: usize = C1 * C1 + C1 / C1;
const C5: &'static usize = &C4;
@ -28,7 +28,7 @@ const C6: usize = {
};
static S1: usize = 3;
static S2: AtomicUsize = ATOMIC_USIZE_INIT;
static S2: AtomicUsize = AtomicUsize::new(0);
mod test {
static A: usize = 4;

View file

@ -13,7 +13,7 @@
// construction.
use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT};
use std::sync::atomic::{Ordering, AtomicUsize};
#[derive(Debug)]
struct Noisy(u8);
@ -69,7 +69,7 @@ pub fn main() {
assert_eq!(0x03_04, event_log());
}
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
static LOG: AtomicUsize = AtomicUsize::new(0);
fn reset_log() {
LOG.store(0, Ordering::SeqCst);

View file

@ -14,9 +14,9 @@
use std::thread;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
static LOG: AtomicUsize = AtomicUsize::new(0);
struct D(u8);

View file

@ -12,7 +12,7 @@
// even when no Drop-implementations are involved.
use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT};
use std::sync::atomic::{Ordering, AtomicUsize};
struct W { wrapped: u32 }
struct S { f0: W, _f1: i32 }
@ -34,7 +34,7 @@ pub fn main() {
"expect: 0x{:x} actual: 0x{:x}", expect, actual);
}
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
static LOG: AtomicUsize = AtomicUsize::new(0);
fn event_log() -> usize {
LOG.load(Ordering::SeqCst)

View file

@ -12,7 +12,7 @@
// even when no Drop-implementations are involved.
use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT};
use std::sync::atomic::{Ordering, AtomicUsize};
struct W { wrapped: u32 }
struct S { f0: W, _f1: i32 }
@ -31,7 +31,7 @@ pub fn main() {
"expect: 0x{:x} actual: 0x{:x}", expect, actual);
}
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
static LOG: AtomicUsize = AtomicUsize::new(0);
fn event_log() -> usize {
LOG.load(Ordering::SeqCst)

View file

@ -11,7 +11,7 @@
#![feature(rand, core)]
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::__rand::{thread_rng, Rng};
use std::thread;
@ -20,20 +20,20 @@ const MAX_LEN: usize = 32;
static drop_counts: [AtomicUsize; MAX_LEN] =
// FIXME #5244: AtomicUsize is not Copy.
[
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
ATOMIC_USIZE_INIT, ATOMIC_USIZE_INIT,
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),
];
static creation_count: AtomicUsize = ATOMIC_USIZE_INIT;
static creation_count: AtomicUsize = AtomicUsize::new(0);
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord)]
struct DropCounter { x: u32, creation_id: usize }