Skip to content

Commit

Permalink
Merge remote-tracking branch 'bstrie/rimov' into incoming
Browse files Browse the repository at this point in the history
Conflicts:
	src/libsyntax/parse/parser.rs
	src/test/bench/graph500-bfs.rs
	src/test/bench/sudoku.rs
	src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs
	src/test/run-pass/empty-mutable-vec.rs
	src/test/run-pass/foreach-nested.rs
	src/test/run-pass/swap-2.rs
  • Loading branch information
brson committed Feb 4, 2013
2 parents 27e1ac5 + aa9c28e commit e08a805
Show file tree
Hide file tree
Showing 36 changed files with 161 additions and 166 deletions.
14 changes: 5 additions & 9 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1719,15 +1719,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 @@ -1749,7 +1746,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 @@ -1912,8 +1908,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 @@ -2008,11 +2004,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
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
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
8 changes: 4 additions & 4 deletions src/libstd/oldmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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 @@ -131,7 +131,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 @@ -369,8 +369,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
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

0 comments on commit e08a805

Please sign in to comment.