* # WARNING
*
* For maximum performance, this type is implemented using some rather
- * unsafe code. In particular, this innocent looking `~[mut A]` pointer
+ * unsafe code. In particular, this innocent looking `~[A]` pointer
* *may be null!* Therefore, it is important you not reach into the
* data structure manually but instead use the provided extensions.
*
* and return a new vector to replace it with.
*/
#[inline(always)]
- fn swap_mut(f: &fn(v: ~[mut A]) -> ~[mut A]) {
+ fn swap_mut(f: &fn(v: ~[A]) -> ~[A]) {
do self.swap |v| {
vec::cast_from_mut(f(vec::cast_to_mut(move v)))
}
}
/// Produces a mut vector from an immutable vector.
-pub pure fn cast_to_mut<T>(v: ~[T]) -> ~[mut T] {
+pub pure fn cast_to_mut<T>(v: ~[T]) -> ~[T] {
unsafe { ::cast::transmute(v) }
}
/// Produces an immutable vector from a mut vector.
-pub pure fn cast_from_mut<T>(v: ~[mut T]) -> ~[T] {
+pub pure fn cast_from_mut<T>(v: ~[T]) -> ~[T] {
unsafe { ::cast::transmute(v) }
}
}
}
-pub fn consume_mut<T>(v: ~[mut T], f: fn(uint, v: T)) {
+pub fn consume_mut<T>(v: ~[T], f: fn(uint, v: T)) {
consume(vec::cast_from_mut(v), f)
}
}
#[inline(always)]
-pub pure fn append_mut<T: Copy>(lhs: ~[mut T], rhs: &[const T]) -> ~[mut T] {
+pub pure fn append_mut<T: Copy>(lhs: ~[T], rhs: &[const T]) -> ~[T] {
cast_to_mut(append(cast_from_mut(lhs), rhs))
}
}
}
- impl<T: Copy> ~[mut T] : Add<&[const T],~[mut T]> {
+ impl<T: Copy> ~[T] : Add<&[const T],~[T]> {
#[inline(always)]
- pure fn add(&self, rhs: & &self/[const T]) -> ~[mut T] {
+ pure fn add(&self, rhs: & &self/[const T]) -> ~[T] {
append_mut(copy *self, (*rhs))
}
}
mut g : fn~()->(),
mut m : ~[maybe_pointy],
- mut n : ~[mut maybe_pointy],
+ mut n : ~[maybe_pointy],
mut o : {x : int, y : maybe_pointy}
};
// To add: objects; traits; anything type-parameterized?
fn unlikely(r : rand::rng, n : uint) -> bool { under(r, n) == 0u }
// shuffle a vec in place
-fn shuffle<T>(r : rand::rng, &v : ~[mut T]) {
+fn shuffle<T>(r : rand::rng, &v : ~[T]) {
let i = vec::len(v);
while i >= 2u {
// Loop invariant: elements with index >= i have been locked in place.
mut storage: ~[uint]
}
-fn BigBitv(storage: ~[mut uint]) -> BigBitv {
+fn BigBitv(storage: ~[uint]) -> BigBitv {
BigBitv {storage: move storage}
}
}
}
- fn chains<K,V>(nchains: uint) -> ~[mut Option<@Entry<K,V>>] {
+ fn chains<K,V>(nchains: uint) -> ~[Option<@Entry<K,V>>] {
vec::cast_to_mut(vec::from_elem(nchains, None))
}
/// Construct a `sha` object
pub fn sha1() -> Sha1 {
type Sha1State =
- {h: ~[mut u32],
+ {h: ~[u32],
mut len_low: u32,
mut len_high: u32,
mut msg_block: ~[u8],
mut msg_block_idx: uint,
mut computed: bool,
- work_buf: @~[mut u32]};
+ work_buf: @~[u32]};
fn add_input(st: &Sha1State, msg: &[const u8]) {
assert (!st.computed);
tabulate_managed(low, high);
}
- fn multiplyVec<T: Copy>(arr: &[const T], num: uint) -> ~[mut T] {
+ fn multiplyVec<T: Copy>(arr: &[const T], num: uint) -> ~[T] {
let size = arr.len();
let res = do vec::from_fn(num) |i| {
arr[i % size]
}
#[doc(hidden)]
fn new_sem_and_signal(count: int, num_condvars: uint)
- -> Sem<~[mut Waitqueue]> {
+ -> Sem<~[Waitqueue]> {
let mut queues = ~[];
for num_condvars.times {
queues.push(new_waitqueue());
}
}
#[doc(hidden)]
-impl &Sem<~[mut Waitqueue]> {
+impl &Sem<~[Waitqueue]> {
fn access<U>(blk: fn() -> U) -> U {
let mut release = None;
unsafe {
// FIXME(#3588) should go inside of access()
#[doc(hidden)]
type SemRelease = SemReleaseGeneric<()>;
-type SemAndSignalRelease = SemReleaseGeneric<~[mut Waitqueue]>;
+type SemAndSignalRelease = SemReleaseGeneric<~[Waitqueue]>;
struct SemReleaseGeneric<Q> { sem: &Sem<Q> }
impl<Q: Owned> SemReleaseGeneric<Q> : Drop {
}
}
-fn SemAndSignalRelease(sem: &r/Sem<~[mut Waitqueue]>)
+fn SemAndSignalRelease(sem: &r/Sem<~[Waitqueue]>)
-> SemAndSignalRelease/&r {
SemReleaseGeneric {
sem: sem
}
/// A mechanism for atomic-unlock-and-deschedule blocking and signalling.
-pub struct Condvar { priv sem: &Sem<~[mut Waitqueue]> }
+pub struct Condvar { priv sem: &Sem<~[Waitqueue]> }
impl Condvar : Drop { fn finalize(&self) {} }
// mutex during unwinding. As long as the wrapper (mutex, etc) is
// bounded in when it gets released, this shouldn't hang forever.
struct SemAndSignalReacquire {
- sem: &Sem<~[mut Waitqueue]>,
+ sem: &Sem<~[Waitqueue]>,
}
impl SemAndSignalReacquire : Drop {
}
}
- fn SemAndSignalReacquire(sem: &r/Sem<~[mut Waitqueue]>)
+ fn SemAndSignalReacquire(sem: &r/Sem<~[Waitqueue]>)
-> SemAndSignalReacquire/&r {
SemAndSignalReacquire {
sem: sem
}
#[doc(hidden)]
-impl &Sem<~[mut Waitqueue]> {
+impl &Sem<~[Waitqueue]> {
// The only other place that condvars get built is rwlock_write_mode.
fn access_cond<U>(blk: fn(c: &Condvar) -> U) -> U {
do self.access { blk(&Condvar { sem: self }) }
* A task which fails while holding a mutex will unlock the mutex as it
* unwinds.
*/
-struct Mutex { priv sem: Sem<~[mut Waitqueue]> }
+struct Mutex { priv sem: Sem<~[Waitqueue]> }
/// Create a new mutex, with one associated condvar.
pub fn Mutex() -> Mutex { mutex_with_condvars(1) }
*/
struct RWlock {
priv order_lock: Semaphore,
- priv access_lock: Sem<~[mut Waitqueue]>,
+ priv access_lock: Sem<~[Waitqueue]>,
priv state: Exclusive<RWlockInner>
}
}
}
-pub fn buf_str(toks: ~[mut token], szs: ~[mut int], left: uint, right: uint,
+pub fn buf_str(toks: ~[token], szs: ~[int], left: uint, right: uint,
lim: uint) -> ~str {
let n = vec::len(toks);
assert (n == vec::len(szs));
export grid_t, read_grid, solve_grid, write_grid;
// internal type of sudoku grids
-type grid = ~[~[mut u8]];
+type grid = ~[~[u8]];
// exported type of sudoku grids
enum grid_t { grid_ctor(grid), }
return sum;
}
-fn has_mut_vec(+v: @~[mut int]) -> int {
+fn has_mut_vec(+v: @~[int]) -> int {
want_slice(*v) //~ ERROR illegal borrow unless pure
//~^ NOTE impure due to access to impure function
}
fn main() {
- assert has_mut_vec(@~[mut 1, 2, 3]) == 6;
+ assert has_mut_vec(@~[1, 2, 3]) == 6;
}
\ No newline at end of file
let mut res = foo(x);
let mut v = ~[];
- v = move ~[mut (move res)] + v; //~ ERROR instantiating a type parameter with an incompatible type (needs `copy`, got `&static`, missing `copy`)
+ v = move ~[(move res)] + v; //~ ERROR instantiating a type parameter with an incompatible type (needs `copy`, got `&static`, missing `copy`)
assert (v.len() == 2);
}
let v = @mut ~[0];
fn f(&&v: @mut ~[const int]) {
- *v = ~[mut 3]
+ *v = ~[3]
}
f(v);
fn main() {
let mut v = ~[@mut ~mut ~[0]];
- fn f(&&v: ~[mut @mut ~mut ~[const int]]) {
+ fn f(&&v: ~[@mut ~mut ~[const int]]) {
}
f(v);
fn f(&&v: *mut ~[const int]) {
unsafe {
- *v = ~[mut 3]
+ *v = ~[3]
}
}
let v = {mut g: ~[0]};
fn f(&&v: {mut g: ~[const int]}) {
- v.g = ~[mut 3]
+ v.g = ~[3]
}
f(v);
let v = ~mut ~[0];
fn f(&&v: ~mut ~[const int]) {
- *v = ~[mut 3]
+ *v = ~[3]
}
f(v);
fn main() {
// Note: explicit type annot is required here
// because otherwise the inference gets smart
- // and assigns a type of ~[mut ~[const int]].
+ // and assigns a type of ~[~[const int]].
let mut v: ~[~[int]] = ~[~[0]];
- fn f(&&v: ~[mut ~[const int]]) {
- v[0] = ~[mut 3]
+ fn f(&&v: ~[~[const int]]) {
+ v[0] = ~[3]
}
f(v); //~ ERROR (values differ in mutability)
fn main() {
// Note: explicit type annot is required here
// because otherwise the inference gets smart
- // and assigns a type of ~[mut ~[const int]].
- let mut v: ~[~[mut int]] = ~[~[0]];
+ // and assigns a type of ~[~[const int]].
+ let mut v: ~[~[int]] = ~[~[0]];
- fn f(&&v: ~[mut ~[const int]]) {
+ fn f(&&v: ~[~[const int]]) {
v[0] = ~[3]
}
fn main() {
// Note: explicit type annot is required here
// because otherwise the inference gets smart
- // and assigns a type of ~[mut ~[const int]].
- let mut v: ~[~[mut ~[int]]] = ~[~[~[0]]];
+ // and assigns a type of ~[~[const int]].
+ let mut v: ~[~[~[int]]] = ~[~[~[0]]];
- fn f(&&v: ~[mut ~[mut ~[const int]]]) {
- v[0][1] = ~[mut 3]
+ fn f(&&v: ~[~[~[const int]]]) {
+ v[0][1] = ~[3]
}
f(v); //~ ERROR (values differ in mutability)
let mut w = ~[~[0]];
let mut x = ~[~[0]];
- fn f(&&v: ~[mut ~[int]]) {
+ fn f(&&v: ~[~[int]]) {
v[0] = ~[3]
}
fn g(&&v: ~[const ~[const int]]) {
}
- fn h(&&v: ~[mut ~[mut int]]) {
- v[0] = ~[mut 3]
+ fn h(&&v: ~[~[int]]) {
+ v[0] = ~[3]
}
- fn i(&&v: ~[mut ~[const int]]) {
- v[0] = ~[mut 3]
+ fn i(&&v: ~[~[const int]]) {
+ v[0] = ~[3]
}
fn j(&&v: ~[~[const int]]) {
j(w); //~ ERROR (values differ in mutability)
// Note that without adding f() or h() to the mix, it is valid for
- // x to have the type ~[mut ~[const int]], and thus we can safely
+ // x to have the type ~[~[const int]], and thus we can safely
// call g() and i() but not j():
g(x);
i(x);
foo({f: 3});
foo({mut f: 3}); //~ ERROR missing `const`
foo(~[1]);
- foo(~[mut 1]); //~ ERROR missing `const`
+ foo(~[1]); //~ ERROR missing `const`
foo(~1);
foo(~mut 1); //~ ERROR missing `const`
foo(@1);
// the right hand side in all cases. We are getting compiler errors
// about this now, so I'm xfailing the test for now. -eholk
-fn add(i: ~[int], m: ~[mut int], c: ~[const int]) {
+fn add(i: ~[int], m: ~[int], c: ~[const int]) {
// Check that:
// (1) vectors of any two mutabilities can be added
m + ~[3],
~[3]);
- add(i + ~[mut 3],
- m + ~[mut 3],
- ~[mut 3]);
+ add(i + ~[3],
+ m + ~[3],
+ ~[3]);
add(i + i,
m + i,
//~^ mismatched types
~[3]);
- add(m + ~[mut 3], //~ ERROR mismatched types
- m + ~[mut 3],
- m + ~[mut 3]);
+ add(m + ~[3], //~ ERROR mismatched types
+ m + ~[3],
+ m + ~[3]);
- add(i + ~[mut 3],
- i + ~[mut 3], //~ ERROR mismatched types
- i + ~[mut 3]);
+ add(i + ~[3],
+ i + ~[3], //~ ERROR mismatched types
+ i + ~[3]);
- add(c + ~[mut 3], //~ ERROR binary operation + cannot be applied
+ add(c + ~[3], //~ ERROR binary operation + cannot be applied
//~^ mismatched types
- c + ~[mut 3], //~ ERROR binary operation + cannot be applied
+ c + ~[3], //~ ERROR binary operation + cannot be applied
//~^ mismatched types
- ~[mut 3]);
+ ~[3]);
add(m + i, //~ ERROR mismatched types
m + i,
return sum;
}
-fn has_mut_vec(+v: ~[mut int]) -> int {
+fn has_mut_vec(+v: ~[int]) -> int {
want_slice(v)
}
fn main() {
- assert has_mut_vec(~[mut 1, 2, 3]) == 6;
+ assert has_mut_vec(~[1, 2, 3]) == 6;
}
\ No newline at end of file
width: uint,
height: uint,
priv fill: char,
- priv lines: ~[~[mut char]],
+ priv lines: ~[~[char]],
// This struct can be quite large so we'll disable copying: developers need
// to either pass these structs around via borrowed pointers or move them.
some(T),
}
-struct Smallintmap<T> {mut v: ~[mut option<T>]}
+struct Smallintmap<T> {mut v: ~[option<T>]}
-struct V<T> { v: ~[mut option<T>] }
+struct V<T> { v: ~[option<T>] }
fn mk<T>() -> @Smallintmap<T> {
let mut v: ~[option<T>] = ~[];
fn main() {
// This just tests whether the vec leaks its members.
let mut pvec: ~[@Pair] =
- ~[mut @Pair{a: 1, b: 2}, @Pair{a: 3, b: 4}, @Pair{a: 5, b: 6}];
+ ~[@Pair{a: 1, b: 2}, @Pair{a: 3, b: 4}, @Pair{a: 5, b: 6}];
}