diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 900cf9dfb44e4..848068f20c2d8 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -928,29 +928,6 @@ impl Add for String { } } -#[cfg(stage0)] -impl ops::Slice for String { - #[inline] - fn as_slice_<'a>(&'a self) -> &'a str { - self.as_slice() - } - - #[inline] - fn slice_from_<'a>(&'a self, from: &uint) -> &'a str { - self[][*from..] - } - - #[inline] - fn slice_to_<'a>(&'a self, to: &uint) -> &'a str { - self[][..*to] - } - - #[inline] - fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str { - self[][*from..*to] - } -} -#[cfg(not(stage0))] impl ops::Slice for String { #[inline] fn as_slice_<'a>(&'a self) -> &'a str { diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index fe8ced7f2aaaf..a022a1bc89016 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -389,15 +389,6 @@ macro_rules! bound { impl TrieMap { // If `upper` is true then returns upper_bound else returns lower_bound. - #[cfg(stage0)] - #[inline] - fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> { - bound!(Entries, self = self, - key = key, is_upper = upper, - slice_from = slice_from_, iter = iter, - mutability = ) - } - #[cfg(not(stage0))] #[inline] fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> { bound!(Entries, self = self, @@ -440,15 +431,6 @@ impl TrieMap { self.bound(key, true) } // If `upper` is true then returns upper_bound else returns lower_bound. - #[cfg(stage0)] - #[inline] - fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> { - bound!(MutEntries, self = self, - key = key, is_upper = upper, - slice_from = slice_from_mut_, iter = iter_mut, - mutability = mut) - } - #[cfg(not(stage0))] #[inline] fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> { bound!(MutEntries, self = self, diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index a82856c013d64..0933bcb8ab82b 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -461,28 +461,6 @@ impl Index for Vec { } }*/ -#[cfg(stage0)] -impl ops::Slice for Vec { - #[inline] - fn as_slice_<'a>(&'a self) -> &'a [T] { - self.as_slice() - } - - #[inline] - fn slice_from_<'a>(&'a self, start: &uint) -> &'a [T] { - self.as_slice().slice_from_(start) - } - - #[inline] - fn slice_to_<'a>(&'a self, end: &uint) -> &'a [T] { - self.as_slice().slice_to_(end) - } - #[inline] - fn slice_<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] { - self.as_slice().slice_(start, end) - } -} -#[cfg(not(stage0))] impl ops::Slice for Vec { #[inline] fn as_slice_<'a>(&'a self) -> &'a [T] { @@ -504,28 +482,6 @@ impl ops::Slice for Vec { } } -#[cfg(stage0)] -impl ops::SliceMut for Vec { - #[inline] - fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] { - self.as_mut_slice() - } - - #[inline] - fn slice_from_mut_<'a>(&'a mut self, start: &uint) -> &'a mut [T] { - self.as_mut_slice().slice_from_mut_(start) - } - - #[inline] - fn slice_to_mut_<'a>(&'a mut self, end: &uint) -> &'a mut [T] { - self.as_mut_slice().slice_to_mut_(end) - } - #[inline] - fn slice_mut_<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] { - self.as_mut_slice().slice_mut_(start, end) - } -} -#[cfg(not(stage0))] impl ops::SliceMut for Vec { #[inline] fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] { diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 7d86b65168f3c..3f7dcb36cf698 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -254,7 +254,6 @@ extern "rust-intrinsic" { /// enabling further optimizations. /// /// NB: This is very different from the `unreachable!()` macro! - #[cfg(not(stage0))] pub fn unreachable() -> !; /// Execute a breakpoint trap, for inspection by a debugger. diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index b08432c773e61..f7cfa4c1bafee 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -711,7 +711,6 @@ pub trait IndexMut { * } * ``` */ -#[cfg(not(stage0))] #[lang="slice"] pub trait Slice for Sized? { /// The method for the slicing operation foo[] @@ -723,21 +722,6 @@ pub trait Slice for Sized? { /// The method for the slicing operation foo[from..to] fn slice_or_fail<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result; } -#[cfg(stage0)] -/** - * - */ -#[lang="slice"] -pub trait Slice for Sized? { - /// The method for the slicing operation foo[] - fn as_slice_<'a>(&'a self) -> &'a Result; - /// The method for the slicing operation foo[from..] - fn slice_from_<'a>(&'a self, from: &Idx) -> &'a Result; - /// The method for the slicing operation foo[..to] - fn slice_to_<'a>(&'a self, to: &Idx) -> &'a Result; - /// The method for the slicing operation foo[from..to] - fn slice_<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result; -} /** * @@ -776,7 +760,6 @@ pub trait Slice for Sized? { * } * ``` */ -#[cfg(not(stage0))] #[lang="slice_mut"] pub trait SliceMut for Sized? { /// The method for the slicing operation foo[] @@ -788,21 +771,7 @@ pub trait SliceMut for Sized? { /// The method for the slicing operation foo[from..to] fn slice_or_fail_mut<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result; } -#[cfg(stage0)] -/** - * - */ -#[lang="slice_mut"] -pub trait SliceMut for Sized? { - /// The method for the slicing operation foo[mut] - fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Result; - /// The method for the slicing operation foo[mut from..] - fn slice_from_mut_<'a>(&'a mut self, from: &Idx) -> &'a mut Result; - /// The method for the slicing operation foo[mut ..to] - fn slice_to_mut_<'a>(&'a mut self, to: &Idx) -> &'a mut Result; - /// The method for the slicing operation foo[mut from..to] - fn slice_mut_<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result; -} + /** * * The `Deref` trait is used to specify the functionality of dereferencing diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 02c0c9bf31069..5847a6177d729 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -488,7 +488,6 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { -#[cfg(not(stage0))] impl ops::Slice for [T] { #[inline] fn as_slice_<'a>(&'a self) -> &'a [T] { @@ -516,36 +515,7 @@ impl ops::Slice for [T] { } } } -#[cfg(stage0)] -impl ops::Slice for [T] { - #[inline] - fn as_slice_<'a>(&'a self) -> &'a [T] { - self - } - - #[inline] - fn slice_from_<'a>(&'a self, start: &uint) -> &'a [T] { - self.slice_(start, &self.len()) - } - #[inline] - fn slice_to_<'a>(&'a self, end: &uint) -> &'a [T] { - self.slice_(&0, end) - } - #[inline] - fn slice_<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] { - assert!(*start <= *end); - assert!(*end <= self.len()); - unsafe { - transmute(RawSlice { - data: self.as_ptr().offset(*start as int), - len: (*end - *start) - }) - } - } -} - -#[cfg(not(stage0))] impl ops::SliceMut for [T] { #[inline] fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] { @@ -574,35 +544,6 @@ impl ops::SliceMut for [T] { } } } -#[cfg(stage0)] -impl ops::SliceMut for [T] { - #[inline] - fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] { - self - } - - #[inline] - fn slice_from_mut_<'a>(&'a mut self, start: &uint) -> &'a mut [T] { - let len = &self.len(); - self.slice_mut_(start, len) - } - - #[inline] - fn slice_to_mut_<'a>(&'a mut self, end: &uint) -> &'a mut [T] { - self.slice_mut_(&0, end) - } - #[inline] - fn slice_mut_<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] { - assert!(*start <= *end); - assert!(*end <= self.len()); - unsafe { - transmute(RawSlice { - data: self.as_ptr().offset(*start as int), - len: (*end - *start) - }) - } - } -} /// Extension methods for slices such that their elements are /// mutable. diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 1cbe955274b65..e8cd93ba7dc42 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1164,29 +1164,6 @@ pub mod traits { fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } } - #[cfg(stage0)] - impl ops::Slice for str { - #[inline] - fn as_slice_<'a>(&'a self) -> &'a str { - self - } - - #[inline] - fn slice_from_<'a>(&'a self, from: &uint) -> &'a str { - self.slice_from(*from) - } - - #[inline] - fn slice_to_<'a>(&'a self, to: &uint) -> &'a str { - self.slice_to(*to) - } - - #[inline] - fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str { - self.slice(*from, *to) - } - } - #[cfg(not(stage0))] impl ops::Slice for str { #[inline] fn as_slice_<'a>(&'a self) -> &'a str { diff --git a/src/libcoretest/atomic.rs b/src/libcoretest/atomic.rs index e8fae3fa6df65..ab9c7ab9f11da 100644 --- a/src/libcoretest/atomic.rs +++ b/src/libcoretest/atomic.rs @@ -69,15 +69,13 @@ fn int_xor() { assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f); } -static mut S_BOOL : AtomicBool = INIT_ATOMIC_BOOL; -static mut S_INT : AtomicInt = INIT_ATOMIC_INT; -static mut S_UINT : AtomicUint = INIT_ATOMIC_UINT; +static S_BOOL : AtomicBool = INIT_ATOMIC_BOOL; +static S_INT : AtomicInt = INIT_ATOMIC_INT; +static S_UINT : AtomicUint = INIT_ATOMIC_UINT; #[test] fn static_init() { - unsafe { - assert!(!S_BOOL.load(SeqCst)); - assert!(S_INT.load(SeqCst) == 0); - assert!(S_UINT.load(SeqCst) == 0); - } + assert!(!S_BOOL.load(SeqCst)); + assert!(S_INT.load(SeqCst) == 0); + assert!(S_UINT.load(SeqCst) == 0); } diff --git a/src/libgreen/lib.rs b/src/libgreen/lib.rs index 8eee7ed845fec..5435a6f74d38b 100644 --- a/src/libgreen/lib.rs +++ b/src/libgreen/lib.rs @@ -335,7 +335,7 @@ impl SchedPool { /// This will configure the pool according to the `config` parameter, and /// initially run `main` inside the pool of schedulers. pub fn new(config: PoolConfig) -> SchedPool { - static mut POOL_ID: AtomicUint = INIT_ATOMIC_UINT; + static POOL_ID: AtomicUint = INIT_ATOMIC_UINT; let PoolConfig { threads: nscheds, @@ -349,7 +349,7 @@ impl SchedPool { threads: vec![], handles: vec![], stealers: vec![], - id: unsafe { POOL_ID.fetch_add(1, SeqCst) }, + id: POOL_ID.fetch_add(1, SeqCst), sleepers: SleeperList::new(), stack_pool: StackPool::new(), deque_pool: deque::BufferPool::new(), diff --git a/src/libgreen/sched.rs b/src/libgreen/sched.rs index feb381e4a21b4..f36a43c3c291e 100644 --- a/src/libgreen/sched.rs +++ b/src/libgreen/sched.rs @@ -1458,7 +1458,7 @@ mod test { #[test] fn test_spawn_sched_blocking() { use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; - static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; // Testing that a task in one scheduler can block in foreign code // without affecting other schedulers diff --git a/src/libgreen/stack.rs b/src/libgreen/stack.rs index 23b41f6c6e75b..6a5772ff6282a 100644 --- a/src/libgreen/stack.rs +++ b/src/libgreen/stack.rs @@ -158,8 +158,8 @@ impl StackPool { } fn max_cached_stacks() -> uint { - static mut AMT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; - match unsafe { AMT.load(atomic::SeqCst) } { + static AMT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; + match AMT.load(atomic::SeqCst) { 0 => {} n => return n - 1, } @@ -169,7 +169,7 @@ fn max_cached_stacks() -> uint { let amt = amt.unwrap_or(10); // 0 is our sentinel value, so ensure that we'll never see 0 after // initialization has run - unsafe { AMT.store(amt + 1, atomic::SeqCst); } + AMT.store(amt + 1, atomic::SeqCst); return amt; } diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index b08ad3b6c6174..9d5080522c26e 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -348,8 +348,8 @@ pub struct LogLocation { /// module's log statement should be emitted or not. #[doc(hidden)] pub fn mod_enabled(level: u32, module: &str) -> bool { - static mut INIT: Once = ONCE_INIT; - unsafe { INIT.doit(init); } + static INIT: Once = ONCE_INIT; + INIT.doit(init); // It's possible for many threads are in this function, only one of them // will perform the global initialization, but all of them will need to check diff --git a/src/libnative/io/helper_thread.rs b/src/libnative/io/helper_thread.rs index 1f51f8eacd634..8aff1732a41fc 100644 --- a/src/libnative/io/helper_thread.rs +++ b/src/libnative/io/helper_thread.rs @@ -55,8 +55,8 @@ pub struct Helper { pub initialized: UnsafeCell, } -macro_rules! helper_init( (static mut $name:ident: Helper<$m:ty>) => ( - static mut $name: Helper<$m> = Helper { +macro_rules! helper_init( (static $name:ident: Helper<$m:ty>) => ( + static $name: Helper<$m> = Helper { lock: ::std::rt::mutex::NATIVE_MUTEX_INIT, chan: ::std::cell::UnsafeCell { value: 0 as *mut Sender<$m> }, signal: ::std::cell::UnsafeCell { value: 0 }, diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index aa2b1a6f14e6b..a4b97a3eb84ef 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -1063,7 +1063,7 @@ mod os { unsafe { use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; static mut INITIALIZED: bool = false; - static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; let _guard = LOCK.lock(); if !INITIALIZED { diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index 7a0c1c35d65c8..2ca25f1eeb916 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -28,7 +28,7 @@ use super::util; #[cfg(unix)] use io::helper_thread::Helper; #[cfg(unix)] -helper_init!(static mut HELPER: Helper) +helper_init!(static HELPER: Helper) /** * A value representing a child process. @@ -988,7 +988,7 @@ fn waitpid(pid: pid_t, deadline: u64) -> IoResult { // The actual communication between the helper thread and this thread is // quite simple, just a channel moving data around. - unsafe { HELPER.boot(register_sigchld, waitpid_helper) } + HELPER.boot(register_sigchld, waitpid_helper); match waitpid_nowait(pid) { Some(ret) => return Ok(ret), @@ -996,7 +996,7 @@ fn waitpid(pid: pid_t, deadline: u64) -> IoResult { } let (tx, rx) = channel(); - unsafe { HELPER.send(NewChild(pid, tx, deadline)); } + HELPER.send(NewChild(pid, tx, deadline)); return match rx.recv_opt() { Ok(e) => Ok(e), Err(()) => Err(util::timeout("wait timed out")), diff --git a/src/libnative/io/timer_unix.rs b/src/libnative/io/timer_unix.rs index 8c6fd83a76bad..4d4ba33aec45f 100644 --- a/src/libnative/io/timer_unix.rs +++ b/src/libnative/io/timer_unix.rs @@ -59,7 +59,7 @@ use io::c; use io::file::FileDesc; use io::helper_thread::Helper; -helper_init!(static mut HELPER: Helper) +helper_init!(static HELPER: Helper) pub struct Timer { id: uint, @@ -204,10 +204,10 @@ impl Timer { pub fn new() -> IoResult { // See notes above regarding using int return value // instead of () - unsafe { HELPER.boot(|| {}, helper); } + HELPER.boot(|| {}, helper); - static mut ID: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; - let id = unsafe { ID.fetch_add(1, atomic::Relaxed) }; + static ID: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; + let id = ID.fetch_add(1, atomic::Relaxed); Ok(Timer { id: id, inner: Some(box Inner { @@ -237,7 +237,7 @@ impl Timer { Some(i) => i, None => { let (tx, rx) = channel(); - unsafe { HELPER.send(RemoveTimer(self.id, tx)); } + HELPER.send(RemoveTimer(self.id, tx)); rx.recv() } } @@ -262,7 +262,7 @@ impl rtio::RtioTimer for Timer { inner.interval = msecs; inner.target = now + msecs; - unsafe { HELPER.send(NewTimer(inner)); } + HELPER.send(NewTimer(inner)); } fn period(&mut self, msecs: u64, cb: Box) { @@ -274,7 +274,7 @@ impl rtio::RtioTimer for Timer { inner.interval = msecs; inner.target = now + msecs; - unsafe { HELPER.send(NewTimer(inner)); } + HELPER.send(NewTimer(inner)); } } diff --git a/src/libnative/io/timer_windows.rs b/src/libnative/io/timer_windows.rs index 82d318111727f..421cc28e157b1 100644 --- a/src/libnative/io/timer_windows.rs +++ b/src/libnative/io/timer_windows.rs @@ -28,7 +28,7 @@ use std::comm; use io::helper_thread::Helper; -helper_init!(static mut HELPER: Helper) +helper_init!(static HELPER: Helper) pub struct Timer { obj: libc::HANDLE, @@ -104,7 +104,7 @@ pub fn now() -> u64 { impl Timer { pub fn new() -> IoResult { - unsafe { HELPER.boot(|| {}, helper) } + HELPER.boot(|| {}, helper); let obj = unsafe { imp::CreateWaitableTimerA(ptr::null_mut(), 0, ptr::null()) @@ -126,7 +126,7 @@ impl Timer { if !self.on_worker { return } let (tx, rx) = channel(); - unsafe { HELPER.send(RemoveTimer(self.obj, tx)) } + HELPER.send(RemoveTimer(self.obj, tx)); rx.recv(); self.on_worker = false; @@ -158,7 +158,7 @@ impl rtio::RtioTimer for Timer { ptr::null_mut(), 0) }, 1); - unsafe { HELPER.send(NewTimer(self.obj, cb, true)) } + HELPER.send(NewTimer(self.obj, cb, true)); self.on_worker = true; } @@ -172,7 +172,7 @@ impl rtio::RtioTimer for Timer { ptr::null_mut(), ptr::null_mut(), 0) }, 1); - unsafe { HELPER.send(NewTimer(self.obj, cb, false)) } + HELPER.send(NewTimer(self.obj, cb, false)); self.on_worker = true; } } diff --git a/src/librustc/back/write.rs b/src/librustc/back/write.rs index 7b4d1780ccd69..603f5ed227cdf 100644 --- a/src/librustc/back/write.rs +++ b/src/librustc/back/write.rs @@ -936,7 +936,7 @@ pub fn run_assembler(sess: &Session, outputs: &OutputFilenames) { unsafe fn configure_llvm(sess: &Session) { use std::sync::{Once, ONCE_INIT}; - static mut INIT: Once = ONCE_INIT; + static INIT: Once = ONCE_INIT; // Copy what clang does by turning on loop vectorization at O2 and // slp vectorization at O3 diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 692017b675011..1a1b2b9d2575e 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -3035,7 +3035,7 @@ pub fn trans_crate<'tcx>(analysis: CrateAnalysis<'tcx>) // Before we touch LLVM, make sure that multithreading is enabled. unsafe { use std::sync::{Once, ONCE_INIT}; - static mut INIT: Once = ONCE_INIT; + static INIT: Once = ONCE_INIT; static mut POISONED: bool = false; INIT.doit(|| { if llvm::LLVMStartMultithreaded() != 1 { diff --git a/src/librustrt/args.rs b/src/librustrt/args.rs index bd63886baeeda..9b1dd7a825494 100644 --- a/src/librustrt/args.rs +++ b/src/librustrt/args.rs @@ -54,8 +54,8 @@ mod imp { use mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; - static mut global_args_ptr: uint = 0; - static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static mut GLOBAL_ARGS_PTR: uint = 0; + static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; pub unsafe fn init(argc: int, argv: *const *const u8) { let args = load_argc_and_argv(argc, argv); @@ -64,7 +64,7 @@ mod imp { pub unsafe fn cleanup() { rtassert!(take().is_some()); - lock.destroy(); + LOCK.destroy(); } pub fn take() -> Option>> { @@ -92,13 +92,13 @@ mod imp { fn with_lock(f: || -> T) -> T { unsafe { - let _guard = lock.lock(); + let _guard = LOCK.lock(); f() } } fn get_global_ptr() -> *mut Option>>> { - unsafe { mem::transmute(&global_args_ptr) } + unsafe { mem::transmute(&GLOBAL_ARGS_PTR) } } unsafe fn load_argc_and_argv(argc: int, argv: *const *const u8) -> Vec> { diff --git a/src/librustrt/at_exit_imp.rs b/src/librustrt/at_exit_imp.rs index 8854c33b169f2..c54afb241aebb 100644 --- a/src/librustrt/at_exit_imp.rs +++ b/src/librustrt/at_exit_imp.rs @@ -24,8 +24,8 @@ use exclusive::Exclusive; type Queue = Exclusive>; -static mut QUEUE: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; -static mut RUNNING: atomic::AtomicBool = atomic::INIT_ATOMIC_BOOL; +static QUEUE: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; +static RUNNING: atomic::AtomicBool = atomic::INIT_ATOMIC_BOOL; pub fn init() { let state: Box = box Exclusive::new(Vec::new()); diff --git a/src/librustrt/bookkeeping.rs b/src/librustrt/bookkeeping.rs index a88bc86828f82..714bbd569bdbc 100644 --- a/src/librustrt/bookkeeping.rs +++ b/src/librustrt/bookkeeping.rs @@ -23,8 +23,8 @@ use core::ops::Drop; use mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; -static mut TASK_COUNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; -static mut TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; +static TASK_COUNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; +static TASK_LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; pub struct Token { _private: () } @@ -35,7 +35,7 @@ impl Drop for Token { /// Increment the number of live tasks, returning a token which will decrement /// the count when dropped. pub fn increment() -> Token { - let _ = unsafe { TASK_COUNT.fetch_add(1, atomic::SeqCst) }; + let _ = TASK_COUNT.fetch_add(1, atomic::SeqCst); Token { _private: () } } diff --git a/src/librustrt/mutex.rs b/src/librustrt/mutex.rs index bd47874d64720..7d4fb2f5c529e 100644 --- a/src/librustrt/mutex.rs +++ b/src/librustrt/mutex.rs @@ -36,7 +36,7 @@ //! use std::rt::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT}; //! //! // Use a statically initialized mutex -//! static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; +//! static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; //! //! unsafe { //! let _guard = LOCK.lock(); @@ -109,7 +109,7 @@ impl StaticNativeMutex { /// /// ```rust /// use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; - /// static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; + /// static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; /// unsafe { /// let _guard = LOCK.lock(); /// // critical section... @@ -655,7 +655,7 @@ mod test { #[test] fn smoke_lock() { - static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { let _guard = lock.lock(); } @@ -663,7 +663,7 @@ mod test { #[test] fn smoke_cond() { - static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { let guard = lock.lock(); let t = Thread::start(proc() { @@ -679,7 +679,7 @@ mod test { #[test] fn smoke_lock_noguard() { - static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { lock.lock_noguard(); lock.unlock_noguard(); @@ -688,7 +688,7 @@ mod test { #[test] fn smoke_cond_noguard() { - static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static lock: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { lock.lock_noguard(); let t = Thread::start(proc() { diff --git a/src/librustrt/unwind.rs b/src/librustrt/unwind.rs index 2a2fa29eca0b2..9483beca1c39d 100644 --- a/src/librustrt/unwind.rs +++ b/src/librustrt/unwind.rs @@ -92,7 +92,7 @@ pub type Callback = fn(msg: &Any + Send, file: &'static str, line: uint); // // For more information, see below. const MAX_CALLBACKS: uint = 16; -static mut CALLBACKS: [atomic::AtomicUint, ..MAX_CALLBACKS] = +static CALLBACKS: [atomic::AtomicUint, ..MAX_CALLBACKS] = [atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, @@ -101,7 +101,7 @@ static mut CALLBACKS: [atomic::AtomicUint, ..MAX_CALLBACKS] = atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT]; -static mut CALLBACK_CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; +static CALLBACK_CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; impl Unwinder { pub fn new() -> Unwinder { @@ -560,7 +560,7 @@ fn begin_unwind_inner(msg: Box, file_line: &(&'static str, uint)) -> // so we just chalk it up to a race condition and move on to the next // callback. Additionally, CALLBACK_CNT may briefly be higher than // MAX_CALLBACKS, so we're sure to clamp it as necessary. - let callbacks = unsafe { + let callbacks = { let amt = CALLBACK_CNT.load(atomic::SeqCst); CALLBACKS[..cmp::min(amt, MAX_CALLBACKS)] }; diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 5cd0b3010c5a1..bc71f8ae7900c 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -230,11 +230,11 @@ pub mod dl { pub fn check_for_errors_in(f: || -> T) -> Result { use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; - static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { // dlerror isn't thread safe, so we need to lock around this entire // sequence - let _guard = lock.lock(); + let _guard = LOCK.lock(); let _old_error = dlerror(); let result = f(); diff --git a/src/libstd/io/tempfile.rs b/src/libstd/io/tempfile.rs index 1d8aedb172bae..e9d6ef2e34130 100644 --- a/src/libstd/io/tempfile.rs +++ b/src/libstd/io/tempfile.rs @@ -38,14 +38,14 @@ impl TempDir { return TempDir::new_in(&os::make_absolute(tmpdir), suffix); } - static mut CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; + static CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; let mut attempts = 0u; loop { let filename = format!("rs-{}-{}-{}", unsafe { libc::getpid() }, - unsafe { CNT.fetch_add(1, atomic::SeqCst) }, + CNT.fetch_add(1, atomic::SeqCst), suffix); let p = tmpdir.join(filename); match fs::mkdir(&p, io::USER_RWX) { diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs index 1a47e20f58580..9b4333a6d8298 100644 --- a/src/libstd/io/test.rs +++ b/src/libstd/io/test.rs @@ -20,22 +20,20 @@ use sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed}; /// Get a port number, starting at 9600, for use in tests pub fn next_test_port() -> u16 { - static mut next_offset: AtomicUint = INIT_ATOMIC_UINT; - unsafe { - base_port() + next_offset.fetch_add(1, Relaxed) as u16 - } + static NEXT_OFFSET: AtomicUint = INIT_ATOMIC_UINT; + base_port() + NEXT_OFFSET.fetch_add(1, Relaxed) as u16 } /// Get a temporary path which could be the location of a unix socket pub fn next_test_unix() -> Path { - static mut COUNT: AtomicUint = INIT_ATOMIC_UINT; + static COUNT: AtomicUint = INIT_ATOMIC_UINT; // base port and pid are an attempt to be unique between multiple // test-runners of different configurations running on one // buildbot, the count is to be unique within this executable. let string = format!("rust-test-unix-path-{}-{}-{}", base_port(), unsafe {libc::getpid()}, - unsafe {COUNT.fetch_add(1, Relaxed)}); + COUNT.fetch_add(1, Relaxed)); if cfg!(unix) { os::tmpdir().join(string) } else { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 60386ec0631b7..03eca5c728b05 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -192,10 +192,10 @@ Serialize access through a global lock. fn with_env_lock(f: || -> T) -> T { use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; - static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; unsafe { - let _guard = lock.lock(); + let _guard = LOCK.lock(); f() } } @@ -1073,7 +1073,7 @@ pub fn last_os_error() -> String { error_string(errno() as uint) } -static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT; +static EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT; /** * Sets the process exit code @@ -1086,13 +1086,13 @@ static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT; * Note that this is not synchronized against modifications of other threads. */ pub fn set_exit_status(code: int) { - unsafe { EXIT_STATUS.store(code, SeqCst) } + EXIT_STATUS.store(code, SeqCst) } /// Fetches the process's current exit code. This defaults to 0 and can change /// by calling `set_exit_status`. pub fn get_exit_status() -> int { - unsafe { EXIT_STATUS.load(SeqCst) } + EXIT_STATUS.load(SeqCst) } #[cfg(target_os = "macos")] diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 6cbbc0af3909e..e05e533be56c5 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -28,20 +28,18 @@ pub use self::imp::write; // For now logging is turned off by default, and this function checks to see // whether the magical environment variable is present to see if it's turned on. pub fn log_enabled() -> bool { - static mut ENABLED: atomic::AtomicInt = atomic::INIT_ATOMIC_INT; - unsafe { - match ENABLED.load(atomic::SeqCst) { - 1 => return false, - 2 => return true, - _ => {} - } + static ENABLED: atomic::AtomicInt = atomic::INIT_ATOMIC_INT; + match ENABLED.load(atomic::SeqCst) { + 1 => return false, + 2 => return true, + _ => {} } let val = match os::getenv("RUST_BACKTRACE") { Some(..) => 2, None => 1, }; - unsafe { ENABLED.store(val, atomic::SeqCst); } + ENABLED.store(val, atomic::SeqCst); val == 2 } @@ -268,7 +266,7 @@ mod imp { // while it doesn't requires lock for work as everything is // local, it still displays much nicer backtraces when a // couple of tasks fail simultaneously - static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; let _g = unsafe { LOCK.lock() }; try!(writeln!(w, "stack backtrace:")); @@ -301,7 +299,7 @@ mod imp { // is semi-reasonable in terms of printing anyway, and we know that all // I/O done here is blocking I/O, not green I/O, so we don't have to // worry about this being a native vs green mutex. - static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; let _g = unsafe { LOCK.lock() }; try!(writeln!(w, "stack backtrace:")); @@ -931,7 +929,7 @@ mod imp { pub fn write(w: &mut Writer) -> IoResult<()> { // According to windows documentation, all dbghelp functions are // single-threaded. - static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; + static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; let _g = unsafe { LOCK.lock() }; // Open up dbghelp.dll, we don't link to it explicitly because it can't diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index ed24ed2a569c7..ec301369804ed 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -41,8 +41,8 @@ pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool { } pub fn min_stack() -> uint { - static mut MIN: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; - match unsafe { MIN.load(atomic::SeqCst) } { + static MIN: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT; + match MIN.load(atomic::SeqCst) { 0 => {} n => return n - 1, } @@ -50,7 +50,7 @@ pub fn min_stack() -> uint { let amt = amt.unwrap_or(2 * 1024 * 1024); // 0 is our sentinel value, so ensure that we'll never see 0 after // initialization has run - unsafe { MIN.store(amt + 1, atomic::SeqCst); } + MIN.store(amt + 1, atomic::SeqCst); return amt; } diff --git a/src/libsync/atomic.rs b/src/libsync/atomic.rs index cd7102a756a4d..e853e44d6f9b5 100644 --- a/src/libsync/atomic.rs +++ b/src/libsync/atomic.rs @@ -93,12 +93,10 @@ //! ``` //! use std::sync::atomic::{AtomicUint, SeqCst, INIT_ATOMIC_UINT}; //! -//! static mut GLOBAL_TASK_COUNT: AtomicUint = INIT_ATOMIC_UINT; +//! static GLOBAL_TASK_COUNT: AtomicUint = INIT_ATOMIC_UINT; //! -//! unsafe { -//! let old_task_count = GLOBAL_TASK_COUNT.fetch_add(1, SeqCst); -//! println!("live tasks: {}", old_task_count + 1); -//! } +//! let old_task_count = GLOBAL_TASK_COUNT.fetch_add(1, SeqCst); +//! println!("live tasks: {}", old_task_count + 1); //! ``` #![allow(deprecated)] diff --git a/src/libsync/deque.rs b/src/libsync/deque.rs index 15c0c14b28a86..3388162932980 100644 --- a/src/libsync/deque.rs +++ b/src/libsync/deque.rs @@ -545,8 +545,8 @@ mod tests { fn stress() { static AMT: int = 100000; static NTHREADS: int = 8; - static mut DONE: AtomicBool = INIT_ATOMIC_BOOL; - static mut HITS: AtomicUint = INIT_ATOMIC_UINT; + static DONE: AtomicBool = INIT_ATOMIC_BOOL; + static HITS: AtomicUint = INIT_ATOMIC_UINT; let pool = BufferPool::::new(); let (w, s) = pool.deque(); @@ -604,7 +604,7 @@ mod tests { fn no_starvation() { static AMT: int = 10000; static NTHREADS: int = 4; - static mut DONE: AtomicBool = INIT_ATOMIC_BOOL; + static DONE: AtomicBool = INIT_ATOMIC_BOOL; let pool = BufferPool::<(int, uint)>::new(); let (w, s) = pool.deque(); diff --git a/src/libsync/mutex.rs b/src/libsync/mutex.rs index c6413d0d09cc7..9861d27c8cdf5 100644 --- a/src/libsync/mutex.rs +++ b/src/libsync/mutex.rs @@ -127,9 +127,9 @@ enum Flavor { /// ```rust /// use sync::mutex::{StaticMutex, MUTEX_INIT}; /// -/// static mut LOCK: StaticMutex = MUTEX_INIT; +/// static LOCK: StaticMutex = MUTEX_INIT; /// -/// unsafe { +/// { /// let _g = LOCK.lock(); /// // do some productive work /// } @@ -536,7 +536,7 @@ mod test { #[test] fn smoke_static() { - static mut m: StaticMutex = MUTEX_INIT; + static m: StaticMutex = MUTEX_INIT; unsafe { drop(m.lock()); drop(m.lock()); @@ -546,7 +546,7 @@ mod test { #[test] fn lots_and_lots() { - static mut m: StaticMutex = MUTEX_INIT; + static m: StaticMutex = MUTEX_INIT; static mut CNT: uint = 0; static M: uint = 1000; static N: uint = 3; diff --git a/src/libsync/one.rs b/src/libsync/one.rs index c740c4f3d2e95..f0c72780be10a 100644 --- a/src/libsync/one.rs +++ b/src/libsync/one.rs @@ -30,13 +30,11 @@ use mutex::{StaticMutex, MUTEX_INIT}; /// ```rust /// use sync::one::{Once, ONCE_INIT}; /// -/// static mut START: Once = ONCE_INIT; +/// static START: Once = ONCE_INIT; /// -/// unsafe { -/// START.doit(|| { -/// // run initialization here -/// }); -/// } +/// START.doit(|| { +/// // run initialization here +/// }); /// ``` pub struct Once { mutex: StaticMutex, @@ -128,17 +126,17 @@ mod test { #[test] fn smoke_once() { - static mut o: Once = ONCE_INIT; + static o: Once = ONCE_INIT; let mut a = 0i; - unsafe { o.doit(|| a += 1); } + o.doit(|| a += 1); assert_eq!(a, 1); - unsafe { o.doit(|| a += 1); } + o.doit(|| a += 1); assert_eq!(a, 1); } #[test] fn stampede_once() { - static mut o: Once = ONCE_INIT; + static o: Once = ONCE_INIT; static mut run: bool = false; let (tx, rx) = channel(); diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index b94885290b3a4..1e051bc1558f1 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -192,7 +192,7 @@ pub fn precise_time_ns() -> u64 { fn os_precise_time_ns() -> u64 { static mut TIMEBASE: libc::mach_timebase_info = libc::mach_timebase_info { numer: 0, denom: 0 }; - static mut ONCE: std::sync::Once = std::sync::ONCE_INIT; + static ONCE: std::sync::Once = std::sync::ONCE_INIT; unsafe { ONCE.doit(|| { imp::mach_timebase_info(&mut TIMEBASE); diff --git a/src/snapshots.txt b/src/snapshots.txt index ab5b6b280dc87..4d88fd6a03164 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -1,3 +1,12 @@ +S 2014-10-10 78a7676 + freebsd-x86_64 511061af382e2e837a6d615823e1a952e8281483 + linux-i386 0644637db852db8a6c603ded0531ccaa60291bd3 + linux-x86_64 656b8c23fbb97794e85973aca725a4b9cd07b29e + macos-i386 e4d9709fcfe485fcca00f0aa1fe456e2f164ed96 + macos-x86_64 6b1aa5a441965da87961be81950e8663eadba377 + winnt-i386 b87f8f040adb464e9f8455a37de8582e9e2c8cf3 + winnt-x86_64 b883264902ac0585a80175ba27dc141f5c4f8618 + S 2014-10-04 749ff5e freebsd-x86_64 f39d94487d29b3d48217b1295ad2cda8c941e694 linux-i386 555aca74f9a268f80cab2df1147dc6406403e9e4