make --enforce-mut-vars always on, add mut annotations to remaining files

This commit is contained in:
Niko Matsakis 2012-03-22 08:39:41 -07:00
parent ea6030878a
commit dc07280b08
179 changed files with 519 additions and 508 deletions

View File

@ -1003,7 +1003,7 @@ fn iter<T>(seq: [T], f: fn(T)) {
for elt: T in seq { f(elt); }
}
fn map<T, U>(seq: [T], f: fn(T) -> U) -> [U] {
let acc = [];
let mut acc = [];
for elt in seq { acc += [f(elt)]; }
acc
}
@ -1104,7 +1104,7 @@ enum animal {
cat
}
let a: animal = dog;
let mut a: animal = dog;
a = cat;
~~~~
@ -1254,7 +1254,7 @@ not given, and the name is mandatory.
~~~~
impl uint_loops for uint {
fn times(f: fn(uint)) {
let i = 0u;
let mut i = 0u;
while i < self { f(i); i += 1u; }
}
}
@ -1775,7 +1775,7 @@ expression. No allocation or destruction is entailed.
An example of three different move expressions:
~~~~~~~~
# let x = [mut 0];
# let mut x = [mut 0];
# let a = [mut 0];
# let b = 0;
# let y = {mut z: 0};
@ -1804,8 +1804,8 @@ expression. No allocation or destruction is entailed.
An example of three different swap expressions:
~~~~~~~~
# let x = [mut 0];
# let 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};
@ -1827,7 +1827,7 @@ expression](#unary-copy-expressions). For example, the following two
expressions have the same effect:
~~~~
# let x = 0;
# let mut x = 0;
# let y = 0;
x = y;
@ -2015,7 +2015,7 @@ loop body. If it evaluates to `false`, control exits the loop.
An example of a simple `while` expression:
~~~~
# let i = 0;
# let mut i = 0;
# let println = io::println;
while i < 10 {
@ -2027,7 +2027,7 @@ while i < 10 {
An example of a `do`-`while` expression:
~~~~
# let i = 0;
# let mut i = 0;
# let println = io::println;
do {
@ -2053,7 +2053,7 @@ For example, the following (contrived) function uses a `loop` with a
~~~~
fn count() -> bool {
let i = 0;
let mut i = 0;
loop {
i += 1;
if i == 20 { ret true; }
@ -2801,7 +2801,7 @@ fn add(x: int, y: int) -> int {
ret x + y;
}
let x = add(5,7);
let mut x = add(5,7);
type binop = fn(int,int) -> int;
let bo: binop = add;
@ -2880,7 +2880,7 @@ has a set of points before and after it in the implied control flow.
For example, this code:
~~~~~~~~
# let s;
# let mut s;
s = "hello, world";
io::println(s);
@ -3154,7 +3154,10 @@ A _reference_ references a value outside the frame. It may refer to a
value allocated in another frame *or* a boxed value in the heap. The
reference-formation rules ensure that the referent will outlive the reference.
Local variables are always implicitly mutable.
Local variables are immutable unless declared with `let mut`. The
`mut` keyword applies to all local variables declared within that
declaration (so `let mut x, y` declares two mutable variables, `x` and
`y`).
Local variables are not initialized when allocated; the entire frame worth of
local variables are allocated at once, on frame-entry, in an uninitialized

View File

@ -26,7 +26,7 @@ a curly-brace language in the tradition of C, C++, and JavaScript.
~~~~
fn fac(n: int) -> int {
let result = 1, i = 1;
let mut result = 1, i = 1;
while i <= n {
result *= i;
i += 1;
@ -286,16 +286,19 @@ fn this_doesnt(_x: int) {}
## Variable declaration
The `let` keyword, as we've seen, introduces a local variable. Global
constants can be defined with `const`:
The `let` keyword, as we've seen, introduces a local variable. Local
variables are immutable by default: `let mut` can be used to introduce
a local variable that can be reassigned. Global constants can be
defined with `const`:
~~~~
use std;
const repeat: uint = 5u;
fn main() {
let count = 0u;
let hi = "Hi!";
let mut count = 0u;
while count < repeat {
io::println("Hi!");
io::println(hi);
count += 1u;
}
}
@ -320,7 +323,7 @@ annotation:
~~~~
// The type of this vector will be inferred based on its use.
let x = [];
# x = [3];
# vec::map(x, fn&(&&_y:int) -> int { _y });
// Explicitly say this is a vector of integers.
let y: [int] = [];
~~~~
@ -665,7 +668,7 @@ keyword `break` can be used to abort the loop, and `cont` can be used
to abort the current iteration and continue with the next.
~~~~
let x = 5;
let mut x = 5;
while true {
x += x - 3;
if x % 5 == 0 { break; }
@ -761,7 +764,7 @@ failure otherwise. It is typically used to double-check things that
*should* hold at a certain point in a program.
~~~~
let x = 100;
let mut x = 100;
while (x > 10) { x -= 10; }
assert x == 10;
~~~~
@ -933,7 +936,7 @@ of integers backwards:
~~~~
fn for_rev(v: [int], act: fn(int)) {
let i = vec::len(v);
let mut i = vec::len(v);
while (i > 0u) {
i -= 1u;
act(v[i]);
@ -1273,7 +1276,7 @@ The `+` operator means concatenation when applied to vector types.
Growing a vector in Rust is not as inefficient as it looks :
~~~~
let myvec = [], i = 0;
let mut myvec = [], i = 0;
while i < 100 {
myvec += [i];
i += 1;
@ -1376,7 +1379,7 @@ in `main`, so we're good. But the call could also look like this:
~~~~
# fn myfunc(a: int, b: fn()) {}
# fn get_another_record() -> int { 1 }
# let x = 1;
# let mut x = 1;
myfunc(x, {|| x = get_another_record(); });
~~~~
@ -1436,7 +1439,7 @@ very cheap, but you'll occasionally have to copy them to ensure
safety.
~~~~
let my_rec = {a: 4, b: [1, 2, 3]};
let mut my_rec = {a: 4, b: [1, 2, 3]};
alt my_rec {
{a, b} {
log(info, b); // This is okay
@ -1497,7 +1500,7 @@ Thus, Rust allows functions and datatypes to have type parameters.
~~~~
fn for_rev<T>(v: [T], act: fn(T)) {
let i = vec::len(v);
let mut i = vec::len(v);
while i > 0u {
i -= 1u;
act(v[i]);
@ -1505,7 +1508,7 @@ fn for_rev<T>(v: [T], act: fn(T)) {
}
fn map<T, U>(v: [T], f: fn(T) -> U) -> [U] {
let acc = [];
let mut acc = [];
for elt in v { acc += [f(elt)]; }
ret acc;
}
@ -1548,7 +1551,7 @@ programs that just can't be typed.
~~~~
let n = option::none;
# n = option::some(1);
# option::may(n, fn&(&&x:int) {})
~~~~
If you never do anything else with `n`, the compiler will not be able
@ -1982,7 +1985,7 @@ parameters.
~~~~
# iface to_str { fn to_str() -> str; }
fn comma_sep<T: to_str>(elts: [T]) -> str {
let result = "", first = true;
let mut result = "", first = true;
for elt in elts {
if first { first = false; }
else { result += ", "; }
@ -2094,7 +2097,7 @@ to leave off the `of` clause.
# fn mk_currency(x: int, s: str) {}
impl int_util for int {
fn times(b: fn(int)) {
let i = 0;
let mut i = 0;
while i < self { b(i); i += 1; }
}
fn dollars() -> currency {
@ -2450,7 +2453,7 @@ Here is the function which implements the child task:
~~~~
fn stringifier(from_parent: comm::port<uint>,
to_parent: comm::chan<str>) {
let value: uint;
let mut value: uint;
do {
value = comm::recv(from_parent);
comm::send(to_parent, uint::to_str(value, 10u));

View File

@ -11,13 +11,6 @@
USE_SNAPSHOT_RUNTIME=0
USE_SNAPSHOT_CORELIB=0
# Do not use --enforce-mut-vars in stage0, for now, as the snapshot
# has an older version of the check.
ENFORCE_MUT_VARS_0=
ENFORCE_MUT_VARS_1=--enforce-mut-vars
ENFORCE_MUT_VARS_2=--enforce-mut-vars
ENFORCE_MUT_VARS_3=--enforce-mut-vars
define TARGET_STAGE_N
$$(TLIB$(1)_T_$(2)_H_$(3))/intrinsics.ll: \
@ -41,8 +34,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)) $$(ENFORCE_MUT_VARS_$(1)) \
-o $$@ $$< && touch $$@
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM): \
rustllvm/$(2)/$$(CFG_RUSTLLVM)
@ -53,8 +45,7 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X): \
$$(RUSTC_INPUTS) \
$$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(ENFORCE_MUT_VARS_$(1)) \
-o $$@ $$<
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$<
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
@ -63,8 +54,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
$$(TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(ENFORCE_MUT_VARS_$(1)) \
-o $$@ $$< && touch $$@
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
endef
@ -127,7 +117,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB): \
$$(CORELIB_CRATE) $$(CORELIB_INPUTS) \
$$(TSREQ$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) --enforce-mut-vars -o $$@ $$< && touch $$@
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
endef

View File

@ -93,9 +93,9 @@ fn error(msg: str) {
fn load_link(mis: [@ast::meta_item]) -> (option<str>,
option<str>,
option<str>) {
let name = none;
let vers = none;
let uuid = none;
let mut name = none;
let mut vers = none;
let mut uuid = none;
for a: @ast::meta_item in mis {
alt a.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
@ -124,12 +124,12 @@ fn load_pkg(filename: str) -> option<pkg> {
};
let c = parser::parse_crate_from_crate_file(filename, [], sess);
let name = none;
let vers = none;
let uuid = none;
let desc = none;
let sigs = none;
let crate_type = none;
let mut name = none;
let mut vers = none;
let mut uuid = none;
let mut desc = none;
let mut sigs = none;
let mut crate_type = none;
for a in c.node.attrs {
alt a.node.value.node {
@ -273,7 +273,7 @@ fn load_one_source_package(&src: source, p: map::hashmap<str, json::json>) {
_ { none }
};
let tags = [];
let mut tags = [];
alt p.find("tags") {
some(json::list(js)) {
for j in js {
@ -390,7 +390,7 @@ fn configure(opts: options) -> cargo {
let sources = map::str_hash::<source>();
try_parse_sources(path::connect(syscargo, "sources.json"), sources);
try_parse_sources(path::connect(syscargo, "local-sources.json"), sources);
let c = {
let mut c = {
pgp: pgp::supported(),
root: p,
bindir: path::connect(p, "bin"),
@ -408,7 +408,7 @@ fn configure(opts: options) -> cargo {
need_dir(c.bindir);
sources.keys { |k|
let s = sources.get(k);
let mut s = sources.get(k);
load_source_packages(c, s);
sources.insert(k, s);
};
@ -597,7 +597,7 @@ fn cargo_suggestion(c: cargo, syncing: bool, fallback: fn())
ret;
}
if !syncing {
let npkg = 0u;
let mut npkg = 0u;
c.sources.values({ |v| npkg += vec::len(v.packages) });
if npkg == 0u {
error("No packages known. You may wish to run " +
@ -609,7 +609,7 @@ fn cargo_suggestion(c: cargo, syncing: bool, fallback: fn())
}
fn install_uuid(c: cargo, wd: str, uuid: str) {
let ps = [];
let mut ps = [];
for_each_package(c, { |s, p|
info(#fmt["%s ? %s", p.uuid, uuid]);
if p.uuid == uuid {
@ -631,7 +631,7 @@ fn install_uuid(c: cargo, wd: str, uuid: str) {
}
fn install_named(c: cargo, wd: str, name: str) {
let ps = [];
let mut ps = [];
for_each_package(c, { |s, p|
if p.name == name {
vec::grow(ps, 1u, (s, p));
@ -698,7 +698,7 @@ fn cmd_install(c: cargo) unsafe {
};
if str::starts_with(target, "uuid:") {
let uuid = rest(target, 5u);
let mut uuid = rest(target, 5u);
alt str::find_char(uuid, '/') {
option::some(idx) {
let source = str::slice(uuid, 0u, idx);
@ -710,7 +710,7 @@ fn cmd_install(c: cargo) unsafe {
}
}
} else {
let name = target;
let mut name = target;
alt str::find_char(name, '/') {
option::some(idx) {
let source = str::slice(name, 0u, idx);
@ -820,7 +820,7 @@ fn cmd_init(c: cargo) {
}
fn print_pkg(s: source, p: package) {
let m = s.name + "/" + p.name + " (" + p.uuid + ")";
let mut m = s.name + "/" + p.name + " (" + p.uuid + ")";
if vec::len(p.tags) > 0u {
m = m + " [" + str::connect(p.tags, ", ") + "]";
}
@ -842,7 +842,7 @@ fn cmd_search(c: cargo) {
cmd_usage();
ret;
}
let n = 0;
let mut n = 0;
let name = c.opts.free[2];
let tags = vec::slice(c.opts.free, 3u, vec::len(c.opts.free));
for_each_package(c, { |s, p|

View File

@ -126,7 +126,7 @@ fn test_opts(config: config) -> test::test_opts {
fn make_tests(config: config) -> [test::test_desc] {
#debug("making tests from %s", config.src_base);
let tests = [];
let mut tests = [];
for file: str in os::list_dir(config.src_base) {
let file = file;
#debug("inspecting file %s", file);
@ -144,7 +144,7 @@ fn is_test(config: config, testfile: str) -> bool {
let invalid_prefixes = [".", "#", "~"];
let name = path::basename(testfile);
let valid = false;
let mut valid = false;
for ext in valid_extensions {
if str::ends_with(name, ext) { valid = true; }

View File

@ -9,9 +9,9 @@ type expected_error = { line: uint, kind: str, msg: str };
// Load any test directives embedded in the file
fn load_errors(testfile: str) -> [expected_error] {
let error_patterns = [];
let mut error_patterns = [];
let rdr = result::get(io::file_reader(testfile));
let line_num = 1u;
let mut line_num = 1u;
while !rdr.eof() {
let ln = rdr.read_line();
error_patterns += parse_expected(line_num, ln);
@ -22,7 +22,7 @@ fn load_errors(testfile: str) -> [expected_error] {
fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
let error_tag = "//!";
let idx;
let mut idx;
alt str::find_str(line, error_tag) {
option::none { ret []; }
option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
@ -30,7 +30,7 @@ fn parse_expected(line_num: uint, line: str) -> [expected_error] unsafe {
// "//!^^^ kind msg" denotes a message expected
// three lines above current line:
let adjust_line = 0u;
let mut adjust_line = 0u;
let len = str::len(line);
while idx < len && line[idx] == ('^' as u8) {
adjust_line += 1u;

View File

@ -22,10 +22,10 @@ type test_props = {
// Load any test directives embedded in the file
fn load_props(testfile: str) -> test_props {
let error_patterns = [];
let aux_builds = [];
let compile_flags = option::none;
let pp_exact = option::none;
let mut error_patterns = [];
let mut aux_builds = [];
let mut compile_flags = option::none;
let mut pp_exact = option::none;
iter_header(testfile) {|ln|
alt parse_error_pattern(ln) {
option::some(ep) { error_patterns += [ep]; }
@ -53,7 +53,7 @@ fn load_props(testfile: str) -> test_props {
}
fn is_test_ignored(config: config, testfile: str) -> bool {
let found = false;
let mut found = false;
iter_header(testfile) {|ln|
// FIXME: Can't return or break from iterator
// (Fix when Issue #1619 is resolved)

View File

@ -60,9 +60,9 @@ fn run(lib_path: str, prog: str, args: [str],
comm::send(ch, (1, output));
};
let status = run::waitpid(pid);
let errs = "";
let outs = "";
let count = 2;
let mut errs = "";
let mut outs = "";
let mut count = 2;
while count > 0 {
let stream = comm::recv(p);
alt check stream {
@ -91,7 +91,7 @@ fn readclose(fd: c_int) -> str {
// Copied from run::program_output
let file = os::fdopen(fd);
let reader = io::FILE_reader(file, false);
let buf = "";
let mut buf = "";
while !reader.eof() {
let bytes = reader.read_bytes(4096u);
buf += str::from_bytes(bytes);

View File

@ -47,7 +47,7 @@ fn run_cfail_test(config: config, props: test_props, testfile: str) {
}
fn run_rfail_test(config: config, props: test_props, testfile: str) {
let procres = compile_test(config, props, testfile);
let mut procres = compile_test(config, props, testfile);
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
@ -75,7 +75,7 @@ fn check_correct_failure_status(procres: procres) {
}
fn run_rpass_test(config: config, props: test_props, testfile: str) {
let procres = compile_test(config, props, testfile);
let mut procres = compile_test(config, props, testfile);
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
@ -93,9 +93,9 @@ fn run_pretty_test(config: config, props: test_props, testfile: str) {
let rounds =
alt props.pp_exact { option::some(_) { 1 } option::none { 2 } };
let srcs = [result::get(io::read_whole_file_str(testfile))];
let mut srcs = [result::get(io::read_whole_file_str(testfile))];
let round = 0;
let mut round = 0;
while round < rounds {
logv(config, #fmt["pretty-printing round %d", round]);
let procres = print_source(config, testfile, srcs[round]);
@ -109,7 +109,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: str) {
round += 1;
}
let expected =
let mut expected =
alt props.pp_exact {
option::some(file) {
let filepath = path::connect(path::dirname(testfile), file);
@ -117,7 +117,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: str) {
}
option::none { srcs[vec::len(srcs) - 2u] }
};
let actual = srcs[vec::len(srcs) - 1u];
let mut actual = srcs[vec::len(srcs) - 1u];
if option::is_some(props.pp_exact) {
// Now we have to care about line endings
@ -176,7 +176,7 @@ actual:\n\
fn make_typecheck_args(config: config, _testfile: str) -> procargs {
let prog = config.rustc_path;
let args = ["-", "--no-trans", "--lib", "-L", config.build_base];
let mut args = ["-", "--no-trans", "--lib", "-L", config.build_base];
args += split_maybe_args(config.rustcflags);
ret {prog: prog, args: args};
}
@ -193,8 +193,8 @@ fn check_error_patterns(props: test_props,
fatal("process did not return an error status");
}
let next_err_idx = 0u;
let next_err_pat = props.error_patterns[next_err_idx];
let mut next_err_idx = 0u;
let mut next_err_pat = props.error_patterns[next_err_idx];
for line: str in str::split_char(procres.stderr, '\n') {
if str::contains(line, next_err_pat) {
#debug("found error pattern %s", next_err_pat);
@ -244,7 +244,7 @@ fn check_expected_errors(expected_errors: [errors::expected_error],
// where line1:col1: is the starting point, line2:col2:
// is the ending point, and * represents ANSI color codes.
for line: str in str::split_char(procres.stderr, '\n') {
let was_expected = false;
let mut was_expected = false;
vec::iteri(expected_errors) {|i, ee|
if !found_flags[i] {
#debug["prefix=%s ee.kind=%s ee.msg=%s line=%s",
@ -321,8 +321,8 @@ fn make_compile_args(config: config, props: test_props, extras: [str],
xform: fn(config, str) -> str, testfile: str) ->
procargs {
let prog = config.rustc_path;
let args = [testfile, "-o", xform(config, testfile),
"-L", config.build_base] + extras;
let mut args = [testfile, "-o", xform(config, testfile),
"-L", config.build_base] + extras;
args += split_maybe_args(config.rustcflags);
args += split_maybe_args(props.compile_flags);
ret {prog: prog, args: args};

View File

@ -217,7 +217,7 @@ fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty, tm: test_mode
}
fn under(n: uint, it: fn(uint)) {
let i: uint = 0u;
let mut i: uint = 0u;
while i < n { it(i); i += 1u; }
}
@ -487,9 +487,9 @@ fn file_might_not_converge(filename: str) -> bool {
fn check_roundtrip_convergence(code: @str, maxIters: uint) {
let i = 0u;
let newv = code;
let oldv = code;
let mut i = 0u;
let mut newv = code;
let mut oldv = code;
while i < maxIters {
oldv = newv;
@ -576,7 +576,7 @@ fn main(args: [str]) {
#error("usage: %s <testdir>", args[0]);
ret;
}
let files = [];
let mut files = [];
let root = args[1];
find_rust_files(files, root);

View File

@ -332,8 +332,8 @@ fn test_select2_stress() {
};
}
let as = 0;
let bs = 0;
let mut as = 0;
let mut bs = 0;
iter::repeat(msgs * times * 2u) {||
alt check select2(po_a, po_b) {
either::left("a") { as += 1 }

View File

@ -715,7 +715,7 @@ mod tests {
assert(vec::slice(ivals, 0u, vec::len(res)) ==
vec::map(res, {|x| x as int}));
}
let i = 0u;
let mut i = 0u;
while i < 8u {
check_read_ln(i, wide_test, ivals);
i += 1u;

View File

@ -232,7 +232,7 @@ fn test_flat_map_with_option() {
#[test]
fn test_flat_map_with_list() {
fn repeat(&&i: int) -> [int] {
let r = [];
let mut r = [];
int::range(0, i) {|_j| r += [i]; }
r
}
@ -246,8 +246,7 @@ fn test_flat_map_with_list() {
#[test]
fn test_repeat() {
let c = [],
i = 0u;
let mut c = [], i = 0u;
repeat(5u) {||
c += [(i * i)];
i += 1u;

View File

@ -617,8 +617,8 @@ mod tests {
#[test]
#[ignore(reason = "fails periodically on mac")]
fn test_getenv_big() {
let s = "";
let i = 0;
let mut s = "";
let mut i = 0;
while i < 100 { s += "aaaaaaaaaa"; i += 1; }
let n = make_rand_name();
setenv(n, s);
@ -659,7 +659,7 @@ mod tests {
fn test_env_setenv() {
let n = make_rand_name();
let e = env();
let mut e = env();
setenv(n, "VALUE");
assert !vec::contains(e, (n, "VALUE"));

View File

@ -366,7 +366,7 @@ mod tests {
// Copied from run::program_output
let file = os::fdopen(fd);
let reader = io::FILE_reader(file, false);
let buf = "";
let mut buf = "";
while !reader.eof() {
let bytes = reader.read_bytes(4096u);
buf += str::from_bytes(bytes);

View File

@ -1675,7 +1675,7 @@ mod tests {
#[test]
fn test_pop_char() {
let data = "ประเทศไทย中华";
let mut data = "ประเทศไทย中华";
let cc = pop_char(data);
assert "ประเทศไทย中" == data;
assert '华' == cc;
@ -1683,7 +1683,7 @@ mod tests {
#[test]
fn test_pop_char_2() {
let data2 = "";
let mut data2 = "";
let cc2 = pop_char(data2);
assert "" == data2;
assert '华' == cc2;
@ -1693,7 +1693,7 @@ mod tests {
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
fn test_pop_char_fail() {
let data = "";
let mut data = "";
let _cc3 = pop_char(data);
}
@ -1887,7 +1887,7 @@ mod tests {
assert find_str_between(data, "ab", 2u, 6u) == some(3u);
assert find_str_between(data, "ab", 2u, 4u) == none;
let data = "ประเทศไทย中华Việt Nam";
let mut data = "ประเทศไทย中华Việt Nam";
data += data;
assert find_str_between(data, "", 0u, 43u) == some(0u);
assert find_str_between(data, "", 6u, 43u) == some(6u);
@ -1959,14 +1959,14 @@ mod tests {
assert (eq("bc", unsafe::slice_bytes("abc", 1u, 3u)));
assert (eq("", unsafe::slice_bytes("abc", 1u, 1u)));
fn a_million_letter_a() -> str {
let i = 0;
let rs = "";
let mut i = 0;
let mut rs = "";
while i < 100000 { rs += "aaaaaaaaaa"; i += 1; }
ret rs;
}
fn half_a_million_letter_a() -> str {
let i = 0;
let rs = "";
let mut i = 0;
let mut rs = "";
while i < 100000 { rs += "aaaaa"; i += 1; }
ret rs;
}
@ -2068,14 +2068,14 @@ mod tests {
assert "" == slice(data, 30u, 33u);
fn a_million_letter_X() -> str {
let i = 0;
let rs = "";
let mut i = 0;
let mut rs = "";
while i < 100000 { rs += "华华华华华华华华华华"; i += 1; }
ret rs;
}
fn half_a_million_letter_X() -> str {
let i = 0;
let rs = "";
let mut i = 0;
let mut rs = "";
while i < 100000 { rs += "华华华华华"; i += 1; }
ret rs;
}
@ -2164,7 +2164,7 @@ mod tests {
#[test]
fn test_shift_byte() unsafe {
let s = "ABC";
let mut s = "ABC";
let b = unsafe::shift_byte(s);
assert (s == "BC");
assert (b == 65u8);
@ -2172,7 +2172,7 @@ mod tests {
#[test]
fn test_pop_byte() unsafe {
let s = "ABC";
let mut s = "ABC";
let b = unsafe::pop_byte(s);
assert (s == "AB");
assert (b == 67u8);
@ -2264,7 +2264,7 @@ mod tests {
let v: [u8] = bytes(s1);
let s2: str = from_bytes(v);
let i: uint = 0u;
let mut i: uint = 0u;
let n1: uint = len(s1);
let n2: uint = vec::len::<u8>(v);
assert (n1 == n2);
@ -2297,7 +2297,7 @@ mod tests {
#[test]
fn test_chars_iter() {
let i = 0;
let mut i = 0;
chars_iter("x\u03c0y") {|ch|
alt check i {
0 { assert ch == 'x'; }
@ -2312,7 +2312,7 @@ mod tests {
#[test]
fn test_bytes_iter() {
let i = 0;
let mut i = 0;
bytes_iter("xyz") {|bb|
alt check i {
@ -2330,7 +2330,7 @@ mod tests {
fn test_split_char_iter() {
let data = "\nMary had a little lamb\nLittle lamb\n";
let ii = 0;
let mut ii = 0;
split_char_iter(data, ' ') {|xx|
alt ii {
@ -2348,7 +2348,7 @@ mod tests {
fn test_splitn_char_iter() {
let data = "\nMary had a little lamb\nLittle lamb\n";
let ii = 0;
let mut ii = 0;
splitn_char_iter(data, ' ', 2u) {|xx|
alt ii {
@ -2365,7 +2365,7 @@ mod tests {
fn test_words_iter() {
let data = "\nMary had a little lamb\nLittle lamb\n";
let ii = 0;
let mut ii = 0;
words_iter(data) {|ww|
alt ii {
@ -2385,7 +2385,7 @@ mod tests {
fn test_lines_iter () {
let lf = "\nMary had a little lamb\nLittle lamb\n";
let ii = 0;
let mut ii = 0;
lines_iter(lf) {|x|
alt ii {

View File

@ -790,7 +790,7 @@ fn test_spawn_sched_blocking() {
comm::recv(start_po);
fn pingpong(po: comm::port<int>, ch: comm::chan<int>) {
let val = 20;
let mut val = 20;
while val > 0 {
val = comm::recv(po);
comm::send(ch, val - 1);

View File

@ -1017,7 +1017,7 @@ mod tests {
fn test_unsafe_ptrs() unsafe {
// Test on-stack copy-from-buf.
let a = [1, 2, 3];
let ptr = unsafe::to_ptr(a);
let mut ptr = unsafe::to_ptr(a);
let b = unsafe::from_buf(ptr, 3u);
assert (len(b) == 3u);
assert (b[0] == 1);
@ -1039,7 +1039,7 @@ mod tests {
#[test]
fn test_from_fn() {
// Test on-stack from_fn.
let v = from_fn(3u, square);
let mut v = from_fn(3u, square);
assert (len(v) == 3u);
assert (v[0] == 0u);
assert (v[1] == 1u);
@ -1058,7 +1058,7 @@ mod tests {
#[test]
fn test_from_elem() {
// Test on-stack from_elem.
let v = from_elem(2u, 10u);
let mut v = from_elem(2u, 10u);
assert (len(v) == 2u);
assert (v[0] == 10u);
assert (v[1] == 10u);
@ -1093,7 +1093,7 @@ mod tests {
#[test]
fn test_tail() {
let a = [11];
let mut a = [11];
assert (tail(a) == []);
a = [11, 12];
@ -1102,7 +1102,7 @@ mod tests {
#[test]
fn test_last() {
let n = last_opt([]);
let mut n = last_opt([]);
assert (n == none);
n = last_opt([1, 2, 3]);
assert (n == some(3));
@ -1113,7 +1113,7 @@ mod tests {
#[test]
fn test_slice() {
// Test on-stack -> on-stack slice.
let v = slice([1, 2, 3], 1u, 3u);
let mut v = slice([1, 2, 3], 1u, 3u);
assert (len(v) == 2u);
assert (v[0] == 2);
assert (v[1] == 3);
@ -1138,8 +1138,8 @@ mod tests {
#[test]
fn test_pop() {
// Test on-stack pop.
let v = [1, 2, 3];
let e = pop(v);
let mut v = [1, 2, 3];
let mut e = pop(v);
assert (len(v) == 2u);
assert (v[0] == 1);
assert (v[1] == 2);
@ -1159,7 +1159,7 @@ mod tests {
#[test]
fn test_push() {
// Test on-stack push().
let v = [];
let mut v = [];
push(v, 1);
assert (len(v) == 1u);
assert (v[0] == 1);
@ -1174,7 +1174,7 @@ mod tests {
#[test]
fn test_grow() {
// Test on-stack grow().
let v = [];
let mut v = [];
grow(v, 2u, 1);
assert (len(v) == 2u);
assert (v[0] == 1);
@ -1192,7 +1192,7 @@ mod tests {
#[test]
fn test_grow_fn() {
let v = [];
let mut v = [];
grow_fn(v, 3u, square);
assert (len(v) == 3u);
assert (v[0] == 0u);
@ -1202,7 +1202,7 @@ mod tests {
#[test]
fn test_grow_set() {
let v = [mutable 1, 2, 3];
let mut v = [mutable 1, 2, 3];
grow_set(v, 4u, 4, 5);
assert (len(v) == 5u);
assert (v[0] == 1);
@ -1215,8 +1215,8 @@ mod tests {
#[test]
fn test_map() {
// Test on-stack map.
let v = [1u, 2u, 3u];
let w = map(v, square_ref);
let mut v = [1u, 2u, 3u];
let mut w = map(v, square_ref);
assert (len(w) == 3u);
assert (w[0] == 1u);
assert (w[1] == 4u);
@ -1240,15 +1240,15 @@ mod tests {
let v0 = [1, 2, 3, 4, 5];
let v1 = [5, 4, 3, 2, 1];
let u = map2::<int, int, int>(v0, v1, f);
let i = 0;
let mut i = 0;
while i < 5 { assert (v0[i] * v1[i] == u[i]); i += 1; }
}
#[test]
fn test_filter_map() {
// Test on-stack filter-map.
let v = [1u, 2u, 3u];
let w = filter_map(v, square_if_odd);
let mut v = [1u, 2u, 3u];
let mut w = filter_map(v, square_if_odd);
assert (len(w) == 2u);
assert (w[0] == 1u);
assert (w[1] == 9u);
@ -1287,8 +1287,8 @@ mod tests {
#[test]
fn test_foldl() {
// Test on-stack fold.
let v = [1u, 2u, 3u];
let sum = foldl(0u, v, add);
let mut v = [1u, 2u, 3u];
let mut sum = foldl(0u, v, add);
assert (sum == 6u);
// Test on-heap fold.
@ -1302,7 +1302,7 @@ mod tests {
fn sub(&&a: int, &&b: int) -> int {
a - b
}
let v = [1, 2, 3, 4];
let mut v = [1, 2, 3, 4];
let sum = foldl(0, v, sub);
assert sum == -10;
}
@ -1312,28 +1312,28 @@ mod tests {
fn sub(&&a: int, &&b: int) -> int {
a - b
}
let v = [1, 2, 3, 4];
let mut v = [1, 2, 3, 4];
let sum = foldr(v, 0, sub);
assert sum == -2;
}
#[test]
fn test_iter_empty() {
let i = 0;
let mut i = 0;
iter::<int>([], { |_v| i += 1 });
assert i == 0;
}
#[test]
fn test_iter_nonempty() {
let i = 0;
let mut i = 0;
iter([1, 2, 3], { |v| i += v });
assert i == 6;
}
#[test]
fn test_iteri() {
let i = 0;
let mut i = 0;
iteri([1, 2, 3], { |j, v|
if i == 0 { assert v == 1; }
assert j + 1u == v as uint;
@ -1344,14 +1344,14 @@ mod tests {
#[test]
fn test_riter_empty() {
let i = 0;
let mut i = 0;
riter::<int>([], { |_v| i += 1 });
assert i == 0;
}
#[test]
fn test_riter_nonempty() {
let i = 0;
let mut i = 0;
riter([1, 2, 3], { |v|
if i == 0 { assert v == 3; }
i += v
@ -1361,7 +1361,7 @@ mod tests {
#[test]
fn test_riteri() {
let i = 0;
let mut i = 0;
riteri([0, 1, 2], { |j, v|
if i == 0 { assert v == 2; }
assert j == v as uint;
@ -1372,7 +1372,7 @@ mod tests {
#[test]
fn test_permute() {
let results: [[int]];
let mut results: [[int]];
results = [];
permute([]) {|v| results += [v]; }
@ -1464,7 +1464,7 @@ mod tests {
assert position_between([], 0u, 0u, f) == none;
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert position_between(v, 0u, 0u, f) == none;
assert position_between(v, 0u, 1u, f) == none;
@ -1493,7 +1493,7 @@ mod tests {
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert find(v, f) == some((1, 'b'));
assert find(v, g) == none;
@ -1504,7 +1504,7 @@ mod tests {
assert find_between([], 0u, 0u, f) == none;
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert find_between(v, 0u, 0u, f) == none;
assert find_between(v, 0u, 1u, f) == none;
@ -1533,7 +1533,7 @@ mod tests {
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert position(v, f) == some(1u);
assert position(v, g) == none;
@ -1544,7 +1544,7 @@ mod tests {
assert rposition_between([], 0u, 0u, f) == none;
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert rposition_between(v, 0u, 0u, f) == none;
assert rposition_between(v, 0u, 1u, f) == none;
@ -1573,7 +1573,7 @@ mod tests {
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' }
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert rfind(v, f) == some((3, 'b'));
assert rfind(v, g) == none;
@ -1584,7 +1584,7 @@ mod tests {
assert rfind_between([], 0u, 0u, f) == none;
fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' }
let v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert rfind_between(v, 0u, 0u, f) == none;
assert rfind_between(v, 0u, 1u, f) == none;
@ -1740,7 +1740,7 @@ mod tests {
#[test]
fn test_unshift() {
let x = [1, 2, 3];
let mut x = [1, 2, 3];
unshift(x, 0);
assert x == [0, 1, 2, 3];
}

View File

@ -234,8 +234,8 @@ fn eq_vec(v0: bitv, v1: [uint]) -> bool {
mod tests {
#[test]
fn test_0_elements() {
let act;
let exp;
let mut act;
let mut exp;
act = bitv(0u, false);
exp = vec::from_elem::<uint>(0u, 0u);
assert (eq_vec(act, exp));
@ -243,7 +243,7 @@ mod tests {
#[test]
fn test_1_element() {
let act;
let mut act;
act = bitv(1u, false);
assert (eq_vec(act, [0u]));
act = bitv(1u, true);
@ -252,7 +252,7 @@ mod tests {
#[test]
fn test_10_elements() {
let act;
let mut act;
// all 0
act = bitv(10u, false);
@ -291,7 +291,7 @@ mod tests {
#[test]
fn test_31_elements() {
let act;
let mut act;
// all 0
act = bitv(31u, false);
@ -364,7 +364,7 @@ mod tests {
#[test]
fn test_32_elements() {
let act;
let mut act;
// all 0
act = bitv(32u, false);
@ -439,7 +439,7 @@ mod tests {
#[test]
fn test_33_elements() {
let act;
let mut act;
// all 0
act = bitv(33u, false);

View File

@ -126,7 +126,7 @@ mod tests {
assert (d.peek_front() == 42);
log(debug, d.peek_back());
assert (d.peek_back() == 137);
let i: int = d.pop_front();
let mut i: int = d.pop_front();
log(debug, i);
assert (i == 42);
i = d.pop_back();

View File

@ -453,7 +453,7 @@ mod tests {
let eqer_uint: map::eqfn<uint> = eq_uint;
let hm_uu: map::hashmap<uint, uint> =
map::hashmap::<uint, uint>(hasher_uint, eqer_uint);
let i: uint = 0u;
let mut i: uint = 0u;
while i < num_to_insert {
assert (hm_uu.insert(i, i * i));
#debug("inserting %u -> %u", i, i*i);
@ -533,7 +533,7 @@ mod tests {
let eqer: map::eqfn<uint> = eq;
let hm: map::hashmap<uint, uint> =
map::hashmap::<uint, uint>(hasher, eqer);
let i: uint = 0u;
let mut i: uint = 0u;
while i < num_to_insert {
assert (hm.insert(i, i * i));
#debug("inserting %u -> %u", i, i*i);

View File

@ -1281,18 +1281,18 @@ mod tests {
#[test]
fn of_string2() {
let buf = @ mutable "1234567890";
let i = 0;
let mut i = 0;
while i < 10 { *buf = *buf + *buf; i+=1;}
let sample = @*buf;
let r = of_str(sample);
assert char_len(r) == str::char_len(*sample);
assert rope_to_string(r) == *sample;
let string_iter = 0u;
let mut string_iter = 0u;
let string_len = str::len(*sample);
let rope_iter = iterator::char::start(r);
let equal = true;
let pos = 0u;
let mut equal = true;
let mut pos = 0u;
while equal {
alt(node::char_iterator::next(rope_iter)) {
option::none {
@ -1314,12 +1314,12 @@ mod tests {
#[test]
fn iter1() {
let buf = @ mutable "1234567890";
let i = 0;
let mut i = 0;
while i < 10 { *buf = *buf + *buf; i+=1;}
let sample = @*buf;
let r = of_str(sample);
let len = 0u;
let mut len = 0u;
let it = iterator::char::start(r);
loop {
alt(node::char_iterator::next(it)) {
@ -1335,11 +1335,11 @@ mod tests {
fn bal1() {
let init = @ "1234567890";
let buf = @ mutable * init;
let i = 0;
let mut i = 0;
while i < 8 { *buf = *buf + *buf; i+=1;}
let sample = @*buf;
let r1 = of_str(sample);
let r2 = of_str(init);
let mut r2 = of_str(init);
i = 0;
while i < 8 { r2 = append_rope(r2, r2); i+= 1;}
@ -1354,19 +1354,19 @@ mod tests {
#[test]
fn char_at1() {
//Generate a large rope
let r = of_str(@ "123456789");
let mut r = of_str(@ "123456789");
uint::range(0u, 10u){|_i|
r = append_rope(r, r);
}
//Copy it in the slowest possible way
let r2 = empty();
let mut r2 = empty();
uint::range(0u, char_len(r)){|i|
r2 = append_char(r2, char_at(r, i));
}
assert eq(r, r2);
let r3 = empty();
let mut r3 = empty();
uint::range(0u, char_len(r)){|i|
r3 = prepend_char(r3, char_at(r, char_len(r) - i - 1u));
}
@ -1387,7 +1387,7 @@ mod tests {
fn concat1() {
//Generate a reasonable rope
let chunk = of_str(@ "123456789");
let r = empty();
let mut r = empty();
uint::range(0u, 10u){|_i|
r = append_rope(r, chunk);
}

View File

@ -264,8 +264,8 @@ mod tests {
type test = {input: str, output: [u8]};
fn a_million_letter_a() -> str {
let i = 0;
let rs = "";
let mut i = 0;
let mut rs = "";
while i < 100000 { rs += "aaaaaaaaaa"; i += 1; }
ret rs;
}
@ -316,7 +316,7 @@ mod tests {
fn check_vec_eq(v0: [u8], v1: [u8]) {
assert (vec::len::<u8>(v0) == vec::len::<u8>(v1));
let len = vec::len::<u8>(v0);
let i = 0u;
let mut i = 0u;
while i < len {
let a = v0[i];
let b = v1[i];
@ -338,7 +338,7 @@ mod tests {
// Test that it works when accepting the message in pieces
for t: test in tests {
let len = str::len(t.input);
let left = len;
let mut left = len;
while left > 0u {
let take = (left + 1u) / 2u;
sh.input_str(str::slice(t.input, len - left,

View File

@ -167,7 +167,7 @@ mod test_qsort3 {
let f1 = lt;
let f2 = equal;
quick_sort3::<int>(f1, f2, v1);
let i = 0u;
let mut i = 0u;
while i < len {
log(debug, v2[i]);
assert (v2[i] == v1[i]);
@ -208,7 +208,7 @@ mod test_qsort {
fn leual(&&a: int, &&b: int) -> bool { ret a <= b; }
let f = leual;
quick_sort::<int>(f, v1);
let i = 0u;
let mut i = 0u;
while i < len {
log(debug, v2[i]);
assert (v2[i] == v1[i]);
@ -266,7 +266,7 @@ mod tests {
fn le(&&a: int, &&b: int) -> bool { ret a <= b; }
let f = le;
let v3 = merge_sort::<int>(f, v1);
let i = 0u;
let mut i = 0u;
while i < len {
log(debug, v3[i]);
assert (v3[i] == v2[i]);

View File

@ -491,7 +491,7 @@ mod tests {
let tests =
{
let testfn = fn~() { };
let tests = [];
let mut tests = [];
for name: str in names {
let test = {name: name, fn: testfn, ignore: false,
should_fail: false};

View File

@ -422,7 +422,6 @@ fn build_session_options(match: getopts::match,
let cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
let test = opt_present(match, "test");
let warn_unused_imports = opt_present(match, "warn-unused-imports");
let enforce_mut_vars = opt_present(match, "enforce-mut-vars");
let sopts: @session::options =
@{crate_type: crate_type,
static: static,
@ -444,8 +443,7 @@ fn build_session_options(match: getopts::match,
parse_only: parse_only,
no_trans: no_trans,
no_asm_comments: no_asm_comments,
warn_unused_imports: warn_unused_imports,
enforce_mut_vars: enforce_mut_vars};
warn_unused_imports: warn_unused_imports};
ret sopts;
}

View File

@ -45,8 +45,7 @@ type options =
parse_only: bool,
no_trans: bool,
no_asm_comments: bool,
warn_unused_imports: bool,
enforce_mut_vars: bool};
warn_unused_imports: bool};
type crate_metadata = {name: str, data: [u8]};
@ -154,7 +153,7 @@ mod test {
}
fn make_crate(with_bin: bool, with_lib: bool) -> @ast::crate {
let attrs = [];
let mut attrs = [];
if with_bin { attrs += [make_crate_type_attr("bin")]; }
if with_lib { attrs += [make_crate_type_attr("lib")]; }
@ast_util::respan(ast_util::dummy_sp(), {

View File

@ -305,7 +305,7 @@ fn is_illegal_to_modify_def(cx: @ctx, def: def, msg: msg) -> option<str> {
// variables are assigned at most once. But this requires a new kind of
// propagation (def. not assigned), so I didn't do that.
def_local(_, false) if msg == msg_move_out { none }
def_local(_, false) if cx.tcx.sess.opts.enforce_mut_vars {
def_local(_, false) {
some("immutable local variable")
}

View File

@ -1134,6 +1134,13 @@ fn print_decl(s: ps, decl: @ast::decl) {
space_if_not_bol(s);
ibox(s, indent_unit);
word_nbsp(s, "let");
// if any are mutable, all are mutable
if vec::any(locs) {|l| l.node.is_mutbl } {
assert vec::all(locs) {|l| l.node.is_mutbl };
word_nbsp(s, "mut");
}
fn print_local(s: ps, &&loc: @ast::local) {
ibox(s, indent_unit);
print_local_decl(s, loc);

View File

@ -77,7 +77,7 @@ fn act(po: comm::port<msg>, source: str, parse: parser) {
ignore_errors
);
let keep_going = true;
let mut keep_going = true;
while keep_going {
alt comm::recv(po) {
handle_request(f) {
@ -147,8 +147,7 @@ fn build_session() -> (session::session, @mutable bool) {
parse_only: false,
no_trans: false,
no_asm_comments: false,
warn_unused_imports: false,
enforce_mut_vars: false
warn_unused_imports: false
};
let codemap = codemap::new_codemap();

View File

@ -131,7 +131,7 @@ fn first_sentence(s: str) -> option<str> {
}
fn first_sentence_(s: str) -> str {
let dotcount = 0;
let mut dotcount = 0;
// The index of the character following a single dot. This allows
// Things like [0..1) to appear in the brief description
let idx = str::find(s) {|ch|
@ -163,10 +163,10 @@ fn first_sentence_(s: str) -> str {
fn paragraphs(s: str) -> [str] {
let lines = str::lines_any(s);
let whitespace_lines = 0;
let accum = "";
let mut whitespace_lines = 0;
let mut accum = "";
let paras = vec::foldl([], lines) {|paras, line|
let res = paras;
let mut res = paras;
if str::is_whitespace(line) {
whitespace_lines += 1;

View File

@ -127,7 +127,7 @@ fn readclose(fd: libc::c_int) -> str {
// Copied from run::program_output
let file = os::fdopen(fd);
let reader = io::FILE_reader(file, false);
let buf = "";
let mut buf = "";
while !reader.eof() {
let bytes = reader.read_bytes(4096u);
buf += str::from_bytes(bytes);
@ -138,8 +138,8 @@ fn readclose(fd: libc::c_int) -> str {
fn generic_writer(process: fn~(markdown: str)) -> writer {
let ch = task::spawn_listener {|po: comm::port<writeinstr>|
let markdown = "";
let keep_going = true;
let mut markdown = "";
let mut keep_going = true;
while keep_going {
alt comm::recv(po) {
write(s) { markdown += s; }
@ -281,7 +281,7 @@ fn future_writer() -> (writer, future::future<str>) {
comm::send(chan, copy instr);
};
let future = future::from_fn {||
let res = "";
let mut res = "";
loop {
alt comm::recv(port) {
write(s) { res += s }

View File

@ -46,7 +46,7 @@ fn to_assoc_list<K:copy, V:copy>(
map: map::hashmap<K, V>
) -> [(K, V)] {
let vec = [];
let mut vec = [];
map.items {|k, v|
vec += [(k, v)];
}
@ -183,7 +183,7 @@ fn build_reexport_path_map(srv: astsrv::srv, -def_map: def_map) -> path_map {
};
let modpath = ast_map::path_to_str(vec::init(*path));
let reexportdocs = [];
let mut reexportdocs = [];
for def in defs {
if !def.reexp { cont; }
alt def_map.find(def.id) {

View File

@ -30,7 +30,7 @@ fn run_passes(
original through each pass"
)];
let passno = 0;
let mut passno = 0;
vec::foldl(doc, passes) {|doc, pass|
log(debug, #fmt("pass #%d", passno));
passno += 1;

View File

@ -90,9 +90,9 @@ fn sectionalize(desc: option<str>) -> (option<str>, [doc::section]) {
let lines = str::lines(option::get(desc));
let new_desc = none;
let current_section = none;
let sections = [];
let mut new_desc = none;
let mut current_section = none;
let mut sections = [];
for line in lines {
alt parse_header(line) {

View File

@ -19,8 +19,8 @@ fn mk_pass() -> pass {
fn unindent(s: str) -> str {
let lines = str::lines_any(s);
let saw_first_line = false;
let saw_second_line = false;
let mut saw_first_line = false;
let mut saw_second_line = false;
let min_indent = vec::foldl(uint::max_value, lines) {|min_indent, line|
// After we see the first non-whitespace line, look at
@ -46,7 +46,7 @@ fn unindent(s: str) -> str {
min_indent
} else {
saw_first_line = true;
let spaces = 0u;
let mut spaces = 0u;
str::all(line) {|char|
// Only comparing against space because I wouldn't
// know what to do with mixed whitespace chars

View File

@ -3,7 +3,7 @@
impl helpers for uint {
#[inline]
fn to(v: uint, f: fn(uint)) {
let i = self;
let mut i = self;
while i < v {
f(i);
i += 1u;

View File

@ -2,7 +2,7 @@
#[inline]
fn iter<T>(v: [T], f: fn(T)) {
let i = 0u;
let mut i = 0u;
let n = vec::len(v);
while i < n {
f(v[i]);

View File

@ -2,7 +2,7 @@
// same as cci_iter_lib, more-or-less, but not marked inline
fn iter(v: [uint], f: fn(uint)) {
let i = 0u;
let mut i = 0u;
let n = vec::len(v);
while i < n {
f(v[i]);

View File

@ -23,9 +23,9 @@ fn b8() -> str {
}
fn sub(t: str, n: int) -> str unsafe {
let b: str = "";
let i: uint = 0u;
let ns: str;
let mut b: str = "";
let mut i: uint = 0u;
let mut ns: str;
alt n {
0 { ns = "no more bottles"; }
1 { ns = "1 bottle"; }
@ -42,7 +42,7 @@ fn sub(t: str, n: int) -> str unsafe {
/* Using an interator */
fn ninetynine(it: fn(int)) {
let n: int = 100;
let mut n: int = 100;
while n > 1 { n -= 1; it(n); }
}

View File

@ -51,7 +51,7 @@ fn next(b: bottle) -> bottle {
fn more(b: bottle) -> bool { alt b { none { ret false; } _ { ret true; } } }
fn main() {
let b: bottle = multiple(99);
let running: bool = true;
let mut b: bottle = multiple(99);
let mut running: bool = true;
while running { show(b); #debug(""); running = more(b); b = next(b); }
}

View File

@ -23,9 +23,9 @@ fn b8() -> str {
}
fn sub(t: str, n: int) -> str unsafe {
let b: str = "";
let i: uint = 0u;
let ns: str;
let mut b: str = "";
let mut i: uint = 0u;
let mut ns: str;
alt n {
0 { ns = "no more bottles"; }
1 { ns = "1 bottle"; }
@ -42,7 +42,7 @@ fn sub(t: str, n: int) -> str unsafe {
/* Straightforward counter */
fn main() {
let n: int = 99;
let mut n: int = 99;
while n > 0 {
log(debug, sub(b1(), n));
log(debug, sub(b2(), n - 1));

View File

@ -15,8 +15,8 @@ enum request {
}
fn server(requests: comm::port<request>, responses: comm::chan<uint>) {
let count = 0u;
let done = false;
let mut count = 0u;
let mut done = false;
while !done {
alt comm::recv(requests) {
get_count { comm::send(responses, copy count); }
@ -37,7 +37,7 @@ fn run(args: [str]) {
let workers = option::get(uint::from_str(args[2]));
let start = std::time::precise_time_s();
let to_child = to_child;
let worker_results = [];
let mut worker_results = [];
uint::range(0u, workers) {|_i|
let builder = task::task_builder();
worker_results += [task::future_result(builder)];

View File

@ -25,7 +25,7 @@ fn main(args: [str]) {
8
};
let min_depth = 4;
let max_depth;
let mut max_depth;
if min_depth + 2 > n {
max_depth = min_depth + 2;
} else { max_depth = n; }
@ -35,13 +35,13 @@ fn main(args: [str]) {
stretch_depth,
item_check(stretch_tree)));
let long_lived_tree = bottom_up_tree(0, max_depth);
let depth = min_depth;
let mut depth = min_depth;
while depth <= max_depth {
let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
let chk = 0;
let i = 1;
let mut chk = 0;
let mut i = 1;
while i <= iterations {
let temp_tree = bottom_up_tree(i, depth);
let mut temp_tree = bottom_up_tree(i, depth);
chk += item_check(temp_tree);
temp_tree = bottom_up_tree(-i, depth);
chk += item_check(temp_tree);

View File

@ -9,13 +9,13 @@ fn fannkuch(n: int) -> int {
let perm = vec::to_mut(vec::from_elem(n as uint, 0));
let perm1 = vec::to_mut(vec::from_fn(n as uint, perm1init));
let count = vec::to_mut(vec::from_elem(n as uint, 0));
let f = 0;
let i = 0;
let k = 0;
let r = 0;
let flips = 0;
let nperm = 0;
let checksum = 0;
let mut f = 0;
let mut i = 0;
let mut k = 0;
let mut r = 0;
let mut flips = 0;
let mut nperm = 0;
let mut checksum = 0;
r = n;
while r > 0 {
i = 0;
@ -40,7 +40,7 @@ fn fannkuch(n: int) -> int {
if nperm & 0x1 == 0 { checksum += f; } else { checksum -= f; }
// Use incremental change to generate another permutation
let go = true;
let mut go = true;
while go {
if r == n {
io::println(#fmt("%d", checksum));

View File

@ -23,8 +23,8 @@ fn myrandom_next(r: myrandom, mx: u32) -> u32 {
type aminoacids = {ch: char, prob: u32};
fn make_cumulative(aa: [aminoacids]) -> [aminoacids] {
let cp: u32 = 0u32;
let ans: [aminoacids] = [];
let mut cp: u32 = 0u32;
let mut ans: [aminoacids] = [];
for a: aminoacids in aa { cp += a.prob; ans += [{ch: a.ch, prob: cp}]; }
ret ans;
}
@ -45,7 +45,7 @@ fn select_random(r: u32, genelist: [aminoacids]) -> char {
fn make_random_fasta(id: str, desc: str, genelist: [aminoacids], n: int) {
log(debug, ">" + id + " " + desc);
let rng = @{mutable last: std::rand::rng().next()};
let op: str = "";
let mut op: str = "";
uint::range(0u, n as uint) {|_i|
str::push_char(op, select_random(myrandom_next(rng, 100u32),
genelist));
@ -59,7 +59,7 @@ fn make_random_fasta(id: str, desc: str, genelist: [aminoacids], n: int) {
fn make_repeat_fasta(id: str, desc: str, s: str, n: int) unsafe {
log(debug, ">" + id + " " + desc);
let op: str = "";
let mut op: str = "";
let sl: uint = str::len(s);
uint::range(0u, n as uint) {|i|
str::unsafe::push_byte(op, s[i % sl]);

View File

@ -36,9 +36,9 @@ pure fn cabs(x: cmplx) -> f64
fn mb(x: cmplx) -> bool
{
let z = {re: 0., im: 0.};
let i = 0;
let in = true;
let mut z = {re: 0., im: 0.};
let mut i = 0;
let mut in = true;
while i < 50 {
z = z*z + x;
if cabs(z) >= 4. {
@ -51,8 +51,8 @@ fn mb(x: cmplx) -> bool
}
fn fillbyte(x: cmplx, incr: f64) -> u8 {
let rv = 0_u8;
let i = 0_u8;
let mut rv = 0_u8;
let mut i = 0_u8;
while i < 8_u8 {
let z = {re: x.re + (i as f64)*incr, im: x.im};
if mb(z) {
@ -65,7 +65,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> ()
{
let crv = [];
let mut crv = [];
let incr = 2./(size as f64);
let y = incr*(i as f64) - 1.;
let xincr = 8.*incr;
@ -107,15 +107,15 @@ fn writer(path: str, writech: comm::chan<comm::chan<line>>, size: uint)
cout.write_line("P4");
cout.write_line(#fmt("%u %u", size, size));
let lines = std::map::uint_hash();
let done = 0_u;
let i = 0_u;
let mut done = 0_u;
let mut i = 0_u;
while i < size {
let aline = comm::recv(p);
if aline.i == done {
#debug("W %u", aline.i);
cout.write(aline.b);
done += 1_u;
let prev = done;
let mut prev = done;
while prev <= i {
if lines.contains_key(prev) {
#debug("WS %u", prev);

View File

@ -21,7 +21,7 @@ fn main(args: [str]) {
};
let bodies: [Body::props] = NBodySystem::MakeNBodySystem();
io::println(#fmt("%f", NBodySystem::energy(bodies)));
let i: int = 0;
let mut i: int = 0;
while i < n { NBodySystem::advance(bodies, 0.01); i += 1; }
io::println(#fmt("%f", NBodySystem::energy(bodies)));
}
@ -37,11 +37,11 @@ mod NBodySystem {
[Body::sun(), Body::jupiter(), Body::saturn(), Body::uranus(),
Body::neptune()];
let px: float = 0.0;
let py: float = 0.0;
let pz: float = 0.0;
let mut px: float = 0.0;
let mut py: float = 0.0;
let mut pz: float = 0.0;
let i: int = 0;
let mut i: int = 0;
while i < 5 {
px += bodies[i].vx * bodies[i].mass;
py += bodies[i].vy * bodies[i].mass;
@ -58,9 +58,9 @@ mod NBodySystem {
fn advance(bodies: [Body::props], dt: float) {
let i: int = 0;
let mut i: int = 0;
while i < 5 {
let j: int = i + 1;
let mut j: int = i + 1;
while j < 5 { advance_one(bodies[i], bodies[j], dt); j += 1; }
i += 1;
@ -96,20 +96,20 @@ mod NBodySystem {
}
fn energy(bodies: [Body::props]) -> float unsafe {
let dx: float;
let dy: float;
let dz: float;
let distance: float;
let e: float = 0.0;
let mut dx: float;
let mut dy: float;
let mut dz: float;
let mut distance: float;
let mut e: float = 0.0;
let i: int = 0;
let mut i: int = 0;
while i < 5 {
e +=
0.5 * bodies[i].mass *
(bodies[i].vx * bodies[i].vx + bodies[i].vy * bodies[i].vy
+ bodies[i].vz * bodies[i].vz);
let j: int = i + 1;
let mut j: int = i + 1;
while j < 5 {
dx = bodies[i].x - bodies[j].x;
dy = bodies[i].y - bodies[j].y;

View File

@ -59,7 +59,7 @@ fn parse_opts(argv: [str]) -> config {
}
fn stress_task(&&id: int) {
let i = 0;
let mut i = 0;
loop {
let n = 15;
assert (fib(n) == fib(n));
@ -69,7 +69,7 @@ fn stress_task(&&id: int) {
}
fn stress(num_tasks: int) {
let results = [];
let mut results = [];
range(0, num_tasks) {|i|
let builder = task::task_builder();
results += [task::future_result(builder)];

View File

@ -8,10 +8,10 @@ fn eval_A(i: uint, j: uint) -> float {
fn eval_A_times_u(u: [const float], Au: [mutable float]) {
let N = vec::len(u);
let i = 0u;
let mut i = 0u;
while i < N {
Au[i] = 0.0;
let j = 0u;
let mut j = 0u;
while j < N {
Au[i] += eval_A(i, j) * u[j];
j += 1u;
@ -22,10 +22,10 @@ fn eval_A_times_u(u: [const float], Au: [mutable float]) {
fn eval_At_times_u(u: [const float], Au: [mutable float]) {
let N = vec::len(u);
let i = 0u;
let mut i = 0u;
while i < N {
Au[i] = 0.0;
let j = 0u;
let mut j = 0u;
while j < N {
Au[i] += eval_A(j, i) * u[j];
j += 1u;
@ -50,16 +50,16 @@ fn main(args: [str]) {
let u = vec::to_mut(vec::from_elem(N, 1.0));
let v = vec::to_mut(vec::from_elem(N, 0.0));
let i = 0u;
let mut i = 0u;
while i < 10u {
eval_AtA_times_u(u, v);
eval_AtA_times_u(v, u);
i += 1u;
}
let vBv = 0.0;
let vv = 0.0;
let i = 0u;
let mut vBv = 0.0;
let mut vv = 0.0;
let mut i = 0u;
while i < N {
vBv += u[i] * v[i];
vv += v[i] * v[i];

View File

@ -59,7 +59,7 @@ fn solve_grid(g: grid_t) {
drop_colors(g, avail, row, col);
// find first remaining color that is available
let i = 1 as uint;
let mut i = 1 as uint;
while i < (10 as uint) { /* FIXME llvm ctlhd */
if bitv::get(avail, i) {
g[row][col] = i as u8;
@ -94,7 +94,7 @@ fn solve_grid(g: grid_t) {
}
}
let work: [(u8, u8)] = []; /* queue of uncolored fields */
let mut work: [(u8, u8)] = []; /* queue of uncolored fields */
u8::range(0u8, 9u8) { |row|
u8::range(0u8, 9u8) { |col|
let color = (*g)[row][col];
@ -102,7 +102,7 @@ fn solve_grid(g: grid_t) {
}
}
let ptr = 0u;
let mut ptr = 0u;
let end = vec::len(work);
while (ptr < end) {
let (row, col) = work[ptr];

View File

@ -9,8 +9,8 @@ enum msg {
fn calc(children: uint, parent_ch: comm::chan<msg>) {
let port = comm::port();
let chan = comm::chan(port);
let child_chs = [];
let sum = 0;
let mut child_chs = [];
let mut sum = 0;
iter::repeat (children) {||
task::spawn {||

View File

@ -1,5 +1,5 @@
fn f(&&n: uint) {
let i = 0u;
let mut i = 0u;
while i < n {
task::try {|| g() };
i += 1u;
@ -13,6 +13,6 @@ fn main(args: [str]) {
if vec::len(args) < 2u {
10u
} else { option::get(uint::parse_buf(str::bytes(args[1]), 10u)) };
let i = 0u;
let mut i = 0u;
while i < n { task::spawn {|| f(n); }; i += 1u; }
}

View File

@ -5,7 +5,7 @@
fn f(&&n: uint) {
uint::range(0u, n) {|i|
let v: [u8] = [];
let mut v: [u8] = [];
vec::reserve(v, 1000u);
}
}

View File

@ -31,7 +31,7 @@ fn map(input: str, emit: map_reduce::putter) {
}
fn reduce(_word: str, get: map_reduce::getter) {
let count = 0;
let mut count = 0;
loop { alt get() { some(_) { count += 1; } none { break; } } }
}
@ -60,7 +60,7 @@ mod map_reduce {
fn start_mappers(ctrl: chan<ctrl_proto>, -inputs: [str]) ->
[future::future<task::task_result>] {
let results = [];
let mut results = [];
for i: str in inputs {
let builder = task::task_builder();
results += [task::future_result(builder)];
@ -75,7 +75,7 @@ mod map_reduce {
fn emit(im: map::hashmap<str, chan<reduce_proto>>,
ctrl: chan<ctrl_proto>, key: str, val: int) {
let c;
let mut c;
alt im.find(key) {
some(_c) {
c = _c;
@ -134,12 +134,12 @@ mod map_reduce {
// This task becomes the master control task. It task::_spawns
// to do the rest.
let reducers: map::hashmap<str, chan<reduce_proto>>;
let mut reducers: map::hashmap<str, chan<reduce_proto>>;
reducers = map::str_hash();
let num_mappers = vec::len(inputs) as int;
let results = start_mappers(chan(ctrl), inputs);
let mut num_mappers = vec::len(inputs) as int;
let mut results = start_mappers(chan(ctrl), inputs);
while num_mappers > 0 {
alt recv(ctrl) {
@ -148,7 +148,7 @@ mod map_reduce {
num_mappers -= 1;
}
find_reducer(k, cc) {
let c;
let mut c;
// log(error, "finding reducer for " + k);
alt reducers.find(k) {
some(_c) {
@ -191,7 +191,7 @@ fn main(argv: [str]) {
map_reduce::map_reduce(inputs);
let stop = time::precise_time_ns();
let elapsed = stop - start;
let mut elapsed = stop - start;
elapsed /= 1000000u64;
log(error, "MapReduce completed in "
@ -199,7 +199,7 @@ fn main(argv: [str]) {
}
fn read_word(r: io::reader) -> option<str> {
let w = "";
let mut w = "";
while !r.eof() {
let c = r.read_char();

View File

@ -1,2 +1,4 @@
// error-pattern:wooooo
fn main() { let a = 1; if 1 == 1 { a = 2; } fail "woooo" + "o"; }
fn main() {
let mut a = 1; if 1 == 1 { a = 2; } fail "woooo" + "o";
}

View File

@ -16,7 +16,7 @@ fn main() {
}
let map = map::hashmap(hash, eq);
let arr = [];
let mut arr = [];
uint::range(0u, 10u) {|i|
arr += [@"key stuff"];
map.insert(arr, arr + [@"value stuff"]);

View File

@ -3,8 +3,8 @@ use std;
import option;
fn foo<T>(y: option<T>) {
let x: int;
let rs: [int] = [];
let mut x: int;
let mut rs: [int] = [];
/* tests that x doesn't get put in the precondition for the
entire if expression */

View File

@ -5,7 +5,7 @@ enum thing { a, b, c, }
fn foo(it: fn(int)) { it(10); }
fn main() {
let x = true;
let mut x = true;
alt a {
a { x = true; foo {|_i|} }
b { x = false; }

View File

@ -9,7 +9,7 @@ enum color {
}
fn process(c: color) -> int {
let x: int;
let mut x: int;
alt c {
rgb(r, _, _) { #debug("rgb"); log(debug, r); x = r; }
rgba(_, _, _, a) { #debug("rgba"); log(debug, a); x = a; }

View File

@ -9,7 +9,7 @@ fn f1(a: {mutable x: int}, &b: int, -c: int) -> int {
fn f2(a: int, f: fn(int)) -> int { f(1); ret a; }
fn main() {
let a = {mutable x: 1}, b = 2, c = 3;
let mut a = {mutable x: 1}, b = 2, c = 3;
assert (f1(a, b, c) == 6);
assert (a.x == 0);
assert (b == 10);

View File

@ -1,19 +1,19 @@
// Issue 483 - Assignment expressions result in nil
fn test_assign() {
let x: int;
let y: () = x = 10;
let mut x: int;
let mut y: () = x = 10;
assert (x == 10);
let z = x = 11;
let mut z = x = 11;
assert (x == 11);
z = x = 12;
assert (x == 12);
}
fn test_assign_op() {
let x: int = 0;
let y: () = x += 10;
let mut x: int = 0;
let mut y: () = x += 10;
assert (x == 10);
let z = x += 11;
let mut z = x += 11;
assert (x == 21);
z = x += 12;
assert (x == 33);

View File

@ -1,5 +1,5 @@
fn main() {
let sum = 0;
let mut sum = 0;
for x in [1, 2, 3, 4, 5] { sum += x; }
assert (sum == 15);
}

View File

@ -14,7 +14,7 @@ fn main() {
let ch = chan(p);
task::spawn {|| a(ch); };
task::spawn {|| a(ch); };
let n: int = 0;
let mut n: int = 0;
n = recv(p);
n = recv(p);
// #debug("Finished.");

View File

@ -15,7 +15,7 @@ fn main() {
let ch = chan(p);
task::spawn {|| a(ch); };
task::spawn {|| b(ch); };
let n: int = 0;
let mut n: int = 0;
n = recv(p);
n = recv(p);
#debug("Finished.");

View File

@ -28,13 +28,13 @@ fn g(x: int, y: str) -> int {
}
fn main() {
let n: int = 2 + 3 * 7;
let mut n: int = 2 + 3 * 7;
let s: str = "hello there";
let p = comm::port();
let ch = comm::chan(p);
task::spawn {|| a(ch); };
task::spawn {|| b(ch); };
let x: int = 10;
let mut x: int = 10;
x = g(n, s);
log(debug, x);
n = recv(p);

View File

@ -11,8 +11,8 @@ fn target() {
}
fn general() {
let a: int = 1;
let b: int = 2;
let mut a: int = 1;
let mut b: int = 2;
a ^= b;
b ^= a;
a = a ^ b;

View File

@ -8,7 +8,7 @@ fn main() {
}
// Usable at all:
let any_negative = vec::any(v) { |e| float::is_negative(e) };
let mut any_negative = vec::any(v) { |e| float::is_negative(e) };
assert any_negative;
// Higher precedence than assignments:

View File

@ -2,7 +2,7 @@ fn iter_vec<T>(v: [T], f: fn(T)) { for x: T in v { f(x); } }
fn main() {
let v = [1, 2, 3, 4, 5, 6, 7];
let odds = 0;
let mut odds = 0;
iter_vec(v, {|i|
log(error, i);
if i % 2 == 1 {

View File

@ -2,7 +2,7 @@ fn iter_vec<T>(v: [T], f: fn(T)) { for x: T in v { f(x); } }
fn main() {
let v = [1, 2, 3, 4, 5];
let sum = 0;
let mut sum = 0;
iter_vec(v, {|i|
iter_vec(v, {|j|
log(error, i * j);

View File

@ -1,7 +1,7 @@
fn main() {
let i = 0;
let mut i = 0;
while i < 20 { i += 1; if i == 10 { break; } }
assert (i == 10);
do { i += 1; if i == 20 { break; } } while i < 30

View File

@ -15,7 +15,7 @@ type ctx = chan<request>;
fn request_task(c: chan<ctx>) {
let p = port();
send(c, chan(p));
let req: request;
let mut req: request;
req = recv(p);
// Need to drop req before receiving it again
req = recv(p);
@ -25,7 +25,7 @@ fn new_cx() -> ctx {
let p = port();
let ch = chan(p);
let t = task::spawn {|| request_task(ch); };
let cx: ctx;
let mut cx: ctx;
cx = recv(p);
ret cx;
}

View File

@ -9,17 +9,17 @@ fn nothing() { }
fn putstr(s: str) { }
fn putint(i: int) {
let i: int = 33;
let mut i: int = 33;
while i < 36 { putstr("hi"); i = i + 1; }
}
fn zerg(i: int) -> int { ret i; }
fn foo(x: int) -> int {
let y: t = x + 2;
let mut y: t = x + 2;
putstr("hello");
while y < 10 { putint(y); if y * 3 == 4 { y = y + 2; nothing(); } }
let z: t;
let mut z: t;
z = 0x55;
foo(z);
ret 0;

View File

@ -3,7 +3,7 @@ fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 1u;
let b: uint = 4u;
let c: uint = 17u;
let mut c: uint = 17u;
check (uint::le(a, b));
c <- a;
log(debug, foo(c, b));

View File

@ -1,7 +1,7 @@
fn main() unsafe {
fn foo(_a: uint, _b: uint) : uint::le(_a, _b) {}
let a: uint = 4u;
let b: uint = 1u;
let mut a: uint = 4u;
let mut b: uint = 1u;
check (uint::le(b, a));
b <-> a;
log(debug, foo(a, b));

View File

@ -5,14 +5,14 @@
// Tests for using alt as an expression
fn test_basic() {
let rs: bool = alt true { true { true } false { false } };
let mut rs: bool = alt true { true { true } false { false } };
assert (rs);
rs = alt false { true { false } false { true } };
assert (rs);
}
fn test_inferrence() {
let rs = alt true { true { true } false { false } };
let mut rs = alt true { true { true } false { false } };
assert (rs);
}

View File

@ -9,7 +9,7 @@ fn test_basic() { let rs: bool = { true }; assert (rs); }
fn test_rec() { let rs = { {v1: 10, v2: 20} }; assert (rs.v2 == 20); }
fn test_filled_with_stuff() {
let rs = { let a = 0; while a < 10 { a += 1; } a };
let rs = { let mut a = 0; while a < 10 { a += 1; } a };
assert (rs == 10);
}

View File

@ -8,7 +8,7 @@ fn g(f: native fn(int, &bool), &called: bool) {
}
fn main() {
let called = false;
let mut called = false;
let h = f;
g(h, called);
assert called == true;

View File

@ -6,7 +6,7 @@ fn two(it: fn(int)) { it(0); it(1); }
fn main() {
let a: [mutable int] = [mutable -1, -1, -1, -1];
let p: int = 0;
let mut p: int = 0;
two {|i|
two {|j| a[p] = 10 * i + j; p += 1; };
};

View File

@ -1,14 +1,14 @@
fn pairs(it: fn((int, int))) {
let i: int = 0;
let j: int = 0;
let mut i: int = 0;
let mut j: int = 0;
while i < 10 { it((i, j)); i += 1; j += i; }
}
fn main() {
let i: int = 10;
let j: int = 0;
let mut i: int = 10;
let mut j: int = 0;
pairs() {|p|
let (_0, _1) = p;
log(debug, _0);

View File

@ -3,7 +3,7 @@
// -*- rust -*-
fn main() {
let sum: int = 0;
let mut sum: int = 0;
first_ten {|i| #debug("main"); log(debug, i); sum = sum + i; };
#debug("sum");
log(debug, sum);
@ -11,6 +11,6 @@ fn main() {
}
fn first_ten(it: fn(int)) {
let i: int = 0;
let mut i: int = 0;
while i < 10 { #debug("first_ten"); it(i); i = i + 1; }
}

View File

@ -7,12 +7,12 @@ fn id<T: copy>(x: T) -> T { ret x; }
type triple = {x: int, y: int, z: int};
fn main() {
let x = 62;
let y = 63;
let mut x = 62;
let mut y = 63;
let a = 'a';
let b = 'b';
let mut b = 'b';
let p: triple = {x: 65, y: 66, z: 67};
let q: triple = {x: 68, y: 69, z: 70};
let mut q: triple = {x: 68, y: 69, z: 70};
y = id::<int>(x);
log(debug, y);
assert (x == y);

View File

@ -3,7 +3,7 @@
enum foo<T> { arm(T), }
fn altfoo<T>(f: foo<T>) {
let hit = false;
let mut hit = false;
alt f { arm::<T>(x) { #debug("in arm"); hit = true; } }
assert (hit);
}

View File

@ -2,4 +2,4 @@
enum option<T> { some(@T), none, }
fn main() { let a: option<int> = some::<int>(@10); a = none::<int>; }
fn main() { let mut a: option<int> = some::<int>(@10); a = none::<int>; }

View File

@ -44,7 +44,7 @@ mod map_reduce {
fn emit(im: map::hashmap<str, int>, ctrl: chan<ctrl_proto>, key: str,
val: str) {
let c;
let mut c;
alt im.find(key) {
some(_c) { c = _c }
none {
@ -69,19 +69,19 @@ mod map_reduce {
// This task becomes the master control task. It spawns others
// to do the rest.
let reducers: map::hashmap<str, int>;
let mut reducers: map::hashmap<str, int>;
reducers = map::str_hash();
start_mappers(chan(ctrl), inputs);
let num_mappers = vec::len(inputs) as int;
let mut num_mappers = vec::len(inputs) as int;
while num_mappers > 0 {
alt recv(ctrl) {
mapper_done { num_mappers -= 1; }
find_reducer(k, cc) {
let c;
let mut c;
alt reducers.find(str::from_bytes(k)) {
some(_c) { c = _c; }
none { c = 0; }

View File

@ -2,4 +2,4 @@
// -*- rust -*-
fn main() { let x: i32 = -400_i32; x = 0_i32 - x; assert (x == 400_i32); }
fn main() { let mut x: i32 = -400_i32; x = 0_i32 - x; assert (x == 400_i32); }

View File

@ -3,7 +3,7 @@
// -*- rust -*-
fn main() {
let x: i8 = -12i8;
let mut x: i8 = -12i8;
let y: i8 = -12i8;
x = x + 1i8;
x = x - 1i8;

View File

@ -16,7 +16,7 @@ iface map<T> {
}
impl <T> of map<T> for [T] {
fn map<U>(f: fn(T) -> U) -> [U] {
let r = [];
let mut r = [];
for x in self { r += [f(x)]; }
r
}

View File

@ -3,7 +3,7 @@ use std;
import vec::*;
fn main() {
let v = from_elem(0u, 0);
let mut v = from_elem(0u, 0);
v += [4, 2];
assert (reversed(v) == [2, 4]);
}

View File

@ -6,11 +6,11 @@ native mod rusti {
}
fn main() unsafe {
let v: [int] = [];
let mut v: [int] = [];
assert (vec_len(v) == 0u); // zero-length
let x = [1, 2];
let mut x = [1, 2];
assert (vec_len(x) == 2u); // on stack
let y = [1, 2, 3, 4, 5];
let mut y = [1, 2, 3, 4, 5];
assert (vec_len(y) == 5u); // on heap
v += [];

View File

@ -1,6 +1,6 @@
fn main () {
let line = "";
let i = 0;
let mut line = "";
let mut i = 0;
do {
line = if i == 9 { "exit" } else { "notexit" };
i += 1;

View File

@ -13,7 +13,7 @@ fn a() {
spawn {|| b(ch); };
recv(p);
}
let i = 0;
let mut i = 0;
while i < 100 {
doit();
i += 1;

View File

@ -33,16 +33,16 @@ fn test_heap_add() {
}
fn test_append() {
let s = "";
let mut s = "";
s += "a";
assert (s == "a");
let s = "a";
let mut s = "a";
s += "b";
log(debug, s);
assert (s == "ab");
let s = "c";
let mut s = "c";
s += "offee";
assert (s == "coffee");

View File

@ -2,12 +2,12 @@
fn range(a: int, b: int, it: fn(int)) {
assert (a < b);
let i: int = a;
let mut i: int = a;
while i < b { it(i); i += 1; }
}
fn main() {
let sum: int = 0;
let mut sum: int = 0;
range(0, 100) {|x| sum += x; }
log(debug, sum);
}

View File

@ -3,7 +3,7 @@ fn double<T: copy>(a: T) -> [T] { ret [a] + [a]; }
fn double_int(a: int) -> [int] { ret [a] + [a]; }
fn main() {
let d = double(1);
let mut d = double(1);
assert (d[0] == 1);
assert (d[1] == 1);

View File

@ -16,7 +16,7 @@ fn main() {
call_me({|| *q}, q);
// Check that no false positives are found in loops.
let q = ~40, p = 10;
let mut q = ~40, p = 10;
loop {
let i = q;
p += *i;

View File

@ -5,7 +5,7 @@ fn incr(&x: int) -> bool { x += 1; assert (false); ret false; }
fn main() {
let x = 1 == 2 || 3 == 3;
assert (x);
let y: int = 10;
let mut y: int = 10;
log(debug, x || incr(y));
assert (y == 10);
if true && x { assert (true); } else { assert (false); }

View File

@ -2,4 +2,4 @@
fn foo(x: int) { log(debug, x); }
fn main() { let x: int; if 1 > 2 { x = 12; } else { x = 10; } foo(x); }
fn main() { let mut x: int; if 1 > 2 { x = 12; } else { x = 10; } foo(x); }

View File

@ -7,7 +7,7 @@ import comm::*;
fn main() {
let p = port();
let ch = chan(p);
let y: int;
let mut y: int;
task::spawn {|| child(ch); };
y = recv(p);

View File

@ -2,4 +2,4 @@
enum t { a, b(@int), }
fn main() { let x = b(@10); x = a; }
fn main() { let mut x = b(@10); x = a; }

Some files were not shown because too many files have changed in this diff Show More