Skip to content

Commit c16919d

Browse files
committed
Removing mut fields from vec.rs, at_vec.rs, str.rs, unstable.rs, and cell.rs.
1 parent 260d74d commit c16919d

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

src/libcore/at_vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub mod raw {
208208
*/
209209
#[inline(always)]
210210
pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
211-
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
211+
let repr: **mut VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
212212
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
213213
}
214214

@@ -226,7 +226,7 @@ pub mod raw {
226226

227227
#[inline(always)] // really pretty please
228228
pub unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
229-
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
229+
let repr: **mut VecRepr = ::cast::reinterpret_cast(&v);
230230
let fill = (**repr).unboxed.fill;
231231
(**repr).unboxed.fill += sys::size_of::<T>();
232232
let p = addr_of(&((**repr).unboxed.data));

src/libcore/cell.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! A mutable, nullable memory location
1212
13-
use cast::transmute;
13+
use cast::transmute_mut;
1414
use prelude::*;
1515

1616
/*
@@ -20,16 +20,12 @@ Similar to a mutable option type, but friendlier.
2020
*/
2121

2222
pub struct Cell<T> {
23-
mut value: Option<T>
23+
value: Option<T>
2424
}
2525

2626
impl<T:cmp::Eq> cmp::Eq for Cell<T> {
2727
fn eq(&self, other: &Cell<T>) -> bool {
28-
unsafe {
29-
let frozen_self: &Option<T> = transmute(&mut self.value);
30-
let frozen_other: &Option<T> = transmute(&mut other.value);
31-
frozen_self == frozen_other
32-
}
28+
(self.value) == (other.value)
3329
}
3430
fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
3531
}
@@ -46,6 +42,7 @@ pub fn empty_cell<T>() -> Cell<T> {
4642
pub impl<T> Cell<T> {
4743
/// Yields the value, failing if the cell is empty.
4844
fn take(&self) -> T {
45+
let mut self = unsafe { transmute_mut(self) };
4946
if self.is_empty() {
5047
fail!(~"attempt to take an empty cell");
5148
}
@@ -57,6 +54,7 @@ pub impl<T> Cell<T> {
5754
5855
/// Returns the value, failing if the cell is full.
5956
fn put_back(&self, value: T) {
57+
let mut self = unsafe { transmute_mut(self) };
6058
if !self.is_empty() {
6159
fail!(~"attempt to put a value back into a full cell");
6260
}

src/libcore/str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2274,8 +2274,8 @@ pub mod raw {
22742274

22752275
/// Sets the length of the string and adds the null terminator
22762276
pub unsafe fn set_len(v: &mut ~str, new_len: uint) {
2277-
let v: **vec::raw::VecRepr = cast::transmute(v);
2278-
let repr: *vec::raw::VecRepr = *v;
2277+
let v: **mut vec::raw::VecRepr = cast::transmute(v);
2278+
let repr: *mut vec::raw::VecRepr = *v;
22792279
(*repr).unboxed.fill = new_len + 1u;
22802280
let null = ptr::mut_offset(cast::transmute(&((*repr).unboxed.data)),
22812281
new_len);

src/libcore/unstable.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool {
106106
****************************************************************************/
107107

108108
struct ArcData<T> {
109-
mut count: libc::intptr_t,
109+
count: libc::intptr_t,
110110
// FIXME(#3224) should be able to make this non-option to save memory
111-
mut data: Option<T>,
111+
data: Option<T>,
112112
}
113113

114114
struct ArcDestruct<T> {
115-
mut data: *libc::c_void,
115+
data: *libc::c_void,
116116
}
117117

118118
#[unsafe_destructor]
@@ -122,7 +122,7 @@ impl<T> Drop for ArcDestruct<T>{
122122
do task::unkillable {
123123
let data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
124124
let new_count =
125-
intrinsics::atomic_xsub(&mut data.count, 1) - 1;
125+
intrinsics::atomic_xsub(cast::transmute_mut(&data.count), 1) - 1;
126126
assert!(new_count >= 0);
127127
if new_count == 0 {
128128
// drop glue takes over.
@@ -186,7 +186,7 @@ pub unsafe fn clone_shared_mutable_state<T:Owned>(rc: &SharedMutableState<T>)
186186
-> SharedMutableState<T> {
187187
unsafe {
188188
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
189-
let new_count = intrinsics::atomic_xadd(&mut ptr.count, 1) + 1;
189+
let new_count = intrinsics::atomic_xadd(cast::transmute_mut(&ptr.count), 1) + 1;
190190
assert!(new_count >= 2);
191191
cast::forget(ptr);
192192
}
@@ -252,15 +252,15 @@ pub impl LittleLock {
252252
}
253253
}
254254

255-
struct ExData<T> { lock: LittleLock, mut failed: bool, mut data: T, }
255+
struct ExData<T> { lock: LittleLock, failed: bool, data: T, }
256256
/**
257257
* An arc over mutable data that is protected by a lock. For library use only.
258258
*/
259259
pub struct Exclusive<T> { x: SharedMutableState<ExData<T>> }
260260

261261
pub fn exclusive<T:Owned>(user_data: T) -> Exclusive<T> {
262262
let data = ExData {
263-
lock: LittleLock(), mut failed: false, mut data: user_data
263+
lock: LittleLock(), failed: false, data: user_data
264264
};
265265
Exclusive { x: unsafe { shared_mutable_state(data) } }
266266
}

src/libcore/vec.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ pub fn push<T>(v: &mut ~[T], initval: T) {
633633
// This doesn't bother to make sure we have space.
634634
#[inline(always)] // really pretty please
635635
unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
636-
let repr: **raw::VecRepr = ::cast::transmute(v);
636+
let repr: **mut raw::VecRepr = ::cast::transmute(v);
637637
let fill = (**repr).unboxed.fill;
638638
(**repr).unboxed.fill += sys::nonzero_size_of::<T>();
639639
let p = addr_of(&((**repr).unboxed.data));
@@ -2148,8 +2148,8 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
21482148

21492149
/// The internal 'unboxed' representation of a vector
21502150
pub struct UnboxedVecRepr {
2151-
mut fill: uint,
2152-
mut alloc: uint,
2151+
fill: uint,
2152+
alloc: uint,
21532153
data: u8
21542154
}
21552155

@@ -2171,8 +2171,8 @@ pub mod raw {
21712171
}
21722172

21732173
pub struct SliceRepr {
2174-
mut data: *u8,
2175-
mut len: uint
2174+
data: *u8,
2175+
len: uint
21762176
}
21772177

21782178
/**
@@ -2184,7 +2184,7 @@ pub mod raw {
21842184
*/
21852185
#[inline(always)]
21862186
pub unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) {
2187-
let repr: **VecRepr = ::cast::transmute(v);
2187+
let repr: **mut VecRepr = ::cast::transmute(v);
21882188
(**repr).unboxed.fill = new_len * sys::nonzero_size_of::<T>();
21892189
}
21902190

0 commit comments

Comments
 (0)