Skip to content

Remove inner mut on vectors #4700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Feb 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ For example:

~~~~
trait Num {
static pure fn from_int(n: int) -> self;
static pure fn from_int(n: int) -> Self;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously unrelated, but was necessary to pass make check after rebasing.

}
impl float: Num {
static pure fn from_int(n: int) -> float { n as float }
Expand Down Expand Up @@ -1716,15 +1716,12 @@ vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]

A [_vector_](#vector-types) _expression_ is written by enclosing zero or
more comma-separated expressions of uniform type in square brackets.
The keyword `mut` can be written after the opening bracket to
indicate that the elements of the resulting vector may be mutated.
When no mutability is specified, the vector is immutable.

~~~~
[1, 2, 3, 4];
["a", "b", "c", "d"];
[0, ..128]; // vector with 128 zeros
[mut 0u8, 0u8, 0u8, 0u8];
[0u8, 0u8, 0u8, 0u8];
~~~~

### Index expressions
Expand All @@ -1746,7 +1743,6 @@ task in a _failing state_.
# do task::spawn_unlinked {

([1, 2, 3, 4])[0];
([mut 'x', 'y'])[1] = 'z';
(["a", "b"])[10]; // fails

# }
Expand Down Expand Up @@ -1909,8 +1905,8 @@ No allocation or destruction is entailed.
An example of three different swap expressions:

~~~~~~~~
# let mut x = &[mut 0];
# let mut a = &[mut 0];
# let mut x = &mut [0];
# let mut a = &mut [0];
# let i = 0;
# let y = {mut z: 0};
# let b = {mut c: 0};
Expand Down Expand Up @@ -2005,11 +2001,11 @@ the unary copy operator is typically only used to cause an argument to a functio
An example of a copy expression:

~~~~
fn mutate(vec: ~[mut int]) {
fn mutate(mut vec: ~[int]) {
vec[0] = 10;
}

let v = ~[mut 1,2,3];
let v = ~[1,2,3];

mutate(copy v); // Pass a copy

Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ Finally, tasks can be configured to not propagate failure to each
other at all, using `task::spawn_unlinked` for _isolated failure_.

~~~
# fn random() -> int { 100 }
# fn sleep_for(i: int) { for i.times { task::yield() } }
# fn random() -> uint { 100 }
# fn sleep_for(i: uint) { for i.times { task::yield() } }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another unrelated change that was necessary to pass the tests after rebasing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is #4704.

# do task::try::<()> {
let (time1, time2) = (random(), random());
do task::spawn_unlinked {
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ Generic `type`, `struct`, and `enum` declarations follow the same pattern:
type Set<T> = HashMap<T, ()>;

struct Stack<T> {
elements: ~[mut T]
elements: ~[T]
}

enum Option<T> {
Expand Down
6 changes: 3 additions & 3 deletions src/libfuzzer/cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type pointy = {
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?
Expand All @@ -58,7 +58,7 @@ fn empty_pointy() -> @pointy {
mut g : fn~()->(){},

mut m : ~[],
mut n : ~[mut],
mut n : ~[],
mut o : {x : 0, y : none}
}
}
Expand All @@ -68,7 +68,7 @@ fn nop<T>(_x: T) { }

fn test_cycles(r : rand::rng, k: uint, n: uint)
{
let v : ~[mut @pointy] = ~[mut];
let mut v : ~[@pointy] = ~[];

// Create a graph with no edges
range(0u, vlen) {|_i|
Expand Down
4 changes: 2 additions & 2 deletions src/libfuzzer/rand_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn choice<T: copy>(r : rand::rng, v : ~[T]) -> T {
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.
Expand Down Expand Up @@ -86,7 +86,7 @@ fn main()
log(error, choice(r, ~[10, 20, 30]));
log(error, if unlikely(r, 5u) { "unlikely" } else { "likely" });

let a = ~[mut 1, 2, 3];
let mut a = ~[1, 2, 3];
shuffle(r, a);
log(error, a);

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/markdown_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn readclose(fd: libc::c_int) -> ~str {
let file = os::fdopen(fd);
let reader = io::FILE_reader(file, false);
let buf = io::with_bytes_writer(|writer| {
let mut bytes = [mut 0, ..4096];
let mut bytes = [0, ..4096];
while !reader.eof() {
let nread = reader.read(bytes, bytes.len());
writer.write(bytes.view(0, nread));
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ impl SmallBitv {

struct BigBitv {
// only mut b/c of clone and lack of other constructor
mut storage: ~[mut uint]
mut storage: ~[uint]
}

fn BigBitv(storage: ~[mut uint]) -> BigBitv {
fn BigBitv(storage: ~[uint]) -> BigBitv {
BigBitv {storage: move storage}
}

Expand Down Expand Up @@ -233,7 +233,7 @@ pub fn Bitv (nbits: uint, init: bool) -> Bitv {
let nelems = nbits/uint_bits +
if nbits % uint_bits == 0 {0} else {1};
let elem = if init {!0} else {0};
let s = cast_to_mut(from_elem(nelems, elem));
let s = from_elem(nelems, elem);
Big(~BigBitv(move s))
};
Bitv {rep: move rep, nbits: nbits}
Expand Down Expand Up @@ -518,7 +518,7 @@ impl Bitv: Clone {
Bitv{nbits: self.nbits, rep: Small(~SmallBitv{bits: b.bits})}
}
Big(ref b) => {
let st = cast_to_mut(from_elem(self.nbits / uint_bits + 1, 0));
let mut st = from_elem(self.nbits / uint_bits + 1, 0);
let len = st.len();
for uint::range(0, len) |i| { st[i] = b.storage[i]; };
Bitv{nbits: self.nbits, rep: Big(~BigBitv{storage: move st})}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub impl BufReader {
}

impl BufReader: Reader {
fn read(&self, bytes: &[mut u8], len: uint) -> uint {
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
self.as_bytes_reader(|r| r.read(bytes, len) )
}
fn read_byte(&self) -> int {
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub mod chained {

struct HashMap_<K, V> {
mut count: uint,
mut chains: ~[mut Option<@Entry<K,V>>]
mut chains: ~[Option<@Entry<K,V>>]
}

pub type T<K, V> = @HashMap_<K, V>;
Expand Down Expand Up @@ -209,7 +209,7 @@ pub mod chained {
fn rehash() {
let n_old_chains = self.chains.len();
let n_new_chains: uint = uint::next_power_of_two(n_old_chains+1u);
let new_chains = chains(n_new_chains);
let mut new_chains = chains(n_new_chains);
for self.each_entry |entry| {
let idx = entry.hash % n_new_chains;
entry.next = new_chains[idx];
Expand Down Expand Up @@ -458,8 +458,8 @@ pub mod chained {
}
}

fn chains<K,V>(nchains: uint) -> ~[mut Option<@Entry<K,V>>] {
vec::cast_to_mut(vec::from_elem(nchains, None))
fn chains<K,V>(nchains: uint) -> ~[Option<@Entry<K,V>>] {
vec::from_elem(nchains, None)
}

pub fn mk<K:Eq IterBytes Hash, V: Copy>() -> T<K,V> {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/net_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ impl TcpSocket {

/// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket`
impl TcpSocketBuf: io::Reader {
fn read(&self, buf: &[mut u8], len: uint) -> uint {
fn read(&self, buf: &mut [u8], len: uint) -> uint {
if len == 0 { return 0 }
let mut count: uint = 0;

Expand Down
9 changes: 4 additions & 5 deletions src/libstd/rope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ pub mod node {
* * forest - The forest. This vector is progressively rewritten during
* execution and should be discarded as meaningless afterwards.
*/
pub fn tree_from_forest_destructive(forest: &[mut @Node]) -> @Node {
pub fn tree_from_forest_destructive(forest: &mut [@Node]) -> @Node {
let mut i;
let mut len = vec::len(forest);
while len > 1u {
Expand Down Expand Up @@ -1158,18 +1158,17 @@ pub mod node {
use core::vec;

pub struct T {
stack: ~[mut @Node],
mut stack: ~[@Node],
mut stackpos: int,
}

pub fn empty() -> T {
let stack : ~[mut @Node] = ~[mut];
let mut stack : ~[@Node] = ~[];
T { stack: stack, stackpos: -1 }
}

pub fn start(node: @Node) -> T {
let stack = vec::cast_to_mut(
vec::from_elem(height(node)+1u, node));
let stack = vec::from_elem(height(node)+1u, node);
T {
stack: stack,
stackpos: 0,
Expand Down
Loading