diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2015-05-27 11:18:36 +0300 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2015-05-27 11:19:03 +0300 |
| commit | 377b0900aede976b2d37a499bbd7b62c2e39b358 (patch) | |
| tree | b4a5a4431d36ed1a4e0a39c7d2ef2563ecac9bf4 /src/test | |
| parent | 6e8e4f847c2ea02fec021ea15dfb2de6beac797a (diff) | |
| download | rust-377b0900aede976b2d37a499bbd7b62c2e39b358.tar.gz rust-377b0900aede976b2d37a499bbd7b62c2e39b358.zip | |
Use `const fn` to abstract away the contents of UnsafeCell & friends.
Diffstat (limited to 'src/test')
22 files changed, 55 insertions, 56 deletions
diff --git a/src/test/auxiliary/issue-17718.rs b/src/test/auxiliary/issue-17718.rs index 67474e79021..b347e674f0a 100644 --- a/src/test/auxiliary/issue-17718.rs +++ b/src/test/auxiliary/issue-17718.rs @@ -11,12 +11,12 @@ use std::sync::atomic; pub const C1: usize = 1; -pub const C2: atomic::AtomicUsize = atomic::ATOMIC_USIZE_INIT; +pub const C2: atomic::AtomicUsize = atomic::AtomicUsize::new(0); pub const C3: fn() = foo; pub const C4: usize = C1 * C1 + C1 / C1; pub const C5: &'static usize = &C4; pub static S1: usize = 3; -pub static S2: atomic::AtomicUsize = atomic::ATOMIC_USIZE_INIT; +pub static S2: atomic::AtomicUsize = atomic::AtomicUsize::new(0); fn foo() {} diff --git a/src/test/compile-fail/dropck_arr_cycle_checked.rs b/src/test/compile-fail/dropck_arr_cycle_checked.rs index f3c3f31e4af..c9713ebcebe 100644 --- a/src/test/compile-fail/dropck_arr_cycle_checked.rs +++ b/src/test/compile-fail/dropck_arr_cycle_checked.rs @@ -18,9 +18,9 @@ use id::Id; mod s { #![allow(unstable)] - use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; + use std::sync::atomic::{AtomicUsize, Ordering}; - static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT; + static S_COUNT: AtomicUsize = AtomicUsize::new(0); pub fn next_count() -> usize { S_COUNT.fetch_add(1, Ordering::SeqCst) + 1 diff --git a/src/test/compile-fail/dropck_tarena_cycle_checked.rs b/src/test/compile-fail/dropck_tarena_cycle_checked.rs index 10bfe70640c..9309f5a243c 100644 --- a/src/test/compile-fail/dropck_tarena_cycle_checked.rs +++ b/src/test/compile-fail/dropck_tarena_cycle_checked.rs @@ -26,9 +26,9 @@ use id::Id; mod s { #![allow(unstable)] - use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; + use std::sync::atomic::{AtomicUsize, Ordering}; - static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT; + static S_COUNT: AtomicUsize = AtomicUsize::new(0); pub fn next_count() -> usize { S_COUNT.fetch_add(1, Ordering::SeqCst) + 1 diff --git a/src/test/compile-fail/dropck_trait_cycle_checked.rs b/src/test/compile-fail/dropck_trait_cycle_checked.rs index 6e543d017f2..1d8c7e9ac3e 100644 --- a/src/test/compile-fail/dropck_trait_cycle_checked.rs +++ b/src/test/compile-fail/dropck_trait_cycle_checked.rs @@ -17,9 +17,9 @@ use std::cell::Cell; use id::Id; mod s { - use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; + use std::sync::atomic::{AtomicUsize, Ordering}; - static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT; + static S_COUNT: AtomicUsize = AtomicUsize::new(0); pub fn next_count() -> usize { S_COUNT.fetch_add(1, Ordering::SeqCst) + 1 diff --git a/src/test/compile-fail/dropck_vec_cycle_checked.rs b/src/test/compile-fail/dropck_vec_cycle_checked.rs index 53a14fd8fac..8722246bb4e 100644 --- a/src/test/compile-fail/dropck_vec_cycle_checked.rs +++ b/src/test/compile-fail/dropck_vec_cycle_checked.rs @@ -17,9 +17,9 @@ use id::Id; mod s { #![allow(unstable)] - use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; + use std::sync::atomic::{AtomicUsize, Ordering}; - static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT; + static S_COUNT: AtomicUsize = AtomicUsize::new(0); pub fn next_count() -> usize { S_COUNT.fetch_add(1, Ordering::SeqCst) + 1 diff --git a/src/test/compile-fail/functional-struct-update-respects-privacy.rs b/src/test/compile-fail/functional-struct-update-respects-privacy.rs index 51e23a689a1..3f41401eb69 100644 --- a/src/test/compile-fail/functional-struct-update-respects-privacy.rs +++ b/src/test/compile-fail/functional-struct-update-respects-privacy.rs @@ -16,7 +16,7 @@ use self::foo::S; mod foo { use std::cell::{UnsafeCell}; - static mut count : UnsafeCell<u64> = UnsafeCell { value: 1 }; + static mut count : UnsafeCell<u64> = UnsafeCell::new(1); pub struct S { pub a: u8, pub b: String, secret_uid: u64 } diff --git a/src/test/compile-fail/issue-17718-const-borrow.rs b/src/test/compile-fail/issue-17718-const-borrow.rs index dfa5bca8ccd..12a9a274631 100644 --- a/src/test/compile-fail/issue-17718-const-borrow.rs +++ b/src/test/compile-fail/issue-17718-const-borrow.rs @@ -10,12 +10,12 @@ use std::cell::UnsafeCell; -const A: UnsafeCell<usize> = UnsafeCell { value: 1 }; +const A: UnsafeCell<usize> = UnsafeCell::new(1); const B: &'static UnsafeCell<usize> = &A; //~^ ERROR: cannot borrow a constant which contains interior mutability struct C { a: UnsafeCell<usize> } -const D: C = C { a: UnsafeCell { value: 1 } }; +const D: C = C { a: UnsafeCell::new(1) }; const E: &'static UnsafeCell<usize> = &D.a; //~^ ERROR: cannot borrow a constant which contains interior mutability const F: &'static C = &D; diff --git a/src/test/compile-fail/issue-7364.rs b/src/test/compile-fail/issue-7364.rs index 5d85fe93a48..999e5f9db2d 100644 --- a/src/test/compile-fail/issue-7364.rs +++ b/src/test/compile-fail/issue-7364.rs @@ -17,6 +17,5 @@ static boxed: Box<RefCell<isize>> = box RefCell::new(0); //~^ ERROR allocations are not allowed in statics //~| ERROR the trait `core::marker::Sync` is not implemented for the type //~| ERROR the trait `core::marker::Sync` is not implemented for the type -//~| ERROR E0015 fn main() { } diff --git a/src/test/compile-fail/std-uncopyable-atomics.rs b/src/test/compile-fail/std-uncopyable-atomics.rs index 9807fc43140..35877db610e 100644 --- a/src/test/compile-fail/std-uncopyable-atomics.rs +++ b/src/test/compile-fail/std-uncopyable-atomics.rs @@ -15,11 +15,11 @@ use std::sync::atomic::*; use std::ptr; fn main() { - let x = ATOMIC_BOOL_INIT; + let x = AtomicBool::new(false); let x = *&x; //~ ERROR: cannot move out of borrowed content - let x = ATOMIC_ISIZE_INIT; + let x = AtomicIsize::new(0); let x = *&x; //~ ERROR: cannot move out of borrowed content - let x = ATOMIC_USIZE_INIT; + let x = AtomicUsize::new(0); let x = *&x; //~ ERROR: cannot move out of borrowed content let x: AtomicPtr<usize> = AtomicPtr::new(ptr::null_mut()); let x = *&x; //~ ERROR: cannot move out of borrowed content diff --git a/src/test/compile-fail/vec-must-not-hide-type-from-dropck.rs b/src/test/compile-fail/vec-must-not-hide-type-from-dropck.rs index c30aa7b817b..0b2112edf72 100644 --- a/src/test/compile-fail/vec-must-not-hide-type-from-dropck.rs +++ b/src/test/compile-fail/vec-must-not-hide-type-from-dropck.rs @@ -28,9 +28,9 @@ use id::Id; mod s { #![allow(unstable)] - use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; + use std::sync::atomic::{AtomicUsize, Ordering}; - static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT; + static S_COUNT: AtomicUsize = AtomicUsize::new(0); /// generates globally unique count (global across the current /// process, that is) diff --git a/src/test/debuginfo/constant-debug-locs.rs b/src/test/debuginfo/constant-debug-locs.rs index 5fc58075504..72448ca2e00 100644 --- a/src/test/debuginfo/constant-debug-locs.rs +++ b/src/test/debuginfo/constant-debug-locs.rs @@ -19,7 +19,7 @@ // This test makes sure that the compiler doesn't crash when trying to assign // debug locations to const-expressions. -use std::sync::MUTEX_INIT; +use std::sync::StaticMutex; use std::cell::UnsafeCell; const CONSTANT: u64 = 3 + 4; @@ -49,7 +49,7 @@ const VEC: [u32; 8] = [0; 8]; const NESTED: (Struct, TupleStruct) = (STRUCT, TUPLE_STRUCT); -const UNSAFE_CELL: UnsafeCell<bool> = UnsafeCell { value: false }; +const UNSAFE_CELL: UnsafeCell<bool> = UnsafeCell::new(false); fn main() { let mut _constant = CONSTANT; @@ -61,6 +61,6 @@ fn main() { let mut _string = STRING; let mut _vec = VEC; let mut _nested = NESTED; - let mut _extern = MUTEX_INIT; + let mut _extern = StaticMutex::new(); let mut _unsafe_cell = UNSAFE_CELL; } diff --git a/src/test/run-pass-valgrind/cast-enum-with-dtor.rs b/src/test/run-pass-valgrind/cast-enum-with-dtor.rs index 0bc1e33ce46..2c3d7ef39e4 100644 --- a/src/test/run-pass-valgrind/cast-enum-with-dtor.rs +++ b/src/test/run-pass-valgrind/cast-enum-with-dtor.rs @@ -22,7 +22,7 @@ enum E { C = 2 } -static FLAG: atomic::AtomicUsize = atomic::ATOMIC_USIZE_INIT; +static FLAG: atomic::AtomicUsize = atomic::AtomicUsize::new(0); impl Drop for E { fn drop(&mut self) { diff --git a/src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs b/src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs index 1830b41d0b5..5ceb1013ad8 100644 --- a/src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs +++ b/src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs @@ -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; } diff --git a/src/test/run-pass/box-of-array-of-drop-1.rs b/src/test/run-pass/box-of-array-of-drop-1.rs index a93a488c1b5..1c7359a0fad 100644 --- a/src/test/run-pass/box-of-array-of-drop-1.rs +++ b/src/test/run-pass/box-of-array-of-drop-1.rs @@ -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); diff --git a/src/test/run-pass/box-of-array-of-drop-2.rs b/src/test/run-pass/box-of-array-of-drop-2.rs index 715571364c8..ad781f00356 100644 --- a/src/test/run-pass/box-of-array-of-drop-2.rs +++ b/src/test/run-pass/box-of-array-of-drop-2.rs @@ -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); diff --git a/src/test/run-pass/issue-17718-static-unsafe-interior.rs b/src/test/run-pass/issue-17718-static-unsafe-interior.rs index 29d72000d07..c18d51e84d8 100644 --- a/src/test/run-pass/issue-17718-static-unsafe-interior.rs +++ b/src/test/run-pass/issue-17718-static-unsafe-interior.rs @@ -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() { diff --git a/src/test/run-pass/issue-17718.rs b/src/test/run-pass/issue-17718.rs index 2b84ce71dd2..457bbb23e18 100644 --- a/src/test/run-pass/issue-17718.rs +++ b/src/test/run-pass/issue-17718.rs @@ -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; diff --git a/src/test/run-pass/issue-21486.rs b/src/test/run-pass/issue-21486.rs index 7f8bd7a95f7..c20237f1f86 100644 --- a/src/test/run-pass/issue-21486.rs +++ b/src/test/run-pass/issue-21486.rs @@ -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); diff --git a/src/test/run-pass/nested-vec-3.rs b/src/test/run-pass/nested-vec-3.rs index 60cf795c918..e59900caf07 100644 --- a/src/test/run-pass/nested-vec-3.rs +++ b/src/test/run-pass/nested-vec-3.rs @@ -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); diff --git a/src/test/run-pass/struct-order-of-eval-3.rs b/src/test/run-pass/struct-order-of-eval-3.rs index 60f9c4465a0..c0ed4ea3ce8 100644 --- a/src/test/run-pass/struct-order-of-eval-3.rs +++ b/src/test/run-pass/struct-order-of-eval-3.rs @@ -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) diff --git a/src/test/run-pass/struct-order-of-eval-4.rs b/src/test/run-pass/struct-order-of-eval-4.rs index 23a7e1ea71b..83ea0e3ab74 100644 --- a/src/test/run-pass/struct-order-of-eval-4.rs +++ b/src/test/run-pass/struct-order-of-eval-4.rs @@ -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) diff --git a/src/test/run-pass/vector-sort-panic-safe.rs b/src/test/run-pass/vector-sort-panic-safe.rs index a51274199b6..f3c4ecb035e 100644 --- a/src/test/run-pass/vector-sort-panic-safe.rs +++ b/src/test/run-pass/vector-sort-panic-safe.rs @@ -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 } |
