annotate libstd and start enforcing mutability

This commit is contained in:
Niko Matsakis 2012-03-14 14:03:56 -04:00
parent 273c5e5f11
commit 6b35875dca
19 changed files with 145 additions and 138 deletions

View file

@ -38,7 +38,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
$$(TSREQ$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
$$(STAGE$(1)_T_$(2)_H_$(3)) --enforce-mut-vars -o $$@ $$< && touch $$@
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM): \
rustllvm/$(2)/$$(CFG_RUSTLLVM)

View file

@ -45,7 +45,7 @@ fn process(v0: t, v1: t, op: fn(uint, uint) -> uint) -> bool {
let len = vec::len(v1.storage);
assert (vec::len(v0.storage) == len);
assert (v0.nbits == v1.nbits);
let changed = false;
let mut changed = false;
uint::range(0u, len) {|i|
let w0 = v0.storage[i];
let w1 = v1.storage[i];
@ -113,7 +113,7 @@ fn equal(v0: t, v1: t) -> bool {
// we can eliminate this painful while-loop
let len = vec::len(v1.storage);
let i = 0u;
let mut i = 0u;
while i < len {
if v0.storage[i] != v1.storage[i] { ret false; }
i = i + 1u;
@ -201,7 +201,7 @@ The resulting string has the same length as the bitvector, and each character
is either '0' or '1'.
"]
fn to_str(v: t) -> str {
let rs = "";
let mut rs = "";
for i: uint in to_vec(v) { if i == 1u { rs += "1"; } else { rs += "0"; } }
ret rs;
}
@ -215,7 +215,7 @@ bitvector and vector must have the same length
fn eq_vec(v0: t, v1: [uint]) -> bool {
assert (v0.nbits == vec::len::<uint>(v1));
let len = v0.nbits;
let i = 0u;
let mut i = 0u;
while i < len {
let w0 = get(v0, i);
let w1 = v1[i];

View file

@ -26,9 +26,9 @@ fn create<T: copy>() -> t<T> {
fn grow<T: copy>(nelts: uint, lo: uint, elts: [mutable cell<T>]) ->
[mutable cell<T>] {
assert (nelts == vec::len(elts));
let rv = [mutable];
let mut rv = [mutable];
let i = 0u;
let mut i = 0u;
let nalloc = uint::next_power_of_two(nelts + 1u);
while i < nalloc {
if i < nelts {

View file

@ -77,7 +77,7 @@ fn doc_at(data: @[u8], start: uint) -> tagged_doc {
}
fn maybe_get_doc(d: doc, tg: uint) -> option<doc> {
let pos = d.start;
let mut pos = d.start;
while pos < d.end {
let elt_tag = vuint_at(*d.data, pos);
let elt_size = vuint_at(*d.data, elt_tag.next);
@ -100,7 +100,7 @@ fn get_doc(d: doc, tg: uint) -> doc {
}
fn docs(d: doc, it: fn(uint, doc)) {
let pos = d.start;
let mut pos = d.start;
while pos < d.end {
let elt_tag = vuint_at(*d.data, pos);
let elt_size = vuint_at(*d.data, elt_tag.next);
@ -110,7 +110,7 @@ fn docs(d: doc, it: fn(uint, doc)) {
}
fn tagged_docs(d: doc, tg: uint, it: fn(doc)) {
let pos = d.start;
let mut pos = d.start;
while pos < d.end {
let elt_tag = vuint_at(*d.data, pos);
let elt_size = vuint_at(*d.data, elt_tag.next);
@ -154,20 +154,19 @@ fn doc_as_i64(d: doc) -> i64 { doc_as_u64(d) as i64 }
type writer = {writer: io::writer, mutable size_positions: [uint]};
fn write_sized_vuint(w: io::writer, n: uint, size: uint) {
let buf: [u8];
alt size {
1u { buf = [0x80u8 | (n as u8)]; }
2u { buf = [0x40u8 | ((n >> 8_u) as u8), n as u8]; }
let buf: [u8] = alt size {
1u { [0x80u8 | (n as u8)] }
2u { [0x40u8 | ((n >> 8_u) as u8), n as u8] }
3u {
buf = [0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
n as u8];
[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
n as u8]
}
4u {
buf = [0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
(n >> 8_u) as u8, n as u8];
[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
(n >> 8_u) as u8, n as u8]
}
_ { fail #fmt("vint to write too big: %?", n); }
}
};
w.write(buf);
}

View file

@ -171,21 +171,21 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
let n_opts = vec::len::<opt>(opts);
fn f(_x: uint) -> [optval] { ret []; }
let vals = vec::to_mut(vec::from_fn(n_opts, f));
let free: [str] = [];
let mut free: [str] = [];
let l = vec::len(args);
let i = 0u;
let mut i = 0u;
while i < l {
let cur = args[i];
let curlen = str::len(cur);
if !is_arg(cur) {
free += [cur];
} else if str::eq(cur, "--") {
let j = i + 1u;
let mut j = i + 1u;
while j < l { free += [args[j]]; j += 1u; }
break;
} else {
let names;
let i_arg = option::none::<str>;
let mut names;
let mut i_arg = option::none::<str>;
if cur[1] == '-' as u8 {
let tail = str::slice(cur, 2u, curlen);
let tail_eq = str::splitn_char(tail, '=', 1u);
@ -198,7 +198,7 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
option::some::<str>(tail_eq[1]);
}
} else {
let j = 1u;
let mut j = 1u;
names = [];
while j < curlen {
let range = str::char_range_at(cur, j);
@ -206,14 +206,13 @@ fn getopts(args: [str], opts: [opt]) -> result unsafe {
j = range.next;
}
}
let name_pos = 0u;
let mut name_pos = 0u;
for nm: name in names {
name_pos += 1u;
let optid;
alt find_opt(opts, nm) {
some(id) { optid = id; }
let optid = alt find_opt(opts, nm) {
some(id) { id }
none { ret err(unrecognized_option(name_str(nm))); }
}
};
alt opts[optid].hasarg {
no {
if !option::is_none::<str>(i_arg) {
@ -289,7 +288,7 @@ Returns a vector of the arguments provided to all matches of the given option.
Used when an option accepts multiple values.
"]
fn opt_strs(m: match, nm: str) -> [str] {
let acc: [str] = [];
let mut acc: [str] = [];
for v: optval in opt_vals(m, nm) {
alt v { val(s) { acc += [s]; } _ { } }
}

View file

@ -46,7 +46,7 @@ fn to_writer(wr: io::writer, j: json) {
num(n) { wr.write_str(float::to_str(n, 6u)); }
string(s) {
wr.write_char('"');
let escaped = "";
let mut escaped = "";
str::chars_iter(s) { |c|
alt c {
'"' { escaped += "\\\""; }
@ -67,7 +67,7 @@ fn to_writer(wr: io::writer, j: json) {
}
list(v) {
wr.write_char('[');
let first = true;
let mut first = true;
vec::iter(v) { |item|
if !first {
wr.write_str(", ");
@ -84,7 +84,7 @@ fn to_writer(wr: io::writer, j: json) {
}
wr.write_str("{ ");
let first = true;
let mut first = true;
d.items { |key, value|
if !first {
wr.write_str(", ");
@ -189,14 +189,14 @@ impl parser for parser {
}
fn parse_number() -> result<json, error> {
let neg = 1f;
let mut neg = 1f;
if self.ch == '-' {
self.bump();
neg = -1f;
}
let res = alt self.parse_integer() {
let mut res = alt self.parse_integer() {
ok(res) { res }
err(e) { ret err(e); }
};
@ -219,7 +219,7 @@ impl parser for parser {
}
fn parse_integer() -> result<float, error> {
let res = 0f;
let mut res = 0f;
alt self.ch {
'0' {
@ -259,8 +259,8 @@ impl parser for parser {
_ { ret self.error("invalid number"); }
}
let res = res;
let dec = 1f;
let mut res = res;
let mut dec = 1f;
while !self.eof() {
alt self.ch {
'0' to '9' {
@ -279,9 +279,9 @@ impl parser for parser {
fn parse_exponent(res: float) -> result<float, error> {
self.bump();
let res = res;
let exp = 0u;
let neg_exp = false;
let mut res = res;
let mut exp = 0u;
let mut neg_exp = false;
alt self.ch {
'+' { self.bump(); }
@ -318,8 +318,8 @@ impl parser for parser {
}
fn parse_str() -> result<str, error> {
let escape = false;
let res = "";
let mut escape = false;
let mut res = "";
while !self.eof() {
self.bump();
@ -336,8 +336,8 @@ impl parser for parser {
't' { str::push_char(res, '\t'); }
'u' {
// Parse \u1234.
let i = 0u;
let n = 0u;
let mut i = 0u;
let mut n = 0u;
while i < 4u {
alt self.next_char() {
'0' to '9' {
@ -346,6 +346,7 @@ impl parser for parser {
}
_ { ret self.error("invalid \\u escape"); }
}
i += 1u;
}
// Error out if we didn't parse 4 digits.
@ -376,7 +377,7 @@ impl parser for parser {
self.bump();
self.parse_whitespace();
let values = [];
let mut values = [];
if self.ch == ']' {
self.bump();
@ -479,7 +480,7 @@ fn eq(value0: json, value1: json) -> bool {
(list(l0), list(l1)) { vec::all2(l0, l1, eq) }
(dict(d0), dict(d1)) {
if d0.size() == d1.size() {
let equal = true;
let mut equal = true;
d0.items { |k, v0|
alt d1.find(k) {
some(v1) {

View file

@ -28,7 +28,7 @@ accumulated result.
* f - The function to apply
"]
fn foldl<T: copy, U>(ls: list<U>, z: T, f: fn(T, U) -> T) -> T {
let accum: T = z;
let mut accum: T = z;
iter(ls) {|elt| accum = f(accum, elt);}
accum
}
@ -41,7 +41,7 @@ When function `f` returns true then an option containing the element
is returned. If `f` matches no elements then none is returned.
"]
fn find<T: copy>(ls: list<T>, f: fn(T) -> bool) -> option<T> {
let ls = ls;
let mut ls = ls;
loop {
alt ls {
cons(hd, tl) {
@ -55,7 +55,7 @@ fn find<T: copy>(ls: list<T>, f: fn(T) -> bool) -> option<T> {
#[doc = "Returns true if a list contains an element with the given value"]
fn has<T: copy>(ls: list<T>, elt: T) -> bool {
let ls = ls;
let mut ls = ls;
loop {
alt ls {
cons(hd, tl) { if elt == hd { ret true; } else { ls = *tl; } }
@ -79,7 +79,7 @@ pure fn is_not_empty<T: copy>(ls: list<T>) -> bool {
#[doc = "Returns the length of a list"]
fn len<T>(ls: list<T>) -> uint {
let count = 0u;
let mut count = 0u;
iter(ls) {|_e| count += 1u;}
count
}
@ -110,7 +110,7 @@ fn iter<T>(l: list<T>, f: fn(T)) {
alt l {
cons(hd, tl) {
f(hd);
let cur = tl;
let mut cur = tl;
loop {
alt *cur {
cons(hd, tl) {

View file

@ -94,8 +94,8 @@ mod chained {
fn search_rem<K: copy, V: copy>(
tbl: t<K,V>, k: K, h: uint, idx: uint,
e_root: @entry<K,V>) -> search_result<K,V> {
let e0 = e_root;
let comp = 1u; // for logging
let mut e0 = e_root;
let mut comp = 1u; // for logging
loop {
alt e0.next {
absent {
@ -207,7 +207,7 @@ mod chained {
fn foreach_entry<K: copy, V: copy>(chain0: chain<K,V>,
blk: fn(@entry<K,V>)) {
let chain = chain0;
let mut chain = chain0;
loop {
alt chain {
absent { ret; }
@ -222,7 +222,8 @@ mod chained {
fn foreach_chain<K: copy, V: copy>(chains: [const chain<K,V>],
blk: fn(@entry<K,V>)) {
let i = 0u, n = vec::len(chains);
let mut i = 0u;
let n = vec::len(chains);
while i < n {
foreach_entry(chains[i], blk);
i += 1u;

View file

@ -5,36 +5,37 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
let orig_len: u64 = (vec::len(msg) * 8u) as u64;
// pad message
let msg = msg + [0x80u8];
let bitlen = orig_len + 8u64;
let mut msg = msg + [0x80u8];
let mut bitlen = orig_len + 8u64;
while (bitlen + 64u64) % 512u64 > 0u64 {
msg += [0u8];
bitlen += 8u64;
}
// append length
let i = 0u64;
let mut i = 0u64;
while i < 8u64 {
msg += [(orig_len >> (i * 8u64)) as u8];
i += 1u64;
}
let a = 0x67452301u32;
let b = 0xefcdab89u32;
let c = 0x98badcfeu32;
let d = 0x10325476u32;
let mut a = 0x67452301u32;
let mut b = 0xefcdab89u32;
let mut c = 0x98badcfeu32;
let mut d = 0x10325476u32;
fn rot(r: int, x: u32) -> u32 {
let r = r as u32;
(x << r) | (x >> (32u32 - r))
}
let i = 0u, e = vec::len(msg);
let mut i = 0u;
let e = vec::len(msg);
let x = vec::to_mut(vec::from_elem(16u, 0u32));
while i < e {
let aa = a, bb = b, cc = c, dd = d;
let j = 0u, base = i;
let mut j = 0u, base = i;
while j < 16u {
x[j] = (msg[base] as u32) + (msg[base + 1u] as u32 << 8u32) +
(msg[base + 2u] as u32 << 16u32) +
@ -42,7 +43,7 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
j += 1u; base += 4u;
}
let j = 0u;
let mut j = 0u;
while j < 16u {
a = rot(3, a + ((b & c) | (!b & d)) + x[j]);
j += 1u;
@ -54,7 +55,8 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
j += 1u;
}
let j = 0u, q = 0x5a827999u32;
let mut j = 0u;
let q = 0x5a827999u32;
while j < 4u {
a = rot(3, a + ((b & c) | ((b & d) | (c & d))) + x[j] + q);
d = rot(5, d + ((a & b) | ((a & c) | (b & c))) + x[j + 4u] + q);
@ -63,7 +65,8 @@ fn md4(msg: [u8]) -> {a: u32, b: u32, c: u32, d: u32} {
j += 1u;
}
let j = 0u, q = 0x6ed9eba1u32;
let mut j = 0u;
let q = 0x6ed9eba1u32;
while j < 8u {
let jj = if j > 2u { j - 3u } else { j };
a = rot(3, a + (b ^ c ^ d) + x[jj] + q);
@ -84,9 +87,9 @@ fn md4_str(msg: [u8]) -> str {
fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
f(a); f(b); f(c); f(d);
}
let result = "";
let mut result = "";
app(a, b, c, d) {|u|
let i = 0u32;
let mut i = 0u32;
while i < 4u32 {
let byte = (u >> (i * 8u32)) as u8;
if byte <= 16u8 { result += "0"; }

View file

@ -155,7 +155,7 @@ measure to ensure that the result is balanced.
"]
fn concat(v: [rope]) -> rope {
//Copy `v` into a mutable vector
let len = vec::len(v);
let mut len = vec::len(v);
if len == 0u { ret node::empty; }
let ropes = vec::to_mut(vec::from_elem(len, v[0]));
uint::range(1u, len) {|i|
@ -684,12 +684,12 @@ mod node {
ret candidate;
} else {
//Firstly, split `str` in slices of hint_max_leaf_char_len
let leaves = uint::div_ceil(char_len, hint_max_leaf_char_len);
let mut leaves = uint::div_ceil(char_len, hint_max_leaf_char_len);
//Number of leaves
let nodes = vec::to_mut(vec::from_elem(leaves, candidate));
let i = 0u;
let offset = byte_start;
let mut i = 0u;
let mut offset = byte_start;
let first_leaf_char_len =
if char_len%hint_max_leaf_char_len == 0u {
hint_max_leaf_char_len
@ -753,17 +753,17 @@ mod node {
execution and should be discarded as meaningless afterwards.
"]
fn tree_from_forest_destructive(forest: [mutable @node]) -> @node {
let i = 0u;
let len = vec::len(forest);
let mut i = 0u;
let mut len = vec::len(forest);
while len > 1u {
i = 0u;
while i < len - 1u {//Concat nodes 0 with 1, 2 with 3 etc.
let left = forest[i];
let right = forest[i+1u];
let mut left = forest[i];
let mut right = forest[i+1u];
let left_len = char_len(left);
let right_len= char_len(right);
let left_height= height(left);
let right_height=height(right);
let mut left_height= height(left);
let mut right_height=height(right);
if left_len + right_len > hint_max_leaf_char_len {
if left_len <= hint_max_leaf_char_len {
left = flatten(left);
@ -797,16 +797,17 @@ mod node {
}
fn serialize_node(node: @node) -> str unsafe {
let buf = vec::to_mut(vec::from_elem(byte_len(node), 0u8));
let offset = 0u;//Current position in the buffer
let mut buf = vec::to_mut(vec::from_elem(byte_len(node), 0u8));
let mut offset = 0u;//Current position in the buffer
let it = leaf_iterator::start(node);
loop {
alt(leaf_iterator::next(it)) {
option::none { break; }
option::some(x) {
//TODO: Replace with memcpy or something similar
let local_buf: [u8] = unsafe::reinterpret_cast(*x.content);
let i = x.byte_offset;
let mut local_buf: [u8] =
unsafe::reinterpret_cast(*x.content);
let mut i = x.byte_offset;
while i < x.byte_len {
buf[offset] = local_buf[i];
offset += 1u;
@ -860,7 +861,7 @@ mod node {
fn bal(node: @node) -> option<@node> {
if height(node) < hint_max_node_height { ret option::none; }
//1. Gather all leaves as a forest
let forest = [mutable];
let mut forest = [mutable];
let it = leaf_iterator::start(node);
loop {
alt (leaf_iterator::next(it)) {
@ -894,8 +895,8 @@ mod node {
valid positions in `node`.
"]
fn sub_bytes(node: @node, byte_offset: uint, byte_len: uint) -> @node {
let node = node;
let byte_offset = byte_offset;
let mut node = node;
let mut byte_offset = byte_offset;
loop {
if byte_offset == 0u && byte_len == node::byte_len(node) {
ret node;
@ -955,8 +956,8 @@ mod node {
valid positions in `node`.
"]
fn sub_chars(node: @node, char_offset: uint, char_len: uint) -> @node {
let node = node;
let char_offset = char_offset;
let mut node = node;
let mut char_offset = char_offset;
loop {
alt(*node) {
node::leaf(x) {
@ -1018,8 +1019,8 @@ mod node {
fn cmp(a: @node, b: @node) -> int {
let ita = char_iterator::start(a);
let itb = char_iterator::start(b);
let result = 0;
let pos = 0u;
let mut result = 0;
let mut pos = 0u;
while result == 0 {
alt((char_iterator::next(ita), char_iterator::next(itb))) {
(option::none, option::none) {
@ -1063,7 +1064,7 @@ mod node {
that is if `it` returned `false` at any point.
"]
fn loop_leaves(node: @node, it: fn(leaf) -> bool) -> bool{
let current = node;
let mut current = node;
loop {
alt(*current) {
leaf(x) {
@ -1098,8 +1099,8 @@ mod node {
length of the largest leaf.
"]
fn char_at(node: @node, pos: uint) -> char {
let node = node;
let pos = pos;
let mut node = node;
let mut pos = pos;
loop {
alt *node {
leaf(x) {

View file

@ -82,13 +82,13 @@ fn sha1() -> sha1 {
// FIXME: Make precondition
assert (vec::len(st.h) == digest_buf_len);
assert (vec::len(st.work_buf) == work_buf_len);
let t: int; // Loop counter
let mut t: int; // Loop counter
let w = st.work_buf;
// Initialize the first 16 words of the vector w
t = 0;
while t < 16 {
let tmp;
let mut tmp;
tmp = (st.msg_block[t * 4] as u32) << 24u32;
tmp = tmp | (st.msg_block[t * 4 + 1] as u32) << 16u32;
tmp = tmp | (st.msg_block[t * 4 + 2] as u32) << 8u32;
@ -103,12 +103,12 @@ fn sha1() -> sha1 {
w[t] = circular_shift(1u32, val);
t += 1;
}
let a = st.h[0];
let b = st.h[1];
let c = st.h[2];
let d = st.h[3];
let e = st.h[4];
let temp: u32;
let mut a = st.h[0];
let mut b = st.h[1];
let mut c = st.h[2];
let mut d = st.h[3];
let mut e = st.h[4];
let mut temp: u32;
t = 0;
while t < 20 {
temp = circular_shift(5u32, a) + (b & c | !b & d) + e + w[t] + k0;
@ -160,7 +160,7 @@ fn sha1() -> sha1 {
}
fn mk_result(st: sha1state) -> [u8] {
if !st.computed { pad_msg(st); st.computed = true; }
let rs: [u8] = [];
let mut rs: [u8] = [];
for hpart: u32 in st.h {
let a = (hpart >> 24u32 & 0xFFu32) as u8;
let b = (hpart >> 16u32 & 0xFFu32) as u8;
@ -237,7 +237,7 @@ fn sha1() -> sha1 {
fn result() -> [u8] { ret mk_result(self); }
fn result_str() -> str {
let r = mk_result(self);
let s = "";
let mut s = "";
for b: u8 in r { s += uint::to_str(b as uint, 16u); }
ret s;
}

View file

@ -66,7 +66,7 @@ fn max_key<T>(m: smallintmap<T>) -> uint {
#[doc = "Implements the map::map interface for smallintmap"]
impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn size() -> uint {
let sz = 0u;
let mut sz = 0u;
for item in self.v {
alt item { some(_) { sz += 1u; } _ {} }
}
@ -90,7 +90,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn find(&&key: uint) -> option<V> { find(self, key) }
fn rehash() { fail }
fn items(it: fn(&&uint, V)) {
let idx = 0u;
let mut idx = 0u;
for item in self.v {
alt item {
some(elt) {
@ -102,7 +102,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
}
}
fn keys(it: fn(&&uint)) {
let idx = 0u;
let mut idx = 0u;
for item in self.v {
if item != none { it(idx); }
idx += 1u;

View file

@ -33,12 +33,12 @@ fn merge_sort<T: copy>(le: le<T>, v: [const T]) -> [T] {
}
fn merge<T: copy>(le: le<T>, a: [T], b: [T]) -> [T] {
let rs = [];
let mut rs = [];
vec::reserve(rs, len(a) + len(b));
let a_len = len(a);
let a_ix = 0u;
let mut a_ix = 0u;
let b_len = len(b);
let b_ix = 0u;
let mut b_ix = 0u;
while a_ix < a_len && b_ix < b_len {
if le(a[a_ix], b[b_ix]) {
rs += [a[a_ix]];
@ -55,8 +55,8 @@ fn part<T: copy>(compare_func: le<T>, arr: [mutable T], left: uint,
right: uint, pivot: uint) -> uint {
let pivot_value = arr[pivot];
arr[pivot] <-> arr[right];
let storage_index: uint = left;
let i: uint = left;
let mut storage_index: uint = left;
let mut i: uint = left;
while i < right {
if compare_func(copy arr[i], pivot_value) {
arr[i] <-> arr[storage_index];
@ -96,10 +96,10 @@ fn qsort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
arr: [mutable T], left: int, right: int) {
if right <= left { ret; }
let v: T = arr[right];
let i: int = left - 1;
let j: int = right;
let p: int = i;
let q: int = j;
let mut i: int = left - 1;
let mut j: int = right;
let mut p: int = i;
let mut q: int = j;
loop {
i += 1;
while compare_func_lt(copy arr[i], v) { i += 1; }
@ -122,7 +122,7 @@ fn qsort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
arr[i] <-> arr[right];
j = i - 1;
i += 1;
let k: int = left;
let mut k: int = left;
while k < p {
arr[k] <-> arr[j];
k += 1;

View file

@ -6,7 +6,7 @@ import rand;
fn mkdtemp(prefix: str, suffix: str) -> option<str> {
let r = rand::rng();
let i = 0u;
let mut i = 0u;
while (i < 1000u) {
let s = prefix + r.gen_str(16u) + suffix;
if os::make_dir(s, 0x1c0i32) { // FIXME: u+rwx

View file

@ -49,7 +49,7 @@ fn color_supported() -> bool {
fn set_color(writer: io::writer, first_char: u8, color: u8) {
assert (color < 16u8);
esc(writer);
let color = color;
let mut color = color;
if color >= 8u8 { writer.write(['1' as u8, ';' as u8]); color -= 8u8; }
writer.write([first_char, ('0' as u8) + color, 'm' as u8]);
}

View file

@ -237,7 +237,7 @@ type monitor_msg = (test_desc, test_result);
fn run_tests(opts: test_opts, tests: [test_desc],
callback: fn@(testevent)) {
let filtered_tests = filter_tests(opts, tests);
let mut filtered_tests = filter_tests(opts, tests);
callback(te_filtered(filtered_tests));
// It's tempting to just spawn all the tests at once, but since we have
@ -246,9 +246,9 @@ fn run_tests(opts: test_opts, tests: [test_desc],
#debug("using %u test tasks", concurrency);
let total = vec::len(filtered_tests);
let run_idx = 0u;
let wait_idx = 0u;
let done_idx = 0u;
let mut run_idx = 0u;
let mut wait_idx = 0u;
let mut done_idx = 0u;
let p = comm::port();
let ch = comm::chan(p);
@ -294,7 +294,7 @@ fn get_concurrency() -> uint {
fn filter_tests(opts: test_opts,
tests: [test_desc]) -> [test_desc] {
let filtered = tests;
let mut filtered = tests;
// Remove tests that don't match the test filter
filtered = if option::is_none(opts.filter) {
@ -355,9 +355,8 @@ fn run_test(+test: test_desc, monitor_ch: comm::chan<monitor_msg>) {
}
task::spawn {||
let testfn = test.fn;
let builder = task::task_builder();
let mut builder = task::task_builder();
let result_future = task::future_result(builder);
task::unsupervise(builder);
task::run(builder, testfn);

View file

@ -12,8 +12,8 @@ Returns the current time as a `timeval` containing the seconds and
microseconds since 1970-01-01T00:00:00Z.
"]
fn get_time() -> timeval {
let sec = 0u32;
let usec = 0u32;
let mut sec = 0u32;
let mut usec = 0u32;
rustrt::get_time(sec, usec);
ret {sec: sec, usec: usec};
}
@ -22,7 +22,11 @@ fn get_time() -> timeval {
Returns the current value of a high-resolution performance counter
in nanoseconds since an unspecified epoch.
"]
fn precise_time_ns() -> u64 { let ns = 0u64; rustrt::precise_time_ns(ns); ns }
fn precise_time_ns() -> u64 {
let mut ns = 0u64;
rustrt::precise_time_ns(ns);
ns
}
#[doc = "
Returns the current value of a high-resolution performance counter

View file

@ -47,6 +47,6 @@ fn set_count(ufnd: ufind) -> uint { ret vec::len::<node>(ufnd.nodes); }
fn prune(ufnd: ufind, n: uint) {
// TODO: Use "slice" once we get rid of "const"
let len = vec::len::<node>(ufnd.nodes);
let mut len = vec::len::<node>(ufnd.nodes);
while len != n { vec::pop::<node>(ufnd.nodes); len -= 1u; }
}

View file

@ -146,8 +146,8 @@ fn loop_new() -> uv_loop unsafe {
// the main loop that this task blocks on.
// should have the same lifetime as the C libuv
// event loop.
let keep_going = true;
while (keep_going) {
let mut keep_going = true;
while keep_going {
alt comm::recv(rust_loop_port) {
msg_run(end_chan) {
// start the libuv event loop
@ -339,7 +339,7 @@ fn async_init (
lp: uv_loop,
async_cb: fn~(uv_handle),
after_cb: fn~(uv_handle)) {
let msg = msg_async_init(async_cb, after_cb);
let mut msg = msg_async_init(async_cb, after_cb);
let loop_chan = get_loop_chan_from_uv_loop(lp);
comm::send(loop_chan, msg);
}
@ -363,7 +363,7 @@ fn close(h: uv_handle, cb: fn~()) {
}
fn timer_init(lp: uv_loop, after_cb: fn~(uv_handle)) {
let msg = msg_timer_init(after_cb);
let mut msg = msg_timer_init(after_cb);
let loop_chan = get_loop_chan_from_uv_loop(lp);
comm::send(loop_chan, msg);
}
@ -372,7 +372,7 @@ fn timer_start(the_timer: uv_handle, timeout: u32, repeat:u32,
timer_cb: fn~(uv_handle)) {
alt the_timer {
uv_timer(id, lp) {
let msg = msg_timer_start(id, timeout, repeat, timer_cb);
let mut msg = msg_timer_start(id, timeout, repeat, timer_cb);
let loop_chan = get_loop_chan_from_uv_loop(lp);
comm::send(loop_chan, msg);
}
@ -387,7 +387,7 @@ fn timer_stop(the_timer: uv_handle, after_cb: fn~(uv_handle)) {
alt the_timer {
uv_timer(id, lp) {
let loop_chan = get_loop_chan_from_uv_loop(lp);
let msg = msg_timer_stop(id, after_cb);
let mut msg = msg_timer_stop(id, after_cb);
comm::send(loop_chan, msg);
}
_ {
@ -466,7 +466,7 @@ crust fn process_operation(
data: *uv_loop_data) unsafe {
let op_port = (*data).operation_port;
let loop_chan = get_loop_chan_from_data(data);
let op_pending = comm::peek(op_port);
let mut op_pending = comm::peek(op_port);
while(op_pending) {
alt comm::recv(op_port) {
op_async_init(id) {