From c16919d3a8e83e4c72668f6ad89d48f6ba8341f6 Mon Sep 17 00:00:00 2001 From: Matthijs Hofstra Date: Tue, 2 Apr 2013 23:15:04 +0200 Subject: [PATCH] Removing mut fields from vec.rs, at_vec.rs, str.rs, unstable.rs, and cell.rs. --- src/libcore/at_vec.rs | 4 ++-- src/libcore/cell.rs | 12 +++++------- src/libcore/str.rs | 4 ++-- src/libcore/unstable.rs | 14 +++++++------- src/libcore/vec.rs | 12 ++++++------ 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 3e3d70530dd35..38a663dc24504 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -208,7 +208,7 @@ pub mod raw { */ #[inline(always)] pub unsafe fn set_len(v: @[T], new_len: uint) { - let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v)); + let repr: **mut VecRepr = ::cast::reinterpret_cast(&addr_of(&v)); (**repr).unboxed.fill = new_len * sys::size_of::(); } @@ -226,7 +226,7 @@ pub mod raw { #[inline(always)] // really pretty please pub unsafe fn push_fast(v: &mut @[T], initval: T) { - let repr: **VecRepr = ::cast::reinterpret_cast(&v); + let repr: **mut VecRepr = ::cast::reinterpret_cast(&v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); let p = addr_of(&((**repr).unboxed.data)); diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 28b3ebe4484c7..c2983e033e537 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -10,7 +10,7 @@ //! A mutable, nullable memory location -use cast::transmute; +use cast::transmute_mut; use prelude::*; /* @@ -20,16 +20,12 @@ Similar to a mutable option type, but friendlier. */ pub struct Cell { - mut value: Option + value: Option } impl cmp::Eq for Cell { fn eq(&self, other: &Cell) -> bool { - unsafe { - let frozen_self: &Option = transmute(&mut self.value); - let frozen_other: &Option = transmute(&mut other.value); - frozen_self == frozen_other - } + (self.value) == (other.value) } fn ne(&self, other: &Cell) -> bool { !self.eq(other) } } @@ -46,6 +42,7 @@ pub fn empty_cell() -> Cell { pub impl Cell { /// Yields the value, failing if the cell is empty. fn take(&self) -> T { + let mut self = unsafe { transmute_mut(self) }; if self.is_empty() { fail!(~"attempt to take an empty cell"); } @@ -57,6 +54,7 @@ pub impl Cell { /// Returns the value, failing if the cell is full. fn put_back(&self, value: T) { + let mut self = unsafe { transmute_mut(self) }; if !self.is_empty() { fail!(~"attempt to put a value back into a full cell"); } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 67fd37996cda0..18ea169d96e5c 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -2274,8 +2274,8 @@ pub mod raw { /// Sets the length of the string and adds the null terminator pub unsafe fn set_len(v: &mut ~str, new_len: uint) { - let v: **vec::raw::VecRepr = cast::transmute(v); - let repr: *vec::raw::VecRepr = *v; + let v: **mut vec::raw::VecRepr = cast::transmute(v); + let repr: *mut vec::raw::VecRepr = *v; (*repr).unboxed.fill = new_len + 1u; let null = ptr::mut_offset(cast::transmute(&((*repr).unboxed.data)), new_len); diff --git a/src/libcore/unstable.rs b/src/libcore/unstable.rs index 665a3e1b6b6d4..e2b57a8dd3eda 100644 --- a/src/libcore/unstable.rs +++ b/src/libcore/unstable.rs @@ -106,13 +106,13 @@ fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool { ****************************************************************************/ struct ArcData { - mut count: libc::intptr_t, + count: libc::intptr_t, // FIXME(#3224) should be able to make this non-option to save memory - mut data: Option, + data: Option, } struct ArcDestruct { - mut data: *libc::c_void, + data: *libc::c_void, } #[unsafe_destructor] @@ -122,7 +122,7 @@ impl Drop for ArcDestruct{ do task::unkillable { let data: ~ArcData = cast::reinterpret_cast(&self.data); let new_count = - intrinsics::atomic_xsub(&mut data.count, 1) - 1; + intrinsics::atomic_xsub(cast::transmute_mut(&data.count), 1) - 1; assert!(new_count >= 0); if new_count == 0 { // drop glue takes over. @@ -186,7 +186,7 @@ pub unsafe fn clone_shared_mutable_state(rc: &SharedMutableState) -> SharedMutableState { unsafe { let ptr: ~ArcData = cast::reinterpret_cast(&(*rc).data); - let new_count = intrinsics::atomic_xadd(&mut ptr.count, 1) + 1; + let new_count = intrinsics::atomic_xadd(cast::transmute_mut(&ptr.count), 1) + 1; assert!(new_count >= 2); cast::forget(ptr); } @@ -252,7 +252,7 @@ pub impl LittleLock { } } -struct ExData { lock: LittleLock, mut failed: bool, mut data: T, } +struct ExData { lock: LittleLock, failed: bool, data: T, } /** * An arc over mutable data that is protected by a lock. For library use only. */ @@ -260,7 +260,7 @@ pub struct Exclusive { x: SharedMutableState> } pub fn exclusive(user_data: T) -> Exclusive { let data = ExData { - lock: LittleLock(), mut failed: false, mut data: user_data + lock: LittleLock(), failed: false, data: user_data }; Exclusive { x: unsafe { shared_mutable_state(data) } } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 0ac86ac280d06..21e876ea0fb02 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -633,7 +633,7 @@ pub fn push(v: &mut ~[T], initval: T) { // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please unsafe fn push_fast(v: &mut ~[T], initval: T) { - let repr: **raw::VecRepr = ::cast::transmute(v); + let repr: **mut raw::VecRepr = ::cast::transmute(v); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::nonzero_size_of::(); let p = addr_of(&((**repr).unboxed.data)); @@ -2148,8 +2148,8 @@ pub unsafe fn from_buf(ptr: *T, elts: uint) -> ~[T] { /// The internal 'unboxed' representation of a vector pub struct UnboxedVecRepr { - mut fill: uint, - mut alloc: uint, + fill: uint, + alloc: uint, data: u8 } @@ -2171,8 +2171,8 @@ pub mod raw { } pub struct SliceRepr { - mut data: *u8, - mut len: uint + data: *u8, + len: uint } /** @@ -2184,7 +2184,7 @@ pub mod raw { */ #[inline(always)] pub unsafe fn set_len(v: &mut ~[T], new_len: uint) { - let repr: **VecRepr = ::cast::transmute(v); + let repr: **mut VecRepr = ::cast::transmute(v); (**repr).unboxed.fill = new_len * sys::nonzero_size_of::(); }