Convert ret to return

This commit is contained in:
Brian Anderson 2012-08-01 17:30:05 -07:00
parent dc499f193e
commit b355936b4d
456 changed files with 3875 additions and 3798 deletions

View File

@ -219,7 +219,7 @@ if impl import
let log loop
mod mut
pure
ret
return
true trait type
unchecked unsafe
while
@ -841,17 +841,17 @@ value has the corresponding [*function type*](#function-types), and can be
used otherwise exactly as a function item (with a minor additional cost of
calling the function indirectly).
Every control path in a function logically ends with a `ret` expression or a
Every control path in a function logically ends with a `return` expression or a
diverging expression. If the outermost block of a function has a
value-producing expression in its final-expression position, that expression
is interpreted as an implicit `ret` expression applied to the
is interpreted as an implicit `return` expression applied to the
final-expression.
An example of a function:
~~~~
fn add(x: int, y: int) -> int {
ret x + y;
return x + y;
}
~~~~
@ -876,7 +876,7 @@ unifies with any type. Rust has no syntax for $\bot$.
It might be necessary to declare a diverging function because as mentioned
previously, the typechecker checks that every control path in a function ends
with a [`ret`](#return-expressions) or diverging expression. So, if `my_err`
with a [`return`](#return-expressions) or diverging expression. So, if `my_err`
were declared without the `!` annotation, the following code would not
typecheck:
@ -885,7 +885,7 @@ typecheck:
fn f(i: int) -> int {
if i == 42 {
ret 42;
return 42;
}
else {
my_err(~"Bad number!");
@ -895,7 +895,7 @@ fn f(i: int) -> int {
The typechecker would complain that `f` doesn't return a value in the
`else` branch. Adding the `!` annotation on `my_err` would
express that `f` requires no explicit `ret`, as if it returns
express that `f` requires no explicit `return`, as if it returns
control to the caller, it returns a value (true because it never returns
control).
@ -915,7 +915,7 @@ An example of a predicate:
~~~~
pure fn lt_42(x: int) -> bool {
ret (x < 42);
return (x < 42);
}
~~~~
@ -1845,7 +1845,7 @@ An example of an `as` expression:
fn avg(v: ~[float]) -> float {
let sum: float = sum(v);
let sz: float = len(v) as float;
ret sum / sz;
return sum / sz;
}
~~~~
@ -2079,21 +2079,21 @@ For a block `b`, the expression `loop b` is semantically equivalent to
typestate analysis pass takes into account that `loop`s are infinite.
For example, the following (contrived) function uses a `loop` with a
`ret` expression:
`return` expression:
~~~~
fn count() -> bool {
let mut i = 0;
loop {
i += 1;
if i == 20 { ret true; }
if i == 20 { return true; }
}
}
~~~~
This function compiles, because typestate recognizes that the `loop`
never terminates (except non-locally, with `ret`), thus there is no
need to insert a spurious `fail` or `ret` after the `loop`. If `loop`
never terminates (except non-locally, with `return`), thus there is no
need to insert a spurious `fail` or `return` after the `loop`. If `loop`
were replaced with `while true`, the function would be rejected
because from the compiler's perspective, there would be a control path
along which `count` does not return a value (that is, if the loop
@ -2200,7 +2200,7 @@ let x: list<int> = cons(10, @cons(11, @nil));
alt x {
cons(_, @nil) { fail ~"singleton list"; }
cons(*) { ret; }
cons(*) { return; }
nil { fail ~"empty list"; }
}
~~~~
@ -2235,7 +2235,7 @@ alt x {
process_ten();
}
nil {
ret;
return;
}
_ {
fail;
@ -2353,7 +2353,7 @@ fn read_file_lines(path: ~str) -> ~[~str] {
lines(f) |s| {
r += ~[s];
}
ret r;
return r;
}
~~~~
@ -2372,23 +2372,23 @@ expression.
### Return expressions
~~~~~~~~{.ebnf .gram}
ret_expr : "ret" expr ? ;
return_expr : "return" expr ? ;
~~~~~~~~
Return expressions are denoted with the keyword `ret`. Evaluating a `ret`
expression^[A `ret` expression is analogous to a `return` expression
Return expressions are denoted with the keyword `return`. Evaluating a `return`
expression^[A `return` expression is analogous to a `return` expression
in the C family.] moves its argument into the output slot of the current
function, destroys the current function activation frame, and transfers
control to the caller frame.
An example of a `ret` expression:
An example of a `return` expression:
~~~~
fn max(a: int, b: int) -> int {
if a > b {
ret a;
return a;
}
ret b;
return b;
}
~~~~
@ -2738,7 +2738,7 @@ An example of a `fn` type:
~~~~~~~~
fn add(x: int, y: int) -> int {
ret x + y;
return x + y;
}
let mut x = add(5,7);
@ -2784,10 +2784,10 @@ Within the body of an item that has type parameter declarations, the names of it
~~~~~~~
fn map<A: copy, B: copy>(f: fn(A) -> B, xs: ~[A]) -> ~[B] {
if xs.len() == 0 { ret ~[]; }
if xs.len() == 0 { return ~[]; }
let first: B = f(xs[0]);
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
ret ~[first] + rest;
return ~[first] + rest;
}
~~~~~~~

View File

@ -54,7 +54,7 @@ fn boring_old_factorial(n: int) -> int {
result *= i;
i += 1;
}
ret result;
return result;
}
~~~~
@ -62,9 +62,7 @@ Several differences from C stand out. Types do not come before, but
after variable names (preceded by a colon). For local variables
(introduced with `let`), types are optional, and will be inferred when
left off. Constructs like `while` and `if` do not require parentheses
around the condition (though they allow them). Also, there's a
tendency towards aggressive abbreviation in the keywords—`fn` for
function, `ret` for return.
around the condition (though they allow them).
You should, however, not conclude that Rust is simply an evolution of
C. As will become clear in the rest of this tutorial, it goes in quite
@ -697,15 +695,15 @@ end of the block:
fn signum(x: int) -> int {
if x < 0 { -1 }
else if x > 0 { 1 }
else { ret 0; }
else { return 0; }
}
~~~~
The `ret` (return) and its semicolon could have been left out without
The `return` and its semicolon could have been left out without
changing the meaning of this function, but it illustrates that you
will not get a type error in this case, although the last arm doesn't
have type `int`, because control doesn't reach the end of that arm
(`ret` is jumping out of the function).
(`return` is jumping out of the function).
## Pattern matching
@ -913,11 +911,11 @@ colons and the return type follows the arrow.
~~~~
fn int_to_str(i: int) -> ~str {
ret ~"tube sock";
return ~"tube sock";
}
~~~~
The `ret` keyword immediately returns from the body of a function. It
The `return` keyword immediately returns from the body of a function. It
is optionally followed by an expression to return. A function can
also return a value by having its top level block produce an
expression.
@ -926,9 +924,9 @@ expression.
# const copernicus: int = 0;
fn int_to_str(i: int) -> ~str {
if i == copernicus {
ret ~"tube sock";
return ~"tube sock";
} else {
ret ~"violin";
return ~"violin";
}
}
~~~~
@ -946,7 +944,7 @@ and both the return type and the return value may be omitted from
the definition. The following two functions are equivalent.
~~~~
fn do_nothing_the_hard_way() -> () { ret (); }
fn do_nothing_the_hard_way() -> () { return (); }
fn do_nothing_the_easy_way() { }
~~~~
@ -1552,7 +1550,7 @@ their environment". For example you couldn't write the following:
let foo = 10;
fn bar() -> int {
ret foo; // `bar` cannot refer to `foo`
return foo; // `bar` cannot refer to `foo`
}
~~~~
@ -1617,7 +1615,7 @@ returns it from a function, and then calls it:
use std;
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
ret fn@(s: ~str) -> ~str { s + suffix };
return fn@(s: ~str) -> ~str { s + suffix };
}
fn main() {
@ -1635,7 +1633,7 @@ be written:
~~~~
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
ret |s| s + suffix;
return |s| s + suffix;
}
~~~~
@ -1742,7 +1740,7 @@ Empty argument lists can be omitted from `do` expressions.
Most iteration in Rust is done with `for` loops. Like `do`,
`for` is a nice syntax for doing control flow with closures.
Additionally, within a `for` loop, `break`, `again`, and `ret`
Additionally, within a `for` loop, `break`, `again`, and `retern`
work just as they do with `while` and `loop`.
Consider again our `each` function, this time improved to
@ -1790,7 +1788,7 @@ for each(~[2, 4, 8, 5, 16]) |n| {
}
~~~~
As an added bonus, you can use the `ret` keyword, which is not
As an added bonus, you can use the `return` keyword, which is not
normally allowed in closures, in a block that appears as the body of a
`for` loop — this will cause a return to happen from the outer
function, not just the loop body.
@ -1799,7 +1797,7 @@ function, not just the loop body.
# import each = vec::each;
fn contains(v: ~[int], elt: int) -> bool {
for each(v) |x| {
if (x == elt) { ret true; }
if (x == elt) { return true; }
}
false
}
@ -1960,7 +1958,7 @@ copy, that's a win.
~~~~
type person = {name: ~str, address: ~str};
fn make_person(+name: ~str, +address: ~str) -> person {
ret {name: name, address: address};
return {name: name, address: address};
}
~~~~
@ -1987,7 +1985,7 @@ fn map<T, U>(vector: ~[T], function: fn(T) -> U) -> ~[U] {
for vector.each |element| {
vec::push(accumulator, function(element));
}
ret accumulator;
return accumulator;
}
~~~~
@ -2473,7 +2471,7 @@ fn comma_sep<T: to_str>(elts: ~[T]) -> ~str {
else { result += ~", "; }
result += elt.to_str();
}
ret result;
return result;
}
~~~~
@ -2633,14 +2631,14 @@ extern mod crypto {
fn as_hex(data: ~[u8]) -> ~str {
let mut acc = ~"";
for data.each |byte| { acc += #fmt("%02x", byte as uint); }
ret acc;
return acc;
}
fn sha1(data: ~str) -> ~str unsafe {
let bytes = str::bytes(data);
let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes),
vec::len(bytes) as c_uint, ptr::null());
ret as_hex(vec::unsafe::from_buf(hash, 20u));
return as_hex(vec::unsafe::from_buf(hash, 20u));
}
fn main(args: ~[~str]) {
@ -2740,7 +2738,7 @@ fn sha1(data: ~str) -> ~str {
let bytes = str::bytes(data);
let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes),
vec::len(bytes), ptr::null());
ret as_hex(vec::unsafe::from_buf(hash, 20u));
return as_hex(vec::unsafe::from_buf(hash, 20u));
}
}
~~~~
@ -2783,7 +2781,7 @@ Let's look at our `sha1` function again.
let bytes = str::bytes(data);
let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes),
vec::len(bytes), ptr::null());
ret as_hex(vec::unsafe::from_buf(hash, 20u));
return as_hex(vec::unsafe::from_buf(hash, 20u));
# }
# }
~~~~
@ -2830,7 +2828,7 @@ extern mod lib_c {
fn unix_time_in_microseconds() -> u64 unsafe {
let x = {mut tv_sec: 0 as c_ulonglong, mut tv_usec: 0 as c_ulonglong};
lib_c::gettimeofday(ptr::addr_of(x), ptr::null());
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
return (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
}
# fn main() { assert #fmt("%?", unix_time_in_microseconds()) != ~""; }

View File

@ -125,7 +125,7 @@ fn is_uuid(id: ~str) -> bool {
}
if !part.all(is_hex_digit) {
ret false;
return false;
}
alt i {
@ -148,10 +148,10 @@ fn is_uuid(id: ~str) -> bool {
}
}
if correct >= 5u {
ret true;
return true;
}
}
ret false;
return false;
}
#[test]
@ -207,10 +207,10 @@ fn is_git_url(url: ~str) -> bool {
fn assume_source_method(url: ~str) -> ~str {
if is_git_url(url) {
ret ~"git";
return ~"git";
}
if str::starts_with(url, ~"file://") || os::path_exists(url) {
ret ~"file";
return ~"file";
}
~"curl"
@ -350,7 +350,7 @@ fn load_crate(filename: ~str) -> option<crate> {
crate_type: crate_type,
deps: deps })
}
_ { ret none; }
_ { return none; }
}
}
@ -367,7 +367,7 @@ fn rest(s: ~str, start: uint) -> ~str {
}
fn need_dir(s: ~str) {
if os::path_is_dir(s) { ret; }
if os::path_is_dir(s) { return; }
if !os::make_dir(s, 493_i32 /* oct: 755 */) {
fail fmt!{"can't make_dir %s", s};
}
@ -419,7 +419,7 @@ fn parse_source(name: ~str, j: json::json) -> source {
if method == ~"file" {
url = os::make_absolute(url);
}
ret @{
return @{
name: name,
mut url: url,
mut method: method,
@ -432,7 +432,7 @@ fn parse_source(name: ~str, j: json::json) -> source {
}
fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) {
if !os::path_exists(filename) { ret; }
if !os::path_exists(filename) { return; }
let c = io::read_whole_file_str(filename);
alt json::from_str(result::get(c)) {
ok(json::dict(j)) {
@ -454,13 +454,13 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
+ src.name + ~", '" + *n + ~"'"+
~" is an invalid name (alphanumeric, underscores and" +
~" dashes only)");
ret;
return;
}
*n
}
_ {
warn(~"malformed source json: " + src.name + ~" (missing name)");
ret;
return;
}
};
@ -470,13 +470,13 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
warn(~"malformed source json: "
+ src.name + ~", '" + *n + ~"'"+
~" is an invalid uuid");
ret;
return;
}
*n
}
_ {
warn(~"malformed source json: " + src.name + ~" (missing uuid)");
ret;
return;
}
};
@ -484,7 +484,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
some(json::string(n)) { *n }
_ {
warn(~"malformed source json: " + src.name + ~" (missing url)");
ret;
return;
}
};
@ -493,7 +493,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
_ {
warn(~"malformed source json: "
+ src.name + ~" (missing method)");
ret;
return;
}
};
@ -520,7 +520,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
_ {
warn(~"malformed source json: " + src.name
+ ~" (missing description)");
ret;
return;
}
};
@ -551,7 +551,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
fn load_source_info(c: cargo, src: source) {
let dir = path::connect(c.sourcedir, src.name);
let srcfile = path::connect(dir, ~"source.json");
if !os::path_exists(srcfile) { ret; }
if !os::path_exists(srcfile) { return; }
let srcstr = io::read_whole_file_str(srcfile);
alt json::from_str(result::get(srcstr)) {
ok(json::dict(s)) {
@ -573,7 +573,7 @@ fn load_source_packages(c: cargo, src: source) {
log(debug, ~"loading source: " + src.name);
let dir = path::connect(c.sourcedir, src.name);
let pkgfile = path::connect(dir, ~"packages.json");
if !os::path_exists(pkgfile) { ret; }
if !os::path_exists(pkgfile) { return; }
let pkgstr = io::read_whole_file_str(pkgfile);
alt json::from_str(result::get(pkgstr)) {
ok(json::list(js)) {
@ -718,7 +718,7 @@ fn run_in_buildpath(what: ~str, path: ~str, subdir: ~str, cf: ~str,
~[~"--out-dir", buildpath, cf] + extra_flags);
if p.status != 0 {
error(fmt!{"rustc failed: %d\n%s\n%s", p.status, p.err, p.out});
ret none;
return none;
}
some(buildpath)
}
@ -726,7 +726,7 @@ fn run_in_buildpath(what: ~str, path: ~str, subdir: ~str, cf: ~str,
fn test_one_crate(_c: cargo, path: ~str, cf: ~str) {
let buildpath = alt run_in_buildpath(~"testing", path, ~"/test", cf,
~[ ~"--test"]) {
none { ret; }
none { return; }
some(bp) { bp }
};
run_programs(buildpath);
@ -735,7 +735,7 @@ fn test_one_crate(_c: cargo, path: ~str, cf: ~str) {
fn install_one_crate(c: cargo, path: ~str, cf: ~str) {
let buildpath = alt run_in_buildpath(~"installing", path,
~"/build", cf, ~[]) {
none { ret; }
none { return; }
some(bp) { bp }
};
let newv = os::list_dir_path(buildpath);
@ -867,7 +867,7 @@ fn cargo_suggestion(c: cargo, fallback: fn())
if c.sources.size() == 0u {
error(~"no sources defined - you may wish to run " +
~"`cargo init`");
ret;
return;
}
fallback();
}
@ -882,12 +882,12 @@ fn install_uuid(c: cargo, wd: ~str, uuid: ~str) {
if vec::len(ps) == 1u {
let (sname, p) = copy ps[0];
install_package(c, sname, wd, p);
ret;
return;
} else if vec::len(ps) == 0u {
cargo_suggestion(c, || {
error(~"can't find package: " + uuid);
});
ret;
return;
}
error(~"found multiple packages:");
for ps.each |elt| {
@ -906,12 +906,12 @@ fn install_named(c: cargo, wd: ~str, name: ~str) {
if vec::len(ps) == 1u {
let (sname, p) = copy ps[0];
install_package(c, sname, wd, p);
ret;
return;
} else if vec::len(ps) == 0u {
cargo_suggestion(c, || {
error(~"can't find package: " + name);
});
ret;
return;
}
error(~"found multiple packages:");
for ps.each |elt| {
@ -929,7 +929,7 @@ fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) {
install_package(c, src, wd, p);
true
} else { false }
}) { ret; }
}) { return; }
}
_ { }
}
@ -945,7 +945,7 @@ fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) {
install_package(c, src, wd, p);
true
} else { false }
}) { ret; }
}) { return; }
}
_ { }
}
@ -955,7 +955,7 @@ fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) {
fn cmd_uninstall(c: cargo) {
if vec::len(c.opts.free) < 3u {
cmd_usage();
ret;
return;
}
let lib = c.libdir;
@ -976,7 +976,7 @@ fn cmd_uninstall(c: cargo) {
} else {
error(~"could not uninstall: '" + full + ~"'");
}
ret;
return;
}
none { again; }
}
@ -994,7 +994,7 @@ fn cmd_uninstall(c: cargo) {
} else {
error(~"could not uninstall: '" + full + ~"'");
}
ret;
return;
}
none { again; }
}
@ -1008,7 +1008,7 @@ fn cmd_uninstall(c: cargo) {
} else {
error(~"could not uninstall: '" + full + ~"'");
}
ret;
return;
}
none { again; }
}
@ -1022,7 +1022,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
alt c.dep_cache.find(target) {
some(inst) {
if inst {
ret;
return;
}
}
none {}
@ -1032,7 +1032,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
if is_archive_path(target) {
install_file(c, wd, target);
ret;
return;
} else if is_git_url(target) {
let reference = if c.opts.free.len() >= 4u {
some(c.opts.free[3u])
@ -1042,7 +1042,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
install_git(c, wd, target, reference);
} else if !valid_pkg_name(target) && has_archive_extension(target) {
install_curl(c, wd, target);
ret;
return;
} else {
let mut ps = copy target;
@ -1094,7 +1094,7 @@ fn cmd_install(c: cargo) unsafe {
}
install_source(c, wd);
ret;
return;
}
sync(c);
@ -1127,7 +1127,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
if !os::copy_file(path::connect(url, ~"packages.json"), pkgfile) {
error(fmt!{"fetch for source %s (url %s) failed", name, url});
ret false;
return false;
}
if os::copy_file(path::connect(url, ~"source.json"), srcfile) {
@ -1143,7 +1143,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
~[~"-f", ~"-s", ~"-o", keyfile, u]);
if p.status != 0 {
error(fmt!{"fetch for source %s (key %s) failed", name, u});
ret false;
return false;
}
pgp::add(c.root, keyfile);
}
@ -1156,7 +1156,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
if !r {
error(fmt!{"signature verification failed for source %s",
name});
ret false;
return false;
}
if has_src_file {
@ -1165,7 +1165,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
if !e {
error(fmt!{"signature verification failed for source %s",
name});
ret false;
return false;
}
}
}
@ -1186,7 +1186,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
info(fmt!{"synced source: %s", name});
ret true;
return true;
}
fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
@ -1227,20 +1227,20 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
if p.status != 0 {
error(fmt!{"fetch for source %s (url %s) failed", name, url});
ret false;
return false;
}
}
else {
if !os::change_dir(dir) {
error(fmt!{"fetch for source %s (url %s) failed", name, url});
ret false;
return false;
}
let p = run::program_output(~"git", ~[~"pull"]);
if p.status != 0 {
error(fmt!{"fetch for source %s (url %s) failed", name, url});
ret false;
return false;
}
}
@ -1253,7 +1253,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
if p.status != 0 {
error(fmt!{"fetch for source %s (key %s) failed", name, u});
rollback(name, dir, false);
ret false;
return false;
}
pgp::add(c.root, keyfile);
}
@ -1267,7 +1267,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
error(fmt!{"signature verification failed for source %s",
name});
rollback(name, dir, false);
ret false;
return false;
}
if has_src_file {
@ -1277,7 +1277,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
error(fmt!{"signature verification failed for source %s",
name});
rollback(name, dir, false);
ret false;
return false;
}
}
}
@ -1288,7 +1288,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
info(fmt!{"synced source: %s", name});
ret true;
return true;
}
fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
@ -1313,7 +1313,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
if p.status != 0 {
error(fmt!{"fetch for source %s (url %s) failed", name, url});
ret false;
return false;
}
if smart {
url = src.url + ~"/source.json";
@ -1332,7 +1332,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
~[~"-f", ~"-s", ~"-o", keyfile, u]);
if p.status != 0 {
error(fmt!{"fetch for source %s (key %s) failed", name, u});
ret false;
return false;
}
pgp::add(c.root, keyfile);
}
@ -1351,7 +1351,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
sigfile, url]);
if p.status != 0 {
error(fmt!{"fetch for source %s (sig %s) failed", name, url});
ret false;
return false;
}
let r = pgp::verify(c.root, pkgfile, sigfile, f);
@ -1359,7 +1359,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
if !r {
error(fmt!{"signature verification failed for source %s",
name});
ret false;
return false;
}
if smart && has_src_file {
@ -1371,7 +1371,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
if p.status != 0 {
error(fmt!{"fetch for source %s (sig %s) failed",
name, url});
ret false;
return false;
}
let e = pgp::verify(c.root, srcfile, srcsigfile, f);
@ -1379,7 +1379,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
if !e {
error(~"signature verification failed for " +
~"source " + name);
ret false;
return false;
}
}
}
@ -1400,7 +1400,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
info(fmt!{"synced source: %s", name});
ret true;
return true;
}
fn sync_one(c: cargo, src: source) {
@ -1435,20 +1435,20 @@ fn cmd_init(c: cargo) {
run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o", srcfile, srcurl]);
if p.status != 0 {
error(fmt!{"fetch of sources.json failed: %s", p.out});
ret;
return;
}
let p =
run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o", sigfile, sigurl]);
if p.status != 0 {
error(fmt!{"fetch of sources.json.sig failed: %s", p.out});
ret;
return;
}
let r = pgp::verify(c.root, srcfile, sigfile, pgp::signing_key_fp());
if !r {
error(fmt!{"signature verification failed for '%s'", srcfile});
ret;
return;
}
copy_warn(srcfile, destsrcfile);
@ -1518,7 +1518,7 @@ fn cmd_list(c: cargo) {
fn cmd_search(c: cargo) {
if vec::len(c.opts.free) < 3u {
cmd_usage();
ret;
return;
}
sync(c);
@ -1559,7 +1559,7 @@ fn dump_cache(c: cargo) {
}
fn dump_sources(c: cargo) {
if c.sources.size() < 1u {
ret;
return;
}
need_dir(c.root);
@ -1618,7 +1618,7 @@ fn cmd_sources(c: cargo) {
info(fmt!{"%s (%s) via %s",
v.name, v.url, v.method});
}
ret;
return;
}
let action = c.opts.free[2u];
@ -1634,7 +1634,7 @@ fn cmd_sources(c: cargo) {
~"add" {
if vec::len(c.opts.free) < 5u {
cmd_usage();
ret;
return;
}
let name = c.opts.free[3u];
@ -1642,7 +1642,7 @@ fn cmd_sources(c: cargo) {
if !valid_pkg_name(name) {
error(fmt!{"'%s' is an invalid source name", name});
ret;
return;
}
alt c.sources.find(name) {
@ -1665,14 +1665,14 @@ fn cmd_sources(c: cargo) {
~"remove" {
if vec::len(c.opts.free) < 4u {
cmd_usage();
ret;
return;
}
let name = c.opts.free[3u];
if !valid_pkg_name(name) {
error(fmt!{"'%s' is an invalid source name", name});
ret;
return;
}
alt c.sources.find(name) {
@ -1688,7 +1688,7 @@ fn cmd_sources(c: cargo) {
~"set-url" {
if vec::len(c.opts.free) < 5u {
cmd_usage();
ret;
return;
}
let name = c.opts.free[3u];
@ -1696,7 +1696,7 @@ fn cmd_sources(c: cargo) {
if !valid_pkg_name(name) {
error(fmt!{"'%s' is an invalid source name", name});
ret;
return;
}
alt c.sources.find(name) {
@ -1719,7 +1719,7 @@ fn cmd_sources(c: cargo) {
~"set-method" {
if vec::len(c.opts.free) < 5u {
cmd_usage();
ret;
return;
}
let name = c.opts.free[3u];
@ -1727,7 +1727,7 @@ fn cmd_sources(c: cargo) {
if !valid_pkg_name(name) {
error(fmt!{"'%s' is an invalid source name", name});
ret;
return;
}
alt c.sources.find(name) {
@ -1753,7 +1753,7 @@ fn cmd_sources(c: cargo) {
~"rename" {
if vec::len(c.opts.free) < 5u {
cmd_usage();
ret;
return;
}
let name = c.opts.free[3u];
@ -1761,11 +1761,11 @@ fn cmd_sources(c: cargo) {
if !valid_pkg_name(name) {
error(fmt!{"'%s' is an invalid source name", name});
ret;
return;
}
if !valid_pkg_name(newn) {
error(fmt!{"'%s' is an invalid source name", newn});
ret;
return;
}
alt c.sources.find(name) {
@ -1879,7 +1879,7 @@ fn main(argv: ~[~str]) {
if vec::len(o.free) < 2u {
cmd_usage();
ret;
return;
}
if o.help {
alt o.free[1] {
@ -1891,11 +1891,11 @@ fn main(argv: ~[~str]) {
~"sources" { cmd_usage_sources(); }
_ { cmd_usage(); }
}
ret;
return;
}
if o.free[1] == ~"usage" {
cmd_usage();
ret;
return;
}
let mut c = configure(o);

View File

@ -1,5 +1,5 @@
fn gpg(args: ~[~str]) -> { status: int, out: ~str, err: ~str } {
ret run::program_output(~"gpg", args);
return run::program_output(~"gpg", args);
}
fn signing_key() -> ~str {
@ -91,7 +91,7 @@ fn verify(root: ~str, data: ~str, sig: ~str, keyfp: ~str) -> bool {
data]);
let res = ~"Primary key fingerprint: " + keyfp;
for str::split_char(p.err, '\n').each |line| {
if line == res { ret true; }
if line == res { return true; }
}
ret false;
return false;
}

View File

@ -47,7 +47,7 @@ fn parse_config(args: ~[~str]) -> config {
err(f) { fail getopts::fail_str(f) }
};
ret {compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"),
return {compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"),
run_lib_path: getopts::opt_str(matches, ~"run-lib-path"),
rustc_path: getopts::opt_str(matches, ~"rustc-path"),
src_base: getopts::opt_str(matches, ~"src-base"),
@ -143,7 +143,7 @@ fn make_tests(config: config) -> ~[test::test_desc] {
vec::push(tests, make_test(config, file))
}
}
ret tests;
return tests;
}
fn is_test(config: config, testfile: ~str) -> bool {
@ -163,7 +163,7 @@ fn is_test(config: config, testfile: ~str) -> bool {
if str::starts_with(name, pre) { valid = false; }
}
ret valid;
return valid;
}
fn make_test(config: config, testfile: ~str) ->

View File

@ -17,14 +17,14 @@ fn load_errors(testfile: ~str) -> ~[expected_error] {
error_patterns += parse_expected(line_num, ln);
line_num += 1u;
}
ret error_patterns;
return error_patterns;
}
fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
let error_tag = ~"//~";
let mut idx;
alt str::find_str(line, error_tag) {
option::none { ret ~[]; }
option::none { return ~[]; }
option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
}
@ -49,5 +49,5 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
debug!{"line=%u kind=%s msg=%s", line_num - adjust_line, kind, msg};
ret ~[{line: line_num - adjust_line, kind: kind, msg: msg}];
return ~[{line: line_num - adjust_line, kind: kind, msg: msg}];
}

View File

@ -51,7 +51,7 @@ fn load_props(testfile: ~str) -> test_props {
vec::push(exec_env, ee);
}
};
ret {
return {
error_patterns: error_patterns,
compile_flags: compile_flags,
pp_exact: pp_exact,
@ -63,12 +63,12 @@ fn load_props(testfile: ~str) -> test_props {
fn is_test_ignored(config: config, testfile: ~str) -> bool {
let mut found = false;
for iter_header(testfile) |ln| {
if parse_name_directive(ln, ~"xfail-test") { ret true; }
if parse_name_directive(ln, xfail_target()) { ret true; }
if parse_name_directive(ln, ~"xfail-test") { return true; }
if parse_name_directive(ln, xfail_target()) { return true; }
if config.mode == common::mode_pretty &&
parse_name_directive(ln, ~"xfail-pretty") { ret true; }
parse_name_directive(ln, ~"xfail-pretty") { return true; }
};
ret found;
return found;
fn xfail_target() -> ~str {
~"xfail-" + os::sysname()
@ -85,10 +85,10 @@ fn iter_header(testfile: ~str, it: fn(~str) -> bool) -> bool {
// with a warm page cache. Maybe with a cold one.
if str::starts_with(ln, ~"fn")
|| str::starts_with(ln, ~"mod") {
ret false;
} else { if !(it(ln)) { ret false; } }
return false;
} else { if !(it(ln)) { return false; } }
}
ret true;
return true;
}
fn parse_error_pattern(line: ~str) -> option<~str> {

View File

@ -21,7 +21,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
if str::ends_with(prog, ~"rustc.exe") {
vec::push(env, (~"RUST_THREADS", ~"1"));
}
ret env;
return env;
}
#[cfg(target_os = "linux")]
@ -84,7 +84,7 @@ fn run(lib_path: ~str,
};
count -= 1;
};
ret {status: status, out: outs, err: errs};
return {status: status, out: outs, err: errs};
}
fn writeclose(fd: c_int, s: option<~str>) {
@ -106,5 +106,5 @@ fn readclose(fd: c_int) -> ~str {
buf += str::from_bytes(bytes);
}
os::fclose(file);
ret buf;
return buf;
}

View File

@ -134,7 +134,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
fatal_procres(~"pretty-printed source does not typecheck", procres);
}
ret;
return;
fn print_source(config: config, testfile: ~str, src: ~str) -> procres {
compose_and_run(config, testfile, make_pp_args(config, testfile),
@ -144,7 +144,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
fn make_pp_args(config: config, _testfile: ~str) -> procargs {
let prog = config.rustc_path;
let args = ~[~"-", ~"--pretty", ~"normal"];
ret {prog: prog, args: args};
return {prog: prog, args: args};
}
fn compare_source(expected: ~str, actual: ~str) {
@ -181,7 +181,7 @@ actual:\n\
~"--no-trans", ~"--lib", ~"-L", config.build_base,
~"-L", aux_output_dir_name(config, testfile)];
args += split_maybe_args(config.rustcflags);
ret {prog: prog, args: args};
return {prog: prog, args: args};
}
}
@ -211,7 +211,7 @@ fn check_error_patterns(props: test_props,
next_err_pat = props.error_patterns[next_err_idx];
}
}
if done { ret; }
if done { return; }
let missing_patterns =
vec::slice(props.error_patterns, next_err_idx,
@ -340,7 +340,7 @@ fn compose_and_run_compiler(
}
fn ensure_dir(path: path) {
if os::path_is_dir(path) { ret; }
if os::path_is_dir(path) { return; }
if !os::make_dir(path, 0x1c0i32) {
fail fmt!{"can't make dir %s", path};
}
@ -351,7 +351,7 @@ fn compose_and_run(config: config, testfile: ~str,
procenv: ~[(~str, ~str)],
lib_path: ~str,
input: option<~str>) -> procres {
ret program_output(config, testfile, lib_path,
return program_output(config, testfile, lib_path,
procargs.prog, procargs.args, procenv, input);
}
@ -363,7 +363,7 @@ fn make_compile_args(config: config, props: test_props, extras: ~[~str],
~"-L", config.build_base] + extras;
args += split_maybe_args(config.rustcflags);
args += split_maybe_args(props.compile_flags);
ret {prog: prog, args: args};
return {prog: prog, args: args};
}
fn make_lib_name(config: config, auxfile: ~str, testfile: ~str) -> ~str {
@ -391,7 +391,7 @@ fn make_run_args(config: config, _props: test_props, testfile: ~str) ->
};
let args = toolargs + ~[make_exe_name(config, testfile)];
ret {prog: args[0], args: vec::slice(args, 1u, vec::len(args))};
return {prog: args[0], args: vec::slice(args, 1u, vec::len(args))};
}
fn split_maybe_args(argstr: option<~str>) -> ~[~str] {
@ -419,7 +419,7 @@ fn program_output(config: config, testfile: ~str, lib_path: ~str, prog: ~str,
};
let res = procsrv::run(lib_path, prog, args, env, input);
dump_output(config, testfile, res.out, res.err);
ret {status: res.status,
return {status: res.status,
stdout: res.out,
stderr: res.err,
cmdline: cmdline};

View File

@ -5,17 +5,17 @@ fn vec_equal<T>(v: ~[T], u: ~[T],
element_equality_test: fn@(&&T, &&T) -> bool) ->
bool {
let Lv = vec::len(v);
if Lv != vec::len(u) { ret false; }
if Lv != vec::len(u) { return false; }
let i = 0u;
while i < Lv {
if !element_equality_test(v[i], u[i]) { ret false; }
if !element_equality_test(v[i], u[i]) { return false; }
i += 1u;
}
ret true;
return true;
}
pure fn builtin_equal<T>(&&a: T, &&b: T) -> bool { ret a == b; }
pure fn builtin_equal_int(&&a: int, &&b: int) -> bool { ret a == b; }
pure fn builtin_equal<T>(&&a: T, &&b: T) -> bool { return a == b; }
pure fn builtin_equal_int(&&a: int, &&b: int) -> bool { return a == b; }
fn main() {
assert (builtin_equal(5, 5));

View File

@ -39,7 +39,7 @@ type pointy = {
// To add: objects; traits; anything type-parameterized?
fn empty_pointy() -> @pointy {
ret @{
return @{
mut a : none,
mut b : ~none,
mut c : @none,

View File

@ -450,7 +450,7 @@ fn has_raw_pointers(c: ast::crate) -> bool {
visit::mk_simple_visitor(@{visit_ty: |a| visit_ty(has_rp, a)
with *visit::default_simple_visitor()});
visit::visit_crate(c, (), v);
ret *has_rp;
return *has_rp;
}
fn content_is_dangerous_to_run(code: ~str) -> bool {
@ -461,16 +461,16 @@ fn content_is_dangerous_to_run(code: ~str) -> bool {
~"unsafe",
~"log"]; // python --> rust pipe deadlock?
for dangerous_patterns.each |p| { if contains(code, p) { ret true; } }
ret false;
for dangerous_patterns.each |p| { if contains(code, p) { return true; } }
return false;
}
fn content_is_dangerous_to_compile(code: ~str) -> bool {
let dangerous_patterns =
~[~"xfail-test"];
for dangerous_patterns.each |p| { if contains(code, p) { ret true; } }
ret false;
for dangerous_patterns.each |p| { if contains(code, p) { return true; } }
return false;
}
fn content_might_not_converge(code: ~str) -> bool {
@ -485,8 +485,8 @@ fn content_might_not_converge(code: ~str) -> bool {
~"\n\n\n\n\n" // https://github.com/mozilla/rust/issues/850
];
for confusing_patterns.each |p| { if contains(code, p) { ret true; } }
ret false;
for confusing_patterns.each |p| { if contains(code, p) { return true; } }
return false;
}
fn file_might_not_converge(filename: ~str) -> bool {
@ -499,9 +499,9 @@ fn file_might_not_converge(filename: ~str) -> bool {
];
for confusing_files.each |f| { if contains(filename, f) { ret true; } }
for confusing_files.each |f| { if contains(filename, f) { return true; } }
ret false;
return false;
}
fn check_roundtrip_convergence(code: @~str, maxIters: uint) {
@ -512,7 +512,7 @@ fn check_roundtrip_convergence(code: @~str, maxIters: uint) {
while i < maxIters {
oldv = newv;
if content_might_not_converge(*oldv) { ret; }
if content_might_not_converge(*oldv) { return; }
newv = @parse_and_print(oldv);
if oldv == newv { break; }
i += 1u;
@ -592,7 +592,7 @@ fn check_variants(files: ~[~str], cx: context) {
fn main(args: ~[~str]) {
if vec::len(args) != 2u {
error!{"usage: %s <testdir>", args[0]};
ret;
return;
}
let mut files = ~[];
let root = args[1];

View File

@ -91,7 +91,7 @@ fn vec_to_str(v: ~[int]) -> str {
if i + 1u < len(v) { s += ", "; }
i += 1u;
}
ret s + "]";
return s + "]";
}
fn show_edits(a: ~[int], xs: ~[int]) {

View File

@ -51,7 +51,7 @@ fn weighted_choice<T: copy>(r : rand::rng, v : ~[weighted<T>]) -> T {
for {weight: weight, item: item} in v {
so_far += weight;
if so_far > chosen {
ret item;
return item;
}
}
core::unreachable();

View File

@ -61,7 +61,7 @@ fn get<T: const send>(rc: &arc<T>) -> &T {
// Cast us back into the correct region
let r = unsafe::reinterpret_cast(&ptr.data);
unsafe::forget(ptr);
ret r;
return r;
}
}

View File

@ -60,7 +60,7 @@ pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> @[A] {
<fn(push: pure fn(+A)), fn(push: fn(+A))>
(builder)(|+x| unsafe::push(vec, x));
}
ret vec;
return vec;
}
/**

View File

@ -51,7 +51,7 @@ import is_XID_continue = unicode::derived_property::XID_Continue;
* in terms of the Unicode General Category 'Ll'
*/
pure fn is_lowercase(c: char) -> bool {
ret unicode::general_category::Ll(c);
return unicode::general_category::Ll(c);
}
/**
@ -59,7 +59,7 @@ pure fn is_lowercase(c: char) -> bool {
* in terms of the Unicode General Category 'Lu'.
*/
pure fn is_uppercase(c: char) -> bool {
ret unicode::general_category::Lu(c);
return unicode::general_category::Lu(c);
}
/**
@ -68,7 +68,7 @@ pure fn is_uppercase(c: char) -> bool {
* additional 'Cc'-category control codes in the range [0x09, 0x0d]
*/
pure fn is_whitespace(c: char) -> bool {
ret ('\x09' <= c && c <= '\x0d')
return ('\x09' <= c && c <= '\x0d')
|| unicode::general_category::Zs(c)
|| unicode::general_category::Zl(c)
|| unicode::general_category::Zp(c);
@ -80,7 +80,7 @@ pure fn is_whitespace(c: char) -> bool {
* 'Nl', 'No' and the Derived Core Property 'Alphabetic'.
*/
pure fn is_alphanumeric(c: char) -> bool {
ret unicode::derived_property::Alphabetic(c) ||
return unicode::derived_property::Alphabetic(c) ||
unicode::general_category::Nd(c) ||
unicode::general_category::Nl(c) ||
unicode::general_category::No(c);
@ -93,7 +93,7 @@ pure fn is_ascii(c: char) -> bool {
/// Indicates whether the character is numeric (Nd, Nl, or No)
pure fn is_digit(c: char) -> bool {
ret unicode::general_category::Nd(c) ||
return unicode::general_category::Nd(c) ||
unicode::general_category::Nl(c) ||
unicode::general_category::No(c);
}
@ -117,7 +117,7 @@ pure fn to_digit(c: char, radix: uint) -> option<uint> {
'0' to '9' { c as uint - ('0' as uint) }
'a' to 'z' { c as uint + 10u - ('a' as uint) }
'A' to 'Z' { c as uint + 10u - ('A' as uint) }
_ { ret none; }
_ { return none; }
};
if val < radix { some(val) }
else { none }
@ -142,7 +142,7 @@ fn escape_unicode(c: char) -> ~str {
str::push_str(out, str::from_char(c));
for uint::range(str::len(s), pad) |_i| { str::push_str(out, ~"0"); }
str::push_str(out, s);
ret out;
return out;
}
/**
@ -178,7 +178,7 @@ fn escape_default(c: char) -> ~str {
* -1 if a < b, 0 if a == b, +1 if a > b
*/
pure fn cmp(a: char, b: char) -> int {
ret if b > a { -1 }
return if b > a { -1 }
else if b < a { 1 }
else { 0 }
}

View File

@ -207,7 +207,7 @@ fn recv_<T: send>(p: *rust_port) -> T {
// this is a good place to yield
task::yield();
}
ret res;
return res;
}
fn peek_(p: *rust_port) -> bool {

View File

@ -72,7 +72,7 @@ fn from_vec<A>(+v: ~[mut A]) -> dvec<A> {
/// Consumes the vector and returns its contents
fn unwrap<A>(-d: dvec<A>) -> ~[mut A] {
let dvec_({data: v}) <- d;
ret v;
return v;
}
impl private_methods<A> for dvec<A> {
@ -92,7 +92,7 @@ impl private_methods<A> for dvec<A> {
data <-> self.data;
let data_ptr: *() = unsafe::reinterpret_cast(data);
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
ret f(data);
return f(data);
}
}
@ -263,7 +263,7 @@ impl extensions<A:copy> for dvec<A> {
#[inline(always)]
pure fn get_elt(idx: uint) -> A {
self.check_not_borrowed();
ret self.data[idx];
return self.data[idx];
}
/// Overwrites the contents of the element at `idx` with `a`
@ -295,7 +295,7 @@ impl extensions<A:copy> for dvec<A> {
fail ~"attempt to retrieve the last element of an empty vector";
}
ret self.data[length - 1u];
return self.data[length - 1u];
}
/// Iterates over the elements in reverse order

View File

@ -28,7 +28,7 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
for vec::each(eithers) |elt| {
alt elt { left(l) { vec::push(result, l); } _ {/* fallthrough */ } }
}
ret result;
return result;
}
fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
@ -38,7 +38,7 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
for vec::each(eithers) |elt| {
alt elt { right(r) { vec::push(result, r); } _ {/* fallthrough */ } }
}
ret result;
return result;
}
fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
@ -58,7 +58,7 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
right(r) { vec::push(rights, r); }
}
}
ret {lefts: lefts, rights: rights};
return {lefts: lefts, rights: rights};
}
pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T> {

View File

@ -90,7 +90,7 @@ mod ct {
let piece = piece_string(buf);
vec::push(pieces, piece);
}
ret ~"";
return ~"";
}
let mut i = 0u;
while i < lim {
@ -114,15 +114,15 @@ mod ct {
} else { buf += curr; i += size; }
}
flush_buf(buf, pieces);
ret pieces;
return pieces;
}
fn peek_num(s: ~str, i: uint, lim: uint) ->
option<{num: uint, next: uint}> {
if i >= lim { ret none; }
if i >= lim { return none; }
let c = s[i];
if !('0' as u8 <= c && c <= '9' as u8) { ret option::none; }
if !('0' as u8 <= c && c <= '9' as u8) { return option::none; }
let n = (c - ('0' as u8)) as uint;
ret alt peek_num(s, i + 1u, lim) {
return alt peek_num(s, i + 1u, lim) {
none { some({num: n, next: i + 1u}) }
some(next) {
let m = next.num;
@ -138,7 +138,7 @@ mod ct {
let width = parse_count(s, flags.next, lim);
let prec = parse_precision(s, width.next, lim);
let ty = parse_type(s, prec.next, lim, error);
ret {piece:
return {piece:
piece_conv({param: parm.param,
flags: flags.flags,
width: width.count,
@ -148,9 +148,9 @@ mod ct {
}
fn parse_parameter(s: ~str, i: uint, lim: uint) ->
{param: option<int>, next: uint} {
if i >= lim { ret {param: none, next: i}; }
if i >= lim { return {param: none, next: i}; }
let num = peek_num(s, i, lim);
ret alt num {
return alt num {
none { {param: none, next: i} }
some(t) {
let n = t.num;
@ -164,7 +164,7 @@ mod ct {
fn parse_flags(s: ~str, i: uint, lim: uint) ->
{flags: ~[flag], next: uint} {
let noflags: ~[flag] = ~[];
if i >= lim { ret {flags: noflags, next: i}; }
if i >= lim { return {flags: noflags, next: i}; }
fn more_(f: flag, s: ~str, i: uint, lim: uint) ->
{flags: ~[flag], next: uint} {
@ -172,11 +172,11 @@ mod ct {
let rest = next.flags;
let j = next.next;
let curr: ~[flag] = ~[f];
ret {flags: vec::append(curr, rest), next: j};
return {flags: vec::append(curr, rest), next: j};
}
let more = |x| more_(x, s, i, lim);
let f = s[i];
ret if f == '-' as u8 {
return if f == '-' as u8 {
more(flag_left_justify)
} else if f == '0' as u8 {
more(flag_left_zero_pad)
@ -190,7 +190,7 @@ mod ct {
}
fn parse_count(s: ~str, i: uint, lim: uint)
-> {count: count, next: uint} {
ret if i >= lim {
return if i >= lim {
{count: count_implied, next: i}
} else if s[i] == '*' as u8 {
let param = parse_parameter(s, i + 1u, lim);
@ -211,7 +211,7 @@ mod ct {
}
fn parse_precision(s: ~str, i: uint, lim: uint) ->
{count: count, next: uint} {
ret if i >= lim {
return if i >= lim {
{count: count_implied, next: i}
} else if s[i] == '.' as u8 {
let count = parse_count(s, i + 1u, lim);
@ -255,7 +255,7 @@ mod ct {
} else if str::eq(tstr, ~"?") {
ty_poly
} else { error(~"unknown type in conversion: " + tstr) };
ret {ty: t, next: i + 1u};
return {ty: t, next: i + 1u};
}
}
@ -288,7 +288,7 @@ mod rt {
unchecked { str::unshift_char(s, ' ') };
}
}
ret unchecked { pad(cv, s, pad_signed) };
return unchecked { pad(cv, s, pad_signed) };
}
pure fn conv_uint(cv: conv, u: uint) -> ~str {
let prec = get_int_precision(cv);
@ -300,17 +300,17 @@ mod rt {
ty_bits { uint_to_str_prec(u, 2u, prec) }
ty_octal { uint_to_str_prec(u, 8u, prec) }
};
ret unchecked { pad(cv, rs, pad_unsigned) };
return unchecked { pad(cv, rs, pad_unsigned) };
}
pure fn conv_bool(cv: conv, b: bool) -> ~str {
let s = if b { ~"true" } else { ~"false" };
// run the boolean conversion through the string conversion logic,
// giving it the same rules for precision, etc.
ret conv_str(cv, s);
return conv_str(cv, s);
}
pure fn conv_char(cv: conv, c: char) -> ~str {
let mut s = str::from_char(c);
ret unchecked { pad(cv, s, pad_nozero) };
return unchecked { pad(cv, s, pad_nozero) };
}
pure fn conv_str(cv: conv, s: &str) -> ~str {
// For strings, precision is the maximum characters
@ -323,7 +323,7 @@ mod rt {
} else { s.to_unique() }
}
};
ret unchecked { pad(cv, unpadded, pad_nozero) };
return unchecked { pad(cv, unpadded, pad_nozero) };
}
pure fn conv_float(cv: conv, f: float) -> ~str {
let (to_str, digits) = alt cv.precision {
@ -338,17 +338,17 @@ mod rt {
s = ~" " + s;
}
}
ret unchecked { pad(cv, s, pad_float) };
return unchecked { pad(cv, s, pad_float) };
}
pure fn conv_poly<T>(cv: conv, v: T) -> ~str {
let s = sys::log_str(v);
ret conv_str(cv, s);
return conv_str(cv, s);
}
// Convert an int to string with minimum number of digits. If precision is
// 0 and num is 0 then the result is the empty string.
pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
ret if num < 0 {
return if num < 0 {
~"-" + uint_to_str_prec(-num as uint, radix, prec)
} else { uint_to_str_prec(num as uint, radix, prec) };
}
@ -357,7 +357,7 @@ mod rt {
// is 0 and num is 0 then the result is the empty string. Could move this
// to uint: but it doesn't seem all that useful.
pure fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> ~str {
ret if prec == 0u && num == 0u {
return if prec == 0u && num == 0u {
~""
} else {
let s = uint::to_str(num, radix);
@ -370,7 +370,7 @@ mod rt {
};
}
pure fn get_int_precision(cv: conv) -> uint {
ret alt cv.precision {
return alt cv.precision {
count_is(c) { c as uint }
count_implied { 1u }
};
@ -378,19 +378,19 @@ mod rt {
enum pad_mode { pad_signed, pad_unsigned, pad_nozero, pad_float }
fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str {
let uwidth : uint = alt cv.width {
count_implied { ret s; }
count_implied { return s; }
count_is(width) {
// FIXME: width should probably be uint (see Issue #1996)
width as uint
}
};
let strlen = str::char_len(s);
if uwidth <= strlen { ret s; }
if uwidth <= strlen { return s; }
let mut padchar = ' ';
let diff = uwidth - strlen;
if have_flag(cv.flags, flag_left_justify) {
let padstr = str::from_chars(vec::from_elem(diff, padchar));
ret s + padstr;
return s + padstr;
}
let {might_zero_pad, signed} = alt mode {
pad_nozero { {might_zero_pad:false, signed:false} }
@ -399,7 +399,7 @@ mod rt {
pad_unsigned { {might_zero_pad:true, signed:false} }
};
pure fn have_precision(cv: conv) -> bool {
ret alt cv.precision { count_implied { false } _ { true } };
return alt cv.precision { count_implied { false } _ { true } };
}
let zero_padding = {
if might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) &&
@ -420,13 +420,13 @@ mod rt {
let head = str::shift_char(s);
if head == '+' || head == '-' || head == ' ' {
let headstr = str::from_chars(vec::from_elem(1u, head));
ret headstr + padstr + s;
return headstr + padstr + s;
}
else {
str::unshift_char(s, head);
}
}
ret padstr + s;
return padstr + s;
}
pure fn have_flag(flags: u32, f: u32) -> bool {
flags & f != 0

View File

@ -31,38 +31,38 @@ const neg_infinity: f32 = -1.0_f32/0.0_f32;
pure fn is_NaN(f: f32) -> bool { f != f }
pure fn add(x: f32, y: f32) -> f32 { ret x + y; }
pure fn add(x: f32, y: f32) -> f32 { return x + y; }
pure fn sub(x: f32, y: f32) -> f32 { ret x - y; }
pure fn sub(x: f32, y: f32) -> f32 { return x - y; }
pure fn mul(x: f32, y: f32) -> f32 { ret x * y; }
pure fn mul(x: f32, y: f32) -> f32 { return x * y; }
pure fn div(x: f32, y: f32) -> f32 { ret x / y; }
pure fn div(x: f32, y: f32) -> f32 { return x / y; }
pure fn rem(x: f32, y: f32) -> f32 { ret x % y; }
pure fn rem(x: f32, y: f32) -> f32 { return x % y; }
pure fn lt(x: f32, y: f32) -> bool { ret x < y; }
pure fn lt(x: f32, y: f32) -> bool { return x < y; }
pure fn le(x: f32, y: f32) -> bool { ret x <= y; }
pure fn le(x: f32, y: f32) -> bool { return x <= y; }
pure fn eq(x: f32, y: f32) -> bool { ret x == y; }
pure fn eq(x: f32, y: f32) -> bool { return x == y; }
pure fn ne(x: f32, y: f32) -> bool { ret x != y; }
pure fn ne(x: f32, y: f32) -> bool { return x != y; }
pure fn ge(x: f32, y: f32) -> bool { ret x >= y; }
pure fn ge(x: f32, y: f32) -> bool { return x >= y; }
pure fn gt(x: f32, y: f32) -> bool { ret x > y; }
pure fn gt(x: f32, y: f32) -> bool { return x > y; }
// FIXME (#1999): replace the predicates below with llvm intrinsics or
// calls to the libmath macros in the rust runtime for performance.
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
pure fn is_positive(x: f32) -> bool
{ ret x > 0.0f32 || (1.0f32/x) == infinity; }
{ return x > 0.0f32 || (1.0f32/x) == infinity; }
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
pure fn is_negative(x: f32) -> bool
{ ret x < 0.0f32 || (1.0f32/x) == neg_infinity; }
{ return x < 0.0f32 || (1.0f32/x) == neg_infinity; }
/**
* Returns true if `x` is a negative number, including -0.0f320 and -Infinity
@ -70,7 +70,7 @@ pure fn is_negative(x: f32) -> bool
* This is the same as `f32::is_negative`.
*/
pure fn is_nonpositive(x: f32) -> bool {
ret x < 0.0f32 || (1.0f32/x) == neg_infinity;
return x < 0.0f32 || (1.0f32/x) == neg_infinity;
}
/**
@ -79,22 +79,22 @@ pure fn is_nonpositive(x: f32) -> bool {
* This is the same as `f32::is_positive`.)
*/
pure fn is_nonnegative(x: f32) -> bool {
ret x > 0.0f32 || (1.0f32/x) == infinity;
return x > 0.0f32 || (1.0f32/x) == infinity;
}
/// Returns true if `x` is a zero number (positive or negative zero)
pure fn is_zero(x: f32) -> bool {
ret x == 0.0f32 || x == -0.0f32;
return x == 0.0f32 || x == -0.0f32;
}
/// Returns true if `x`is an infinite number
pure fn is_infinite(x: f32) -> bool {
ret x == infinity || x == neg_infinity;
return x == infinity || x == neg_infinity;
}
/// Returns true if `x`is a finite number
pure fn is_finite(x: f32) -> bool {
ret !(is_NaN(x) || is_infinite(x));
return !(is_NaN(x) || is_infinite(x));
}
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify.
@ -145,38 +145,38 @@ mod consts {
}
pure fn signbit(x: f32) -> int {
if is_negative(x) { ret 1; } else { ret 0; }
if is_negative(x) { return 1; } else { return 0; }
}
#[cfg(target_os="linux")]
#[cfg(target_os="macos")]
#[cfg(target_os="win32")]
pure fn logarithm(n: f32, b: f32) -> f32 {
ret log2(n) / log2(b);
return log2(n) / log2(b);
}
#[cfg(target_os="freebsd")]
pure fn logarithm(n: f32, b: f32) -> f32 {
// FIXME (#2000): check if it is good to use log2 instead of ln here;
// in theory should be faster since the radix is 2
ret ln(n) / ln(b);
return ln(n) / ln(b);
}
#[cfg(target_os="freebsd")]
pure fn log2(n: f32) -> f32 {
ret ln(n) / consts::ln_2;
return ln(n) / consts::ln_2;
}
impl num of num::num for f32 {
pure fn add(&&other: f32) -> f32 { ret self + other; }
pure fn sub(&&other: f32) -> f32 { ret self - other; }
pure fn mul(&&other: f32) -> f32 { ret self * other; }
pure fn div(&&other: f32) -> f32 { ret self / other; }
pure fn modulo(&&other: f32) -> f32 { ret self % other; }
pure fn neg() -> f32 { ret -self; }
pure fn add(&&other: f32) -> f32 { return self + other; }
pure fn sub(&&other: f32) -> f32 { return self - other; }
pure fn mul(&&other: f32) -> f32 { return self * other; }
pure fn div(&&other: f32) -> f32 { return self / other; }
pure fn modulo(&&other: f32) -> f32 { return self % other; }
pure fn neg() -> f32 { return -self; }
pure fn to_int() -> int { ret self as int; }
pure fn from_int(n: int) -> f32 { ret n as f32; }
pure fn to_int() -> int { return self as int; }
pure fn from_int(n: int) -> f32 { return n as f32; }
}
//

View File

@ -57,27 +57,27 @@ const neg_infinity: f64 = -1.0_f64/0.0_f64;
pure fn is_NaN(f: f64) -> bool { f != f }
pure fn add(x: f64, y: f64) -> f64 { ret x + y; }
pure fn add(x: f64, y: f64) -> f64 { return x + y; }
pure fn sub(x: f64, y: f64) -> f64 { ret x - y; }
pure fn sub(x: f64, y: f64) -> f64 { return x - y; }
pure fn mul(x: f64, y: f64) -> f64 { ret x * y; }
pure fn mul(x: f64, y: f64) -> f64 { return x * y; }
pure fn div(x: f64, y: f64) -> f64 { ret x / y; }
pure fn div(x: f64, y: f64) -> f64 { return x / y; }
pure fn rem(x: f64, y: f64) -> f64 { ret x % y; }
pure fn rem(x: f64, y: f64) -> f64 { return x % y; }
pure fn lt(x: f64, y: f64) -> bool { ret x < y; }
pure fn lt(x: f64, y: f64) -> bool { return x < y; }
pure fn le(x: f64, y: f64) -> bool { ret x <= y; }
pure fn le(x: f64, y: f64) -> bool { return x <= y; }
pure fn eq(x: f64, y: f64) -> bool { ret x == y; }
pure fn eq(x: f64, y: f64) -> bool { return x == y; }
pure fn ne(x: f64, y: f64) -> bool { ret x != y; }
pure fn ne(x: f64, y: f64) -> bool { return x != y; }
pure fn ge(x: f64, y: f64) -> bool { ret x >= y; }
pure fn ge(x: f64, y: f64) -> bool { return x >= y; }
pure fn gt(x: f64, y: f64) -> bool { ret x > y; }
pure fn gt(x: f64, y: f64) -> bool { return x > y; }
pure fn sqrt(x: f64) -> f64 {
cmath::c_double::sqrt(x as libc::c_double) as f64
@ -85,11 +85,11 @@ pure fn sqrt(x: f64) -> f64 {
/// Returns true if `x` is a positive number, including +0.0f640 and +Infinity
pure fn is_positive(x: f64) -> bool
{ ret x > 0.0f64 || (1.0f64/x) == infinity; }
{ return x > 0.0f64 || (1.0f64/x) == infinity; }
/// Returns true if `x` is a negative number, including -0.0f640 and -Infinity
pure fn is_negative(x: f64) -> bool
{ ret x < 0.0f64 || (1.0f64/x) == neg_infinity; }
{ return x < 0.0f64 || (1.0f64/x) == neg_infinity; }
/**
* Returns true if `x` is a negative number, including -0.0f640 and -Infinity
@ -97,7 +97,7 @@ pure fn is_negative(x: f64) -> bool
* This is the same as `f64::is_negative`.
*/
pure fn is_nonpositive(x: f64) -> bool {
ret x < 0.0f64 || (1.0f64/x) == neg_infinity;
return x < 0.0f64 || (1.0f64/x) == neg_infinity;
}
/**
@ -106,22 +106,22 @@ pure fn is_nonpositive(x: f64) -> bool {
* This is the same as `f64::positive`.
*/
pure fn is_nonnegative(x: f64) -> bool {
ret x > 0.0f64 || (1.0f64/x) == infinity;
return x > 0.0f64 || (1.0f64/x) == infinity;
}
/// Returns true if `x` is a zero number (positive or negative zero)
pure fn is_zero(x: f64) -> bool {
ret x == 0.0f64 || x == -0.0f64;
return x == 0.0f64 || x == -0.0f64;
}
/// Returns true if `x`is an infinite number
pure fn is_infinite(x: f64) -> bool {
ret x == infinity || x == neg_infinity;
return x == infinity || x == neg_infinity;
}
/// Returns true if `x`is a finite number
pure fn is_finite(x: f64) -> bool {
ret !(is_NaN(x) || is_infinite(x));
return !(is_NaN(x) || is_infinite(x));
}
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify
@ -172,38 +172,38 @@ mod consts {
}
pure fn signbit(x: f64) -> int {
if is_negative(x) { ret 1; } else { ret 0; }
if is_negative(x) { return 1; } else { return 0; }
}
#[cfg(target_os="linux")]
#[cfg(target_os="macos")]
#[cfg(target_os="win32")]
pure fn logarithm(n: f64, b: f64) -> f64 {
ret log2(n) / log2(b);
return log2(n) / log2(b);
}
#[cfg(target_os="freebsd")]
pure fn logarithm(n: f64, b: f64) -> f64 {
// FIXME (#2000): check if it is good to use log2 instead of ln here; in
// theory should be faster since the radix is 2
ret ln(n) / ln(b);
return ln(n) / ln(b);
}
#[cfg(target_os="freebsd")]
pure fn log2(n: f64) -> f64 {
ret ln(n) / consts::ln_2;
return ln(n) / consts::ln_2;
}
impl num of num::num for f64 {
pure fn add(&&other: f64) -> f64 { ret self + other; }
pure fn sub(&&other: f64) -> f64 { ret self - other; }
pure fn mul(&&other: f64) -> f64 { ret self * other; }
pure fn div(&&other: f64) -> f64 { ret self / other; }
pure fn modulo(&&other: f64) -> f64 { ret self % other; }
pure fn neg() -> f64 { ret -self; }
pure fn add(&&other: f64) -> f64 { return self + other; }
pure fn sub(&&other: f64) -> f64 { return self - other; }
pure fn mul(&&other: f64) -> f64 { return self * other; }
pure fn div(&&other: f64) -> f64 { return self / other; }
pure fn modulo(&&other: f64) -> f64 { return self % other; }
pure fn neg() -> f64 { return -self; }
pure fn to_int() -> int { ret self as int; }
pure fn from_int(n: int) -> f64 { ret n as f64; }
pure fn to_int() -> int { return self as int; }
pure fn from_int(n: int) -> f64 { return n as f64; }
}
//

View File

@ -103,9 +103,9 @@ mod consts {
* * exact - Whether to enforce the exact number of significant digits
*/
fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
if is_NaN(num) { ret ~"NaN"; }
if num == infinity { ret ~"inf"; }
if num == neg_infinity { ret ~"-inf"; }
if is_NaN(num) { return ~"NaN"; }
if num == infinity { return ~"inf"; }
if num == neg_infinity { return ~"-inf"; }
let mut (num, sign) = if num < 0.0 { (-num, ~"-") } else { (num, ~"") };
@ -122,7 +122,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
// This used to return right away without rounding, as "~[-]num",
// but given epsilon like in f64.rs, I don't see how the comparison
// to epsilon did much when only used there.
// if (frac < epsilon && !exact) || digits == 0u { ret accum; }
// if (frac < epsilon && !exact) || digits == 0u { return accum; }
//
// With something better, possibly weird results like this can be avoided:
// assert "3.14158999999999988262" == my_to_str_exact(3.14159, 20u);
@ -176,7 +176,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
acc = sign + ones + ~"." + racc;
}
ret acc;
return acc;
}
/**
@ -240,25 +240,25 @@ fn to_str(num: float, digits: uint) -> ~str {
*/
fn from_str(num: ~str) -> option<float> {
if num == ~"inf" {
ret some(infinity as float);
return some(infinity as float);
} else if num == ~"-inf" {
ret some(neg_infinity as float);
return some(neg_infinity as float);
} else if num == ~"NaN" {
ret some(NaN as float);
return some(NaN as float);
}
let mut pos = 0u; //Current byte position in the string.
//Used to walk the string in O(n).
let len = str::len(num); //Length of the string, in bytes.
if len == 0u { ret none; }
if len == 0u { return none; }
let mut total = 0f; //Accumulated result
let mut c = 'z'; //Latest char.
//The string must start with one of the following characters.
alt str::char_at(num, 0u) {
'-' | '+' | '0' to '9' | '.' {}
_ { ret none; }
_ { return none; }
}
//Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly.
@ -288,7 +288,7 @@ fn from_str(num: ~str) -> option<float> {
break;
}
_ {
ret none;
return none;
}
}
}
@ -308,7 +308,7 @@ fn from_str(num: ~str) -> option<float> {
break;
}
_ {
ret none;
return none;
}
}
}
@ -353,17 +353,17 @@ fn from_str(num: ~str) -> option<float> {
total = total * multiplier;
}
} else {
ret none;
return none;
}
}
if(pos < len) {
ret none;
return none;
} else {
if(neg) {
total *= -1f;
}
ret some(total);
return some(total);
}
}
@ -386,9 +386,9 @@ fn from_str(num: ~str) -> option<float> {
fn pow_with_uint(base: uint, pow: uint) -> float {
if base == 0u {
if pow == 0u {
ret NaN as float;
return NaN as float;
}
ret 0.;
return 0.;
}
let mut my_pow = pow;
let mut total = 1f;
@ -400,7 +400,7 @@ fn pow_with_uint(base: uint, pow: uint) -> float {
my_pow /= 2u;
multiplier *= multiplier;
}
ret total;
return total;
}
pure fn is_positive(x: float) -> bool { f64::is_positive(x as f64) }
@ -420,15 +420,15 @@ pure fn cos(x: float) -> float { f64::cos(x as f64) as float }
pure fn tan(x: float) -> float { f64::tan(x as f64) as float }
impl num of num::num for float {
pure fn add(&&other: float) -> float { ret self + other; }
pure fn sub(&&other: float) -> float { ret self - other; }
pure fn mul(&&other: float) -> float { ret self * other; }
pure fn div(&&other: float) -> float { ret self / other; }
pure fn modulo(&&other: float) -> float { ret self % other; }
pure fn neg() -> float { ret -self; }
pure fn add(&&other: float) -> float { return self + other; }
pure fn sub(&&other: float) -> float { return self - other; }
pure fn mul(&&other: float) -> float { return self * other; }
pure fn div(&&other: float) -> float { return self / other; }
pure fn modulo(&&other: float) -> float { return self % other; }
pure fn neg() -> float { return -self; }
pure fn to_int() -> int { ret self as int; }
pure fn from_int(n: int) -> float { ret n as float; }
pure fn to_int() -> int { return self as int; }
pure fn from_int(n: int) -> float { return n as float; }
}
#[test]

View File

@ -10,7 +10,7 @@
*/
pure fn hash_bytes(buf: &[const u8]) -> u64 {
ret hash_bytes_keyed(buf, 0u64, 0u64);
return hash_bytes_keyed(buf, 0u64, 0u64);
}
pure fn hash_u64(val: u64) -> u64 {
@ -113,7 +113,7 @@ pure fn hash_bytes_keyed(buf: &[const u8], k0: u64, k1: u64) -> u64 {
compress!{v0,v1,v2,v3};
compress!{v0,v1,v2,v3};
ret v0 ^ v1 ^ v2 ^ v3;
return v0 ^ v1 ^ v2 ^ v3;
}
@ -156,7 +156,7 @@ fn siphash(key0 : u64, key1 : u64) -> streaming {
}
st.ntail += length;
ret;
return;
}
let mut t = 0;
@ -229,7 +229,7 @@ fn siphash(key0 : u64, key1 : u64) -> streaming {
let h = v0 ^ v1 ^ v2 ^ v3;
ret ~[
return ~[
(h >> 0) as u8,
(h >> 8) as u8,
(h >> 16) as u8,
@ -252,12 +252,12 @@ fn siphash(key0 : u64, key1 : u64) -> streaming {
}
fn input(msg: ~[u8]) { add_input(self, msg); }
fn input_str(msg: ~str) { add_input(self, str::bytes(msg)); }
fn result() -> ~[u8] { ret mk_result(self); }
fn result() -> ~[u8] { return mk_result(self); }
fn result_str() -> ~str {
let r = mk_result(self);
let mut s = ~"";
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
ret s;
return s;
}
}
@ -275,7 +275,7 @@ fn siphash(key0 : u64, key1 : u64) -> streaming {
let sh = st as streaming;
sh.reset();
ret sh;
return sh;
}
#[test]
@ -357,7 +357,7 @@ fn test_siphash() {
fn to_hex_str(r:[u8]/8) -> ~str {
let mut s = ~"";
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
ret s;
return s;
}
while t < 64 {

View File

@ -67,7 +67,7 @@ pure fn abs(i: T) -> T {
* * radix - The base of the number
*/
fn parse_buf(buf: ~[u8], radix: uint) -> option<T> {
if vec::len(buf) == 0u { ret none; }
if vec::len(buf) == 0u { return none; }
let mut i = vec::len(buf) - 1u;
let mut start = 0u;
let mut power = 1 as T;
@ -80,10 +80,10 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> {
loop {
alt char::to_digit(buf[i] as char, radix) {
some(d) { n += (d as T) * power; }
none { ret none; }
none { return none; }
}
power *= radix as T;
if i <= start { ret some(n); }
if i <= start { return some(n); }
i -= 1u;
};
}
@ -109,30 +109,30 @@ fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
}
/// Convert to a string
fn str(i: T) -> ~str { ret to_str(i, 10u); }
fn str(i: T) -> ~str { return to_str(i, 10u); }
impl ord of ord for T {
pure fn lt(&&other: T) -> bool {
ret self < other;
return self < other;
}
}
impl eq of eq for T {
pure fn eq(&&other: T) -> bool {
ret self == other;
return self == other;
}
}
impl num of num::num for T {
pure fn add(&&other: T) -> T { ret self + other; }
pure fn sub(&&other: T) -> T { ret self - other; }
pure fn mul(&&other: T) -> T { ret self * other; }
pure fn div(&&other: T) -> T { ret self / other; }
pure fn modulo(&&other: T) -> T { ret self % other; }
pure fn neg() -> T { ret -self; }
pure fn add(&&other: T) -> T { return self + other; }
pure fn sub(&&other: T) -> T { return self - other; }
pure fn mul(&&other: T) -> T { return self * other; }
pure fn div(&&other: T) -> T { return self / other; }
pure fn modulo(&&other: T) -> T { return self % other; }
pure fn neg() -> T { return -self; }
pure fn to_int() -> int { ret self as int; }
pure fn from_int(n: int) -> T { ret n as T; }
pure fn to_int() -> int { return self as int; }
pure fn from_int(n: int) -> T { return n as T; }
}
impl times of iter::times for T {

View File

@ -7,12 +7,12 @@ const bits: T = 32 as T;
const bits: T = 64 as T;
/// Produce a uint suitable for use in a hash table
pure fn hash(&&x: int) -> uint { ret x as uint; }
pure fn hash(&&x: int) -> uint { return x as uint; }
/// Returns `base` raised to the power of `exponent`
fn pow(base: int, exponent: uint) -> int {
if exponent == 0u { ret 1; } //Not mathemtically true if ~[base == 0]
if base == 0 { ret 0; }
if exponent == 0u { return 1; } //Not mathemtically true if ~[base == 0]
if base == 0 { return 0; }
let mut my_pow = exponent;
let mut acc = 1;
let mut multiplier = base;
@ -23,7 +23,7 @@ fn pow(base: int, exponent: uint) -> int {
my_pow /= 2u;
multiplier *= multiplier;
}
ret acc;
return acc;
}
#[test]

View File

@ -69,7 +69,7 @@ impl reader_util for reader {
}
// can't satisfy this char with the existing data
if end > vec::len(buf) {
ret (i - 1u, end - vec::len(buf));
return (i - 1u, end - vec::len(buf));
}
let mut val = 0u;
while i < end {
@ -85,7 +85,7 @@ impl reader_util for reader {
<< (w - 1u) * 6u - w - 1u;
vec::push(chars, val as char );
}
ret (i, 0u);
return (i, 0u);
}
let mut buf: ~[u8] = ~[];
let mut chars: ~[char] = ~[];
@ -115,10 +115,10 @@ impl reader_util for reader {
fn read_char() -> char {
let c = self.read_chars(1u);
if vec::len(c) == 0u {
ret -1 as char; // FIXME will this stay valid? // #2004
return -1 as char; // FIXME will this stay valid? // #2004
}
assert(vec::len(c) == 1u);
ret c[0];
return c[0];
}
fn read_line() -> ~str {
@ -196,7 +196,7 @@ impl reader_util for reader {
// Reader implementations
fn convert_whence(whence: seek_style) -> i32 {
ret alt whence {
return alt whence {
seek_set { 0i32 }
seek_cur { 1i32 }
seek_end { 2i32 }
@ -214,14 +214,14 @@ impl of reader for *libc::FILE {
count as uint
}
}
fn read_byte() -> int { ret libc::fgetc(self) as int; }
fn read_byte() -> int { return libc::fgetc(self) as int; }
fn unread_byte(byte: int) { libc::ungetc(byte as c_int, self); }
fn eof() -> bool { ret libc::feof(self) != 0 as c_int; }
fn eof() -> bool { return libc::feof(self) != 0 as c_int; }
fn seek(offset: int, whence: seek_style) {
assert libc::fseek(self, offset as c_long, convert_whence(whence))
== 0 as c_int;
}
fn tell() -> uint { ret libc::ftell(self) as uint; }
fn tell() -> uint { return libc::ftell(self) as uint; }
}
// A forwarding impl of reader that also holds on to a resource for the
@ -262,7 +262,7 @@ fn file_reader(path: ~str) -> result<reader, ~str> {
libc::fopen(pathbuf, modebuf)
)
});
ret if f as uint == 0u { result::err(~"error opening " + path) }
return if f as uint == 0u { result::err(~"error opening " + path) }
else {
result::ok(FILE_reader(f, true))
}
@ -285,10 +285,10 @@ impl of reader for byte_buf {
count
}
fn read_byte() -> int {
if self.pos == self.len { ret -1; }
if self.pos == self.len { return -1; }
let b = self.buf[self.pos];
self.pos += 1u;
ret b as int;
return b as int;
}
// FIXME (#2738): implement this
fn unread_byte(_byte: int) { error!{"Unimplemented: unread_byte"}; fail; }
@ -530,7 +530,7 @@ fn u64_from_be_bytes(data: ~[u8], start: uint, size: uint) -> u64 {
val += (data[pos] as u64) << ((sz * 8u) as u64);
pos += 1u;
}
ret val;
return val;
}
impl writer_util for writer {
@ -616,7 +616,7 @@ fn buffered_file_writer(path: ~str) -> result<writer, ~str> {
libc::fopen(pathbuf, modebuf)
}
};
ret if f as uint == 0u { result::err(~"error opening " + path) }
return if f as uint == 0u { result::err(~"error opening " + path) }
else { result::ok(FILE_writer(f, true)) }
}
@ -639,7 +639,7 @@ impl of writer for mem_buffer {
if self.pos == buf_len {
self.buf.push_all(v);
self.pos += vlen;
ret;
return;
}
// FIXME #2004--use memcpy here?
@ -696,7 +696,7 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) ->
seek_end { bpos = blen + offset; }
}
if bpos < 0 { bpos = 0; } else if bpos > blen { bpos = blen; }
ret bpos as uint;
return bpos as uint;
}
fn read_whole_file_str(file: ~str) -> result<~str, ~str> {
@ -764,7 +764,7 @@ mod fsync {
blk(res({
val: file.f, opt_level: opt_level,
fsync_fn: fn@(&&file: *libc::FILE, l: level) -> int {
ret os::fsync_fd(libc::fileno(file), l) as int;
return os::fsync_fd(libc::fileno(file), l) as int;
}
}));
}
@ -775,7 +775,7 @@ mod fsync {
blk(res({
val: fd.fd, opt_level: opt_level,
fsync_fn: fn@(&&fd: fd_t, l: level) -> int {
ret os::fsync_fd(fd, l) as int;
return os::fsync_fd(fd, l) as int;
}
}));
}
@ -787,7 +787,7 @@ mod fsync {
fn obj_sync(&&o: t, opt_level: option<level>, blk: fn(&&res<t>)) {
blk(res({
val: o, opt_level: opt_level,
fsync_fn: fn@(&&o: t, l: level) -> int { ret o.fsync(l); }
fsync_fn: fn@(&&o: t, l: level) -> int { return o.fsync(l); }
}));
}
}

View File

@ -41,8 +41,8 @@ impl extensions<A:copy> of iter::copyable_iter<A> for IMPL_T<A> {
fn find(p: fn(A) -> bool) -> option<A> {
for self.each |i| {
if p(i) { ret some(i) }
if p(i) { return some(i) }
}
ret none;
return none;
}
}

View File

@ -39,16 +39,16 @@ fn eachi<A,IA:base_iter<A>>(self: IA, blk: fn(uint, A) -> bool) {
fn all<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool {
for self.each |a| {
if !blk(a) { ret false; }
if !blk(a) { return false; }
}
ret true;
return true;
}
fn any<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool {
for self.each |a| {
if blk(a) { ret true; }
if blk(a) { return true; }
}
ret false;
return false;
}
fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA,
@ -58,7 +58,7 @@ fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA,
for self.each |a| {
if prd(a) { vec::push(result, a); }
}
ret result;
return result;
}
fn map_to_vec<A:copy,B,IA:base_iter<A>>(self: IA, op: fn(A) -> B) -> ~[B] {
@ -67,7 +67,7 @@ fn map_to_vec<A:copy,B,IA:base_iter<A>>(self: IA, op: fn(A) -> B) -> ~[B] {
for self.each |a| {
vec::push(result, op(a));
}
ret result;
return result;
}
fn flat_map_to_vec<A:copy,B:copy,IA:base_iter<A>,IB:base_iter<B>>(
@ -79,7 +79,7 @@ fn flat_map_to_vec<A:copy,B:copy,IA:base_iter<A>,IB:base_iter<B>>(
vec::push(result, b);
}
}
ret result;
return result;
}
fn foldl<A,B,IA:base_iter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
@ -87,7 +87,7 @@ fn foldl<A,B,IA:base_iter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
for self.each |a| {
b = blk(b, a);
}
ret b;
return b;
}
fn to_vec<A:copy,IA:base_iter<A>>(self: IA) -> ~[A] {
@ -96,9 +96,9 @@ fn to_vec<A:copy,IA:base_iter<A>>(self: IA) -> ~[A] {
fn contains<A,IA:base_iter<A>>(self: IA, x: A) -> bool {
for self.each |a| {
if a == x { ret true; }
if a == x { return true; }
}
ret false;
return false;
}
fn count<A,IA:base_iter<A>>(self: IA, x: A) -> uint {
@ -115,10 +115,10 @@ fn position<A,IA:base_iter<A>>(self: IA, f: fn(A) -> bool)
-> option<uint> {
let mut i = 0;
for self.each |a| {
if f(a) { ret some(i); }
if f(a) { return some(i); }
i += 1;
}
ret none;
return none;
}
// note: 'rposition' would only make sense to provide with a bidirectional
@ -191,7 +191,7 @@ fn test_map_directly_on_vec() {
#[test]
fn test_filter_on_int_range() {
fn is_even(&&i: int) -> bool {
ret (i % 2) == 0;
return (i % 2) == 0;
}
let l = to_vec(bind filter(bind int::range(0, 10, _), is_even, _));
@ -201,7 +201,7 @@ fn test_filter_on_int_range() {
#[test]
fn test_filter_on_uint_range() {
fn is_even(&&i: uint) -> bool {
ret (i % 2u) == 0u;
return (i % 2u) == 0u;
}
let l = to_vec(bind filter(bind uint::range(0u, 10u, _), is_even, _));

View File

@ -23,7 +23,7 @@ pure fn get<T: copy>(opt: option<T>) -> T {
* Fails if the value equals `none`
*/
alt opt { some(x) { ret x; } none { fail ~"option none"; } }
alt opt { some(x) { return x; } none { fail ~"option none"; } }
}
pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T {
@ -116,7 +116,7 @@ pure fn unwrap<T>(-opt: option<T>) -> T {
};
let liberated_value = unsafe::reinterpret_cast(*addr);
unsafe::forget(opt);
ret liberated_value;
return liberated_value;
}
}

View File

@ -100,7 +100,7 @@ mod win32 {
}
}
}
ret res;
return res;
}
fn as_utf16_p<T>(s: ~str, f: fn(*u16) -> T) -> T {
@ -209,14 +209,14 @@ mod global_env {
assert vec::len(vs) == 2u;
vec::push(pairs, (vs[0], vs[1]));
}
ret pairs;
return pairs;
}
#[cfg(unix)]
fn getenv(n: ~str) -> option<~str> {
unsafe {
let s = str::as_c_str(n, libc::getenv);
ret if unsafe::reinterpret_cast(s) == 0 {
return if unsafe::reinterpret_cast(s) == 0 {
option::none::<~str>
} else {
let s = unsafe::reinterpret_cast(s);
@ -267,7 +267,7 @@ mod global_env {
}
fn fdopen(fd: c_int) -> *FILE {
ret do as_c_charp(~"r") |modebuf| {
return do as_c_charp(~"r") |modebuf| {
libc::fdopen(fd, modebuf)
};
}
@ -278,7 +278,7 @@ fn fdopen(fd: c_int) -> *FILE {
#[cfg(windows)]
fn fsync_fd(fd: c_int, _level: io::fsync::level) -> c_int {
import libc::funcs::extra::msvcrt::*;
ret commit(fd);
return commit(fd);
}
#[cfg(target_os = "linux")]
@ -286,8 +286,8 @@ fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int {
import libc::funcs::posix01::unistd::*;
alt level {
io::fsync::fsync
| io::fsync::fullfsync { ret fsync(fd); }
io::fsync::fdatasync { ret fdatasync(fd); }
| io::fsync::fullfsync { return fsync(fd); }
io::fsync::fdatasync { return fdatasync(fd); }
}
}
@ -297,13 +297,13 @@ fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int {
import libc::funcs::posix88::fcntl::*;
import libc::funcs::posix01::unistd::*;
alt level {
io::fsync::fsync { ret fsync(fd); }
io::fsync::fsync { return fsync(fd); }
_ {
// According to man fnctl, the ok retval is only specified to be !=-1
if (fcntl(F_FULLFSYNC as c_int, fd) == -1 as c_int)
{ ret -1 as c_int; }
{ return -1 as c_int; }
else
{ ret 0 as c_int; }
{ return 0 as c_int; }
}
}
}
@ -311,13 +311,13 @@ fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int {
#[cfg(target_os = "freebsd")]
fn fsync_fd(fd: c_int, _l: io::fsync::level) -> c_int {
import libc::funcs::posix01::unistd::*;
ret fsync(fd);
return fsync(fd);
}
#[cfg(windows)]
fn waitpid(pid: pid_t) -> c_int {
ret rustrt::rust_process_wait(pid);
return rustrt::rust_process_wait(pid);
}
#[cfg(unix)]
@ -327,7 +327,7 @@ fn waitpid(pid: pid_t) -> c_int {
assert (waitpid(pid, ptr::mut_addr_of(status),
0 as c_int) != (-1 as c_int));
ret status;
return status;
}
@ -336,7 +336,7 @@ fn pipe() -> {in: c_int, out: c_int} {
let fds = {mut in: 0 as c_int,
mut out: 0 as c_int };
assert (libc::pipe(ptr::mut_addr_of(fds.in)) == (0 as c_int));
ret {in: fds.in, out: fds.out};
return {in: fds.in, out: fds.out};
}
@ -358,12 +358,12 @@ fn pipe() -> {in: c_int, out: c_int} {
assert (res == 0 as c_int);
assert (fds.in != -1 as c_int && fds.in != 0 as c_int);
assert (fds.out != -1 as c_int && fds.in != 0 as c_int);
ret {in: fds.in, out: fds.out};
return {in: fds.in, out: fds.out};
}
fn dll_filename(base: ~str) -> ~str {
ret pre() + base + dll_suffix();
return pre() + base + dll_suffix();
#[cfg(unix)]
fn pre() -> ~str { ~"lib" }
@ -442,7 +442,7 @@ fn self_exe_path() -> option<path> {
* Otherwise, homedir returns option::none.
*/
fn homedir() -> option<path> {
ret alt getenv(~"HOME") {
return alt getenv(~"HOME") {
some(p) {
if !str::is_empty(p) {
some(p)
@ -497,7 +497,7 @@ fn walk_dir(p: path, f: fn(path) -> bool) {
}
}
}
ret keepgoing;
return keepgoing;
}
}
@ -538,7 +538,7 @@ fn make_absolute(p: path) -> path {
/// Creates a directory at the specified path
fn make_dir(p: path, mode: c_int) -> bool {
ret mkdir(p, mode);
return mkdir(p, mode);
#[cfg(windows)]
fn mkdir(p: path, _mode: c_int) -> bool {
@ -600,7 +600,7 @@ fn list_dir_path(p: path) -> ~[~str] {
/// Removes a directory at the specified path
fn remove_dir(p: path) -> bool {
ret rmdir(p);
return rmdir(p);
#[cfg(windows)]
fn rmdir(p: path) -> bool {
@ -608,21 +608,21 @@ fn remove_dir(p: path) -> bool {
import libc::funcs::extra::kernel32::*;
import libc::types::os::arch::extra::*;
import win32::*;
ret do as_utf16_p(p) |buf| {
return do as_utf16_p(p) |buf| {
RemoveDirectoryW(buf) != (0 as BOOL)
};
}
#[cfg(unix)]
fn rmdir(p: path) -> bool {
ret do as_c_charp(p) |buf| {
return do as_c_charp(p) |buf| {
libc::rmdir(buf) == (0 as c_int)
};
}
}
fn change_dir(p: path) -> bool {
ret chdir(p);
return chdir(p);
#[cfg(windows)]
fn chdir(p: path) -> bool {
@ -630,14 +630,14 @@ fn change_dir(p: path) -> bool {
import libc::funcs::extra::kernel32::*;
import libc::types::os::arch::extra::*;
import win32::*;
ret do as_utf16_p(p) |buf| {
return do as_utf16_p(p) |buf| {
SetCurrentDirectoryW(buf) != (0 as BOOL)
};
}
#[cfg(unix)]
fn chdir(p: path) -> bool {
ret do as_c_charp(p) |buf| {
return do as_c_charp(p) |buf| {
libc::chdir(buf) == (0 as c_int)
};
}
@ -645,7 +645,7 @@ fn change_dir(p: path) -> bool {
/// Copies a file from one location to another
fn copy_file(from: path, to: path) -> bool {
ret do_copy_file(from, to);
return do_copy_file(from, to);
#[cfg(windows)]
fn do_copy_file(from: path, to: path) -> bool {
@ -653,7 +653,7 @@ fn copy_file(from: path, to: path) -> bool {
import libc::funcs::extra::kernel32::*;
import libc::types::os::arch::extra::*;
import win32::*;
ret do as_utf16_p(from) |fromp| {
return do as_utf16_p(from) |fromp| {
do as_utf16_p(to) |top| {
CopyFileW(fromp, top, (0 as BOOL)) != (0 as BOOL)
}
@ -668,7 +668,7 @@ fn copy_file(from: path, to: path) -> bool {
}
};
if istream as uint == 0u {
ret false;
return false;
}
let ostream = do as_c_charp(to) |top| {
do as_c_charp(~"w+b") |modebuf| {
@ -677,7 +677,7 @@ fn copy_file(from: path, to: path) -> bool {
};
if ostream as uint == 0u {
fclose(istream);
ret false;
return false;
}
let mut buf : ~[mut u8] = ~[mut];
let bufsize = 8192u;
@ -702,13 +702,13 @@ fn copy_file(from: path, to: path) -> bool {
}
fclose(istream);
fclose(ostream);
ret ok;
return ok;
}
}
/// Deletes an existing file
fn remove_file(p: path) -> bool {
ret unlink(p);
return unlink(p);
#[cfg(windows)]
fn unlink(p: path) -> bool {
@ -717,14 +717,14 @@ fn remove_file(p: path) -> bool {
import libc::funcs::extra::kernel32::*;
import libc::types::os::arch::extra::*;
import win32::*;
ret do as_utf16_p(p) |buf| {
return do as_utf16_p(p) |buf| {
DeleteFileW(buf) != (0 as BOOL)
};
}
#[cfg(unix)]
fn unlink(p: path) -> bool {
ret do as_c_charp(p) |buf| {
return do as_c_charp(p) |buf| {
libc::unlink(buf) == (0 as c_int)
};
}

View File

@ -51,14 +51,14 @@ fn path_is_absolute(p: path) -> bool {
#[cfg(windows)]
fn path_is_absolute(p: ~str) -> bool {
ret str::char_at(p, 0u) == '/' ||
return str::char_at(p, 0u) == '/' ||
str::char_at(p, 1u) == ':'
&& (str::char_at(p, 2u) == consts::path_sep
|| str::char_at(p, 2u) == consts::alt_path_sep);
}
/// Get the default path separator for the host platform
fn path_sep() -> ~str { ret str::from_char(consts::path_sep); }
fn path_sep() -> ~str { return str::from_char(consts::path_sep); }
fn split_dirname_basename (pp: path) -> {dirname: ~str, basename: ~str} {
alt str::rfind(pp, |ch|
@ -82,7 +82,7 @@ fn split_dirname_basename (pp: path) -> {dirname: ~str, basename: ~str} {
* If the path is not prefixed with a directory, then "." is returned.
*/
fn dirname(pp: path) -> path {
ret split_dirname_basename(pp).dirname;
return split_dirname_basename(pp).dirname;
}
/**
@ -95,7 +95,7 @@ fn dirname(pp: path) -> path {
* with a path separator then an empty path is returned.
*/
fn basename(pp: path) -> path {
ret split_dirname_basename(pp).basename;
return split_dirname_basename(pp).basename;
}
/**
@ -119,7 +119,7 @@ fn connect(pre: path, post: path) -> path {
str::unsafe::shift_byte(post_);
}
}
ret pre_ + path_sep() + post_;
return pre_ + path_sep() + post_;
}
/**
@ -128,7 +128,7 @@ fn connect(pre: path, post: path) -> path {
* Inserts path separators as needed.
*/
fn connect_many(paths: ~[path]) -> path {
ret if vec::len(paths) == 1u {
return if vec::len(paths) == 1u {
paths[0]
} else {
let rest = vec::slice(paths, 1u, vec::len(paths));
@ -231,7 +231,7 @@ fn normalize(p: path) -> path {
s
};
ret s;
return s;
fn strip_dots(s: ~[path]) -> ~[path] {
vec::filter_map(s, |elem|
@ -244,7 +244,7 @@ fn normalize(p: path) -> path {
fn rollup_doubledots(s: ~[path]) -> ~[path] {
if vec::is_empty(s) {
ret ~[];
return ~[];
}
let mut t = ~[];
@ -267,7 +267,7 @@ fn normalize(p: path) -> path {
vec::push(t, ~"..");
skip -= 1;
}
ret t;
return t;
}
#[cfg(unix)]
@ -292,9 +292,9 @@ fn normalize(p: path) -> path {
let last = orig[str::len(orig) - 1u];
if last == consts::path_sep as u8
|| last == consts::path_sep as u8 {
ret newp + path_sep();
return newp + path_sep();
} else {
ret newp;
return newp;
}
}
}

View File

@ -390,11 +390,11 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>)
let mut payload = none;
payload <-> p.payload;
p.header.state = empty;
ret some(option::unwrap(payload))
return some(option::unwrap(payload))
}
terminated {
assert old_state == terminated;
ret none;
return none;
}
}
first = false;
@ -906,7 +906,7 @@ struct port_set<T: send> : recv<T> {
// It'd be nice to use self.port.each, but that version isn't
// pure.
for vec::each(self.ports) |p| {
if p.peek() { ret true }
if p.peek() { return true }
}
false
}

View File

@ -79,7 +79,7 @@ unsafe fn buf_len<T>(buf: **T) -> uint {
unsafe fn position<T>(buf: *T, f: fn(T) -> bool) -> uint {
let mut i = 0u;
loop {
if f(*offset(buf, i)) { ret i; }
if f(*offset(buf, i)) { return i; }
else { i += 1u; }
}
}

View File

@ -110,7 +110,7 @@ impl extensions for rng {
let u2 = self.next() as f64;
let u3 = self.next() as f64;
const scale : f64 = (u32::max_value as f64) + 1.0f64;
ret ((u1 / scale + u2) / scale + u3) / scale;
return ((u1 / scale + u2) / scale + u3) / scale;
}
/// Return a random char
@ -195,14 +195,14 @@ impl extensions for rng {
total += item.weight;
}
if total == 0u {
ret none;
return none;
}
let chosen = self.gen_uint_range(0u, total);
let mut so_far = 0u;
for v.each |item| {
so_far += item.weight;
if so_far > chosen {
ret some(item.item);
return some(item.item);
}
}
unreachable();
@ -226,7 +226,7 @@ impl extensions for rng {
fn shuffle<T:copy>(values: ~[T]) -> ~[T] {
let mut m = vec::to_mut(values);
self.shuffle_mut(m);
ret vec::from_mut(m);
return vec::from_mut(m);
}
/// Shuffle a mutable vec in place
@ -249,7 +249,7 @@ class rand_res {
}
impl of rng for @rand_res {
fn next() -> u32 { ret rustrt::rand_next((*self).c); }
fn next() -> u32 { return rustrt::rand_next((*self).c); }
}
/// Create a new random seed for seeded_rng

View File

@ -244,8 +244,8 @@ impl extensions<T:copy, E:copy> for result<T,E> {
* checking for overflow:
*
* fn inc_conditionally(x: uint) -> result<uint,str> {
* if x == uint::max_value { ret err("overflow"); }
* else { ret ok(x+1u); }
* if x == uint::max_value { return err("overflow"); }
* else { return ok(x+1u); }
* }
* map(~[1u, 2u, 3u], inc_conditionally).chain {|incd|
* assert incd == ~[2u, 3u, 4u];
@ -259,10 +259,10 @@ fn map_vec<T,U:copy,V:copy>(
for vec::each(ts) |t| {
alt op(t) {
ok(v) { vec::push(vs, v); }
err(u) { ret err(u); }
err(u) { return err(u); }
}
}
ret ok(vs);
return ok(vs);
}
fn map_opt<T,U:copy,V:copy>(
@ -299,11 +299,11 @@ fn map_vec2<S,T,U:copy,V:copy>(ss: ~[S], ts: ~[T],
while i < n {
alt op(ss[i],ts[i]) {
ok(v) { vec::push(vs, v); }
err(u) { ret err(u); }
err(u) { return err(u); }
}
i += 1u;
}
ret ok(vs);
return ok(vs);
}
/**
@ -320,11 +320,11 @@ fn iter_vec2<S,T,U:copy>(ss: ~[S], ts: ~[T],
while i < n {
alt op(ss[i],ts[i]) {
ok(()) { }
err(u) { ret err(u); }
err(u) { return err(u); }
}
i += 1u;
}
ret ok(());
return ok(());
}
/// Unwraps a result, assuming it is an `ok(T)`
@ -336,7 +336,7 @@ fn unwrap<T, U>(-res: result<T, U>) -> T {
};
let liberated_value = unsafe::reinterpret_cast(*addr);
unsafe::forget(res);
ret liberated_value;
return liberated_value;
}
}

View File

@ -34,7 +34,7 @@ fn rt_fail(expr: *c_char, file: *c_char, line: size_t) {
#[rt(exchange_malloc)]
fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
ret rustrt::rust_upcall_exchange_malloc(td, size);
return rustrt::rust_upcall_exchange_malloc(td, size);
}
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
@ -47,7 +47,7 @@ fn rt_exchange_free(ptr: *c_char) {
#[rt(malloc)]
fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
ret rustrt::rust_upcall_malloc(td, size);
return rustrt::rust_upcall_malloc(td, size);
}
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from

View File

@ -169,7 +169,7 @@ fn run_program(prog: ~str, args: ~[~str]) -> int {
let pid = spawn_process(prog, args, none, none,
0i32, 0i32, 0i32);
if pid == -1 as pid_t { fail; }
ret waitpid(pid);
return waitpid(pid);
}
/**
@ -216,10 +216,10 @@ fn start_program(prog: ~str, args: ~[~str]) -> program {
}
}
fn finish_repr(r: prog_repr) -> int {
if r.finished { ret 0; }
if r.finished { return 0; }
r.finished = true;
close_repr_input(r);
ret waitpid(r.pid);
return waitpid(r.pid);
}
fn destroy_repr(r: prog_repr) {
finish_repr(r);
@ -233,7 +233,7 @@ fn start_program(prog: ~str, args: ~[~str]) -> program {
}
impl of program for prog_res {
fn get_id() -> pid_t { ret self.r.pid; }
fn get_id() -> pid_t { return self.r.pid; }
fn input() -> io::writer { io::fd_writer(self.r.in_fd, false) }
fn output() -> io::reader { io::FILE_reader(self.r.out_file, false) }
fn err() -> io::reader { io::FILE_reader(self.r.err_file, false) }
@ -246,7 +246,7 @@ fn start_program(prog: ~str, args: ~[~str]) -> program {
out_file: os::fdopen(pipe_output.in),
err_file: os::fdopen(pipe_err.in),
mut finished: false};
ret prog_res(repr) as program;
return prog_res(repr) as program;
}
fn read_all(rd: io::reader) -> ~str {
@ -255,7 +255,7 @@ fn read_all(rd: io::reader) -> ~str {
let bytes = rd.read_bytes(4096u);
buf += str::from_bytes(bytes);
}
ret buf;
return buf;
}
/**
@ -323,7 +323,7 @@ fn program_output(prog: ~str, args: ~[~str]) ->
};
count -= 1;
};
ret {status: status, out: outs, err: errs};
return {status: status, out: outs, err: errs};
}
fn writeclose(fd: c_int, s: ~str) {
@ -345,12 +345,12 @@ fn readclose(fd: c_int) -> ~str {
buf += str::from_bytes(bytes);
}
os::fclose(file);
ret buf;
return buf;
}
/// Waits for a process to exit and returns the exit code
fn waitpid(pid: pid_t) -> int {
ret waitpid_os(pid);
return waitpid_os(pid);
#[cfg(windows)]
fn waitpid_os(pid: pid_t) -> int {
@ -382,7 +382,7 @@ fn waitpid(pid: pid_t) -> int {
}
let status = os::waitpid(pid);
ret if WIFEXITED(status) {
return if WIFEXITED(status) {
WEXITSTATUS(status) as int
} else {
1

View File

@ -80,7 +80,7 @@ mod linear {
unsafe{ // argh. log not considered pure.
debug!{"next_bucket(%?, %?) = %?", idx, len_buckets, n};
}
ret n;
return n;
}
#[inline(always)]
@ -90,11 +90,11 @@ mod linear {
let mut idx = start_idx;
loop {
if !op(idx) {
ret idx;
return idx;
}
idx = self.next_bucket(idx, len_buckets);
if idx == start_idx {
ret start_idx;
return start_idx;
}
}
}
@ -118,15 +118,15 @@ mod linear {
alt buckets[i] {
some(bkt) {
if bkt.hash == hash && self.eqfn(k, &bkt.key) {
ret found_entry(i);
return found_entry(i);
}
}
none => {
ret found_hole(i);
return found_hole(i);
}
}
};
ret table_full;
return table_full;
}
}
@ -167,13 +167,13 @@ mod linear {
k, v, idx, hash};
self.buckets[idx] = some({hash: hash, key: k, value: v});
self.size += 1;
ret true;
return true;
}
found_entry(idx) => {
debug!{"insert overwrite (%?->%?) at idx %?, hash %?",
k, v, idx, hash};
self.buckets[idx] = some({hash: hash, key: k, value: v});
ret false;
return false;
}
}
}
@ -213,7 +213,7 @@ mod linear {
let mut idx = alt self.bucket_for_key(self.buckets, k) {
table_full | found_hole(_) => {
ret false;
return false;
}
found_entry(idx) => {
idx
@ -230,7 +230,7 @@ mod linear {
idx = self.next_bucket(idx, len_buckets);
}
self.size -= 1;
ret true;
return true;
}
}
@ -339,7 +339,7 @@ mod test {
pure fn uint_eq(x: &uint, y: &uint) -> bool { *x == *y }
fn int_linear_map<V>() -> linear_map<uint,V> {
ret linear_map(uint_hash, uint_eq);
return linear_map(uint_hash, uint_eq);
}
#[test]

View File

@ -51,7 +51,7 @@ fn test_simple() {
#[test]
fn test_simple_deep() {
fn run(i: int) {
if i == 0 { ret }
if i == 0 { return }
for walk_stack |_frame| {
unsafe {

View File

@ -128,7 +128,7 @@ Section: Creating a string
*/
pure fn from_bytes(vv: &[const u8]) -> ~str {
assert is_utf8(vv);
ret unsafe { unsafe::from_bytes(vv) };
return unsafe { unsafe::from_bytes(vv) };
}
/// Copy a slice into a new unique str
@ -229,7 +229,7 @@ fn push_char(&s: ~str, ch: char) {
pure fn from_char(ch: char) -> ~str {
let mut buf = ~"";
unchecked { push_char(buf, ch); }
ret buf;
return buf;
}
/// Convert a vector of chars to a string
@ -239,7 +239,7 @@ pure fn from_chars(chs: &[char]) -> ~str {
reserve(buf, chs.len());
for vec::each(chs) |ch| { push_char(buf, ch); }
}
ret buf;
return buf;
}
/// Appends a string slice to the back of a string, without overallocating
@ -282,7 +282,7 @@ pure fn append(+lhs: ~str, rhs: &str) -> ~str {
unchecked {
push_str_no_overallocate(v, rhs);
}
ret v;
return v;
}
@ -290,7 +290,7 @@ pure fn append(+lhs: ~str, rhs: &str) -> ~str {
pure fn concat(v: &[~str]) -> ~str {
let mut s: ~str = ~"";
for vec::each(v) |ss| { unchecked { push_str(s, ss) }; }
ret s;
return s;
}
/// Concatenate a vector of strings, placing a given separator between each
@ -300,7 +300,7 @@ pure fn connect(v: &[~str], sep: &str) -> ~str {
if first { first = false; } else { unchecked { push_str(s, sep); } }
unchecked { push_str(s, ss) };
}
ret s;
return s;
}
/*
@ -319,7 +319,7 @@ fn pop_char(&s: ~str) -> char {
assert end > 0u;
let {ch, prev} = char_range_at_reverse(s, end);
unsafe { unsafe::set_len(s, prev); }
ret ch;
return ch;
}
/**
@ -332,7 +332,7 @@ fn pop_char(&s: ~str) -> char {
fn shift_char(&s: ~str) -> char {
let {ch, next} = char_range_at(s, 0u);
s = unsafe { unsafe::slice_bytes(s, next, len(s)) };
ret ch;
return ch;
}
/// Prepend a char to a string
@ -376,7 +376,7 @@ pure fn bytes(s: &str) -> ~[u8] {
let mut s_copy = from_slice(s);
let mut v: ~[u8] = ::unsafe::transmute(s_copy);
vec::unsafe::set_len(v, len(s));
ret v;
return v;
}
}
@ -397,7 +397,7 @@ pure fn chars(s: &str) -> ~[char] {
unchecked { vec::push(buf, ch); }
i = next;
}
ret buf;
return buf;
}
/**
@ -643,16 +643,16 @@ pure fn eq(&&a: ~str, &&b: ~str) -> bool {
// shape code.
let a_len = a.len();
let b_len = b.len();
if a_len != b_len { ret false; }
if a_len != b_len { return false; }
let mut end = uint::min(a_len, b_len);
let mut i = 0u;
while i < end {
if a[i] != b[i] { ret false; }
if a[i] != b[i] { return false; }
i += 1u;
}
ret true;
return true;
}
/// Bytewise less than or equal
@ -663,7 +663,7 @@ pure fn hash(&&s: ~str) -> uint {
let x = do as_bytes(s) |bytes| {
hash::hash_bytes(bytes)
};
ret x as uint;
return x as uint;
}
/*
@ -855,10 +855,10 @@ pure fn find_char_between(s: &str, c: char, start: uint, end: uint)
let mut i = start;
let b = c as u8;
while i < end {
if s[i] == b { ret some(i); }
if s[i] == b { return some(i); }
i += 1u;
}
ret none;
return none;
} else {
find_between(s, start, end, |x| x == c)
}
@ -935,9 +935,9 @@ pure fn rfind_char_between(s: &str, c: char, start: uint, end: uint)
let b = c as u8;
while i > end {
i -= 1u;
if s[i] == b { ret some(i); }
if s[i] == b { return some(i); }
}
ret none;
return none;
} else {
rfind_between(s, start, end, |x| x == c)
}
@ -1016,10 +1016,10 @@ pure fn find_between(s: &str, start: uint, end: uint, f: fn(char) -> bool)
let mut i = start;
while i < end {
let {ch, next} = char_range_at(s, i);
if f(ch) { ret some(i); }
if f(ch) { return some(i); }
i = next;
}
ret none;
return none;
}
/**
@ -1095,17 +1095,17 @@ pure fn rfind_between(s: &str, start: uint, end: uint, f: fn(char) -> bool)
let mut i = start;
while i > end {
let {ch, prev} = char_range_at_reverse(s, i);
if f(ch) { ret some(prev); }
if f(ch) { return some(prev); }
i = prev;
}
ret none;
return none;
}
// Utility used by various searching functions
pure fn match_at(haystack: &a/str, needle: &b/str, at: uint) -> bool {
let mut i = at;
for each(needle) |c| { if haystack[i] != c { ret false; } i += 1u; }
ret true;
for each(needle) |c| { if haystack[i] != c { return false; } i += 1u; }
return true;
}
/**
@ -1175,16 +1175,16 @@ pure fn find_str_between(haystack: &a/str, needle: &b/str, start: uint,
// See Issue #1932 for why this is a naive search
assert end <= len(haystack);
let needle_len = len(needle);
if needle_len == 0u { ret some(start); }
if needle_len > end { ret none; }
if needle_len == 0u { return some(start); }
if needle_len > end { return none; }
let mut i = start;
let e = end - needle_len;
while i <= e {
if match_at(haystack, needle, i) { ret some(i); }
if match_at(haystack, needle, i) { return some(i); }
i += 1u;
}
ret none;
return none;
}
/**
@ -1248,8 +1248,8 @@ Section: String properties
/// Determines if a string contains only ASCII characters
pure fn is_ascii(s: &str) -> bool {
let mut i: uint = len(s);
while i > 0u { i -= 1u; if !u8::is_ascii(s[i]) { ret false; } }
ret true;
while i > 0u { i -= 1u; if !u8::is_ascii(s[i]) { return false; } }
return true;
}
/// Returns true if the string has length 0
@ -1264,7 +1264,7 @@ pure fn is_not_empty(s: &str) -> bool { !is_empty(s) }
* Whitespace characters are determined by `char::is_whitespace`
*/
pure fn is_whitespace(s: &str) -> bool {
ret all(s, char::is_whitespace);
return all(s, char::is_whitespace);
}
/**
@ -1273,7 +1273,7 @@ pure fn is_whitespace(s: &str) -> bool {
* Alphanumeric characters are determined by `char::is_alphanumeric`
*/
fn is_alphanumeric(s: &str) -> bool {
ret all(s, char::is_alphanumeric);
return all(s, char::is_alphanumeric);
}
/// Returns the string length/size in bytes not counting the null terminator
@ -1294,16 +1294,16 @@ pure fn is_utf8(v: &[const u8]) -> bool {
let total = vec::len::<u8>(v);
while i < total {
let mut chsize = utf8_char_width(v[i]);
if chsize == 0u { ret false; }
if i + chsize > total { ret false; }
if chsize == 0u { return false; }
if i + chsize > total { return false; }
i += 1u;
while chsize > 1u {
if v[i] & 192u8 != tag_cont_u8 { ret false; }
if v[i] & 192u8 != tag_cont_u8 { return false; }
i += 1u;
chsize -= 1u;
}
}
ret true;
return true;
}
/// Determines if a vector of `u16` contains valid UTF-16
@ -1317,14 +1317,14 @@ pure fn is_utf16(v: &[u16]) -> bool {
i += 1u;
} else {
if i+1u < len { ret false; }
if i+1u < len { return false; }
let u2 = v[i+1u];
if u < 0xD7FF_u16 || u > 0xDBFF_u16 { ret false; }
if u2 < 0xDC00_u16 || u2 > 0xDFFF_u16 { ret false; }
if u < 0xD7FF_u16 || u > 0xDBFF_u16 { return false; }
if u2 < 0xDC00_u16 || u2 > 0xDFFF_u16 { return false; }
i += 2u;
}
}
ret true;
return true;
}
/// Converts to a vector of `u16` encoded as UTF-16
@ -1347,7 +1347,7 @@ pure fn to_utf16(s: &str) -> ~[u16] {
vec::push_all(u, ~[w1, w2])
}
}
ret u;
return u;
}
pure fn utf16_chars(v: &[u16], f: fn(char)) {
@ -1381,7 +1381,7 @@ pure fn from_utf16(v: &[u16]) -> ~str {
reserve(buf, vec::len(v));
utf16_chars(v, |ch| push_char(buf, ch));
}
ret buf;
return buf;
}
@ -1407,7 +1407,7 @@ pure fn count_chars(s: &str, start: uint, end: uint) -> uint {
len += 1u;
i = next;
}
ret len;
return len;
}
/// Counts the number of bytes taken by the `n` in `s` starting from `start`.
@ -1427,14 +1427,14 @@ pure fn count_bytes(s: &b/str, start: uint, n: uint) -> uint {
/// Given a first byte, determine how many bytes are in this UTF-8 character
pure fn utf8_char_width(b: u8) -> uint {
let byte: uint = b as uint;
if byte < 128u { ret 1u; }
if byte < 128u { return 1u; }
// Not a valid start byte
if byte < 192u { ret 0u; }
if byte < 224u { ret 2u; }
if byte < 240u { ret 3u; }
if byte < 248u { ret 4u; }
if byte < 252u { ret 5u; }
ret 6u;
if byte < 192u { return 0u; }
if byte < 224u { return 2u; }
if byte < 240u { return 3u; }
if byte < 248u { return 4u; }
if byte < 252u { return 5u; }
return 6u;
}
/**
@ -1442,9 +1442,9 @@ pure fn utf8_char_width(b: u8) -> uint {
* character sequence.
*/
pure fn is_char_boundary(s: &str, index: uint) -> bool {
if index == len(s) { ret true; }
if index == len(s) { return true; }
let b = s[index];
ret b < 128u8 || b >= 192u8;
return b < 128u8 || b >= 192u8;
}
/**
@ -1500,7 +1500,7 @@ pure fn char_range_at(s: &str, i: uint) -> {ch: char, next: uint} {
let b0 = s[i];
let w = utf8_char_width(b0);
assert (w != 0u);
if w == 1u { ret {ch: b0 as char, next: i + 1u}; }
if w == 1u { return {ch: b0 as char, next: i + 1u}; }
let mut val = 0u;
let end = i + w;
let mut i = i + 1u;
@ -1515,11 +1515,11 @@ pure fn char_range_at(s: &str, i: uint) -> {ch: char, next: uint} {
// the first to clip off the marker bits at the left of the byte, and then
// a second (as uint) to get it to the right position.
val += ((b0 << ((w + 1u) as u8)) as uint) << ((w - 1u) * 6u - w - 1u);
ret {ch: val as char, next: i};
return {ch: val as char, next: i};
}
/// Pluck a character out of a string
pure fn char_at(s: &str, i: uint) -> char { ret char_range_at(s, i).ch; }
pure fn char_at(s: &str, i: uint) -> char { return char_range_at(s, i).ch; }
/**
* Given a byte position and a str, return the previous char and its position
@ -1540,7 +1540,7 @@ pure fn char_range_at_reverse(ss: &str, start: uint)
prev -= 1u;
let ch = char_at(ss, prev);
ret {ch:ch, prev:prev};
return {ch:ch, prev:prev};
}
/**
@ -1571,10 +1571,10 @@ pure fn all_between(s: &str, start: uint, end: uint,
let mut i = start;
while i < end {
let {ch, next} = char_range_at(s, i);
if !it(ch) { ret false; }
if !it(ch) { return false; }
i = next;
}
ret true;
return true;
}
/**
@ -1747,7 +1747,7 @@ pure fn escape_default(s: &str) -> ~str {
reserve_at_least(out, str::len(s));
chars_iter(s, |c| push_str(out, char::escape_default(c)));
}
ret out;
return out;
}
/// Escape each char in `s` with char::escape_unicode.
@ -1757,7 +1757,7 @@ pure fn escape_unicode(s: &str) -> ~str {
reserve_at_least(out, str::len(s));
chars_iter(s, |c| push_str(out, char::escape_unicode(c)));
}
ret out;
return out;
}
/// Unsafe operations
@ -1781,7 +1781,7 @@ mod unsafe {
i += 1u;
curr = ptr::offset(buf, i);
}
ret from_buf_len(buf, i);
return from_buf_len(buf, i);
}
/// Create a Rust string from a *u8 buffer of the given length
@ -1793,7 +1793,7 @@ mod unsafe {
vec::push(v, 0u8);
assert is_utf8(v);
ret ::unsafe::transmute(v);
return ::unsafe::transmute(v);
}
/// Create a Rust string from a null-terminated C string
@ -1861,7 +1861,7 @@ mod unsafe {
assert (len > 0u);
let b = s[len - 1u];
unsafe { set_len(s, len - 1u) };
ret b;
return b;
}
/// Removes the first byte from a string and returns it. (Not UTF-8 safe).
@ -1870,7 +1870,7 @@ mod unsafe {
assert (len > 0u);
let b = s[0];
s = unsafe { unsafe::slice_bytes(s, 1u, len) };
ret b;
return b;
}
/// Sets the length of the string and adds the null terminator
@ -2405,13 +2405,13 @@ mod tests {
let mut i = 0;
let mut rs = ~"";
while i < 100000 { push_str(rs, ~"aaaaaaaaaa"); i += 1; }
ret rs;
return rs;
}
fn half_a_million_letter_a() -> ~str {
let mut i = 0;
let mut rs = ~"";
while i < 100000 { push_str(rs, ~"aaaaa"); i += 1; }
ret rs;
return rs;
}
assert eq(half_a_million_letter_a(),
unsafe::slice_bytes(a_million_letter_a(),
@ -2516,13 +2516,13 @@ mod tests {
let mut i = 0;
let mut rs = ~"";
while i < 100000 { push_str(rs, ~"华华华华华华华华华华"); i += 1; }
ret rs;
return rs;
}
fn half_a_million_letter_X() -> ~str {
let mut i = 0;
let mut rs = ~"";
while i < 100000 { push_str(rs, ~"华华华华华"); i += 1; }
ret rs;
return rs;
}
assert eq(half_a_million_letter_X(),
slice(a_million_letter_X(), 0u, 3u * 500000u));

View File

@ -833,7 +833,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) {
// if parent_group {
// if !enlist_in_group(parent_group) {
// leave_group(child_group); // Roll back
// ret; // Parent group failed. Don't run child's f().
// return; // Parent group failed. Don't run child's f().
// }
// }
// stash_taskgroup_data_in_TLS(child_group, parent_group);
@ -1024,7 +1024,7 @@ unsafe fn local_get_helper<T: owned>(
do_pop: bool) -> option<@T> {
let map = get_task_local_map(task);
// Interpret our findings from the map
// Interpreturn our findings from the map
do local_data_lookup(map, key).map |result| {
// A reference count magically appears on 'data' out of thin air. It
// was referenced in the local_data box, though, not here, so before
@ -1743,7 +1743,7 @@ fn test_child_doesnt_ref_parent() {
// climbing the task tree to dereference each ancestor. (See #1789)
const generations: uint = 128;
fn child_no(x: uint) -> fn~() {
ret || {
return || {
if x < generations {
task::spawn(child_no(x+1));
}

View File

@ -11,19 +11,19 @@ impl extensions <T:copy, U:copy> of tuple_ops<T,U> for (T, U) {
/// Return the first element of self
pure fn first() -> T {
let (t, _) = self;
ret t;
return t;
}
/// Return the second element of self
pure fn second() -> U {
let (_, u) = self;
ret u;
return u;
}
/// Return the results of swapping the two elements of self
pure fn swap() -> (U, T) {
let (t, u) = self;
ret (u, t);
return (u, t);
}
}

View File

@ -54,26 +54,26 @@ pure fn compl(i: T) -> T {
impl ord of ord for T {
pure fn lt(&&other: T) -> bool {
ret self < other;
return self < other;
}
}
impl eq of eq for T {
pure fn eq(&&other: T) -> bool {
ret self == other;
return self == other;
}
}
impl num of num::num for T {
pure fn add(&&other: T) -> T { ret self + other; }
pure fn sub(&&other: T) -> T { ret self - other; }
pure fn mul(&&other: T) -> T { ret self * other; }
pure fn div(&&other: T) -> T { ret self / other; }
pure fn modulo(&&other: T) -> T { ret self % other; }
pure fn neg() -> T { ret -self; }
pure fn add(&&other: T) -> T { return self + other; }
pure fn sub(&&other: T) -> T { return self - other; }
pure fn mul(&&other: T) -> T { return self * other; }
pure fn div(&&other: T) -> T { return self / other; }
pure fn modulo(&&other: T) -> T { return self % other; }
pure fn neg() -> T { return -self; }
pure fn to_int() -> int { ret self as int; }
pure fn from_int(n: int) -> T { ret n as T; }
pure fn to_int() -> int { return self as int; }
pure fn from_int(n: int) -> T { return n as T; }
}
/**
@ -89,17 +89,17 @@ impl num of num::num for T {
* `buf` must not be empty
*/
fn parse_buf(buf: ~[u8], radix: uint) -> option<T> {
if vec::len(buf) == 0u { ret none; }
if vec::len(buf) == 0u { return none; }
let mut i = vec::len(buf) - 1u;
let mut power = 1u as T;
let mut n = 0u as T;
loop {
alt char::to_digit(buf[i] as char, radix) {
some(d) { n += d as T * power; }
none { ret none; }
none { return none; }
}
power *= radix as T;
if i == 0u { ret some(n); }
if i == 0u { return some(n); }
i -= 1u;
};
}
@ -138,16 +138,16 @@ fn from_str(s: ~str) -> option<T> { parse_buf(str::bytes(s), 10u) }
/// Parse a string as an unsigned integer.
fn from_str_radix(buf: ~str, radix: u64) -> option<u64> {
if str::len(buf) == 0u { ret none; }
if str::len(buf) == 0u { return none; }
let mut i = str::len(buf) - 1u;
let mut power = 1u64, n = 0u64;
loop {
alt char::to_digit(buf[i] as char, radix as uint) {
some(d) { n += d as u64 * power; }
none { ret none; }
none { return none; }
}
power *= radix;
if i == 0u { ret some(n); }
if i == 0u { return some(n); }
i -= 1u;
};
}
@ -233,7 +233,7 @@ pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
}
/// Convert to a string
fn str(i: T) -> ~str { ret to_str(i, 10u); }
fn str(i: T) -> ~str { return to_str(i, 10u); }
#[test]
fn test_to_str() {

View File

@ -3,4 +3,4 @@ type T = u8;
// Type-specific functions here. These must be reexported by the
// parent module so that they appear in core::u8 and not core::u8::u8;
pure fn is_ascii(x: T) -> bool { ret 0 as T == x & 128 as T; }
pure fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; }

View File

@ -14,8 +14,8 @@ type T = uint;
*/
pure fn div_ceil(x: uint, y: uint) -> uint {
let div = div(x, y);
if x % y == 0u { ret div;}
else { ret div + 1u; }
if x % y == 0u { return div;}
else { return div + 1u; }
}
/**
@ -32,8 +32,8 @@ pure fn div_ceil(x: uint, y: uint) -> uint {
*/
pure fn div_round(x: uint, y: uint) -> uint {
let div = div(x, y);
if x % y * 2u < y { ret div;}
else { ret div + 1u; }
if x % y * 2u < y { return div;}
else { return div + 1u; }
}
/**
@ -51,10 +51,10 @@ pure fn div_round(x: uint, y: uint) -> uint {
* The smallest integer `q` such that `x/y <= q`. This
* is either `x/y` or `x/y + 1`.
*/
pure fn div_floor(x: uint, y: uint) -> uint { ret x / y; }
pure fn div_floor(x: uint, y: uint) -> uint { return x / y; }
/// Produce a uint suitable for use in a hash table
pure fn hash(&&x: uint) -> uint { ret x; }
pure fn hash(&&x: uint) -> uint { return x; }
/**
* Iterate over the range [`lo`..`hi`), or stop when requested
@ -74,10 +74,10 @@ pure fn hash(&&x: uint) -> uint { ret x; }
pure fn iterate(lo: uint, hi: uint, it: fn(uint) -> bool) -> bool {
let mut i = lo;
while i < hi {
if (!it(i)) { ret false; }
if (!it(i)) { return false; }
i += 1u;
}
ret true;
return true;
}
/// Returns the smallest power of 2 greater than or equal to `n`
@ -87,7 +87,7 @@ fn next_power_of_two(n: uint) -> uint {
let mut tmp: uint = n - 1u;
let mut shift: uint = 1u;
while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; }
ret tmp + 1u;
return tmp + 1u;
}
#[test]

View File

@ -1,6 +1,6 @@
mod general_category {
pure fn Cc(c: char) -> bool {
ret alt c {
return alt c {
'\x00' to '\x1f'
| '\x7f' to '\x9f'
{ true }
@ -9,7 +9,7 @@ mod general_category {
}
pure fn Cf(c: char) -> bool {
ret alt c {
return alt c {
'\xad'
| '\u0600' to '\u0603'
| '\u06dd'
@ -29,7 +29,7 @@ mod general_category {
}
pure fn Co(c: char) -> bool {
ret alt c {
return alt c {
'\ue000' to '\uf8ff'
{ true }
_ { false }
@ -37,7 +37,7 @@ mod general_category {
}
pure fn Cs(c: char) -> bool {
ret alt c {
return alt c {
'\ud800' to '\udfff'
{ true }
_ { false }
@ -45,7 +45,7 @@ mod general_category {
}
pure fn Ll(c: char) -> bool {
ret alt c {
return alt c {
'\x61' to '\x7a'
| '\xaa'
| '\xb5'
@ -650,7 +650,7 @@ mod general_category {
}
pure fn Lm(c: char) -> bool {
ret alt c {
return alt c {
'\u02b0' to '\u02c1'
| '\u02c6' to '\u02d1'
| '\u02e0' to '\u02e4'
@ -706,7 +706,7 @@ mod general_category {
}
pure fn Lo(c: char) -> bool {
ret alt c {
return alt c {
'\u01bb'
| '\u01c0' to '\u01c3'
| '\u0294'
@ -892,7 +892,7 @@ mod general_category {
}
pure fn Lt(c: char) -> bool {
ret alt c {
return alt c {
'\u01c5'
| '\u01c8'
| '\u01cb'
@ -909,7 +909,7 @@ mod general_category {
}
pure fn Lu(c: char) -> bool {
ret alt c {
return alt c {
'\x41' to '\x5a'
| '\xc0' to '\xd6'
| '\xd8' to '\xde'
@ -1501,7 +1501,7 @@ mod general_category {
}
pure fn Mc(c: char) -> bool {
ret alt c {
return alt c {
'\u0903'
| '\u093b'
| '\u093e' to '\u0940'
@ -1612,7 +1612,7 @@ mod general_category {
}
pure fn Me(c: char) -> bool {
ret alt c {
return alt c {
'\u0488' to '\u0489'
| '\u20dd' to '\u20e0'
| '\u20e2' to '\u20e4'
@ -1623,7 +1623,7 @@ mod general_category {
}
pure fn Mn(c: char) -> bool {
ret alt c {
return alt c {
'\u0300' to '\u036f'
| '\u0483' to '\u0487'
| '\u0591' to '\u05bd'
@ -1816,7 +1816,7 @@ mod general_category {
}
pure fn Nd(c: char) -> bool {
ret alt c {
return alt c {
'\x30' to '\x39'
| '\u0660' to '\u0669'
| '\u06f0' to '\u06f9'
@ -1860,7 +1860,7 @@ mod general_category {
}
pure fn Nl(c: char) -> bool {
ret alt c {
return alt c {
'\u16ee' to '\u16f0'
| '\u2160' to '\u2182'
| '\u2185' to '\u2188'
@ -1879,7 +1879,7 @@ mod general_category {
}
pure fn No(c: char) -> bool {
ret alt c {
return alt c {
'\xb2' to '\xb3'
| '\xb9'
| '\xbc' to '\xbe'
@ -1927,7 +1927,7 @@ mod general_category {
}
pure fn Pc(c: char) -> bool {
ret alt c {
return alt c {
'\x5f'
| '\u203f' to '\u2040'
| '\u2054'
@ -1940,7 +1940,7 @@ mod general_category {
}
pure fn Pd(c: char) -> bool {
ret alt c {
return alt c {
'\x2d'
| '\u058a'
| '\u05be'
@ -1962,7 +1962,7 @@ mod general_category {
}
pure fn Pe(c: char) -> bool {
ret alt c {
return alt c {
'\x29'
| '\x5d'
| '\x7d'
@ -2039,7 +2039,7 @@ mod general_category {
}
pure fn Pf(c: char) -> bool {
ret alt c {
return alt c {
'\xbb'
| '\u2019'
| '\u201d'
@ -2056,7 +2056,7 @@ mod general_category {
}
pure fn Pi(c: char) -> bool {
ret alt c {
return alt c {
'\xab'
| '\u2018'
| '\u201b' to '\u201c'
@ -2074,7 +2074,7 @@ mod general_category {
}
pure fn Po(c: char) -> bool {
ret alt c {
return alt c {
'\x21' to '\x23'
| '\x25' to '\x27'
| '\x2a'
@ -2207,7 +2207,7 @@ mod general_category {
}
pure fn Ps(c: char) -> bool {
ret alt c {
return alt c {
'\x28'
| '\x5b'
| '\x7b'
@ -2286,7 +2286,7 @@ mod general_category {
}
pure fn Sc(c: char) -> bool {
ret alt c {
return alt c {
'\x24'
| '\xa2' to '\xa5'
| '\u060b'
@ -2309,7 +2309,7 @@ mod general_category {
}
pure fn Sk(c: char) -> bool {
ret alt c {
return alt c {
'\x5e'
| '\x60'
| '\xa8'
@ -2343,7 +2343,7 @@ mod general_category {
}
pure fn Sm(c: char) -> bool {
ret alt c {
return alt c {
'\x2b'
| '\x3c' to '\x3e'
| '\x7c'
@ -2414,7 +2414,7 @@ mod general_category {
}
pure fn So(c: char) -> bool {
ret alt c {
return alt c {
'\xa6' to '\xa7'
| '\xa9'
| '\xae'
@ -2533,7 +2533,7 @@ mod general_category {
}
pure fn Zl(c: char) -> bool {
ret alt c {
return alt c {
'\u2028'
{ true }
_ { false }
@ -2541,7 +2541,7 @@ mod general_category {
}
pure fn Zp(c: char) -> bool {
ret alt c {
return alt c {
'\u2029'
{ true }
_ { false }
@ -2549,7 +2549,7 @@ mod general_category {
}
pure fn Zs(c: char) -> bool {
ret alt c {
return alt c {
'\x20'
| '\xa0'
| '\u1680'
@ -2567,7 +2567,7 @@ mod general_category {
mod derived_property {
/// Check if a character has the alphabetic unicode property
pure fn Alphabetic(c: char) -> bool {
ret alt c {
return alt c {
'\x41' to '\x5a'
| '\x61' to '\x7a'
| '\xaa'
@ -3305,7 +3305,7 @@ mod derived_property {
}
pure fn XID_Continue(c: char) -> bool {
ret alt c {
return alt c {
'\x30' to '\x39'
| '\x41' to '\x5a'
| '\x5f'
@ -4176,7 +4176,7 @@ mod derived_property {
}
pure fn XID_Start(c: char) -> bool {
ret alt c {
return alt c {
'\x41' to '\x5a'
| '\x61' to '\x7a'
| '\xaa'

View File

@ -44,7 +44,7 @@ unsafe fn bump_box_refcount<T>(+t: @T) { forget(t); }
unsafe fn transmute<L, G>(-thing: L) -> G {
let newthing = reinterpret_cast(thing);
forget(thing);
ret newthing;
return newthing;
}
#[cfg(test)]

View File

@ -191,7 +191,7 @@ pure fn from_fn<T>(n_elts: uint, op: init_op<T>) -> ~[T] {
let mut i: uint = 0u;
while i < n_elts unsafe { unsafe::set(v, i, op(i)); i += 1u; }
unsafe { unsafe::set_len(v, n_elts); }
ret v;
return v;
}
/**
@ -208,7 +208,7 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] {
while i < n_elts { unsafe::set(v, i, t); i += 1u; }
unsafe { unsafe::set_len(v, n_elts); }
}
ret v;
return v;
}
/**
@ -234,7 +234,7 @@ pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> ~[A] {
<fn(push: pure fn(+A)), fn(push: fn(+A))>
(builder)(|+x| push(vec, x));
}
ret vec;
return vec;
}
/**
@ -269,7 +269,7 @@ pure fn head<T: copy>(v: &[const T]) -> T { v[0] }
/// Returns a vector containing all but the first element of a slice
pure fn tail<T: copy>(v: &[const T]) -> ~[T] {
ret slice(v, 1u, len(v));
return slice(v, 1u, len(v));
}
/**
@ -297,7 +297,7 @@ pure fn last<T: copy>(v: &[const T]) -> T {
* or `none` if the vector is empty.
*/
pure fn last_opt<T: copy>(v: &[const T]) -> option<T> {
if len(v) == 0u { ret none; }
if len(v) == 0u { return none; }
some(v[len(v) - 1u])
}
@ -309,7 +309,7 @@ pure fn slice<T: copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
unchecked {
for uint::range(start, end) |i| { vec::push(result, v[i]) }
}
ret result;
return result;
}
/// Return a slice that points into another slice.
@ -351,7 +351,7 @@ pure fn const_view<T>(v: &[const T], start: uint, end: uint) -> &[const T] {
/// Split the vector `v` by applying each element against the predicate `f`.
fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { ret ~[] }
if (ln == 0u) { return ~[] }
let mut start = 0u;
let mut result = ~[];
@ -374,7 +374,7 @@ fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
*/
fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { ret ~[] }
if (ln == 0u) { return ~[] }
let mut start = 0u;
let mut count = n;
@ -400,7 +400,7 @@ fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
*/
fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { ret ~[] }
if (ln == 0u) { return ~[] }
let mut end = ln;
let mut result = ~[];
@ -423,7 +423,7 @@ fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
*/
fn rsplitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { ret ~[] }
if (ln == 0u) { return ~[] }
let mut end = ln;
let mut count = n;
@ -564,7 +564,7 @@ pure fn append<T: copy>(+lhs: ~[T], rhs: &[const T]) -> ~[T] {
unchecked {
push_all(v, rhs);
}
ret v;
return v;
}
#[inline(always)]
@ -591,7 +591,7 @@ pure fn append_mut<T: copy>(lhs: &[mut T], rhs: &[const T]) -> ~[mut T] {
}
i += 1u;
}
ret v;
return v;
}
/**
@ -649,7 +649,7 @@ pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> ~[U] {
let mut result = ~[];
unchecked{reserve(result, len(v));}
for each(v) |elem| { unsafe { push(result, f(elem)); } }
ret result;
return result;
}
fn map_consume<T, U>(+v: ~[T], f: fn(+T) -> U) -> ~[U] {
@ -665,7 +665,7 @@ pure fn mapi<T, U>(v: &[T], f: fn(uint, T) -> U) -> ~[U] {
let mut result = ~[];
unchecked{reserve(result, len(v));}
for eachi(v) |i, elem| { unsafe { push(result, f(i, elem)); } }
ret result;
return result;
}
/**
@ -675,7 +675,7 @@ pure fn mapi<T, U>(v: &[T], f: fn(uint, T) -> U) -> ~[U] {
pure fn flat_map<T, U>(v: &[T], f: fn(T) -> ~[U]) -> ~[U] {
let mut result = ~[];
for each(v) |elem| { unchecked{ push_all_move(result, f(elem)); } }
ret result;
return result;
}
/// Apply a function to each pair of elements and return the results
@ -689,7 +689,7 @@ pure fn map2<T: copy, U: copy, V>(v0: &[T], v1: &[U],
unsafe { push(u, f(copy v0[i], copy v1[i])) };
i += 1u;
}
ret u;
return u;
}
/**
@ -707,7 +707,7 @@ pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> option<U>)
some(result_elem) { unsafe { push(result, result_elem); } }
}
}
ret result;
return result;
}
/**
@ -722,7 +722,7 @@ pure fn filter<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
for each(v) |elem| {
if f(elem) { unsafe { push(result, elem); } }
}
ret result;
return result;
}
/**
@ -733,7 +733,7 @@ pure fn filter<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
pure fn concat<T: copy>(v: &[~[T]]) -> ~[T] {
let mut r = ~[];
for each(v) |inner| { unsafe { push_all(r, inner); } }
ret r;
return r;
}
/// Concatenate a vector of vectors, placing a given separator between each
@ -744,7 +744,7 @@ pure fn connect<T: copy>(v: &[~[T]], sep: T) -> ~[T] {
if first { first = false; } else { unsafe { push(r, sep); } }
unchecked { push_all(r, inner) };
}
ret r;
return r;
}
/// Reduce a vector from left to right
@ -753,7 +753,7 @@ pure fn foldl<T: copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
do iter(v) |elt| {
accum = p(accum, elt);
}
ret accum;
return accum;
}
/// Reduce a vector from right to left
@ -762,7 +762,7 @@ pure fn foldr<T, U: copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
do riter(v) |elt| {
accum = p(elt, accum);
}
ret accum;
return accum;
}
/**
@ -771,8 +771,8 @@ pure fn foldr<T, U: copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
* If the vector contains no elements then false is returned.
*/
pure fn any<T>(v: &[T], f: fn(T) -> bool) -> bool {
for each(v) |elem| { if f(elem) { ret true; } }
ret false;
for each(v) |elem| { if f(elem) { return true; } }
return false;
}
/**
@ -786,10 +786,10 @@ pure fn any2<T, U>(v0: &[T], v1: &[U],
let v1_len = len(v1);
let mut i = 0u;
while i < v0_len && i < v1_len {
if f(v0[i], v1[i]) { ret true; };
if f(v0[i], v1[i]) { return true; };
i += 1u;
}
ret false;
return false;
}
/**
@ -798,8 +798,8 @@ pure fn any2<T, U>(v0: &[T], v1: &[U],
* If the vector contains no elements then true is returned.
*/
pure fn all<T>(v: &[T], f: fn(T) -> bool) -> bool {
for each(v) |elem| { if !f(elem) { ret false; } }
ret true;
for each(v) |elem| { if !f(elem) { return false; } }
return true;
}
/**
@ -808,8 +808,8 @@ pure fn all<T>(v: &[T], f: fn(T) -> bool) -> bool {
* If the vector contains no elements then true is returned.
*/
pure fn alli<T>(v: &[T], f: fn(uint, T) -> bool) -> bool {
for eachi(v) |i, elem| { if !f(i, elem) { ret false; } }
ret true;
for eachi(v) |i, elem| { if !f(i, elem) { return false; } }
return true;
}
/**
@ -820,23 +820,23 @@ pure fn alli<T>(v: &[T], f: fn(uint, T) -> bool) -> bool {
pure fn all2<T, U>(v0: &[T], v1: &[U],
f: fn(T, U) -> bool) -> bool {
let v0_len = len(v0);
if v0_len != len(v1) { ret false; }
if v0_len != len(v1) { return false; }
let mut i = 0u;
while i < v0_len { if !f(v0[i], v1[i]) { ret false; }; i += 1u; }
ret true;
while i < v0_len { if !f(v0[i], v1[i]) { return false; }; i += 1u; }
return true;
}
/// Return true if a vector contains an element with the given value
pure fn contains<T>(v: &[T], x: T) -> bool {
for each(v) |elt| { if x == elt { ret true; } }
ret false;
for each(v) |elt| { if x == elt { return true; } }
return false;
}
/// Returns the number of elements that are equal to a given value
pure fn count<T>(v: &[T], x: T) -> uint {
let mut cnt = 0u;
for each(v) |elt| { if x == elt { cnt += 1u; } }
ret cnt;
return cnt;
}
/**
@ -913,8 +913,8 @@ pure fn position_between<T>(v: &[T], start: uint, end: uint,
assert start <= end;
assert end <= len(v);
let mut i = start;
while i < end { if f(v[i]) { ret some::<uint>(i); } i += 1u; }
ret none;
while i < end { if f(v[i]) { return some::<uint>(i); } i += 1u; }
return none;
}
/// Find the last index containing a matching value
@ -947,10 +947,10 @@ pure fn rposition_between<T>(v: &[T], start: uint, end: uint,
assert end <= len(v);
let mut i = end;
while i > start {
if f(v[i - 1u]) { ret some::<uint>(i - 1u); }
if f(v[i - 1u]) { return some::<uint>(i - 1u); }
i -= 1u;
}
ret none;
return none;
}
// FIXME: if issue #586 gets implemented, could have a postcondition
@ -974,7 +974,7 @@ pure fn unzip<T: copy, U: copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
vec::push(bs, b);
}
}
ret (as, bs);
return (as, bs);
}
/**
@ -989,7 +989,7 @@ pure fn zip<T: copy, U: copy>(v: &[const T], u: &[const U]) -> ~[(T, U)] {
let mut i = 0u;
assert sz == len(u);
while i < sz unchecked { vec::push(zipped, (v[i], u[i])); i += 1u; }
ret zipped;
return zipped;
}
/**
@ -1017,12 +1017,12 @@ fn reverse<T>(v: ~[mut T]) {
pure fn reversed<T: copy>(v: &[const T]) -> ~[T] {
let mut rs: ~[T] = ~[];
let mut i = len::<T>(v);
if i == 0u { ret rs; } else { i -= 1u; }
if i == 0u { return rs; } else { i -= 1u; }
unchecked {
while i != 0u { vec::push(rs, v[i]); i -= 1u; }
vec::push(rs, v[0]);
}
ret rs;
return rs;
}
/**
@ -1229,7 +1229,7 @@ pure fn windowed<TT: copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
vec::push(ww, vec::slice(xx, ii, ii+nn));
}
});
ret ww;
return ww;
}
/**
@ -1541,7 +1541,7 @@ mod unsafe {
*/
#[inline(always)]
unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
ret ::unsafe::reinterpret_cast(
return ::unsafe::reinterpret_cast(
rustrt::vec_from_buf_shared(sys::get_type_desc::<T>(),
ptr as *(),
elts as size_t));
@ -1572,14 +1572,14 @@ mod unsafe {
#[inline(always)]
unsafe fn to_ptr<T>(v: ~[const T]) -> *T {
let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
ret ::unsafe::reinterpret_cast(addr_of((**repr).data));
return ::unsafe::reinterpret_cast(addr_of((**repr).data));
}
#[inline(always)]
unsafe fn to_ptr_slice<T>(v: &[const T]) -> *T {
let repr: **slice_repr = ::unsafe::reinterpret_cast(addr_of(v));
ret ::unsafe::reinterpret_cast(addr_of((**repr).data));
return ::unsafe::reinterpret_cast(addr_of((**repr).data));
}
@ -1775,21 +1775,21 @@ impl extensions/&<A:copy> of iter_trait_extensions<A> for &[A] {
#[cfg(test)]
mod tests {
fn square(n: uint) -> uint { ret n * n; }
fn square(n: uint) -> uint { return n * n; }
fn square_ref(&&n: uint) -> uint { ret n * n; }
fn square_ref(&&n: uint) -> uint { return n * n; }
pure fn is_three(&&n: uint) -> bool { ret n == 3u; }
pure fn is_three(&&n: uint) -> bool { return n == 3u; }
pure fn is_odd(&&n: uint) -> bool { ret n % 2u == 1u; }
pure fn is_odd(&&n: uint) -> bool { return n % 2u == 1u; }
pure fn is_equal(&&x: uint, &&y:uint) -> bool { ret x == y; }
pure fn is_equal(&&x: uint, &&y:uint) -> bool { return x == y; }
fn square_if_odd(&&n: uint) -> option<uint> {
ret if n % 2u == 1u { some(n * n) } else { none };
return if n % 2u == 1u { some(n * n) } else { none };
}
fn add(&&x: uint, &&y: uint) -> uint { ret x + y; }
fn add(&&x: uint, &&y: uint) -> uint { return x + y; }
#[test]
fn test_unsafe_ptrs() {
@ -2015,7 +2015,7 @@ mod tests {
#[test]
fn test_map2() {
fn times(&&x: int, &&y: int) -> int { ret x * y; }
fn times(&&x: int, &&y: int) -> int { return x * y; }
let f = times;
let v0 = ~[1, 2, 3, 4, 5];
let v1 = ~[5, 4, 3, 2, 1];
@ -2043,10 +2043,10 @@ mod tests {
fn halve(&&i: int) -> option<int> {
if i % 2 == 0 {
ret option::some::<int>(i / 2);
} else { ret option::none::<int>; }
return option::some::<int>(i / 2);
} else { return option::none::<int>; }
}
fn halve_for_sure(&&i: int) -> int { ret i / 2; }
fn halve_for_sure(&&i: int) -> int { return i / 2; }
let all_even: ~[int] = ~[0, 2, 8, 6];
let all_odd1: ~[int] = ~[1, 7, 3];
let all_odd2: ~[int] = ~[];
@ -2230,8 +2230,8 @@ mod tests {
#[test]
fn test_position() {
fn less_than_three(&&i: int) -> bool { ret i < 3; }
fn is_eighteen(&&i: int) -> bool { ret i == 18; }
fn less_than_three(&&i: int) -> bool { return i < 3; }
fn is_eighteen(&&i: int) -> bool { return i == 18; }
assert position(~[], less_than_three) == none;

View File

@ -20,7 +20,7 @@ fn chunk(size: uint) -> @chunk {
}
fn arena_with_size(initial_size: uint) -> arena {
ret arena_({mut chunks: @cons(chunk(initial_size), @nil)});
return arena_({mut chunks: @cons(chunk(initial_size), @nil)});
}
fn arena() -> arena {
@ -36,7 +36,7 @@ impl arena for arena {
head = chunk(uint::next_power_of_two(new_min_chunk_size + 1u));
self.chunks = @cons(head, self.chunks);
ret self.alloc_inner(n_bytes, align);
return self.alloc_inner(n_bytes, align);
}
#[inline(always)]
@ -48,13 +48,13 @@ impl arena for arena {
start = (start + alignm1) & !alignm1;
let end = start + n_bytes;
if end > vec::capacity(head.data) {
ret self.alloc_grow(n_bytes, align);
return self.alloc_grow(n_bytes, align);
}
unsafe {
let p = ptr::offset(vec::unsafe::to_ptr(head.data), start);
head.fill = end;
ret unsafe::reinterpret_cast(p);
return unsafe::reinterpret_cast(p);
}
}

View File

@ -100,11 +100,11 @@ impl of from_base64 for ~[u8] {
1u {
vec::push(r, ((n >> 16u) & 0xFFu) as u8);
vec::push(r, ((n >> 8u ) & 0xFFu) as u8);
ret copy r;
return copy r;
}
2u {
vec::push(r, ((n >> 10u) & 0xFFu) as u8);
ret copy r;
return copy r;
}
_ {
fail ~"invalid base64 padding";

View File

@ -143,7 +143,7 @@ class big_bitv {
fn equals(b: &big_bitv) -> bool {
let len = b.storage.len();
for uint::iterate(0, len) |i| {
if self.storage[i] != b.storage[i] { ret false; }
if self.storage[i] != b.storage[i] { return false; }
}
}
}
@ -287,7 +287,7 @@ class bitv {
*/
#[inline(always)]
fn equal(v1: bitv) -> bool {
if self.nbits != v1.nbits { ret false; }
if self.nbits != v1.nbits { return false; }
alt self.rep {
small(b) {
alt v1.rep {
@ -300,7 +300,7 @@ class bitv {
big(s1) {
s.equals(s1)
}
small(_) { ret false; }
small(_) { return false; }
}
}
}
@ -354,7 +354,7 @@ class bitv {
alt self.rep {
small(b) { b.is_true() }
_ {
for self.each() |i| { if !i { ret false; } }
for self.each() |i| { if !i { return false; } }
true
}
}
@ -375,14 +375,14 @@ class bitv {
alt self.rep {
small(b) { b.is_false() }
big(_) {
for self.each() |i| { if i { ret false; } }
for self.each() |i| { if i { return false; } }
true
}
}
}
fn init_to_vec(i: uint) -> uint {
ret if self.get(i) { 1 } else { 0 };
return if self.get(i) { 1 } else { 0 };
}
/**
@ -392,7 +392,7 @@ class bitv {
*/
fn to_vec() -> ~[uint] {
let sub = |x| self.init_to_vec(x);
ret vec::from_fn::<uint>(self.nbits, sub);
return vec::from_fn::<uint>(self.nbits, sub);
}
/**
@ -420,7 +420,7 @@ class bitv {
while i < self.nbits {
let w0 = self.get(i);
let w1 = v[i];
if !w0 && w1 != 0u || w0 && w1 == 0u { ret false; }
if !w0 && w1 != 0u || w0 && w1 == 0u { return false; }
i = i + 1;
}
true
@ -438,11 +438,11 @@ class bitv {
const uint_bits: uint = 32u + (1u << 32u >> 27u);
pure fn lor(w0: uint, w1: uint) -> uint { ret w0 | w1; }
pure fn lor(w0: uint, w1: uint) -> uint { return w0 | w1; }
pure fn land(w0: uint, w1: uint) -> uint { ret w0 & w1; }
pure fn land(w0: uint, w1: uint) -> uint { return w0 & w1; }
pure fn right(_w0: uint, w1: uint) -> uint { ret w1; }
pure fn right(_w0: uint, w1: uint) -> uint { return w1; }
impl extensions of ops::index<uint,bool> for bitv {
pure fn index(&&i: uint) -> bool {

View File

@ -66,7 +66,7 @@ class dtor_res {
* * len - The number of elements in the buffer
*/
unsafe fn c_vec<T>(base: *mut T, len: uint) -> c_vec<T> {
ret c_vec_({
return c_vec_({
base: base,
len: len,
rsrc: @dtor_res(option::none)
@ -86,7 +86,7 @@ unsafe fn c_vec<T>(base: *mut T, len: uint) -> c_vec<T> {
*/
unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
-> c_vec<T> {
ret c_vec_({
return c_vec_({
base: base,
len: len,
rsrc: @dtor_res(option::some(dtor))
@ -104,7 +104,7 @@ unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
*/
fn get<T: copy>(t: c_vec<T>, ofs: uint) -> T {
assert ofs < len(t);
ret unsafe { *ptr::mut_offset((*t).base, ofs) };
return unsafe { *ptr::mut_offset((*t).base, ofs) };
}
/**
@ -123,12 +123,12 @@ fn set<T: copy>(t: c_vec<T>, ofs: uint, v: T) {
/// Returns the length of the vector
fn len<T>(t: c_vec<T>) -> uint {
ret (*t).len;
return (*t).len;
}
/// Returns a pointer to the first element of the vector
unsafe fn ptr<T>(t: c_vec<T>) -> *mut T {
ret (*t).base;
return (*t).base;
}
#[cfg(test)]
@ -140,7 +140,7 @@ mod tests {
assert mem as int != 0;
ret unsafe { c_vec_with_dtor(mem as *mut u8, n as uint,
return unsafe { c_vec_with_dtor(mem as *mut u8, n as uint,
||free(mem)) };
}

View File

@ -8,19 +8,19 @@ trait fuzzy_eq {
impl fuzzy_eq of fuzzy_eq for float {
pure fn fuzzy_eq(&&other: float) -> bool {
ret float::abs(self - other) < fuzzy_epsilon;
return float::abs(self - other) < fuzzy_epsilon;
}
}
impl fuzzy_eq of fuzzy_eq for f32 {
pure fn fuzzy_eq(&&other: f32) -> bool {
ret f32::abs(self - other) < (fuzzy_epsilon as f32);
return f32::abs(self - other) < (fuzzy_epsilon as f32);
}
}
impl fuzzy_eq of fuzzy_eq for f64 {
pure fn fuzzy_eq(&&other: f64) -> bool {
ret f64::abs(self - other) < (fuzzy_epsilon as f64);
return f64::abs(self - other) < (fuzzy_epsilon as f64);
}
}

View File

@ -38,7 +38,7 @@ fn create<T: copy>() -> t<T> {
i += 1u;
}
ret rv;
return rv;
}
fn get<T: copy>(elts: dvec<cell<T>>, i: uint) -> T {
alt elts.get_elt(i) { some(t) { t } _ { fail } }
@ -50,7 +50,7 @@ fn create<T: copy>() -> t<T> {
elts: dvec<cell<T>>};
impl <T: copy> of t<T> for repr<T> {
fn size() -> uint { ret self.nelts; }
fn size() -> uint { return self.nelts; }
fn add_front(t: T) {
let oldlo: uint = self.lo;
if self.lo == 0u {
@ -83,7 +83,7 @@ fn create<T: copy>() -> t<T> {
self.elts.set_elt(self.lo, none);
self.lo = (self.lo + 1u) % self.elts.len();
self.nelts -= 1u;
ret t;
return t;
}
fn pop_back() -> T {
if self.hi == 0u {
@ -92,13 +92,13 @@ fn create<T: copy>() -> t<T> {
let t: T = get(self.elts, self.hi);
self.elts.set_elt(self.hi, none);
self.nelts -= 1u;
ret t;
return t;
}
fn peek_front() -> T { ret get(self.elts, self.lo); }
fn peek_back() -> T { ret get(self.elts, self.hi - 1u); }
fn peek_front() -> T { return get(self.elts, self.lo); }
fn peek_back() -> T { return get(self.elts, self.hi - 1u); }
fn get(i: int) -> T {
let idx = (self.lo + (i as uint)) % self.elts.len();
ret get(self.elts, idx);
return get(self.elts, idx);
}
}
@ -235,21 +235,25 @@ mod tests {
#[test]
fn test() {
fn inteq(&&a: int, &&b: int) -> bool { ret a == b; }
fn intboxeq(&&a: @int, &&b: @int) -> bool { ret a == b; }
fn inteq(&&a: int, &&b: int) -> bool { return a == b; }
fn intboxeq(&&a: @int, &&b: @int) -> bool { return a == b; }
fn taggyeq(a: taggy, b: taggy) -> bool {
alt a {
one(a1) { alt b { one(b1) { ret a1 == b1; } _ { ret false; } } }
one(a1) {
alt b { one(b1) {return a1 == b1; } _ { return false; } }
}
two(a1, a2) {
alt b {
two(b1, b2) { ret a1 == b1 && a2 == b2; }
_ { ret false; }
two(b1, b2) { return a1 == b1 && a2 == b2; }
_ { return false; }
}
}
three(a1, a2, a3) {
alt b {
three(b1, b2, b3) { ret a1 == b1 && a2 == b2 && a3 == b3; }
_ { ret false; }
three(b1, b2, b3) {
return a1 == b1 && a2 == b2 && a3 == b3;
}
_ { return false; }
}
}
}
@ -257,26 +261,28 @@ mod tests {
fn taggypareq<T>(a: taggypar<T>, b: taggypar<T>) -> bool {
alt a {
onepar::<T>(a1) {
alt b { onepar::<T>(b1) { ret a1 == b1; } _ { ret false; } }
alt b {
onepar::<T>(b1) { return a1 == b1; } _ { return false; }
}
}
twopar::<T>(a1, a2) {
alt b {
twopar::<T>(b1, b2) { ret a1 == b1 && a2 == b2; }
_ { ret false; }
twopar::<T>(b1, b2) { return a1 == b1 && a2 == b2; }
_ { return false; }
}
}
threepar::<T>(a1, a2, a3) {
alt b {
threepar::<T>(b1, b2, b3) {
ret a1 == b1 && a2 == b2 && a3 == b3;
return a1 == b1 && a2 == b2 && a3 == b3;
}
_ { ret false; }
_ { return false; }
}
}
}
}
fn reccyeq(a: reccy, b: reccy) -> bool {
ret a.x == b.x && a.y == b.y && taggyeq(a.t, b.t);
return a.x == b.x && a.y == b.y && taggyeq(a.t, b.t);
}
debug!{"*** test boxes"};
test_boxes(@5, @72, @64, @175);

View File

@ -63,19 +63,19 @@ impl extensions of ops::index<uint,doc> for doc {
fn vuint_at(data: &[u8], start: uint) -> {val: uint, next: uint} {
let a = data[start];
if a & 0x80u8 != 0u8 {
ret {val: (a & 0x7fu8) as uint, next: start + 1u};
return {val: (a & 0x7fu8) as uint, next: start + 1u};
}
if a & 0x40u8 != 0u8 {
ret {val: ((a & 0x3fu8) as uint) << 8u |
return {val: ((a & 0x3fu8) as uint) << 8u |
(data[start + 1u] as uint),
next: start + 2u};
} else if a & 0x20u8 != 0u8 {
ret {val: ((a & 0x1fu8) as uint) << 16u |
return {val: ((a & 0x1fu8) as uint) << 16u |
(data[start + 1u] as uint) << 8u |
(data[start + 2u] as uint),
next: start + 3u};
} else if a & 0x10u8 != 0u8 {
ret {val: ((a & 0x0fu8) as uint) << 24u |
return {val: ((a & 0x0fu8) as uint) << 24u |
(data[start + 1u] as uint) << 16u |
(data[start + 2u] as uint) << 8u |
(data[start + 3u] as uint),
@ -84,14 +84,14 @@ fn vuint_at(data: &[u8], start: uint) -> {val: uint, next: uint} {
}
fn doc(data: @~[u8]) -> doc {
ret {data: data, start: 0u, end: vec::len::<u8>(*data)};
return {data: data, start: 0u, end: vec::len::<u8>(*data)};
}
fn doc_at(data: @~[u8], start: uint) -> tagged_doc {
let elt_tag = vuint_at(*data, start);
let elt_size = vuint_at(*data, elt_tag.next);
let end = elt_size.next + elt_size.val;
ret {tag: elt_tag.val,
return {tag: elt_tag.val,
doc: {data: data, start: elt_size.next, end: end}};
}
@ -102,15 +102,19 @@ fn maybe_get_doc(d: doc, tg: uint) -> option<doc> {
let elt_size = vuint_at(*d.data, elt_tag.next);
pos = elt_size.next + elt_size.val;
if elt_tag.val == tg {
ret some::<doc>({data: d.data, start: elt_size.next, end: pos});
return some::<doc>({
data: d.data,
start: elt_size.next,
end: pos
});
}
}
ret none::<doc>;
return none::<doc>;
}
fn get_doc(d: doc, tg: uint) -> doc {
alt maybe_get_doc(d, tg) {
some(d) { ret d; }
some(d) { return d; }
none {
error!{"failed to find block with tag %u", tg};
fail;
@ -147,29 +151,29 @@ fn tagged_docs(d: doc, tg: uint, it: fn(doc) -> bool) {
fn doc_data(d: doc) -> ~[u8] { vec::slice::<u8>(*d.data, d.start, d.end) }
fn with_doc_data<T>(d: doc, f: fn(x: &[u8]) -> T) -> T {
ret f(vec::view(*d.data, d.start, d.end));
return f(vec::view(*d.data, d.start, d.end));
}
fn doc_as_str(d: doc) -> ~str { ret str::from_bytes(doc_data(d)); }
fn doc_as_str(d: doc) -> ~str { return str::from_bytes(doc_data(d)); }
fn doc_as_u8(d: doc) -> u8 {
assert d.end == d.start + 1u;
ret (*d.data)[d.start];
return (*d.data)[d.start];
}
fn doc_as_u16(d: doc) -> u16 {
assert d.end == d.start + 2u;
ret io::u64_from_be_bytes(*d.data, d.start, 2u) as u16;
return io::u64_from_be_bytes(*d.data, d.start, 2u) as u16;
}
fn doc_as_u32(d: doc) -> u32 {
assert d.end == d.start + 4u;
ret io::u64_from_be_bytes(*d.data, d.start, 4u) as u32;
return io::u64_from_be_bytes(*d.data, d.start, 4u) as u32;
}
fn doc_as_u64(d: doc) -> u64 {
assert d.end == d.start + 8u;
ret io::u64_from_be_bytes(*d.data, d.start, 8u);
return io::u64_from_be_bytes(*d.data, d.start, 8u);
}
fn doc_as_i8(d: doc) -> i8 { doc_as_u8(d) as i8 }
@ -205,16 +209,16 @@ fn write_sized_vuint(w: io::writer, n: uint, size: uint) {
}
fn write_vuint(w: io::writer, n: uint) {
if n < 0x7f_u { write_sized_vuint(w, n, 1u); ret; }
if n < 0x4000_u { write_sized_vuint(w, n, 2u); ret; }
if n < 0x200000_u { write_sized_vuint(w, n, 3u); ret; }
if n < 0x10000000_u { write_sized_vuint(w, n, 4u); ret; }
if n < 0x7f_u { write_sized_vuint(w, n, 1u); return; }
if n < 0x4000_u { write_sized_vuint(w, n, 2u); return; }
if n < 0x200000_u { write_sized_vuint(w, n, 3u); return; }
if n < 0x10000000_u { write_sized_vuint(w, n, 4u); return; }
fail fmt!{"vint to write too big: %?", n};
}
fn writer(w: io::writer) -> writer {
let size_positions: ~[uint] = ~[];
ret writer_({writer: w, mut size_positions: size_positions});
return writer_({writer: w, mut size_positions: size_positions});
}
// FIXME (#2741): Provide a function to write the standard ebml header.
@ -462,7 +466,7 @@ impl deserializer_priv for ebml_deserializer {
r_doc.end, self.parent.end};
}
self.pos = r_doc.end;
ret r_doc;
return r_doc;
}
fn push_doc<T: copy>(d: ebml::doc, f: fn() -> T) -> T{
@ -473,13 +477,13 @@ impl deserializer_priv for ebml_deserializer {
let r = f();
self.parent = old_parent;
self.pos = old_pos;
ret r;
return r;
}
fn _next_uint(exp_tag: ebml_serializer_tag) -> uint {
let r = ebml::doc_as_u32(self.next_doc(exp_tag));
debug!{"_next_uint exp_tag=%? result=%?", exp_tag, r};
ret r as uint;
return r as uint;
}
}
@ -495,7 +499,7 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
if v > (core::uint::max_value as u64) {
fail fmt!{"uint %? too large for this architecture", v};
}
ret v as uint;
return v as uint;
}
fn read_i64() -> i64 { ebml::doc_as_u64(self.next_doc(es_i64)) as i64 }
@ -507,7 +511,7 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
if v > (int::max_value as i64) || v < (int::min_value as i64) {
fail fmt!{"int %? out of range for this architecture", v};
}
ret v as int;
return v as int;
}
fn read_bool() -> bool { ebml::doc_as_u8(self.next_doc(es_bool)) as bool }

View File

@ -49,14 +49,14 @@
* };
* if opt_present(matches, "h") || opt_present(matches, "help") {
* print_usage(program);
* ret;
* return;
* }
* let output = opt_maybe_str(matches, "o");
* let input = if vec::is_not_empty(matches.free) {
* matches.free[0]
* } else {
* print_usage(program);
* ret;
* return;
* };
* do_work(input, output);
* }
@ -94,29 +94,29 @@ enum occur { req, optional, multi, }
type opt = {name: name, hasarg: hasarg, occur: occur};
fn mkname(nm: ~str) -> name {
ret if str::len(nm) == 1u {
return if str::len(nm) == 1u {
short(str::char_at(nm, 0u))
} else { long(nm) };
}
/// Create an option that is required and takes an argument
fn reqopt(name: ~str) -> opt {
ret {name: mkname(name), hasarg: yes, occur: req};
return {name: mkname(name), hasarg: yes, occur: req};
}
/// Create an option that is optional and takes an argument
fn optopt(name: ~str) -> opt {
ret {name: mkname(name), hasarg: yes, occur: optional};
return {name: mkname(name), hasarg: yes, occur: optional};
}
/// Create an option that is optional and does not take an argument
fn optflag(name: ~str) -> opt {
ret {name: mkname(name), hasarg: no, occur: optional};
return {name: mkname(name), hasarg: no, occur: optional};
}
/// Create an option that is optional and takes an optional argument
fn optflagopt(name: ~str) -> opt {
ret {name: mkname(name), hasarg: maybe, occur: optional};
return {name: mkname(name), hasarg: maybe, occur: optional};
}
/**
@ -124,7 +124,7 @@ fn optflagopt(name: ~str) -> opt {
* multiple times
*/
fn optmulti(name: ~str) -> opt {
ret {name: mkname(name), hasarg: yes, occur: multi};
return {name: mkname(name), hasarg: yes, occur: multi};
}
enum optval { val(~str), given, }
@ -136,11 +136,11 @@ enum optval { val(~str), given, }
type matches = {opts: ~[opt], vals: ~[~[optval]], free: ~[~str]};
fn is_arg(arg: ~str) -> bool {
ret str::len(arg) > 1u && arg[0] == '-' as u8;
return str::len(arg) > 1u && arg[0] == '-' as u8;
}
fn name_str(nm: name) -> ~str {
ret alt nm { short(ch) { str::from_char(ch) } long(s) { s } };
return alt nm { short(ch) { str::from_char(ch) } long(s) { s } };
}
fn find_opt(opts: ~[opt], nm: name) -> option<uint> {
@ -161,7 +161,7 @@ enum fail_ {
/// Convert a `fail_` enum into an error string
fn fail_str(f: fail_) -> ~str {
ret alt f {
return alt f {
argument_missing(nm) {
~"Argument to option '" + nm + ~"' missing."
}
@ -191,7 +191,7 @@ type result = result::result<matches, fail_>;
*/
fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
let n_opts = vec::len::<opt>(opts);
fn f(_x: uint) -> ~[optval] { ret ~[]; }
fn f(_x: uint) -> ~[optval] { return ~[]; }
let vals = vec::to_mut(vec::from_fn(n_opts, f));
let mut free: ~[~str] = ~[];
let l = vec::len(args);
@ -262,12 +262,12 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
name_pos += 1u;
let optid = alt find_opt(opts, nm) {
some(id) { id }
none { ret err(unrecognized_option(name_str(nm))); }
none { return err(unrecognized_option(name_str(nm))); }
};
alt opts[optid].hasarg {
no {
if !option::is_none::<~str>(i_arg) {
ret err(unexpected_argument(name_str(nm)));
return err(unexpected_argument(name_str(nm)));
}
vec::push(vals[optid], given);
}
@ -284,7 +284,7 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
vec::push(vals[optid],
val(option::get::<~str>(i_arg)));
} else if i + 1u == l {
ret err(argument_missing(name_str(nm)));
return err(argument_missing(name_str(nm)));
} else { i += 1u; vec::push(vals[optid], val(args[i])); }
}
}
@ -298,42 +298,42 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe {
let occ = opts[i].occur;
if occ == req {
if n == 0u {
ret err(option_missing(name_str(opts[i].name)));
return err(option_missing(name_str(opts[i].name)));
}
}
if occ != multi {
if n > 1u {
ret err(option_duplicated(name_str(opts[i].name)));
return err(option_duplicated(name_str(opts[i].name)));
}
}
i += 1u;
}
ret ok({opts: opts, vals: vec::from_mut(vals), free: free});
return ok({opts: opts, vals: vec::from_mut(vals), free: free});
}
fn opt_vals(m: matches, nm: ~str) -> ~[optval] {
ret alt find_opt(m.opts, mkname(nm)) {
return alt find_opt(m.opts, mkname(nm)) {
some(id) { m.vals[id] }
none { error!{"No option '%s' defined", nm}; fail }
};
}
fn opt_val(m: matches, nm: ~str) -> optval { ret opt_vals(m, nm)[0]; }
fn opt_val(m: matches, nm: ~str) -> optval { return opt_vals(m, nm)[0]; }
/// Returns true if an option was matched
fn opt_present(m: matches, nm: ~str) -> bool {
ret vec::len::<optval>(opt_vals(m, nm)) > 0u;
return vec::len::<optval>(opt_vals(m, nm)) > 0u;
}
/// Returns true if any of several options were matched
fn opts_present(m: matches, names: ~[~str]) -> bool {
for vec::each(names) |nm| {
alt find_opt(m.opts, mkname(nm)) {
some(_) { ret true; }
some(_) { return true; }
_ { }
}
}
ret false;
return false;
}
@ -344,7 +344,7 @@ fn opts_present(m: matches, names: ~[~str]) -> bool {
* argument
*/
fn opt_str(m: matches, nm: ~str) -> ~str {
ret alt opt_val(m, nm) { val(s) { s } _ { fail } };
return alt opt_val(m, nm) { val(s) { s } _ { fail } };
}
/**
@ -356,7 +356,7 @@ fn opt_str(m: matches, nm: ~str) -> ~str {
fn opts_str(m: matches, names: ~[~str]) -> ~str {
for vec::each(names) |nm| {
alt opt_val(m, nm) {
val(s) { ret s }
val(s) { return s }
_ { }
}
}
@ -375,14 +375,14 @@ fn opt_strs(m: matches, nm: ~str) -> ~[~str] {
for vec::each(opt_vals(m, nm)) |v| {
alt v { val(s) { vec::push(acc, s); } _ { } }
}
ret acc;
return acc;
}
/// Returns the string argument supplied to a matching option or none
fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> {
let vals = opt_vals(m, nm);
if vec::len::<optval>(vals) == 0u { ret none::<~str>; }
ret alt vals[0] { val(s) { some::<~str>(s) } _ { none::<~str> } };
if vec::len::<optval>(vals) == 0u { return none::<~str>; }
return alt vals[0] { val(s) { some::<~str>(s) } _ { none::<~str> } };
}
@ -395,8 +395,8 @@ fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> {
*/
fn opt_default(m: matches, nm: ~str, def: ~str) -> option<~str> {
let vals = opt_vals(m, nm);
if vec::len::<optval>(vals) == 0u { ret none::<~str>; }
ret alt vals[0] { val(s) { some::<~str>(s) } _ { some::<~str>(def) } }
if vec::len::<optval>(vals) == 0u { return none::<~str>; }
return alt vals[0] { val(s) { some::<~str>(s) } _ { some::<~str>(def) } }
}
#[cfg(test)]

View File

@ -68,7 +68,7 @@ fn to_writer(wr: io::writer, j: json) {
dict(d) {
if d.size() == 0u {
wr.write_str(~"{}");
ret;
return;
}
wr.write_str(~"{ ");
@ -168,7 +168,7 @@ impl parser for parser {
fn parse_value() -> result<json, error> {
self.parse_whitespace();
if self.eof() { ret self.error(~"EOF while parsing value"); }
if self.eof() { return self.error(~"EOF while parsing value"); }
alt self.ch {
'n' { self.parse_ident(~"ull", null) }
@ -210,20 +210,20 @@ impl parser for parser {
let mut res = alt self.parse_integer() {
ok(res) { res }
err(e) { ret err(e); }
err(e) { return err(e); }
};
if self.ch == '.' {
alt self.parse_decimal(res) {
ok(r) { res = r; }
err(e) { ret err(e); }
err(e) { return err(e); }
}
}
if self.ch == 'e' || self.ch == 'E' {
alt self.parse_exponent(res) {
ok(r) { res = r; }
err(e) { ret err(e); }
err(e) { return err(e); }
}
}
@ -239,7 +239,7 @@ impl parser for parser {
// There can be only one leading '0'.
alt self.ch {
'0' to '9' { ret self.error(~"invalid number"); }
'0' to '9' { return self.error(~"invalid number"); }
_ {}
}
}
@ -256,7 +256,7 @@ impl parser for parser {
}
}
}
_ { ret self.error(~"invalid number"); }
_ { return self.error(~"invalid number"); }
}
ok(res)
@ -268,7 +268,7 @@ impl parser for parser {
// Make sure a digit follows the decimal place.
alt self.ch {
'0' to '9' {}
_ { ret self.error(~"invalid number"); }
_ { return self.error(~"invalid number"); }
}
let mut res = res;
@ -304,7 +304,7 @@ impl parser for parser {
// Make sure a digit follows the exponent place.
alt self.ch {
'0' to '9' {}
_ { ret self.error(~"invalid number"); }
_ { return self.error(~"invalid number"); }
}
while !self.eof() {
@ -356,19 +356,19 @@ impl parser for parser {
n = n * 10u +
(self.ch as uint) - ('0' as uint);
}
_ { ret self.error(~"invalid \\u escape"); }
_ { return self.error(~"invalid \\u escape"); }
}
i += 1u;
}
// Error out if we didn't parse 4 digits.
if i != 4u {
ret self.error(~"invalid \\u escape");
return self.error(~"invalid \\u escape");
}
str::push_char(res, n as char);
}
_ { ret self.error(~"invalid escape"); }
_ { return self.error(~"invalid escape"); }
}
escape = false;
} else if self.ch == '\\' {
@ -376,7 +376,7 @@ impl parser for parser {
} else {
if self.ch == '"' {
self.bump();
ret ok(@res);
return ok(@res);
}
str::push_char(res, self.ch);
}
@ -393,24 +393,24 @@ impl parser for parser {
if self.ch == ']' {
self.bump();
ret ok(list(@values));
return ok(list(@values));
}
loop {
alt self.parse_value() {
ok(v) { vec::push(values, v); }
e { ret e; }
e { return e; }
}
self.parse_whitespace();
if self.eof() {
ret self.error(~"EOF while parsing list");
return self.error(~"EOF while parsing list");
}
alt self.ch {
',' { self.bump(); }
']' { self.bump(); ret ok(list(@values)); }
_ { ret self.error(~"expected `,` or `]`"); }
']' { self.bump(); return ok(list(@values)); }
_ { return self.error(~"expected `,` or `]`"); }
}
};
}
@ -423,46 +423,46 @@ impl parser for parser {
if self.ch == '}' {
self.bump();
ret ok(dict(values));
return ok(dict(values));
}
while !self.eof() {
self.parse_whitespace();
if self.ch != '"' {
ret self.error(~"key must be a string");
return self.error(~"key must be a string");
}
let key = alt self.parse_str() {
ok(key) { key }
err(e) { ret err(e); }
err(e) { return err(e); }
};
self.parse_whitespace();
if self.ch != ':' {
if self.eof() { break; }
ret self.error(~"expected `:`");
return self.error(~"expected `:`");
}
self.bump();
alt self.parse_value() {
ok(value) { values.insert(copy *key, value); }
e { ret e; }
e { return e; }
}
self.parse_whitespace();
alt self.ch {
',' { self.bump(); }
'}' { self.bump(); ret ok(dict(values)); }
'}' { self.bump(); return ok(dict(values)); }
_ {
if self.eof() { break; }
ret self.error(~"expected `,` or `}`");
return self.error(~"expected `,` or `}`");
}
}
}
ret self.error(~"EOF while parsing object");
return self.error(~"EOF while parsing object");
}
}

View File

@ -45,10 +45,10 @@ fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> option<T> {
loop {
ls = alt *ls {
cons(hd, tl) {
if f(hd) { ret some(hd); }
if f(hd) { return some(hd); }
tl
}
nil { ret none; }
nil { return none; }
}
};
}
@ -56,9 +56,9 @@ fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> option<T> {
/// Returns true if a list contains an element with the given value
fn has<T: copy>(ls: @list<T>, elt: T) -> bool {
for each(ls) |e| {
if e == elt { ret true; }
if e == elt { return true; }
}
ret false;
return false;
}
/// Returns true if the list is empty
@ -71,7 +71,7 @@ pure fn is_empty<T: copy>(ls: @list<T>) -> bool {
/// Returns true if the list is not empty
pure fn is_not_empty<T: copy>(ls: @list<T>) -> bool {
ret !is_empty(ls);
return !is_empty(ls);
}
/// Returns the length of a list
@ -84,7 +84,7 @@ fn len<T>(ls: @list<T>) -> uint {
/// Returns all but the first element of a list
pure fn tail<T: copy>(ls: @list<T>) -> @list<T> {
alt *ls {
cons(_, tl) { ret tl; }
cons(_, tl) { return tl; }
nil { fail ~"list empty" }
}
}
@ -97,8 +97,8 @@ pure fn head<T: copy>(ls: @list<T>) -> T {
/// Appends one list to another
pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> {
alt *l {
nil { ret m; }
cons(x, xs) { let rest = append(xs, m); ret @cons(x, rest); }
nil { return m; }
cons(x, xs) { let rest = append(xs, m); return @cons(x, rest); }
}
}
@ -127,7 +127,7 @@ fn each<T>(l: @list<T>, f: fn(T) -> bool) {
loop {
cur = alt *cur {
cons(hd, tl) {
if !f(hd) { ret; }
if !f(hd) { return; }
tl
}
nil { break; }
@ -174,7 +174,7 @@ mod tests {
#[test]
fn test_foldl() {
fn add(&&a: uint, &&b: int) -> uint { ret a + (b as uint); }
fn add(&&a: uint, &&b: int) -> uint { return a + (b as uint); }
let l = from_vec(~[0, 1, 2, 3, 4]);
let empty = @list::nil::<int>;
assert (list::foldl(0u, l, add) == 10u);
@ -192,14 +192,14 @@ mod tests {
#[test]
fn test_find_success() {
fn match_(&&i: int) -> bool { ret i == 2; }
fn match_(&&i: int) -> bool { return i == 2; }
let l = from_vec(~[0, 1, 2]);
assert (list::find(l, match_) == option::some(2));
}
#[test]
fn test_find_fail() {
fn match_(&&_i: int) -> bool { ret false; }
fn match_(&&_i: int) -> bool { return false; }
let l = from_vec(~[0, 1, 2]);
let empty = @list::nil::<int>;
assert (list::find(l, match_) == option::none::<int>);

View File

@ -124,7 +124,7 @@ mod chained {
absent {
debug!{"search_tbl: absent, comp %u, hash %u, idx %u",
comp, h, idx};
ret not_found;
return not_found;
}
present(e1) {
comp += 1u;
@ -132,7 +132,7 @@ mod chained {
debug!{"search_tbl: present, comp %u, \
hash %u, idx %u",
comp, h, idx};
ret found_after(e0, e1);
return found_after(e0, e1);
} else {
e0 = e1;
}
@ -147,15 +147,15 @@ mod chained {
absent {
debug!{"search_tbl: absent, comp %u, hash %u, idx %u",
0u, h, idx};
ret not_found;
return not_found;
}
present(e) {
if e.hash == h && self.eqer(e.key, k) {
debug!{"search_tbl: present, comp %u, hash %u, idx %u",
1u, h, idx};
ret found_first(idx, e);
return found_first(idx, e);
} else {
ret self.search_rem(k, h, idx, e);
return self.search_rem(k, h, idx, e);
}
}
}
@ -182,7 +182,7 @@ mod chained {
absent { break; }
present(entry) {
let next = entry.next;
if !blk(entry) { ret; }
if !blk(entry) { return; }
next
}
}
@ -224,15 +224,15 @@ mod chained {
self.rehash();
}
ret true;
return true;
}
found_first(_, entry) {
entry.value = v;
ret false;
return false;
}
found_after(_, entry) {
entry.value = v;
ret false
return false
}
}
}
@ -292,7 +292,7 @@ mod chained {
fn to_writer(wr: io::writer) {
if self.count == 0u {
wr.write_str("{}");
ret;
return;
}
wr.write_str("{ ");
@ -324,7 +324,7 @@ mod chained {
fn chains<K,V>(nchains: uint) -> ~[mut chain<K,V>] {
ret vec::to_mut(vec::from_elem(nchains, absent));
return vec::to_mut(vec::from_elem(nchains, absent));
}
fn mk<K, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>) -> t<K,V> {
@ -353,32 +353,32 @@ fn hashmap<K: const, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>)
/// Construct a hashmap for string keys
fn str_hash<V: copy>() -> hashmap<~str, V> {
ret hashmap(str::hash, str::eq);
return hashmap(str::hash, str::eq);
}
/// Construct a hashmap for boxed string keys
fn box_str_hash<V: copy>() -> hashmap<@~str, V> {
ret hashmap(|x: @~str| str::hash(*x), |x,y| str::eq(*x,*y));
return hashmap(|x: @~str| str::hash(*x), |x,y| str::eq(*x,*y));
}
/// Construct a hashmap for byte string keys
fn bytes_hash<V: copy>() -> hashmap<~[u8], V> {
ret hashmap(vec::u8::hash, vec::u8::eq);
return hashmap(vec::u8::hash, vec::u8::eq);
}
/// Construct a hashmap for int keys
fn int_hash<V: copy>() -> hashmap<int, V> {
ret hashmap(int::hash, int::eq);
return hashmap(int::hash, int::eq);
}
/// Construct a hashmap for uint keys
fn uint_hash<V: copy>() -> hashmap<uint, V> {
ret hashmap(uint::hash, uint::eq);
return hashmap(uint::hash, uint::eq);
}
/// Convenience function for adding keys to a hashmap with nil type keys
fn set_add<K: const copy>(set: set<K>, key: K) -> bool {
ret set.insert(key, ());
return set.insert(key, ());
}
/// Convert a set into a vector.
@ -428,7 +428,7 @@ mod tests {
#[test]
fn test_simple() {
debug!{"*** starting test_simple"};
fn eq_uint(&&x: uint, &&y: uint) -> bool { ret x == y; }
fn eq_uint(&&x: uint, &&y: uint) -> bool { return x == y; }
fn uint_id(&&x: uint) -> uint { x }
let hasher_uint: map::hashfn<uint> = uint_id;
let eqer_uint: map::eqfn<uint> = eq_uint;
@ -501,7 +501,7 @@ mod tests {
fn test_growth() {
debug!{"*** starting test_growth"};
let num_to_insert: uint = 64u;
fn eq_uint(&&x: uint, &&y: uint) -> bool { ret x == y; }
fn eq_uint(&&x: uint, &&y: uint) -> bool { return x == y; }
fn uint_id(&&x: uint) -> uint { x }
debug!{"uint -> uint"};
let hasher_uint: map::hashfn<uint> = uint_id;
@ -574,12 +574,12 @@ mod tests {
fn test_removal() {
debug!{"*** starting test_removal"};
let num_to_insert: uint = 64u;
fn eq(&&x: uint, &&y: uint) -> bool { ret x == y; }
fn eq(&&x: uint, &&y: uint) -> bool { return x == y; }
fn hash(&&u: uint) -> uint {
// This hash function intentionally causes collisions between
// consecutive integer pairs.
ret u / 2u * 2u;
return u / 2u * 2u;
}
assert (hash(0u) == hash(1u));
assert (hash(2u) == hash(3u));

View File

@ -79,7 +79,7 @@ fn md4(msg: ~[u8]) -> {a: u32, b: u32, c: u32, d: u32} {
a += aa; b += bb; c += cc; d += dd;
i += 64u;
}
ret {a: a, b: b, c: c, d: d};
return {a: a, b: b, c: c, d: d};
}
fn md4_str(msg: ~[u8]) -> ~str {

View File

@ -183,7 +183,7 @@ mod v4 {
let ip_rep_result = parse_to_ipv4_rep(ip);
if result::is_err(ip_rep_result) {
let err_str = result::get_err(ip_rep_result);
ret result::err({err_msg: err_str})
return result::err({err_msg: err_str})
}
// ipv4_rep.as_u32 is unsafe :/
let input_is_inaddr_none =
@ -196,11 +196,11 @@ mod v4 {
let ref_ip_rep_result = parse_to_ipv4_rep(reformatted_name);
if result::is_err(ref_ip_rep_result) {
let err_str = result::get_err(ref_ip_rep_result);
ret result::err({err_msg: err_str})
return result::err({err_msg: err_str})
}
if result::get(ref_ip_rep_result).as_u32() == INADDR_NONE &&
!input_is_inaddr_none {
ret result::err(
return result::err(
{err_msg: ~"uv_ip4_name produced invalid result."})
}
else {

View File

@ -779,7 +779,7 @@ impl tcp_socket_buf of io::reader for @tcp_socket_buf {
debug!{"ERROR sock_buf as io::reader.read err %? %?",
err_data.err_name, err_data.err_msg};
ret 0;
return 0;
}
}
else {
@ -1581,7 +1581,7 @@ mod test {
}
}
let ret_val = server_ch.recv();
log(debug, fmt!{"SERVER: exited and got ret val: '%s'", ret_val});
log(debug, fmt!{"SERVER: exited and got return val: '%s'", ret_val});
ret_val
}

View File

@ -31,9 +31,9 @@ fn userinfo(-user: ~str, -pass: option<~str>) -> userinfo {
fn split_char_first(s: ~str, c: char) -> (~str, ~str) {
let mut v = str::splitn_char(s, c, 1);
if v.len() == 1 {
ret (s, ~"");
return (s, ~"");
} else {
ret (vec::shift(v), vec::pop(v));
return (vec::shift(v), vec::pop(v));
}
}
@ -44,16 +44,16 @@ fn userinfo_from_str(uinfo: ~str) -> userinfo {
} else {
option::some(p)
};
ret userinfo(user, pass);
return userinfo(user, pass);
}
fn userinfo_to_str(-userinfo: userinfo) -> ~str {
if option::is_some(userinfo.pass) {
ret str::concat(~[copy userinfo.user, ~":",
return str::concat(~[copy userinfo.user, ~":",
option::unwrap(copy userinfo.pass),
~"@"]);
} else {
ret str::concat(~[copy userinfo.user, ~"@"]);
return str::concat(~[copy userinfo.user, ~"@"]);
}
}
@ -65,7 +65,7 @@ fn query_from_str(rawquery: ~str) -> query {
vec::push(query, (k, v));
};
}
ret query;
return query;
}
fn query_to_str(query: query) -> ~str {
@ -74,7 +74,7 @@ fn query_to_str(query: query) -> ~str {
let (k, v) = kv;
strvec += ~[fmt!{"%s=%s", k, v}];
};
ret str::connect(strvec, ~"&");
return str::connect(strvec, ~"&");
}
fn get_scheme(rawurl: ~str) -> option::option<(~str, ~str)> {
@ -82,13 +82,13 @@ fn get_scheme(rawurl: ~str) -> option::option<(~str, ~str)> {
if char::is_alphabetic(c) {
again;
} else if c == ':' && i != 0 {
ret option::some((rawurl.slice(0,i),
return option::some((rawurl.slice(0,i),
rawurl.slice(i+3,str::len(rawurl))));
} else {
ret option::none;
return option::none;
}
};
ret option::none;
return option::none;
}
/**
@ -107,7 +107,7 @@ fn get_scheme(rawurl: ~str) -> option::option<(~str, ~str)> {
fn from_str(rawurl: ~str) -> result::result<url, ~str> {
let mut schm = get_scheme(rawurl);
if option::is_none(schm) {
ret result::err(~"invalid scheme");
return result::err(~"invalid scheme");
}
let (scheme, rest) = option::unwrap(schm);
let (u, rest) = split_char_first(rest, '@');
@ -135,7 +135,7 @@ fn from_str(rawurl: ~str) -> result::result<url, ~str> {
str::unshift_char(path, '/');
}
ret result::ok(url(scheme, user, host, path, query, fragment));
return result::ok(url(scheme, user, host, path, query, fragment));
}
/**
@ -170,7 +170,7 @@ fn to_str(url: url) -> ~str {
~""
};
ret str::concat(~[copy url.scheme,
return str::concat(~[copy url.scheme,
~"://",
user,
copy url.host,

View File

@ -33,7 +33,7 @@ type rope = node::root;
/// Create an empty rope
fn empty() -> rope {
ret node::empty;
return node::empty;
}
/**
@ -54,7 +54,7 @@ fn empty() -> rope {
* * the function runs in linear time.
*/
fn of_str(str: @~str) -> rope {
ret of_substr(str, 0u, str::len(*str));
return of_substr(str, 0u, str::len(*str));
}
/**
@ -80,9 +80,9 @@ fn of_str(str: @~str) -> rope {
* * this function fails if `byte_offset` or `byte_len` do not match `str`.
*/
fn of_substr(str: @~str, byte_offset: uint, byte_len: uint) -> rope {
if byte_len == 0u { ret node::empty; }
if byte_len == 0u { return node::empty; }
if byte_offset + byte_len > str::len(*str) { fail; }
ret node::content(node::of_substr(str, byte_offset, byte_len));
return node::content(node::of_substr(str, byte_offset, byte_len));
}
/*
@ -97,7 +97,7 @@ Section: Adding things to a rope
* * this function executes in near-constant time
*/
fn append_char(rope: rope, char: char) -> rope {
ret append_str(rope, @str::from_chars(~[char]));
return append_str(rope, @str::from_chars(~[char]));
}
/**
@ -108,7 +108,7 @@ fn append_char(rope: rope, char: char) -> rope {
* * this function executes in near-linear time
*/
fn append_str(rope: rope, str: @~str) -> rope {
ret append_rope(rope, of_str(str))
return append_rope(rope, of_str(str))
}
/**
@ -118,7 +118,7 @@ fn append_str(rope: rope, str: @~str) -> rope {
* * this function executes in near-constant time
*/
fn prepend_char(rope: rope, char: char) -> rope {
ret prepend_str(rope, @str::from_chars(~[char]));
return prepend_str(rope, @str::from_chars(~[char]));
}
/**
@ -128,18 +128,18 @@ fn prepend_char(rope: rope, char: char) -> rope {
* * this function executes in near-linear time
*/
fn prepend_str(rope: rope, str: @~str) -> rope {
ret append_rope(of_str(str), rope)
return append_rope(of_str(str), rope)
}
/// Concatenate two ropes
fn append_rope(left: rope, right: rope) -> rope {
alt(left) {
node::empty { ret right; }
node::empty { return right; }
node::content(left_content) {
alt(right) {
node::empty { ret left; }
node::empty { return left; }
node::content(right_content) {
ret node::content(node::concat2(left_content, right_content));
return node::content(node::concat2(left_content, right_content));
}
}
}
@ -156,7 +156,7 @@ fn append_rope(left: rope, right: rope) -> rope {
fn concat(v: ~[rope]) -> rope {
//Copy `v` into a mut vector
let mut len = vec::len(v);
if len == 0u { ret node::empty; }
if len == 0u { return node::empty; }
let ropes = vec::to_mut(vec::from_elem(len, v[0]));
for uint::range(1u, len) |i| {
ropes[i] = v[i];
@ -176,7 +176,7 @@ fn concat(v: ~[rope]) -> rope {
}
//Return final rope
ret ropes[0];
return ropes[0];
}
@ -198,7 +198,7 @@ Section: Keeping ropes healthy
*/
fn bal(rope:rope) -> rope {
alt(rope) {
node::empty { ret rope }
node::empty { return rope }
node::content(x) {
alt(node::bal(x)) {
option::none { rope }
@ -227,13 +227,13 @@ Section: Transforming ropes
* valid positions in rope
*/
fn sub_chars(rope: rope, char_offset: uint, char_len: uint) -> rope {
if char_len == 0u { ret node::empty; }
if char_len == 0u { return node::empty; }
alt(rope) {
node::empty { fail }
node::content(node) {
if char_len > node::char_len(node) { fail }
else {
ret node::content(node::sub_chars(node, char_offset, char_len))
return node::content(node::sub_chars(node, char_offset, char_len))
}
}
}
@ -253,13 +253,13 @@ fn sub_chars(rope: rope, char_offset: uint, char_len: uint) -> rope {
* valid positions in rope
*/
fn sub_bytes(rope: rope, byte_offset: uint, byte_len: uint) -> rope {
if byte_len == 0u { ret node::empty; }
if byte_len == 0u { return node::empty; }
alt(rope) {
node::empty { fail }
node::content(node) {
if byte_len > node::byte_len(node) { fail }
else {
ret node::content(node::sub_bytes(node, byte_offset, byte_len))
return node::content(node::sub_bytes(node, byte_offset, byte_len))
}
}
}
@ -281,11 +281,11 @@ Section: Comparing ropes
*/
fn cmp(left: rope, right: rope) -> int {
alt((left, right)) {
(node::empty, node::empty) { ret 0; }
(node::empty, _) { ret -1;}
(_, node::empty) { ret 1;}
(node::empty, node::empty) { return 0; }
(node::empty, _) { return -1;}
(_, node::empty) { return 1;}
(node::content(a), node::content(b)) {
ret node::cmp(a, b);
return node::cmp(a, b);
}
}
}
@ -295,7 +295,7 @@ fn cmp(left: rope, right: rope) -> int {
* their structure), `false` otherwise
*/
fn eq(left: rope, right: rope) -> bool {
ret cmp(left, right) == 0;
return cmp(left, right) == 0;
}
/**
@ -310,7 +310,7 @@ fn eq(left: rope, right: rope) -> bool {
* structure), `false` otherwise
*/
fn le(left: rope, right: rope) -> bool {
ret cmp(left, right) <= 0;
return cmp(left, right) <= 0;
}
/**
@ -325,7 +325,7 @@ fn le(left: rope, right: rope) -> bool {
* structure), `false` otherwise
*/
fn lt(left: rope, right: rope) -> bool {
ret cmp(left, right) < 0;
return cmp(left, right) < 0;
}
/**
@ -340,7 +340,7 @@ fn lt(left: rope, right: rope) -> bool {
* structure), `false` otherwise
*/
fn ge(left: rope, right: rope) -> bool {
ret cmp(left, right) >= 0;
return cmp(left, right) >= 0;
}
/**
@ -355,7 +355,7 @@ fn ge(left: rope, right: rope) -> bool {
* structure), `false` otherwise
*/
fn gt(left: rope, right: rope) -> bool {
ret cmp(left, right) > 0;
return cmp(left, right) > 0;
}
/*
@ -384,8 +384,8 @@ Section: Iterating
*/
fn loop_chars(rope: rope, it: fn(char) -> bool) -> bool {
alt(rope) {
node::empty { ret true }
node::content(x) { ret node::loop_chars(x, it) }
node::empty { return true }
node::content(x) { return node::loop_chars(x, it) }
}
}
@ -427,8 +427,8 @@ fn iter_chars(rope: rope, it: fn(char)) {
*/
fn loop_leaves(rope: rope, it: fn(node::leaf) -> bool) -> bool{
alt(rope) {
node::empty { ret true }
node::content(x) {ret node::loop_leaves(x, it)}
node::empty { return true }
node::content(x) {return node::loop_leaves(x, it)}
}
}
@ -436,23 +436,23 @@ mod iterator {
mod leaf {
fn start(rope: rope) -> node::leaf_iterator::t {
alt(rope) {
node::empty { ret node::leaf_iterator::empty() }
node::content(x) { ret node::leaf_iterator::start(x) }
node::empty { return node::leaf_iterator::empty() }
node::content(x) { return node::leaf_iterator::start(x) }
}
}
fn next(it: node::leaf_iterator::t) -> option<node::leaf> {
ret node::leaf_iterator::next(it);
return node::leaf_iterator::next(it);
}
}
mod char {
fn start(rope: rope) -> node::char_iterator::t {
alt(rope) {
node::empty { ret node::char_iterator::empty() }
node::content(x) { ret node::char_iterator::start(x) }
node::empty { return node::char_iterator::empty() }
node::content(x) { return node::char_iterator::start(x) }
}
}
fn next(it: node::char_iterator::t) -> option<char> {
ret node::char_iterator::next(it)
return node::char_iterator::next(it)
}
}
}
@ -474,8 +474,8 @@ mod iterator {
*/
fn height(rope: rope) -> uint {
alt(rope) {
node::empty { ret 0u; }
node::content(x) { ret node::height(x); }
node::empty { return 0u; }
node::content(x) { return node::height(x); }
}
}
@ -490,8 +490,8 @@ fn height(rope: rope) -> uint {
*/
pure fn char_len(rope: rope) -> uint {
alt(rope) {
node::empty { ret 0u; }
node::content(x) { ret node::char_len(x) }
node::empty { return 0u; }
node::content(x) { return node::char_len(x) }
}
}
@ -504,8 +504,8 @@ pure fn char_len(rope: rope) -> uint {
*/
pure fn byte_len(rope: rope) -> uint {
alt(rope) {
node::empty { ret 0u; }
node::content(x) { ret node::byte_len(x) }
node::empty { return 0u; }
node::content(x) { return node::byte_len(x) }
}
}
@ -528,7 +528,7 @@ pure fn byte_len(rope: rope) -> uint {
fn char_at(rope: rope, pos: uint) -> char {
alt(rope) {
node::empty { fail }
node::content(x) { ret node::char_at(x, pos) }
node::content(x) { return node::char_at(x, pos) }
}
}
@ -628,7 +628,7 @@ mod node {
* the length of `str`.
*/
fn of_str(str: @~str) -> @node {
ret of_substr(str, 0u, str::len(*str));
return of_substr(str, 0u, str::len(*str));
}
/**
@ -649,7 +649,7 @@ mod node {
* valid positions in `str`
*/
fn of_substr(str: @~str, byte_start: uint, byte_len: uint) -> @node {
ret of_substr_unsafer(str, byte_start, byte_len,
return of_substr_unsafer(str, byte_start, byte_len,
str::count_chars(*str, byte_start, byte_len));
}
@ -683,7 +683,7 @@ mod node {
char_len: char_len,
content: str});
if char_len <= hint_max_leaf_char_len {
ret candidate;
return candidate;
} else {
//Firstly, split `str` in slices of hint_max_leaf_char_len
let mut leaves = uint::div_ceil(char_len, hint_max_leaf_char_len);
@ -728,22 +728,22 @@ mod node {
}
leaves = uint::div_ceil(leaves, 2u);
}
ret nodes[0u];
return nodes[0u];
}
}
pure fn byte_len(node: @node) -> uint {
//FIXME (#2744): Could we do this without the pattern-matching?
alt(*node) {
leaf(y) { ret y.byte_len; }
concat(y){ ret y.byte_len; }
leaf(y) { return y.byte_len; }
concat(y){ return y.byte_len; }
}
}
pure fn char_len(node: @node) -> uint {
alt(*node) {
leaf(y) { ret y.char_len; }
concat(y) { ret y.char_len; }
leaf(y) { return y.char_len; }
concat(y) { return y.char_len; }
}
}
@ -796,7 +796,7 @@ mod node {
}
len = uint::div_ceil(len, 2u);
}
ret forest[0];
return forest[0];
}
fn serialize_node(node: @node) -> ~str unsafe {
@ -820,7 +820,7 @@ mod node {
}
}
}
ret unsafe::transmute(buf);
return unsafe::transmute(buf);
}
/**
@ -832,9 +832,9 @@ mod node {
*/
fn flatten(node: @node) -> @node unsafe {
alt(*node) {
leaf(_) { ret node }
leaf(_) { return node }
concat(x) {
ret @leaf({
return @leaf({
byte_offset: 0u,
byte_len: x.byte_len,
char_len: x.char_len,
@ -860,7 +860,7 @@ mod node {
* as `node` bot lower height and/or fragmentation.
*/
fn bal(node: @node) -> option<@node> {
if height(node) < hint_max_node_height { ret option::none; }
if height(node) < hint_max_node_height { return option::none; }
//1. Gather all leaves as a forest
let mut forest = ~[mut];
let it = leaf_iterator::start(node);
@ -872,7 +872,7 @@ mod node {
}
//2. Rebuild tree from forest
let root = @*tree_from_forest_destructive(forest);
ret option::some(root);
return option::some(root);
}
@ -900,13 +900,13 @@ mod node {
let mut byte_offset = byte_offset;
loop {
if byte_offset == 0u && byte_len == node::byte_len(node) {
ret node;
return node;
}
alt(*node) {
node::leaf(x) {
let char_len =
str::count_chars(*x.content, byte_offset, byte_len);
ret @leaf({byte_offset: byte_offset,
return @leaf({byte_offset: byte_offset,
byte_len: byte_len,
char_len: char_len,
content: x.content});
@ -925,7 +925,7 @@ mod node {
sub_bytes(x.left, byte_offset, left_len);
let right_result =
sub_bytes(x.right, 0u, left_len - byte_offset);
ret concat2(left_result, right_result);
return concat2(left_result, right_result);
}
} else {
//Case 3: Everything fits in x.right
@ -963,19 +963,19 @@ mod node {
alt(*node) {
node::leaf(x) {
if char_offset == 0u && char_len == x.char_len {
ret node;
return node;
}
let byte_offset =
str::count_bytes(*x.content, 0u, char_offset);
let byte_len =
str::count_bytes(*x.content, byte_offset, char_len);
ret @leaf({byte_offset: byte_offset,
return @leaf({byte_offset: byte_offset,
byte_len: byte_len,
char_len: char_len,
content: x.content});
}
node::concat(x) {
if char_offset == 0u && char_len == x.char_len {ret node;}
if char_offset == 0u && char_len == x.char_len {return node;}
let left_len : uint = node::char_len(x.left);
if char_offset <= left_len {
if char_offset + char_len <= left_len {
@ -989,7 +989,7 @@ mod node {
sub_chars(x.left, char_offset, left_len);
let right_result =
sub_chars(x.right, 0u, left_len - char_offset);
ret concat2(left_result, right_result);
return concat2(left_result, right_result);
}
} else {
//Case 3: Everything fits in x.right, tail call
@ -1002,7 +1002,7 @@ mod node {
}
fn concat2(left: @node, right: @node) -> @node {
ret @concat({left : left,
return @concat({left : left,
right : right,
char_len: char_len(left) + char_len(right),
byte_len: byte_len(left) + byte_len(right),
@ -1012,8 +1012,8 @@ mod node {
fn height(node: @node) -> uint {
alt(*node) {
leaf(_) { ret 0u; }
concat(x) { ret x.height; }
leaf(_) { return 0u; }
concat(x) { return x.height; }
}
}
@ -1037,11 +1037,11 @@ mod node {
}
}
}
ret result;
return result;
}
fn loop_chars(node: @node, it: fn(char) -> bool) -> bool {
ret loop_leaves(node,|leaf| {
return loop_leaves(node,|leaf| {
str::all_between(*leaf.content,
leaf.byte_offset,
leaf.byte_len, it)
@ -1067,13 +1067,13 @@ mod node {
loop {
alt(*current) {
leaf(x) {
ret it(x);
return it(x);
}
concat(x) {
if loop_leaves(x.left, it) { //non tail call
current = x.right; //tail call
} else {
ret false;
return false;
}
}
}
@ -1103,7 +1103,7 @@ mod node {
loop {
alt *node {
leaf(x) {
ret str::char_at(*x.content, pos);
return str::char_at(*x.content, pos);
}
concat({left, right, _}) {
let left_len = char_len(left);
@ -1122,19 +1122,19 @@ mod node {
fn empty() -> t {
let stack : ~[mut @node] = ~[mut];
ret {stack: stack, mut stackpos: -1}
return {stack: stack, mut stackpos: -1}
}
fn start(node: @node) -> t {
let stack = vec::to_mut(vec::from_elem(height(node)+1u, node));
ret {
return {
stack: stack,
mut stackpos: 0
}
}
fn next(it: t) -> option<leaf> {
if it.stackpos < 0 { ret option::none; }
if it.stackpos < 0 { return option::none; }
loop {
let current = it.stack[it.stackpos];
it.stackpos -= 1;
@ -1146,7 +1146,7 @@ mod node {
it.stack[it.stackpos] = x.left;
}
leaf(x) {
ret option::some(x);
return option::some(x);
}
}
};
@ -1161,7 +1161,7 @@ mod node {
};
fn start(node: @node) -> t {
ret {
return {
leaf_iterator: leaf_iterator::start(node),
mut leaf: option::none,
mut leaf_byte_pos: 0u
@ -1169,7 +1169,7 @@ mod node {
}
fn empty() -> t {
ret {
return {
leaf_iterator: leaf_iterator::empty(),
mut leaf: option::none,
mut leaf_byte_pos: 0u
@ -1179,7 +1179,7 @@ mod node {
fn next(it: t) -> option<char> {
loop {
alt(get_current_or_next_leaf(it)) {
option::none { ret option::none; }
option::none { return option::none; }
option::some(_) {
let next_char = get_next_char_in_leaf(it);
alt(next_char) {
@ -1187,7 +1187,7 @@ mod node {
again;
}
option::some(_) {
ret next_char;
return next_char;
}
}
}
@ -1197,15 +1197,15 @@ mod node {
fn get_current_or_next_leaf(it: t) -> option<leaf> {
alt(it.leaf) {
option::some(_) { ret it.leaf }
option::some(_) { return it.leaf }
option::none {
let next = leaf_iterator::next(it.leaf_iterator);
alt(next) {
option::none { ret option::none }
option::none { return option::none }
option::some(_) {
it.leaf = next;
it.leaf_byte_pos = 0u;
ret next;
return next;
}
}
}
@ -1214,18 +1214,18 @@ mod node {
fn get_next_char_in_leaf(it: t) -> option<char> {
alt copy it.leaf {
option::none { ret option::none }
option::none { return option::none }
option::some(aleaf) {
if it.leaf_byte_pos >= aleaf.byte_len {
//We are actually past the end of the leaf
it.leaf = option::none;
ret option::none
return option::none
} else {
let {ch, next} =
str::char_range_at(*aleaf.content,
it.leaf_byte_pos + aleaf.byte_offset);
it.leaf_byte_pos = next - aleaf.byte_offset;
ret option::some(ch)
return option::some(ch)
}
}
}
@ -1239,7 +1239,7 @@ mod tests {
//Utility function, used for sanity check
fn rope_to_string(r: rope) -> ~str {
alt(r) {
node::empty { ret ~"" }
node::empty { return ~"" }
node::content(x) {
let str = @mut ~"";
fn aux(str: @mut ~str, node: @node::node) unsafe {
@ -1256,7 +1256,7 @@ mod tests {
}
}
aux(str, x);
ret *str
return *str
}
}
}

View File

@ -155,7 +155,7 @@ fn sha1() -> sha1 {
st.msg_block_idx = 0u;
}
fn circular_shift(bits: u32, word: u32) -> u32 {
ret word << bits | word >> 32u32 - bits;
return word << bits | word >> 32u32 - bits;
}
fn mk_result(st: sha1state) -> ~[u8] {
if !st.computed { pad_msg(st); st.computed = true; }
@ -167,7 +167,7 @@ fn sha1() -> sha1 {
let d = (hpart & 0xFFu32) as u8;
rs = vec::append(rs, ~[a, b, c, d]);
}
ret rs;
return rs;
}
/*
@ -233,12 +233,12 @@ fn sha1() -> sha1 {
}
fn input(msg: ~[u8]) { add_input(self, msg); }
fn input_str(msg: ~str) { add_input(self, str::bytes(msg)); }
fn result() -> ~[u8] { ret mk_result(self); }
fn result() -> ~[u8] { return mk_result(self); }
fn result_str() -> ~str {
let r = mk_result(self);
let mut s = ~"";
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
ret s;
return s;
}
}
let st = {
@ -252,7 +252,7 @@ fn sha1() -> sha1 {
};
let sh = st as sha1;
sh.reset();
ret sh;
return sh;
}
#[cfg(test)]
@ -266,7 +266,7 @@ mod tests {
let mut i = 0;
let mut rs = ~"";
while i < 100000 { str::push_str(rs, ~"aaaaaaaaaa"); i += 1; }
ret rs;
return rs;
}
// Test messages from FIPS 180-1

View File

@ -18,7 +18,7 @@ enum smallintmap<T:copy> {
/// Create a smallintmap
fn mk<T: copy>() -> smallintmap<T> {
let v = dvec();
ret smallintmap_(@{v: v});
return smallintmap_(@{v: v});
}
/**
@ -36,8 +36,8 @@ fn insert<T: copy>(self: smallintmap<T>, key: uint, val: T) {
* in the map then returns none
*/
pure fn find<T: copy>(self: smallintmap<T>, key: uint) -> option<T> {
if key < self.v.len() { ret self.v.get_elt(key); }
ret none::<T>;
if key < self.v.len() { return self.v.get_elt(key); }
return none::<T>;
}
/**
@ -50,13 +50,13 @@ pure fn find<T: copy>(self: smallintmap<T>, key: uint) -> option<T> {
pure fn get<T: copy>(self: smallintmap<T>, key: uint) -> T {
alt find(self, key) {
none { error!{"smallintmap::get(): key not present"}; fail; }
some(v) { ret v; }
some(v) { return v; }
}
}
/// Returns true if the map contains a value for the specified key
fn contains_key<T: copy>(self: smallintmap<T>, key: uint) -> bool {
ret !option::is_none(find(self, key));
return !option::is_none(find(self, key));
}
/// Implements the map::map interface for smallintmap
@ -72,10 +72,10 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn insert(+key: uint, +value: V) -> bool {
let exists = contains_key(self, key);
insert(self, key, value);
ret !exists;
return !exists;
}
fn remove(&&key: uint) -> option<V> {
if key >= self.v.len() { ret none; }
if key >= self.v.len() { return none; }
let old = self.v.get_elt(key);
self.v.set_elt(key, none);
old
@ -105,7 +105,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn each_key(it: fn(&&uint) -> bool) {
let mut idx = 0u, l = self.v.len();
while idx < l {
if self.v.get_elt(idx) != none && !it(idx) { ret; }
if self.v.get_elt(idx) != none && !it(idx) { return; }
idx += 1u;
}
}

View File

@ -18,7 +18,7 @@ type le<T> = fn(T, T) -> bool;
fn merge_sort<T: copy>(le: le<T>, v: ~[const T]) -> ~[T] {
type slice = (uint, uint);
ret merge_sort_(le, v, (0u, len(v)));
return merge_sort_(le, v, (0u, len(v)));
fn merge_sort_<T: copy>(le: le<T>, v: ~[const T], slice: slice)
-> ~[T] {
@ -26,13 +26,13 @@ fn merge_sort<T: copy>(le: le<T>, v: ~[const T]) -> ~[T] {
let end = slice.second();
let v_len = end - begin;
if v_len == 0u { ret ~[]; }
if v_len == 1u { ret ~[v[begin]]; }
if v_len == 0u { return ~[]; }
if v_len == 1u { return ~[v[begin]]; }
let mid = v_len / 2u + begin;
let a = (begin, mid);
let b = (mid, end);
ret merge(le, merge_sort_(le, v, a), merge_sort_(le, v, b));
return merge(le, merge_sort_(le, v, a), merge_sort_(le, v, b));
}
fn merge<T: copy>(le: le<T>, a: ~[T], b: ~[T]) -> ~[T] {
@ -50,7 +50,7 @@ fn merge_sort<T: copy>(le: le<T>, v: ~[const T]) -> ~[T] {
}
rs = vec::append(rs, vec::slice(a, a_ix, a_len));
rs = vec::append(rs, vec::slice(b, b_ix, b_len));
ret rs;
return rs;
}
}
@ -68,7 +68,7 @@ fn part<T: copy>(compare_func: le<T>, arr: ~[mut T], left: uint,
i += 1u;
}
arr[storage_index] <-> arr[right];
ret storage_index;
return storage_index;
}
fn qsort<T: copy>(compare_func: le<T>, arr: ~[mut T], left: uint,
@ -91,13 +91,13 @@ fn qsort<T: copy>(compare_func: le<T>, arr: ~[mut T], left: uint,
* This is an unstable sort.
*/
fn quick_sort<T: copy>(compare_func: le<T>, arr: ~[mut T]) {
if len::<T>(arr) == 0u { ret; }
if len::<T>(arr) == 0u { return; }
qsort::<T>(compare_func, arr, 0u, len::<T>(arr) - 1u);
}
fn qsort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
arr: ~[mut T], left: int, right: int) {
if right <= left { ret; }
if right <= left { return; }
let v: T = arr[right];
let mut i: int = left - 1;
let mut j: int = right;
@ -154,7 +154,7 @@ fn qsort3<T: copy>(compare_func_lt: le<T>, compare_func_eq: le<T>,
* This is an unstable sort.
*/
fn quick_sort3<T: copy ord eq>(arr: ~[mut T]) {
if len::<T>(arr) == 0u { ret; }
if len::<T>(arr) == 0u { return; }
qsort3::<T>(|x, y| x.lt(y), |x, y| x.eq(y), arr, 0,
(len::<T>(arr) as int) - 1);
}
@ -202,7 +202,7 @@ mod test_qsort3 {
mod test_qsort {
fn check_sort(v1: ~[mut int], v2: ~[mut int]) {
let len = vec::len::<int>(v1);
fn leual(&&a: int, &&b: int) -> bool { ret a <= b; }
fn leual(&&a: int, &&b: int) -> bool { return a <= b; }
let f = leual;
quick_sort::<int>(f, v1);
let mut i = 0u;
@ -264,7 +264,7 @@ mod tests {
fn check_sort(v1: ~[int], v2: ~[int]) {
let len = vec::len::<int>(v1);
fn le(&&a: int, &&b: int) -> bool { ret a <= b; }
fn le(&&a: int, &&b: int) -> bool { return a <= b; }
let f = le;
let v3 = merge_sort::<int>(f, v1);
let mut i = 0u;
@ -294,7 +294,7 @@ mod tests {
#[test]
fn test_merge_sort_mutable() {
fn le(&&a: int, &&b: int) -> bool { ret a <= b; }
fn le(&&a: int, &&b: int) -> bool { return a <= b; }
let v1 = ~[mut 3, 2, 1];
let v2 = merge_sort(le, v1);
assert v2 == ~[1, 2, 3];

View File

@ -11,11 +11,11 @@ fn mkdtemp(prefix: ~str, suffix: ~str) -> option<~str> {
while (i < 1000u) {
let s = prefix + r.gen_str(16u) + suffix;
if os::make_dir(s, 0x1c0i32) { // FIXME: u+rwx (#2349)
ret some(s);
return some(s);
}
i += 1u;
}
ret none;
return none;
}
#[test]

View File

@ -35,10 +35,10 @@ fn reset(writer: io::writer) {
fn color_supported() -> bool {
let supported_terms = ~[~"xterm-color", ~"xterm",
~"screen-bce", ~"xterm-256color"];
ret alt os::getenv(~"TERM") {
return alt os::getenv(~"TERM") {
option::some(env) {
for vec::each(supported_terms) |term| {
if str::eq(term, env) { ret true; }
if str::eq(term, env) { return true; }
}
false
}
@ -56,12 +56,12 @@ fn set_color(writer: io::writer, first_char: u8, color: u8) {
/// Set the foreground color
fn fg(writer: io::writer, color: u8) {
ret set_color(writer, '3' as u8, color);
return set_color(writer, '3' as u8, color);
}
/// Set the background color
fn bg(writer: io::writer, color: u8) {
ret set_color(writer, '4' as u8, color);
return set_color(writer, '4' as u8, color);
}
// Local Variables:

View File

@ -71,7 +71,7 @@ fn parse_opts(args: ~[~str]) -> opt_res {
let matches =
alt getopts::getopts(args_, opts) {
ok(m) { m }
err(f) { ret either::right(getopts::fail_str(f)) }
err(f) { return either::right(getopts::fail_str(f)) }
};
let filter =
@ -85,7 +85,7 @@ fn parse_opts(args: ~[~str]) -> opt_res {
let test_opts = {filter: filter, run_ignored: run_ignored,
logfile: logfile};
ret either::left(test_opts);
return either::left(test_opts);
}
enum test_result { tr_ok, tr_failed, tr_ignored, }
@ -180,7 +180,7 @@ fn run_tests_console(opts: test_opts,
st.out.write_str(fmt!{". %u passed; %u failed; %u ignored\n\n", st.passed,
st.failed, st.ignored});
ret success;
return success;
fn write_log(out: io::writer, result: test_result, test: test_desc) {
out.write_line(fmt!{"%s %s",
@ -262,7 +262,7 @@ fn should_sort_failures_before_printing_them() {
assert apos < bpos;
}
fn use_color() -> bool { ret get_concurrency() == 1u; }
fn use_color() -> bool { return get_concurrency() == 1u; }
enum testevent {
te_filtered(~[test_desc]),
@ -346,8 +346,8 @@ fn filter_tests(opts: test_opts,
fn filter_fn(test: test_desc, filter_str: ~str) ->
option<test_desc> {
if str::contains(test.name, filter_str) {
ret option::some(copy test);
} else { ret option::none; }
return option::some(copy test);
} else { return option::none; }
}
let filter = |x| filter_fn(x, filter_str);
@ -361,11 +361,11 @@ fn filter_tests(opts: test_opts,
} else {
fn filter(test: test_desc) -> option<test_desc> {
if test.ignore {
ret option::some({name: test.name,
return option::some({name: test.name,
fn: copy test.fn,
ignore: false,
should_fail: test.should_fail});
} else { ret option::none; }
} else { return option::none; }
};
vec::filter_map(filtered, |x| filter(x))
@ -380,7 +380,7 @@ fn filter_tests(opts: test_opts,
sort::merge_sort(|x,y| lteq(x, y), filtered)
};
ret filtered;
return filtered;
}
type test_future = {test: test_desc, wait: fn@() -> test_result};
@ -388,7 +388,7 @@ type test_future = {test: test_desc, wait: fn@() -> test_result};
fn run_test(+test: test_desc, monitor_ch: comm::chan<monitor_msg>) {
if test.ignore {
comm::send(monitor_ch, (copy test, tr_ignored));
ret;
return;
}
do task::spawn {

View File

@ -40,7 +40,7 @@ fn get_time() -> timespec {
let mut sec = 0i64;
let mut nsec = 0i32;
rustrt::get_time(sec, nsec);
ret {sec: sec, nsec: nsec};
return {sec: sec, nsec: nsec};
}
/**
@ -58,7 +58,7 @@ fn precise_time_ns() -> u64 {
* in seconds since an unspecified epoch.
*/
fn precise_time_s() -> float {
ret (precise_time_ns() as float) / 1000000000.;
return (precise_time_ns() as float) / 1000000000.;
}
fn tzset() {
@ -148,11 +148,11 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
let mut i = pos;
for str::each(needle) |ch| {
if s[i] != ch {
ret false;
return false;
}
i += 1u;
}
ret true;
return true;
}
fn match_strs(s: ~str, pos: uint, strs: ~[(~str, i32)])
@ -163,7 +163,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
let (needle, value) = strs[i];
if match_str(s, pos, needle) {
ret some((value, pos + str::len(needle)));
return some((value, pos + str::len(needle)));
}
i += 1u;
}
@ -186,7 +186,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
value = value * 10_i32 + (ch as i32 - '0' as i32);
}
' ' if ws { }
_ { ret none; }
_ { return none; }
}
i += 1u;
}

View File

@ -36,7 +36,7 @@ fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
mut value: v,
mut left: none,
mut right: none}));
ret;
return;
}
some(node) {
if k == node.key {

View File

@ -160,12 +160,12 @@ mod icu {
}
pure fn is_XID_start(c: char) -> bool {
ret icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
== icu::TRUE;
}
pure fn is_XID_continue(c: char) -> bool {
ret icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
return icu::libicu::u_hasBinaryProperty(c, icu::UCHAR_XID_START)
== icu::TRUE;
}
@ -175,7 +175,7 @@ Function: is_digit
Returns true if a character is a digit.
*/
pure fn is_digit(c: char) -> bool {
ret icu::libicu::u_isdigit(c) == icu::TRUE;
return icu::libicu::u_isdigit(c) == icu::TRUE;
}
/*
@ -184,7 +184,7 @@ Function: is_lower
Returns true if a character is a lowercase letter.
*/
pure fn is_lower(c: char) -> bool {
ret icu::libicu::u_islower(c) == icu::TRUE;
return icu::libicu::u_islower(c) == icu::TRUE;
}
/*
@ -193,7 +193,7 @@ Function: is_space
Returns true if a character is space.
*/
pure fn is_space(c: char) -> bool {
ret icu::libicu::u_isspace(c) == icu::TRUE;
return icu::libicu::u_isspace(c) == icu::TRUE;
}
/*
@ -202,7 +202,7 @@ Function: is_upper
Returns true if a character is an uppercase letter.
*/
pure fn is_upper(c: char) -> bool {
ret icu::libicu::u_isupper(c) == icu::TRUE;
return icu::libicu::u_isupper(c) == icu::TRUE;
}
#[cfg(test)]

View File

@ -28,7 +28,7 @@ extern mod rustrt {
* loop.
*/
fn get() -> iotask {
ret get_monitor_task_gl();
return get_monitor_task_gl();
}
#[doc(hidden)]

View File

@ -213,7 +213,7 @@ mod test {
run_loop(iotask_ch);
exit_ch.send(());
};
ret comm::recv(iotask_port);
return comm::recv(iotask_port);
}
extern fn lifetime_handle_close(handle: *libc::c_void) unsafe {

View File

@ -303,15 +303,15 @@ type uv_getaddrinfo_t = {
mod uv_ll_struct_stubgen {
fn gen_stub_uv_tcp_t() -> uv_tcp_t {
ret gen_stub_os();
return gen_stub_os();
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
fn gen_stub_os() -> uv_tcp_t {
ret gen_stub_arch();
return gen_stub_arch();
#[cfg(target_arch="x86_64")]
fn gen_stub_arch() -> uv_tcp_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -336,7 +336,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(target_arch="x86")]
fn gen_stub_arch() -> uv_tcp_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -364,7 +364,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(windows)]
fn gen_stub_os() -> uv_tcp_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -385,7 +385,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(unix)]
fn gen_stub_uv_connect_t() -> uv_connect_t {
ret {
return {
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
a03: 0 as *u8,
a04: 0 as *u8, a05: 0 as *u8
@ -393,7 +393,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(windows)]
fn gen_stub_uv_connect_t() -> uv_connect_t {
ret {
return {
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
a03: 0 as *u8,
a04: 0 as *u8, a05: 0 as *u8, a06: 0 as *u8,
@ -403,10 +403,10 @@ mod uv_ll_struct_stubgen {
}
#[cfg(unix)]
fn gen_stub_uv_async_t() -> uv_async_t {
ret gen_stub_arch();
return gen_stub_arch();
#[cfg(target_arch = "x86_64")]
fn gen_stub_arch() -> uv_async_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -421,7 +421,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(target_arch = "x86")]
fn gen_stub_arch() -> uv_async_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -438,7 +438,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(windows)]
fn gen_stub_uv_async_t() -> uv_async_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -452,10 +452,10 @@ mod uv_ll_struct_stubgen {
}
#[cfg(unix)]
fn gen_stub_uv_timer_t() -> uv_timer_t {
ret gen_stub_arch();
return gen_stub_arch();
#[cfg(target_arch = "x86_64")]
fn gen_stub_arch() -> uv_timer_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -470,7 +470,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(target_arch = "x86")]
fn gen_stub_arch() -> uv_timer_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -489,7 +489,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(windows)]
fn gen_stub_uv_timer_t() -> uv_timer_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -502,10 +502,10 @@ mod uv_ll_struct_stubgen {
}
#[cfg(unix)]
fn gen_stub_uv_write_t() -> uv_write_t {
ret gen_stub_arch();
return gen_stub_arch();
#[cfg(target_arch="x86_64")]
fn gen_stub_arch() -> uv_write_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -519,7 +519,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(target_arch="x86")]
fn gen_stub_arch() -> uv_write_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -534,7 +534,7 @@ mod uv_ll_struct_stubgen {
}
#[cfg(windows)]
fn gen_stub_uv_write_t() -> uv_write_t {
ret { fields: { loop_handle: ptr::null(), type_: 0u32,
return { fields: { loop_handle: ptr::null(), type_: 0u32,
close_cb: ptr::null(),
mut data: ptr::null() },
a00: 0 as *u8, a01: 0 as *u8, a02: 0 as *u8,
@ -676,7 +676,7 @@ extern mod rustrt {
}
unsafe fn loop_new() -> *libc::c_void {
ret rustrt::rust_uv_loop_new();
return rustrt::rust_uv_loop_new();
}
unsafe fn loop_delete(loop_handle: *libc::c_void) {
@ -684,7 +684,7 @@ unsafe fn loop_delete(loop_handle: *libc::c_void) {
}
unsafe fn loop_refcount(loop_ptr: *libc::c_void) -> libc::c_int {
ret rustrt::rust_uv_loop_refcount(loop_ptr);
return rustrt::rust_uv_loop_refcount(loop_ptr);
}
unsafe fn run(loop_handle: *libc::c_void) {
@ -697,7 +697,7 @@ unsafe fn close<T>(handle: *T, cb: *u8) {
unsafe fn tcp_init(loop_handle: *libc::c_void, handle: *uv_tcp_t)
-> libc::c_int {
ret rustrt::rust_uv_tcp_init(loop_handle, handle);
return rustrt::rust_uv_tcp_init(loop_handle, handle);
}
// FIXME ref #2064
unsafe fn tcp_connect(connect_ptr: *uv_connect_t,
@ -707,7 +707,7 @@ unsafe fn tcp_connect(connect_ptr: *uv_connect_t,
-> libc::c_int {
log(debug, fmt!{"b4 foreign tcp_connect--addr port: %u cb: %u",
(*addr_ptr).sin_port as uint, after_connect_cb as uint});
ret rustrt::rust_uv_tcp_connect(connect_ptr, tcp_handle_ptr,
return rustrt::rust_uv_tcp_connect(connect_ptr, tcp_handle_ptr,
after_connect_cb, addr_ptr);
}
// FIXME ref #2064
@ -716,30 +716,30 @@ unsafe fn tcp_connect6(connect_ptr: *uv_connect_t,
addr_ptr: *sockaddr_in6,
++after_connect_cb: *u8)
-> libc::c_int {
ret rustrt::rust_uv_tcp_connect6(connect_ptr, tcp_handle_ptr,
return rustrt::rust_uv_tcp_connect6(connect_ptr, tcp_handle_ptr,
after_connect_cb, addr_ptr);
}
// FIXME ref #2064
unsafe fn tcp_bind(tcp_server_ptr: *uv_tcp_t,
addr_ptr: *sockaddr_in) -> libc::c_int {
ret rustrt::rust_uv_tcp_bind(tcp_server_ptr,
return rustrt::rust_uv_tcp_bind(tcp_server_ptr,
addr_ptr);
}
// FIXME ref #2064
unsafe fn tcp_bind6(tcp_server_ptr: *uv_tcp_t,
addr_ptr: *sockaddr_in6) -> libc::c_int {
ret rustrt::rust_uv_tcp_bind6(tcp_server_ptr,
return rustrt::rust_uv_tcp_bind6(tcp_server_ptr,
addr_ptr);
}
unsafe fn listen<T>(stream: *T, backlog: libc::c_int,
cb: *u8) -> libc::c_int {
ret rustrt::rust_uv_listen(stream as *libc::c_void, backlog, cb);
return rustrt::rust_uv_listen(stream as *libc::c_void, backlog, cb);
}
unsafe fn accept(server: *libc::c_void, client: *libc::c_void)
-> libc::c_int {
ret rustrt::rust_uv_accept(server as *libc::c_void,
return rustrt::rust_uv_accept(server as *libc::c_void,
client as *libc::c_void);
}
@ -747,41 +747,41 @@ unsafe fn write<T>(req: *uv_write_t, stream: *T,
buf_in: *~[uv_buf_t], cb: *u8) -> libc::c_int {
let buf_ptr = vec::unsafe::to_ptr(*buf_in);
let buf_cnt = vec::len(*buf_in) as i32;
ret rustrt::rust_uv_write(req as *libc::c_void,
return rustrt::rust_uv_write(req as *libc::c_void,
stream as *libc::c_void,
buf_ptr, buf_cnt, cb);
}
unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8,
on_read: *u8) -> libc::c_int {
ret rustrt::rust_uv_read_start(stream as *libc::c_void,
return rustrt::rust_uv_read_start(stream as *libc::c_void,
on_alloc, on_read);
}
unsafe fn read_stop(stream: *uv_stream_t) -> libc::c_int {
ret rustrt::rust_uv_read_stop(stream as *libc::c_void);
return rustrt::rust_uv_read_stop(stream as *libc::c_void);
}
unsafe fn last_error(loop_handle: *libc::c_void) -> uv_err_t {
ret rustrt::rust_uv_last_error(loop_handle);
return rustrt::rust_uv_last_error(loop_handle);
}
unsafe fn strerror(err: *uv_err_t) -> *libc::c_char {
ret rustrt::rust_uv_strerror(err);
return rustrt::rust_uv_strerror(err);
}
unsafe fn err_name(err: *uv_err_t) -> *libc::c_char {
ret rustrt::rust_uv_err_name(err);
return rustrt::rust_uv_err_name(err);
}
unsafe fn async_init(loop_handle: *libc::c_void,
async_handle: *uv_async_t,
cb: *u8) -> libc::c_int {
ret rustrt::rust_uv_async_init(loop_handle,
return rustrt::rust_uv_async_init(loop_handle,
async_handle,
cb);
}
unsafe fn async_send(async_handle: *uv_async_t) {
ret rustrt::rust_uv_async_send(async_handle);
return rustrt::rust_uv_async_send(async_handle);
}
unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t {
let out_buf = { base: ptr::null(), len: 0 as libc::size_t };
@ -800,8 +800,8 @@ unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t {
log(debug, fmt!{"buf_init - result %u len %u",
res_base as uint,
res_len as uint});
ret out_buf;
//ret result;
return out_buf;
//return result;
}
unsafe fn ip4_addr(ip: ~str, port: int)
-> sockaddr_in {
@ -860,15 +860,15 @@ unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
unsafe fn timer_init(loop_ptr: *libc::c_void,
timer_ptr: *uv_timer_t) -> libc::c_int {
ret rustrt::rust_uv_timer_init(loop_ptr, timer_ptr);
return rustrt::rust_uv_timer_init(loop_ptr, timer_ptr);
}
unsafe fn timer_start(timer_ptr: *uv_timer_t, cb: *u8, timeout: uint,
repeat: uint) -> libc::c_int {
ret rustrt::rust_uv_timer_start(timer_ptr, cb, timeout as libc::c_uint,
return rustrt::rust_uv_timer_start(timer_ptr, cb, timeout as libc::c_uint,
repeat as libc::c_uint);
}
unsafe fn timer_stop(timer_ptr: *uv_timer_t) -> libc::c_int {
ret rustrt::rust_uv_timer_stop(timer_ptr);
return rustrt::rust_uv_timer_stop(timer_ptr);
}
unsafe fn getaddrinfo(loop_ptr: *libc::c_void,
handle: *uv_getaddrinfo_t,
@ -889,38 +889,38 @@ unsafe fn freeaddrinfo(res: *addrinfo) {
// libuv struct initializers
unsafe fn tcp_t() -> uv_tcp_t {
ret uv_ll_struct_stubgen::gen_stub_uv_tcp_t();
return uv_ll_struct_stubgen::gen_stub_uv_tcp_t();
}
unsafe fn connect_t() -> uv_connect_t {
ret uv_ll_struct_stubgen::gen_stub_uv_connect_t();
return uv_ll_struct_stubgen::gen_stub_uv_connect_t();
}
unsafe fn write_t() -> uv_write_t {
ret uv_ll_struct_stubgen::gen_stub_uv_write_t();
return uv_ll_struct_stubgen::gen_stub_uv_write_t();
}
unsafe fn async_t() -> uv_async_t {
ret uv_ll_struct_stubgen::gen_stub_uv_async_t();
return uv_ll_struct_stubgen::gen_stub_uv_async_t();
}
unsafe fn timer_t() -> uv_timer_t {
ret uv_ll_struct_stubgen::gen_stub_uv_timer_t();
return uv_ll_struct_stubgen::gen_stub_uv_timer_t();
}
unsafe fn getaddrinfo_t() -> uv_getaddrinfo_t {
ret uv_ll_struct_stubgen::gen_stub_uv_getaddrinfo_t();
return uv_ll_struct_stubgen::gen_stub_uv_getaddrinfo_t();
}
// data access helpers
unsafe fn get_loop_for_uv_handle<T>(handle: *T)
-> *libc::c_void {
ret rustrt::rust_uv_get_loop_for_uv_handle(handle as *libc::c_void);
return rustrt::rust_uv_get_loop_for_uv_handle(handle as *libc::c_void);
}
unsafe fn get_stream_handle_from_connect_req(connect: *uv_connect_t)
-> *uv_stream_t {
ret rustrt::rust_uv_get_stream_handle_from_connect_req(
return rustrt::rust_uv_get_stream_handle_from_connect_req(
connect);
}
unsafe fn get_stream_handle_from_write_req(
write_req: *uv_write_t)
-> *uv_stream_t {
ret rustrt::rust_uv_get_stream_handle_from_write_req(
return rustrt::rust_uv_get_stream_handle_from_write_req(
write_req);
}
unsafe fn get_data_for_uv_loop(loop_ptr: *libc::c_void) -> *libc::c_void {
@ -930,7 +930,7 @@ unsafe fn set_data_for_uv_loop(loop_ptr: *libc::c_void, data: *libc::c_void) {
rustrt::rust_uv_set_data_for_uv_loop(loop_ptr, data);
}
unsafe fn get_data_for_uv_handle<T>(handle: *T) -> *libc::c_void {
ret rustrt::rust_uv_get_data_for_uv_handle(handle as *libc::c_void);
return rustrt::rust_uv_get_data_for_uv_handle(handle as *libc::c_void);
}
unsafe fn set_data_for_uv_handle<T, U>(handle: *T,
data: *U) {
@ -938,7 +938,7 @@ unsafe fn set_data_for_uv_handle<T, U>(handle: *T,
data as *libc::c_void);
}
unsafe fn get_data_for_req<T>(req: *T) -> *libc::c_void {
ret rustrt::rust_uv_get_data_for_req(req as *libc::c_void);
return rustrt::rust_uv_get_data_for_req(req as *libc::c_void);
}
unsafe fn set_data_for_req<T, U>(req: *T,
data: *U) {
@ -946,14 +946,14 @@ unsafe fn set_data_for_req<T, U>(req: *T,
data as *libc::c_void);
}
unsafe fn get_base_from_buf(buf: uv_buf_t) -> *u8 {
ret rustrt::rust_uv_get_base_from_buf(buf);
return rustrt::rust_uv_get_base_from_buf(buf);
}
unsafe fn get_len_from_buf(buf: uv_buf_t) -> libc::size_t {
ret rustrt::rust_uv_get_len_from_buf(buf);
return rustrt::rust_uv_get_len_from_buf(buf);
}
unsafe fn malloc_buf_base_of(suggested_size: libc::size_t)
-> *u8 {
ret rustrt::rust_uv_malloc_buf_base_of(suggested_size);
return rustrt::rust_uv_malloc_buf_base_of(suggested_size);
}
unsafe fn free_base_of_buf(buf: uv_buf_t) {
rustrt::rust_uv_free_base_of_buf(buf);
@ -964,7 +964,7 @@ unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str {
let err_ptr = ptr::addr_of(err);
let err_name = str::unsafe::from_c_str(err_name(err_ptr));
let err_msg = str::unsafe::from_c_str(strerror(err_ptr));
ret fmt!{"LIBUV ERROR: name: %s msg: %s",
return fmt!{"LIBUV ERROR: name: %s msg: %s",
err_name, err_msg};
}
@ -1028,7 +1028,7 @@ mod test {
handle,
char_ptr as uint,
suggested_size as uint});
ret buf_init(char_ptr, suggested_size as uint);
return buf_init(char_ptr, suggested_size as uint);
}
extern fn on_read_cb(stream: *uv_stream_t,
@ -1277,7 +1277,7 @@ mod test {
let err_msg = get_last_err_info(test_loop);
log(debug, fmt!{"server_connect_cb: non-zero status: %?",
err_msg});
ret;
return;
}
let server_data = get_data_for_uv_handle(
server_stream_ptr as *libc::c_void) as *tcp_server_data;

View File

@ -61,7 +61,7 @@ fn extend(cx: ctx, +elt: ident) -> @path {
}
fn mk_ast_map_visitor() -> vt {
ret visit::mk_vt(@{
return visit::mk_vt(@{
visit_item: map_item,
visit_expr: map_expr,
visit_fn: map_fn,
@ -79,7 +79,7 @@ fn map_crate(diag: span_handler, c: crate) -> map {
mut local_id: 0u,
diag: diag};
visit::visit_crate(c, cx, mk_ast_map_visitor());
ret cx.map;
return cx.map;
}
// Used for items loaded from external crate that are being inlined into this

View File

@ -19,7 +19,7 @@ pure fn mk_sp(lo: uint, hi: uint) -> span {
}
// make this a const, once the compiler supports it
pure fn dummy_sp() -> span { ret mk_sp(0u, 0u); }
pure fn dummy_sp() -> span { return mk_sp(0u, 0u); }
pure fn path_name(p: @path) -> ~str { path_name_i(p.idents) }
@ -44,7 +44,7 @@ pure fn stmt_id(s: stmt) -> node_id {
fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} {
alt d { def_variant(enum_id, var_id) {
ret {enm: enum_id, var: var_id}; }
return {enm: enum_id, var: var_id}; }
_ { fail ~"non-variant in variant_def_ids"; } }
}
@ -66,40 +66,40 @@ pure fn def_id_of_def(d: def) -> def_id {
pure fn binop_to_str(op: binop) -> ~str {
alt op {
add { ret ~"+"; }
subtract { ret ~"-"; }
mul { ret ~"*"; }
div { ret ~"/"; }
rem { ret ~"%"; }
and { ret ~"&&"; }
or { ret ~"||"; }
bitxor { ret ~"^"; }
bitand { ret ~"&"; }
bitor { ret ~"|"; }
shl { ret ~"<<"; }
shr { ret ~">>"; }
eq { ret ~"=="; }
lt { ret ~"<"; }
le { ret ~"<="; }
ne { ret ~"!="; }
ge { ret ~">="; }
gt { ret ~">"; }
add { return ~"+"; }
subtract { return ~"-"; }
mul { return ~"*"; }
div { return ~"/"; }
rem { return ~"%"; }
and { return ~"&&"; }
or { return ~"||"; }
bitxor { return ~"^"; }
bitand { return ~"&"; }
bitor { return ~"|"; }
shl { return ~"<<"; }
shr { return ~">>"; }
eq { return ~"=="; }
lt { return ~"<"; }
le { return ~"<="; }
ne { return ~"!="; }
ge { return ~">="; }
gt { return ~">"; }
}
}
pure fn binop_to_method_name(op: binop) -> option<~str> {
alt op {
add { ret some(~"add"); }
subtract { ret some(~"sub"); }
mul { ret some(~"mul"); }
div { ret some(~"div"); }
rem { ret some(~"modulo"); }
bitxor { ret some(~"bitxor"); }
bitand { ret some(~"bitand"); }
bitor { ret some(~"bitor"); }
shl { ret some(~"shl"); }
shr { ret some(~"shr"); }
and | or | eq | lt | le | ne | ge | gt { ret none; }
add { return some(~"add"); }
subtract { return some(~"sub"); }
mul { return some(~"mul"); }
div { return some(~"div"); }
rem { return some(~"modulo"); }
bitxor { return some(~"bitxor"); }
bitand { return some(~"bitand"); }
bitor { return some(~"bitor"); }
shl { return some(~"shl"); }
shr { return some(~"shr"); }
and | or | eq | lt | le | ne | ge | gt { return none; }
}
}
@ -117,16 +117,16 @@ pure fn is_shift_binop(b: binop) -> bool {
pure fn unop_to_str(op: unop) -> ~str {
alt op {
box(mt) { if mt == m_mutbl { ret ~"@mut "; } ret ~"@"; }
uniq(mt) { if mt == m_mutbl { ret ~"~mut "; } ret ~"~"; }
deref { ret ~"*"; }
not { ret ~"!"; }
neg { ret ~"-"; }
box(mt) { if mt == m_mutbl { ~"@mut " } else { ~"@" } }
uniq(mt) { if mt == m_mutbl { ~"~mut " } else { ~"~" } }
deref { ~"*" }
not { ~"!" }
neg { ~"-" }
}
}
pure fn is_path(e: @expr) -> bool {
ret alt e.node { expr_path(_) { true } _ { false } };
return alt e.node { expr_path(_) { true } _ { false } };
}
pure fn int_ty_to_str(t: int_ty) -> ~str {
@ -192,10 +192,10 @@ fn is_exported(i: ident, m: _mod) -> bool {
for vps.each |vp| {
alt vp.node {
ast::view_path_simple(id, _, _) {
if id == i { ret true; }
if id == i { return true; }
alt parent_enum {
some(parent_enum_id) {
if id == parent_enum_id { ret true; }
if id == parent_enum_id { return true; }
}
_ {}
}
@ -203,9 +203,9 @@ fn is_exported(i: ident, m: _mod) -> bool {
ast::view_path_list(path, ids, _) {
if vec::len(path.idents) == 1u {
if i == path.idents[0] { ret true; }
if i == path.idents[0] { return true; }
for ids.each |id| {
if id.node.name == i { ret true; }
if id.node.name == i { return true; }
}
} else {
fail ~"export of path-qualified list";
@ -223,40 +223,40 @@ fn is_exported(i: ident, m: _mod) -> bool {
// If there are no declared exports then
// everything not imported is exported
// even if it's local (since it's explicit)
ret !has_explicit_exports && local;
return !has_explicit_exports && local;
}
pure fn is_call_expr(e: @expr) -> bool {
alt e.node { expr_call(_, _, _) { true } _ { false } }
}
fn eq_ty(&&a: @ty, &&b: @ty) -> bool { ret box::ptr_eq(a, b); }
fn eq_ty(&&a: @ty, &&b: @ty) -> bool { return box::ptr_eq(a, b); }
fn hash_ty(&&t: @ty) -> uint {
let res = (t.span.lo << 16u) + t.span.hi;
ret res;
return res;
}
fn def_eq(a: ast::def_id, b: ast::def_id) -> bool {
ret a.crate == b.crate && a.node == b.node;
return a.crate == b.crate && a.node == b.node;
}
fn hash_def(d: ast::def_id) -> uint {
let mut h = 5381u;
h = (h << 5u) + h ^ (d.crate as uint);
h = (h << 5u) + h ^ (d.node as uint);
ret h;
return h;
}
fn new_def_hash<V: copy>() -> std::map::hashmap<ast::def_id, V> {
let hasher: std::map::hashfn<ast::def_id> = hash_def;
let eqer: std::map::eqfn<ast::def_id> = def_eq;
ret std::map::hashmap::<ast::def_id, V>(hasher, eqer);
return std::map::hashmap::<ast::def_id, V>(hasher, eqer);
}
fn block_from_expr(e: @expr) -> blk {
let blk_ = default_block(~[], option::some::<@expr>(e), e.id);
ret {node: blk_, span: e.span};
return {node: blk_, span: e.span};
}
fn default_block(+stmts1: ~[@stmt], expr1: option<@expr>, id1: node_id) ->
@ -551,7 +551,7 @@ fn compute_id_range(visit_ids_fn: fn(fn@(node_id))) -> id_range {
*min = int::min(*min, id);
*max = int::max(*max, id + 1);
}
ret {min:*min, max:*max};
return {min:*min, max:*max};
}
fn compute_id_range_for_inlined_item(item: inlined_item) -> id_range {

View File

@ -52,25 +52,25 @@ export require_unique_names;
fn mk_name_value_item_str(+name: ast::ident, +value: ~str) ->
@ast::meta_item {
let value_lit = dummy_spanned(ast::lit_str(@value));
ret mk_name_value_item(name, value_lit);
return mk_name_value_item(name, value_lit);
}
fn mk_name_value_item(+name: ast::ident, +value: ast::lit)
-> @ast::meta_item {
ret @dummy_spanned(ast::meta_name_value(name, value));
return @dummy_spanned(ast::meta_name_value(name, value));
}
fn mk_list_item(+name: ast::ident, +items: ~[@ast::meta_item]) ->
@ast::meta_item {
ret @dummy_spanned(ast::meta_list(name, items));
return @dummy_spanned(ast::meta_list(name, items));
}
fn mk_word_item(+name: ast::ident) -> @ast::meta_item {
ret @dummy_spanned(ast::meta_word(name));
return @dummy_spanned(ast::meta_word(name));
}
fn mk_attr(item: @ast::meta_item) -> ast::attribute {
ret dummy_spanned({style: ast::attr_inner, value: *item,
return dummy_spanned({style: ast::attr_inner, value: *item,
is_sugared_doc: false});
}
@ -81,7 +81,7 @@ fn mk_sugared_doc_attr(text: ~str, lo: uint, hi: uint) -> ast::attribute {
value: spanned(lo, hi, ast::meta_name_value(@~"doc", lit)),
is_sugared_doc: true
};
ret spanned(lo, hi, attr);
return spanned(lo, hi, attr);
}
/* Conversion */
@ -92,7 +92,7 @@ fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value }
fn attr_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
let mut mitems = ~[];
for attrs.each |a| { vec::push(mitems, attr_meta(a)); }
ret mitems;
return mitems;
}
fn desugar_doc_attr(attr: ast::attribute) -> ast::attribute {
@ -100,7 +100,7 @@ fn desugar_doc_attr(attr: ast::attribute) -> ast::attribute {
let comment = get_meta_item_value_str(@attr.node.value).get();
let meta = mk_name_value_item_str(@~"doc",
strip_doc_comment_decoration(*comment));
ret mk_attr(meta);
return mk_attr(meta);
} else {
attr
}
@ -178,7 +178,7 @@ fn find_attrs_by_name(attrs: ~[ast::attribute], +name: ~str) ->
} else { option::none }
}
);
ret vec::filter_map(attrs, filter);
return vec::filter_map(attrs, filter);
}
/// Searcha list of meta items and return only those with a specific name
@ -189,7 +189,7 @@ fn find_meta_items_by_name(metas: ~[@ast::meta_item], +name: ~str) ->
option::some(m)
} else { option::none }
};
ret vec::filter_map(metas, filter);
return vec::filter_map(metas, filter);
}
/**
@ -202,14 +202,14 @@ fn contains(haystack: ~[@ast::meta_item], needle: @ast::meta_item) -> bool {
for haystack.each |item| {
debug!{"looking in %s",
print::pprust::meta_item_to_str(*item)};
if eq(item, needle) { debug!{"found it!"}; ret true; }
if eq(item, needle) { debug!{"found it!"}; return true; }
}
#debug("found it not :(");
ret false;
return false;
}
fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
ret alt a.node {
return alt a.node {
ast::meta_word(na) {
alt b.node { ast::meta_word(nb) { na == nb } _ { false } }
}
@ -232,7 +232,7 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
fn contains_name(metas: ~[@ast::meta_item], +name: ~str) -> bool {
let matches = find_meta_items_by_name(metas, name);
ret vec::len(matches) > 0u;
return vec::len(matches) > 0u;
}
fn attrs_contains_name(attrs: ~[ast::attribute], +name: ~str) -> bool {
@ -243,9 +243,9 @@ fn first_attr_value_str_by_name(attrs: ~[ast::attribute], +name: ~str)
-> option<@~str> {
let mattrs = find_attrs_by_name(attrs, name);
if vec::len(mattrs) > 0u {
ret get_meta_item_value_str(attr_meta(mattrs[0]));
return get_meta_item_value_str(attr_meta(mattrs[0]));
}
ret option::none;
return option::none;
}
fn last_meta_item_by_name(
@ -297,19 +297,19 @@ fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
ast::meta_list(name, _) { /* FIXME (#2543) */ copy name }
}
}
ret key(ma) <= key(mb);
return key(ma) <= key(mb);
}
// This is sort of stupid here, converting to a vec of mutables and back
let v: ~[mut @ast::meta_item] = vec::to_mut(items);
std::sort::quick_sort(lteq, v);
ret vec::from_mut(v);
return vec::from_mut(v);
}
fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ast::ident) ->
~[@ast::meta_item] {
ret vec::filter_map(items, |item| {
return vec::filter_map(items, |item| {
if get_meta_item_name(item) != name {
option::some(/* FIXME (#2543) */ copy item)
} else {
@ -326,7 +326,7 @@ fn find_linkage_attrs(attrs: ~[ast::attribute]) -> ~[ast::attribute] {
_ { debug!{"ignoring link attribute that has incorrect type"}; }
}
}
ret found;
return found;
}
/**
@ -342,7 +342,7 @@ fn find_linkage_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
}
fn foreign_abi(attrs: ~[ast::attribute]) -> either<~str, ast::foreign_abi> {
ret alt attr::first_attr_value_str_by_name(attrs, ~"abi") {
return alt attr::first_attr_value_str_by_name(attrs, ~"abi") {
option::none {
either::right(ast::foreign_abi_cdecl)
}

View File

@ -58,7 +58,7 @@ fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
src: @~str,
start_pos_ch: uint, start_pos_byte: uint)
-> filemap {
ret @{name: filename, substr: substr, src: src,
return @{name: filename, substr: substr, src: src,
start_pos: {ch: start_pos_ch, byte: start_pos_byte},
mut lines: ~[{ch: start_pos_ch, byte: start_pos_byte}]};
}
@ -66,14 +66,14 @@ fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
fn new_filemap(+filename: filename, src: @~str,
start_pos_ch: uint, start_pos_byte: uint)
-> filemap {
ret new_filemap_w_substr(filename, fss_none, src,
return new_filemap_w_substr(filename, fss_none, src,
start_pos_ch, start_pos_byte);
}
fn mk_substr_filename(cm: codemap, sp: span) -> ~str
{
let pos = lookup_char_pos(cm, sp.lo);
ret fmt!{"<%s:%u:%u>", pos.file.name, pos.line, pos.col};
return fmt!{"<%s:%u:%u>", pos.file.name, pos.line, pos.col};
}
fn next_line(file: filemap, chpos: uint, byte_pos: uint) {
@ -102,22 +102,22 @@ fn lookup_line(map: codemap, pos: uint, lookup: lookup_fn)
let m = (a + b) / 2u;
if lookup(f.lines[m]) > pos { b = m; } else { a = m; }
}
ret {fm: f, line: a};
return {fm: f, line: a};
}
fn lookup_pos(map: codemap, pos: uint, lookup: lookup_fn) -> loc {
let {fm: f, line: a} = lookup_line(map, pos, lookup);
ret {file: f, line: a + 1u, col: pos - lookup(f.lines[a])};
return {file: f, line: a + 1u, col: pos - lookup(f.lines[a])};
}
fn lookup_char_pos(map: codemap, pos: uint) -> loc {
pure fn lookup(pos: file_pos) -> uint { ret pos.ch; }
ret lookup_pos(map, pos, lookup);
pure fn lookup(pos: file_pos) -> uint { return pos.ch; }
return lookup_pos(map, pos, lookup);
}
fn lookup_byte_pos(map: codemap, pos: uint) -> loc {
pure fn lookup(pos: file_pos) -> uint { ret pos.byte; }
ret lookup_pos(map, pos, lookup);
pure fn lookup(pos: file_pos) -> uint { return pos.byte; }
return lookup_pos(map, pos, lookup);
}
fn lookup_char_pos_adj(map: codemap, pos: uint)
@ -144,7 +144,7 @@ fn lookup_char_pos_adj(map: codemap, pos: uint)
}
fn adjust_span(map: codemap, sp: span) -> span {
pure fn lookup(pos: file_pos) -> uint { ret pos.ch; }
pure fn lookup(pos: file_pos) -> uint { return pos.ch; }
let line = lookup_line(map, sp.lo, lookup);
alt (line.fm.substr) {
fss_none {sp}
@ -166,14 +166,14 @@ type span = {lo: uint, hi: uint, expn_info: expn_info};
fn span_to_str_no_adj(sp: span, cm: codemap) -> ~str {
let lo = lookup_char_pos(cm, sp.lo);
let hi = lookup_char_pos(cm, sp.hi);
ret fmt!{"%s:%u:%u: %u:%u", lo.file.name,
return fmt!{"%s:%u:%u: %u:%u", lo.file.name,
lo.line, lo.col, hi.line, hi.col}
}
fn span_to_str(sp: span, cm: codemap) -> ~str {
let lo = lookup_char_pos_adj(cm, sp.lo);
let hi = lookup_char_pos_adj(cm, sp.hi);
ret fmt!{"%s:%u:%u: %u:%u", lo.filename,
return fmt!{"%s:%u:%u: %u:%u", lo.filename,
lo.line, lo.col, hi.line, hi.col}
}
@ -181,7 +181,7 @@ type file_lines = {file: filemap, lines: ~[uint]};
fn span_to_filename(sp: span, cm: codemap::codemap) -> filename {
let lo = lookup_char_pos(cm, sp.lo);
ret /* FIXME (#2543) */ copy lo.file.name;
return /* FIXME (#2543) */ copy lo.file.name;
}
fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
@ -191,7 +191,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
for uint::range(lo.line - 1u, hi.line as uint) |i| {
vec::push(lines, i);
};
ret @{file: lo.file, lines: lines};
return @{file: lo.file, lines: lines};
}
fn get_line(fm: filemap, line: int) -> ~str unsafe {
@ -205,7 +205,7 @@ fn get_line(fm: filemap, line: int) -> ~str unsafe {
fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
-> {fm: filemap, pos: uint} {
pure fn lookup(pos: file_pos) -> uint { ret pos.ch; }
pure fn lookup(pos: file_pos) -> uint { return pos.ch; }
let {fm, line} = lookup_line(cm, chpos, lookup);
let line_offset = fm.lines[line].byte - fm.start_pos.byte;
let col = chpos - fm.lines[line].ch;
@ -217,17 +217,17 @@ fn span_to_snippet(sp: span, cm: codemap::codemap) -> ~str {
let begin = lookup_byte_offset(cm, sp.lo);
let end = lookup_byte_offset(cm, sp.hi);
assert begin.fm == end.fm;
ret str::slice(*begin.fm.src, begin.pos, end.pos);
return str::slice(*begin.fm.src, begin.pos, end.pos);
}
fn get_snippet(cm: codemap::codemap, fidx: uint, lo: uint, hi: uint) -> ~str
{
let fm = cm.files[fidx];
ret str::slice(*fm.src, lo, hi)
return str::slice(*fm.src, lo, hi)
}
fn get_filemap(cm: codemap, filename: ~str) -> filemap {
for cm.files.each |fm| { if fm.name == filename { ret fm; } }
for cm.files.each |fm| { if fm.name == filename { return fm; } }
//XXjdm the following triggers a mismatched type bug
// (or expected function, found _|_)
fail; // ("asking for " + filename + " which we don't know about");

View File

@ -88,7 +88,7 @@ impl codemap_handler of handler for handler_t {
fn abort_if_errors() {
let s;
alt self.err_count {
0u { ret; }
0u { return; }
1u { s = ~"aborting due to previous error"; }
_ { s = fmt!{"aborting due to %u previous errors",
self.err_count}; }

View File

@ -107,7 +107,7 @@ fn syntax_expander_table() -> hashmap<~str, syntax_extension> {
builtin(ext::source_util::expand_mod));
syntax_expanders.insert(~"proto",
builtin_item_tt(ext::pipes::expand_proto));
ret syntax_expanders;
return syntax_expanders;
}
@ -148,7 +148,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
fn backtrace() -> expn_info { self.backtrace }
fn mod_push(i: ast::ident) { vec::push(self.mod_path, i); }
fn mod_pop() { vec::pop(self.mod_path); }
fn mod_path() -> ~[ast::ident] { ret self.mod_path; }
fn mod_path() -> ~[ast::ident] { return self.mod_path; }
fn bt_push(ei: codemap::expn_info_) {
alt ei {
expanded_from({call_site: cs, callie: callie}) {
@ -193,7 +193,7 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
self.parse_sess.span_diagnostic.handler().bug(msg);
}
fn next_id() -> ast::node_id {
ret parse::next_node_id(self.parse_sess);
return parse::next_node_id(self.parse_sess);
}
}
let imp : ctxt_repr = {
@ -202,14 +202,14 @@ fn mk_ctxt(parse_sess: parse::parse_sess,
mut backtrace: none,
mut mod_path: ~[]
};
ret imp as ext_ctxt
return imp as ext_ctxt
}
fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str {
alt expr.node {
ast::expr_lit(l) {
alt l.node {
ast::lit_str(s) { ret *s; }
ast::lit_str(s) { return *s; }
_ { cx.span_fatal(l.span, error); }
}
}
@ -222,7 +222,7 @@ fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident {
ast::expr_path(p) {
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u {
cx.span_fatal(expr.span, error);
} else { ret p.idents[0]; }
} else { return p.idents[0]; }
}
_ { cx.span_fatal(expr.span, error); }
}
@ -230,7 +230,7 @@ fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident {
fn get_mac_args_no_max(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
min: uint, name: ~str) -> ~[@ast::expr] {
ret get_mac_args(cx, sp, arg, min, none, name);
return get_mac_args(cx, sp, arg, min, none, name);
}
fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
@ -250,7 +250,7 @@ fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
cx.span_fatal(sp, fmt!{"#%s needs at least %u arguments.",
name, min});
}
_ { ret elts; /* we're good */}
_ { return elts; /* we're good */}
}
}
_ {
@ -308,7 +308,7 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree])
_ { fail ~"badly-structured parse result"; }
};
ret some(@{id: parse::next_node_id(cx.parse_sess()),
return some(@{id: parse::next_node_id(cx.parse_sess()),
callee_id: parse::next_node_id(cx.parse_sess()),
node: ast::expr_vec(args, ast::m_imm), span: sp});
}

View File

@ -3,7 +3,7 @@ import base::ext_ctxt;
fn mk_expr(cx: ext_ctxt, sp: codemap::span, expr: ast::expr_) ->
@ast::expr {
ret @{id: cx.next_id(), callee_id: cx.next_id(),
return @{id: cx.next_id(), callee_id: cx.next_id(),
node: expr, span: sp};
}
@ -13,15 +13,15 @@ fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
}
fn mk_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
let lit = ast::lit_int(i as i64, ast::ty_i);
ret mk_lit(cx, sp, lit);
return mk_lit(cx, sp, lit);
}
fn mk_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr {
let lit = ast::lit_uint(u as u64, ast::ty_u);
ret mk_lit(cx, sp, lit);
return mk_lit(cx, sp, lit);
}
fn mk_u8(cx: ext_ctxt, sp: span, u: u8) -> @ast::expr {
let lit = ast::lit_uint(u as u64, ast::ty_u8);
ret mk_lit(cx, sp, lit);
return mk_lit(cx, sp, lit);
}
fn mk_binary(cx: ext_ctxt, sp: span, op: ast::binop,
lhs: @ast::expr, rhs: @ast::expr)
@ -48,7 +48,7 @@ fn mk_access_(cx: ext_ctxt, sp: span, p: @ast::expr, m: ast::ident)
fn mk_access(cx: ext_ctxt, sp: span, p: ~[ast::ident], m: ast::ident)
-> @ast::expr {
let pathexpr = mk_path(cx, sp, p);
ret mk_access_(cx, sp, pathexpr, m);
return mk_access_(cx, sp, pathexpr, m);
}
fn mk_call_(cx: ext_ctxt, sp: span, fn_expr: @ast::expr,
args: ~[@ast::expr]) -> @ast::expr {
@ -57,7 +57,7 @@ fn mk_call_(cx: ext_ctxt, sp: span, fn_expr: @ast::expr,
fn mk_call(cx: ext_ctxt, sp: span, fn_path: ~[ast::ident],
args: ~[@ast::expr]) -> @ast::expr {
let pathexpr = mk_path(cx, sp, fn_path);
ret mk_call_(cx, sp, pathexpr, args);
return mk_call_(cx, sp, pathexpr, args);
}
// e = expr, t = type
fn mk_base_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
@ -79,7 +79,7 @@ fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
}
fn mk_base_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
let lit = ast::lit_str(@s);
ret mk_lit(cx, sp, lit);
return mk_lit(cx, sp, lit);
}
fn mk_uniq_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::vstore_uniq)

View File

@ -8,7 +8,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
res += *expr_to_ident(cx, e, ~"expected an ident");
}
ret @{id: cx.next_id(),
return @{id: cx.next_id(),
callee_id: cx.next_id(),
node: ast::expr_path(@{span: sp, global: false, idents: ~[@res],
rp: none, types: ~[]}),

View File

@ -17,8 +17,8 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
let var = expr_to_str(cx, args[0], ~"#env requires a string");
alt os::getenv(var) {
option::none { ret mk_uniq_str(cx, sp, ~""); }
option::some(s) { ret mk_uniq_str(cx, sp, s); }
option::none { return mk_uniq_str(cx, sp, ~""); }
option::some(s) { return mk_uniq_str(cx, sp, s); }
}
}

View File

@ -15,7 +15,7 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
orig: fn@(expr_, span, ast_fold) -> (expr_, span))
-> (expr_, span)
{
ret alt e {
return alt e {
// expr_mac should really be expr_ext or something; it's the
// entry-point for all syntax extensions.
expr_mac(mac) {
@ -159,7 +159,7 @@ fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
}
};
ret {items: new_items with module_};
return {items: new_items with module_};
}
@ -185,9 +185,9 @@ fn expand_item(exts: hashmap<~str, syntax_extension>,
if is_mod { cx.mod_push(it.ident); }
let ret_val = orig(it, fld);
if is_mod { cx.mod_pop(); }
ret ret_val;
return ret_val;
}
none { ret none; }
none { return none; }
}
}
@ -221,7 +221,7 @@ fn expand_item_mac(exts: hashmap<~str, syntax_extension>,
}
};
cx.bt_pop();
ret maybe_it
return maybe_it
}
_ { cx.span_fatal(it.span,
fmt!{"%s is not a legal here", *extname}) }
@ -235,7 +235,7 @@ fn expand_item_mac(exts: hashmap<~str, syntax_extension>,
fn new_span(cx: ext_ctxt, sp: span) -> span {
/* this discards information in the case of macro-defining macros */
ret {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
return {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
}
// FIXME (#2247): this is a terrible kludge to inject some macros into
@ -244,7 +244,7 @@ fn new_span(cx: ext_ctxt, sp: span) -> span {
// compiled part of libcore at very least.
fn core_macros() -> ~str {
ret
return
~"{
#macro[[#error[f, ...], log(core::error, #fmt[f, ...])]];
#macro[[#warn[f, ...], log(core::warn, #fmt[f, ...])]];
@ -275,7 +275,7 @@ fn expand_crate(parse_sess: parse::parse_sess,
f.fold_expr(cm);
let res = @f.fold_crate(*c);
ret res;
return res;
}
// Local Variables:
// mode: rust

View File

@ -27,7 +27,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
parse_fmt_err_(cx, fmtspan, s)
};
let pieces = parse_fmt_string(fmt, parse_fmt_err);
ret pieces_to_expr(cx, sp, pieces, args);
return pieces_to_expr(cx, sp, pieces, args);
}
// FIXME (#2249): A lot of these functions for producing expressions can
@ -38,12 +38,12 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
pieces: ~[piece], args: ~[@ast::expr])
-> @ast::expr {
fn make_path_vec(_cx: ext_ctxt, ident: ast::ident) -> ~[ast::ident] {
ret ~[@~"extfmt", @~"rt", ident];
return ~[@~"extfmt", @~"rt", ident];
}
fn make_rt_path_expr(cx: ext_ctxt, sp: span,
ident: ast::ident) -> @ast::expr {
let path = make_path_vec(cx, ident);
ret mk_path(cx, sp, path);
return mk_path(cx, sp, path);
}
// Produces an AST expression that represents a RT::conv record,
// which tells the RT::conv* functions how to perform the conversion
@ -62,18 +62,18 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
tmp_expr = mk_binary(cx, sp, ast::bitor, tmp_expr,
make_rt_path_expr(cx, sp, @fstr));
}
ret tmp_expr;
return tmp_expr;
}
fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr {
alt cnt {
count_implied {
ret make_rt_path_expr(cx, sp, @~"count_implied");
return make_rt_path_expr(cx, sp, @~"count_implied");
}
count_is(c) {
let count_lit = mk_int(cx, sp, c);
let count_is_path = make_path_vec(cx, @~"count_is");
let count_is_args = ~[count_lit];
ret mk_call(cx, sp, count_is_path, count_is_args);
return mk_call(cx, sp, count_is_path, count_is_args);
}
_ { cx.span_unimpl(sp, ~"unimplemented #fmt conversion"); }
}
@ -91,12 +91,12 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
ty_octal { rt_type = ~"ty_octal"; }
_ { rt_type = ~"ty_default"; }
}
ret make_rt_path_expr(cx, sp, @rt_type);
return make_rt_path_expr(cx, sp, @rt_type);
}
fn make_conv_rec(cx: ext_ctxt, sp: span, flags_expr: @ast::expr,
width_expr: @ast::expr, precision_expr: @ast::expr,
ty_expr: @ast::expr) -> @ast::expr {
ret mk_rec_e(cx, sp,
return mk_rec_e(cx, sp,
~[{ident: @~"flags", ex: flags_expr},
{ident: @~"width", ex: width_expr},
{ident: @~"precision", ex: precision_expr},
@ -106,7 +106,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
let rt_conv_width = make_count(cx, sp, cnv.width);
let rt_conv_precision = make_count(cx, sp, cnv.precision);
let rt_conv_ty = make_ty(cx, sp, cnv.ty);
ret make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width,
return make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width,
rt_conv_precision, rt_conv_ty);
}
fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: ~str, cnv: conv,
@ -115,7 +115,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
let path = make_path_vec(cx, @fname);
let cnv_expr = make_rt_conv_expr(cx, sp, cnv);
let args = ~[cnv_expr, arg];
ret mk_call(cx, arg.span, path, args);
return mk_call(cx, arg.span, path, args);
}
fn make_new_conv(cx: ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) ->
@ -125,10 +125,10 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
fn is_signed_type(cnv: conv) -> bool {
alt cnv.ty {
ty_int(s) {
alt s { signed { ret true; } unsigned { ret false; } }
alt s { signed { return true; } unsigned { return false; } }
}
ty_float { ret true; }
_ { ret false; }
ty_float { return true; }
_ { return false; }
}
}
let unsupported = ~"conversion not supported in #fmt string";
@ -168,22 +168,28 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
_ { cx.span_unimpl(sp, unsupported); }
}
alt cnv.ty {
ty_str { ret make_conv_call(cx, arg.span, ~"str", cnv, arg); }
ty_str { return make_conv_call(cx, arg.span, ~"str", cnv, arg); }
ty_int(sign) {
alt sign {
signed { ret make_conv_call(cx, arg.span, ~"int", cnv, arg); }
signed {
return make_conv_call(cx, arg.span, ~"int", cnv, arg);
}
unsigned {
ret make_conv_call(cx, arg.span, ~"uint", cnv, arg);
return make_conv_call(cx, arg.span, ~"uint", cnv, arg);
}
}
}
ty_bool { ret make_conv_call(cx, arg.span, ~"bool", cnv, arg); }
ty_char { ret make_conv_call(cx, arg.span, ~"char", cnv, arg); }
ty_hex(_) { ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
ty_bits { ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
ty_octal { ret make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
ty_float { ret make_conv_call(cx, arg.span, ~"float", cnv, arg); }
ty_poly { ret make_conv_call(cx, arg.span, ~"poly", cnv, arg); }
ty_bool { return make_conv_call(cx, arg.span, ~"bool", cnv, arg); }
ty_char { return make_conv_call(cx, arg.span, ~"char", cnv, arg); }
ty_hex(_) {
return make_conv_call(cx, arg.span, ~"uint", cnv, arg);
}
ty_bits { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
ty_octal { return make_conv_call(cx, arg.span, ~"uint", cnv, arg); }
ty_float {
return make_conv_call(cx, arg.span, ~"float", cnv, arg);
}
ty_poly { return make_conv_call(cx, arg.span, ~"poly", cnv, arg); }
}
}
fn log_conv(c: conv) {
@ -275,7 +281,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
}
let arg_vec = mk_fixed_vec_e(cx, fmt_sp, piece_exprs);
ret mk_call(cx, fmt_sp, ~[@~"str", @~"concat"], ~[arg_vec]);
return mk_call(cx, fmt_sp, ~[@~"str", @~"concat"], ~[arg_vec]);
}
//
// Local Variables:

View File

@ -6,6 +6,6 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
_body: ast::mac_body) -> @ast::expr {
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),~"ident_to_str");
ret mk_uniq_str(cx, sp, *expr_to_ident(cx, args[0u],
return mk_uniq_str(cx, sp, *expr_to_ident(cx, args[0u],
~"expected an ident"));
}

View File

@ -11,6 +11,6 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
);
//trivial expression
ret @{id: cx.next_id(), callee_id: cx.next_id(),
return @{id: cx.next_id(), callee_id: cx.next_id(),
node: ast::expr_rec(~[], option::none), span: sp};
}

View File

@ -19,7 +19,7 @@ impl proto_parser of proto_parser for parser {
{sep: none, trailing_sep_allowed: false},
|self| self.parse_state(proto));
ret proto;
return proto;
}
fn parse_state(proto: protocol) {

View File

@ -149,7 +149,7 @@ class protocol_ {
fn has_ty_params() -> bool {
for self.states.each |s| {
if s.ty_params.len() > 0 {
ret true;
return true;
}
}
false

View File

@ -112,7 +112,7 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
do cx.gather.swap |v| {
vec::to_mut(std::sort::merge_sort(|a,b| a.lo < b.lo, v))
};
ret cx;
return cx;
}
fn visit_aq<T:qq_helper>(node: T, constr: ~str, &&cx: aq_ctxt, v: vt<aq_ctxt>)
@ -155,7 +155,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span,
}
let body = get_mac_body(ecx,_sp,body);
ret alt what {
return alt what {
~"crate" {finish(ecx, body, parse_crate)}
~"expr" {finish(ecx, body, parse_expr)}
~"ty" {finish(ecx, body, parse_ty)}
@ -268,7 +268,7 @@ fn finish<T: qq_helper>
~[@~"syntax", @~"ext", @~"qquote",
@node.get_fold_fn()])]);
}
ret rcall;
return rcall;
}
fn replace<T>(node: T, repls: ~[fragment], ff: fn (ast_fold, T) -> T)
@ -280,7 +280,7 @@ fn replace<T>(node: T, repls: ~[fragment], ff: fn (ast_fold, T) -> T)
fold_ty: |a,b,c|replace_ty(repls, a, b, c,
aft.fold_ty)
with *aft};
ret ff(make_fold(f_pre), node);
return ff(make_fold(f_pre), node);
}
fn fold_crate(f: ast_fold, &&n: @ast::crate) -> @ast::crate {
@f.fold_crate(*n)

View File

@ -13,9 +13,9 @@ export add_new_extension;
fn path_to_ident(pth: @path) -> option<ident> {
if vec::len(pth.idents) == 1u && vec::len(pth.types) == 0u {
ret some(pth.idents[0u]);
return some(pth.idents[0u]);
}
ret none;
return none;
}
//a vec of binders might be a little big.
@ -94,7 +94,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) ->
}
idx += 1u;
}
ret alt res {
return alt res {
some(val) { val }
none { {pre: elts, rep: none, post: ~[]} }
}
@ -104,18 +104,18 @@ fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: ~[T]) ->
option<~[U]> {
let mut res = ~[];
for v.each |elem| {
alt f(elem) { none { ret none; } some(fv) { vec::push(res, fv); } }
alt f(elem) { none { return none; } some(fv) { vec::push(res, fv); } }
}
ret some(res);
return some(res);
}
fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
alt ad {
leaf(x) { ret f(x); }
leaf(x) { return f(x); }
seq(ads, span) {
alt option_flatten_map(|x| a_d_map(x, f), *ads) {
none { ret none; }
some(ts) { ret some(seq(@ts, span)); }
none { return none; }
some(ts) { return some(seq(@ts, span)); }
}
}
}
@ -123,12 +123,12 @@ fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
fn compose_sels(s1: selector, s2: selector) -> selector {
fn scomp(s1: selector, s2: selector, m: matchable) -> match_result {
ret alt s1(m) {
return alt s1(m) {
none { none }
some(matches) { a_d_map(matches, s2) }
}
}
ret { |x| scomp(s1, s2, x) };
return { |x| scomp(s1, s2, x) };
}
@ -150,9 +150,11 @@ fn pattern_to_selectors(cx: ext_ctxt, e: @expr) -> binders {
literal_ast_matchers: dvec()};
//this oughta return binders instead, but macro args are a sequence of
//expressions, rather than a single expression
fn trivial_selector(m: matchable) -> match_result { ret some(leaf(m)); }
fn trivial_selector(m: matchable) -> match_result {
return some(leaf(m));
}
p_t_s_rec(cx, match_expr(e), trivial_selector, res);
ret res;
return res;
}
@ -165,7 +167,7 @@ fn use_selectors_to_bind(b: binders, e: @expr) -> option<bindings> {
let res = box_str_hash::<arb_depth<matchable>>();
//need to do this first, to check vec lengths.
for b.literal_ast_matchers.each |sel| {
alt sel(match_expr(e)) { none { ret none; } _ { } }
alt sel(match_expr(e)) { none { return none; } _ { } }
}
let mut never_mind: bool = false;
for b.real_binders.each |key, val| {
@ -175,18 +177,18 @@ fn use_selectors_to_bind(b: binders, e: @expr) -> option<bindings> {
}
};
//HACK: `ret` doesn't work in `for each`
if never_mind { ret none; }
ret some(res);
if never_mind { return none; }
return some(res);
}
/* use the bindings on the body to generate the expanded code */
fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr {
let idx_path: @mut ~[uint] = @mut ~[];
fn new_id(_old: node_id, cx: ext_ctxt) -> node_id { ret cx.next_id(); }
fn new_id(_old: node_id, cx: ext_ctxt) -> node_id { return cx.next_id(); }
fn new_span(cx: ext_ctxt, sp: span) -> span {
/* this discards information in the case of macro-defining macros */
ret {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
return {lo: sp.lo, hi: sp.hi, expn_info: cx.backtrace()};
}
let afp = default_ast_fold();
let f_pre =
@ -209,7 +211,7 @@ fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr {
with *afp};
let f = make_fold(f_pre);
let result = f.fold_expr(body);
ret result;
return result;
}
@ -219,25 +221,25 @@ fn follow(m: arb_depth<matchable>, idx_path: @mut ~[uint]) ->
let mut res: arb_depth<matchable> = m;
for vec::each(*idx_path) |idx| {
res = alt res {
leaf(_) { ret res;/* end of the line */ }
leaf(_) { return res;/* end of the line */ }
seq(new_ms, _) { new_ms[idx] }
}
}
ret res;
return res;
}
fn follow_for_trans(cx: ext_ctxt, mmaybe: option<arb_depth<matchable>>,
idx_path: @mut ~[uint]) -> option<matchable> {
alt mmaybe {
none { ret none }
none { return none }
some(m) {
ret alt follow(m, idx_path) {
return alt follow(m, idx_path) {
seq(_, sp) {
cx.span_fatal(sp,
~"syntax matched under ... but not " +
~"used that way.")
}
leaf(m) { ret some(m) }
leaf(m) { return some(m) }
}
}
}
@ -250,7 +252,7 @@ fn free_vars(b: bindings, e: @expr, it: fn(ident)) {
fn mark_ident(&&i: ident, _fld: ast_fold, b: bindings,
idents: hashmap<ident, ()>) -> ident {
if b.contains_key(i) { idents.insert(i, ()); }
ret i;
return i;
}
// using fold is a hack: we want visit, but it doesn't hit idents ) :
// solve this with macros
@ -319,7 +321,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
}
}
res = vec::append(res, vec::map(post, recur));
ret res;
return res;
}
}
}
@ -329,7 +331,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
// substitute, in a position that's required to be an ident
fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
&&i: ident, _fld: ast_fold) -> ident {
ret alt follow_for_trans(cx, b.find(i), idx_path) {
return alt follow_for_trans(cx, b.find(i), idx_path) {
some(match_ident(a_id)) { a_id.node }
some(m) { match_error(cx, m, ~"an identifier") }
none { i }
@ -340,7 +342,7 @@ fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
p: path, _fld: ast_fold) -> path {
// Don't substitute into qualified names.
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; }
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { return p; }
alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
some(match_ident(id)) {
{span: id.span, global: false, idents: ~[id.node],
@ -358,7 +360,7 @@ fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
orig: fn@(ast::expr_, span, ast_fold)->(ast::expr_, span))
-> (ast::expr_, span)
{
ret alt e {
return alt e {
expr_path(p) {
// Don't substitute into qualified names.
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u {
@ -387,7 +389,7 @@ fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
orig: fn@(ast::ty_, span, ast_fold) -> (ast::ty_, span))
-> (ast::ty_, span)
{
ret alt t {
return alt t {
ast::ty_path(pth, _) {
alt path_to_ident(pth) {
some(id) {
@ -413,7 +415,7 @@ fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
orig: fn@(blk_, span, ast_fold) -> (blk_, span))
-> (blk_, span)
{
ret alt block_to_ident(blk) {
return alt block_to_ident(blk) {
some(id) {
alt follow_for_trans(cx, b.find(id), idx_path) {
some(match_block(new_blk)) { (new_blk.node, new_blk.span) }
@ -474,7 +476,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
_ {
fn select(cx: ext_ctxt, m: matchable, pat: @expr) ->
match_result {
ret alt m {
return alt m {
match_expr(e) {
if e == pat { some(leaf(match_exact)) } else { none }
}
@ -494,7 +496,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
/* make a match more precise */
fn specialize_match(m: matchable) -> matchable {
ret alt m {
return alt m {
match_expr(e) {
alt e.node {
expr_path(pth) {
@ -515,7 +517,7 @@ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
alt path_to_ident(p) {
some(p_id) {
fn select(cx: ext_ctxt, m: matchable) -> match_result {
ret alt m {
return alt m {
match_expr(e) { some(leaf(specialize_match(m))) }
_ { cx.bug(~"broken traversal in p_t_s_r") }
}
@ -530,8 +532,8 @@ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
}
fn block_to_ident(blk: blk_) -> option<ident> {
if vec::len(blk.stmts) != 0u { ret none; }
ret alt blk.expr {
if vec::len(blk.stmts) != 0u { return none; }
return alt blk.expr {
some(expr) {
alt expr.node { expr_path(pth) { path_to_ident(pth) } _ { none } }
}
@ -542,7 +544,7 @@ fn block_to_ident(blk: blk_) -> option<ident> {
fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) {
fn select_pt_1(cx: ext_ctxt, m: matchable,
fn_m: fn(ast::mac) -> match_result) -> match_result {
ret alt m {
return alt m {
match_expr(e) {
alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } }
}
@ -565,7 +567,7 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector,
b: binders) {
fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) ->
match_result {
ret alt m {
return alt m {
match_expr(e) {
alt e.node {
expr_vec(arg_elts, _) {
@ -595,7 +597,7 @@ fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector,
b: binders) {
fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) ->
match_result {
ret alt m {
return alt m {
match_expr(e) {
alt e.node {
expr_vec(arg_elts, _) {
@ -619,7 +621,7 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool,
let mut idx: uint = 0u;
while idx < vec::len(elts) {
fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result {
ret alt m {
return alt m {
match_expr(e) {
alt e.node {
expr_vec(arg_elts, _) {
@ -709,7 +711,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
let ext = |a,b,c,d, move clauses| generic_extension(a,b,c,d,clauses);
ret {ident:
return {ident:
alt macro_name {
some(id) { id }
none {
@ -728,7 +730,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
};
for clauses.each |c| {
alt use_selectors_to_bind(c.params, arg) {
some(bindings) { ret transcribe(cx, bindings, c.body); }
some(bindings) { return transcribe(cx, bindings, c.body); }
none { again; }
}
}

View File

@ -18,7 +18,7 @@ fn expand_line(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
_body: ast::mac_body) -> @ast::expr {
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"line");
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
ret mk_uint(cx, sp, loc.line);
return mk_uint(cx, sp, loc.line);
}
/* col!{}: expands to the current column number */
@ -26,7 +26,7 @@ fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
_body: ast::mac_body) -> @ast::expr {
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"col");
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
ret mk_uint(cx, sp, loc.col);
return mk_uint(cx, sp, loc.col);
}
/* file!{}: expands to the current filename */
@ -37,19 +37,19 @@ fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"file");
let { file: @{ name: filename, _ }, _ } =
codemap::lookup_char_pos(cx.codemap(), sp.lo);
ret mk_uniq_str(cx, sp, filename);
return mk_uniq_str(cx, sp, filename);
}
fn expand_stringify(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
_body: ast::mac_body) -> @ast::expr {
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), ~"stringify");
ret mk_uniq_str(cx, sp, pprust::expr_to_str(args[0]));
return mk_uniq_str(cx, sp, pprust::expr_to_str(args[0]));
}
fn expand_mod(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body)
-> @ast::expr {
get_mac_args(cx, sp, arg, 0u, option::some(0u), ~"file");
ret mk_uniq_str(cx, sp,
return mk_uniq_str(cx, sp,
str::connect(cx.mod_path().map(|x|*x), ~"::"));
}
@ -60,7 +60,7 @@ fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
let p = parse::new_parser_from_file(cx.parse_sess(), cx.cfg(),
res_rel_file(cx, sp, file),
parse::parser::SOURCE_FILE);
ret p.parse_expr();
return p.parse_expr();
}
fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
@ -77,7 +77,7 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
}
}
ret mk_uniq_str(cx, sp, result::unwrap(res));
return mk_uniq_str(cx, sp, result::unwrap(res));
}
fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
@ -91,7 +91,7 @@ fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
let u8_exprs = vec::map(src, |char: u8| {
mk_u8(cx, sp, char)
});
ret mk_uniq_vec_e(cx, sp, u8_exprs);
return mk_uniq_vec_e(cx, sp, u8_exprs);
}
result::err(e) {
cx.parse_sess().span_diagnostic.handler().fatal(e)
@ -104,9 +104,9 @@ fn res_rel_file(cx: ext_ctxt, sp: codemap::span, +arg: path) -> path {
if !path::path_is_absolute(arg) {
let cu = codemap::span_to_filename(sp, cx.codemap());
let dir = path::dirname(cu);
ret path::connect(dir, arg);
return path::connect(dir, arg);
} else {
ret arg;
return arg;
}
}

View File

@ -129,7 +129,7 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match])
}
let ret_val = box_str_hash::<@named_match>();
for ms.each() |m| { n_rec(p_s, m, res, ret_val) }
ret ret_val;
return ret_val;
}
enum parse_result {
@ -260,13 +260,13 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
/* error messages here could be improved with links to orig. rules */
if tok == EOF {
if eof_eis.len() == 1u {
ret success(
return success(
nameize(sess, ms,
vec::map(eof_eis[0u].matches, |dv| dv.pop())));
} else if eof_eis.len() > 1u {
ret failure(sp, ~"Ambiguity: multiple successful parses");
return failure(sp, ~"Ambiguity: multiple successful parses");
} else {
ret failure(sp, ~"Unexpected end of macro invocation");
return failure(sp, ~"Unexpected end of macro invocation");
}
} else {
if (bb_eis.len() > 0u && next_eis.len() > 0u)
@ -277,12 +277,12 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
fmt!{"%s ('%s')", *name, *bind}
}
_ { fail; } } }), ~" or ");
ret failure(sp, fmt!{
return failure(sp, fmt!{
"Local ambiguity: multiple parsing options: \
built-in NTs %s or %u other options.",
nts, next_eis.len()});
} else if (bb_eis.len() == 0u && next_eis.len() == 0u) {
ret failure(sp, ~"No rules expected the token "
return failure(sp, ~"No rules expected the token "
+ to_str(*rdr.interner(), tok));
} else if (next_eis.len() > 0u) {
/* Now process the next token */

View File

@ -70,7 +70,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
~[rhs]);
let p = parser(cx.parse_sess(), cx.cfg(),
trncbr as reader, SOURCE_FILE);
ret mr_expr(p.parse_expr());
return mr_expr(p.parse_expr());
}
failure(sp, msg) {
if sp.lo >= best_fail_spot.lo {
@ -87,5 +87,8 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
let exp = |cx, sp, arg| generic_extension(cx, sp, arg, lhses, rhses);
ret mr_def({ident: name, ext: expr_tt({expander: exp, span: some(sp)})});
return mr_def({
ident: name,
ext: expr_tt({expander: exp, span: some(sp)})
});
}

View File

@ -56,7 +56,7 @@ fn new_tt_reader(sp_diag: span_handler, itr: @interner<@~str>,
mut cur_span: ast_util::mk_sp(0u,0u)
};
tt_next_token(r); /* get cur_tok and cur_span set up */
ret r;
return r;
}
pure fn dup_tt_frame(&&f: tt_frame) -> tt_frame {
@ -145,7 +145,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
alt r.cur.up {
tt_frame_up(none) {
r.cur_tok = EOF;
ret ret_val;
return ret_val;
}
tt_frame_up(some(tt_f)) {
if r.cur.dotdotdoted {
@ -163,7 +163,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
alt r.cur.sep {
some(tk) {
r.cur_tok = tk; /* repeat same span, I guess */
ret ret_val;
return ret_val;
}
none {}
}
@ -180,7 +180,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
tt_tok(sp, tok) {
r.cur_span = sp; r.cur_tok = tok;
r.cur.idx += 1u;
ret ret_val;
return ret_val;
}
tt_seq(sp, tts, sep, zerok) {
alt lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) {
@ -204,7 +204,7 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
}
r.cur.idx += 1u;
ret tt_next_token(r);
return tt_next_token(r);
} else {
vec::push(r.repeat_len, len);
vec::push(r.repeat_idx, 0u);
@ -223,12 +223,12 @@ fn tt_next_token(&&r: tt_reader) -> {tok: token, sp: span} {
matched_nonterminal(nt_ident(sn,b)) {
r.cur_span = sp; r.cur_tok = IDENT(sn,b);
r.cur.idx += 1u;
ret ret_val;
return ret_val;
}
matched_nonterminal(other_whole_nt) {
r.cur_span = sp; r.cur_tok = INTERPOLATED(other_whole_nt);
r.cur.idx += 1u;
ret ret_val;
return ret_val;
}
matched_seq(*) {
r.sp_diag.span_fatal(

View File

@ -79,7 +79,7 @@ type ast_fold_precursor = @{
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
ret @{node:
return @{node:
alt mi.node {
meta_word(id) { meta_word(fld.fold_ident(id)) }
meta_list(id, mis) {
@ -97,21 +97,21 @@ fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
//used in noop_fold_item and noop_fold_crate
fn fold_attribute_(at: attribute, fld: ast_fold) ->
attribute {
ret {node: {style: at.node.style,
return {node: {style: at.node.style,
value: *fold_meta_item_(@at.node.value, fld),
is_sugared_doc: at.node.is_sugared_doc },
span: fld.new_span(at.span)};
}
//used in noop_fold_foreign_item and noop_fold_fn_decl
fn fold_arg_(a: arg, fld: ast_fold) -> arg {
ret {mode: a.mode,
return {mode: a.mode,
ty: fld.fold_ty(a.ty),
ident: fld.fold_ident(a.ident),
id: fld.new_id(a.id)};
}
//used in noop_fold_expr, and possibly elsewhere in the future
fn fold_mac_(m: mac, fld: ast_fold) -> mac {
ret {node:
return {node:
alt m.node {
mac_invoc(pth, arg, body) {
mac_invoc(fld.fold_path(pth),
@ -126,7 +126,7 @@ fn fold_mac_(m: mac, fld: ast_fold) -> mac {
}
fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl {
ret {inputs: vec::map(decl.inputs, |x| fold_arg_(x, fld) ),
return {inputs: vec::map(decl.inputs, |x| fold_arg_(x, fld) ),
output: fld.fold_ty(decl.output),
purity: decl.purity,
cf: decl.cf}
@ -153,15 +153,17 @@ fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ {
let fold_meta_item = |x| fold_meta_item_(x, fld);
let fold_attribute = |x| fold_attribute_(x, fld);
ret {directives: vec::map(c.directives, |x| fld.fold_crate_directive(x)),
module: fld.fold_mod(c.module),
attrs: vec::map(c.attrs, fold_attribute),
config: vec::map(c.config, fold_meta_item)};
return {
directives: vec::map(c.directives, |x| fld.fold_crate_directive(x)),
module: fld.fold_mod(c.module),
attrs: vec::map(c.attrs, fold_attribute),
config: vec::map(c.config, fold_meta_item)
};
}
fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
crate_directive_ {
ret alt cd {
return alt cd {
cdir_src_mod(id, attrs) {
cdir_src_mod(fld.fold_ident(id), /* FIXME (#2543) */ copy attrs)
}
@ -176,7 +178,7 @@ fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
}
fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ {
ret /* FIXME (#2543) */ copy vi;
return /* FIXME (#2543) */ copy vi;
}
@ -185,7 +187,7 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
let fold_arg = |x| fold_arg_(x, fld);
let fold_attribute = |x| fold_attribute_(x, fld);
ret @{ident: fld.fold_ident(ni.ident),
return @{ident: fld.fold_ident(ni.ident),
attrs: vec::map(ni.attrs, fold_attribute),
node:
alt ni.node {
@ -204,7 +206,7 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
fn noop_fold_item(&&i: @item, fld: ast_fold) -> option<@item> {
let fold_attribute = |x| fold_attribute_(x, fld);
ret some(@{ident: fld.fold_ident(i.ident),
return some(@{ident: fld.fold_ident(i.ident),
attrs: vec::map(i.attrs, fold_attribute),
id: fld.new_id(i.id),
node: fld.fold_item_underscore(i.node),
@ -225,7 +227,7 @@ fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold)
}
fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
ret alt i {
return alt i {
item_const(t, e) { item_const(fld.fold_ty(t), fld.fold_expr(e)) }
item_fn(decl, typms, body) {
item_fn(fold_fn_decl(decl, fld),
@ -294,7 +296,7 @@ fn fold_trait_ref(&&p: @trait_ref, fld: ast_fold) -> @trait_ref {
}
fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
ret @{ident: fld.fold_ident(m.ident),
return @{ident: fld.fold_ident(m.ident),
attrs: /* FIXME (#2543) */ copy m.attrs,
tps: fold_ty_params(m.tps, fld),
self_ty: m.self_ty,
@ -308,7 +310,7 @@ fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
ret {view_items: vec::map(b.view_items, |x| fld.fold_view_item(x)),
return {view_items: vec::map(b.view_items, |x| fld.fold_view_item(x)),
stmts: vec::map(b.stmts, |x| fld.fold_stmt(x)),
expr: option::map(b.expr, |x| fld.fold_expr(x)),
id: fld.new_id(b.id),
@ -316,7 +318,7 @@ fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
}
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
ret alt s {
return alt s {
stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), fld.new_id(nid)) }
stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), fld.new_id(nid)) }
stmt_semi(e, nid) { stmt_semi(fld.fold_expr(e), fld.new_id(nid)) }
@ -324,13 +326,13 @@ fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
}
fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
ret {pats: vec::map(a.pats, |x| fld.fold_pat(x)),
return {pats: vec::map(a.pats, |x| fld.fold_pat(x)),
guard: option::map(a.guard, |x| fld.fold_expr(x)),
body: fld.fold_block(a.body)};
}
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
ret alt p {
return alt p {
pat_wild { pat_wild }
pat_ident(binding_mode, pth, sub) {
pat_ident(binding_mode,
@ -375,14 +377,14 @@ fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
fn wrap<T>(f: fn@(T, ast_fold) -> T)
-> fn@(T, span, ast_fold) -> (T, span)
{
ret fn@(x: T, s: span, fld: ast_fold) -> (T, span) {
return fn@(x: T, s: span, fld: ast_fold) -> (T, span) {
(f(x, fld), s)
}
}
fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
fn fold_field_(field: field, fld: ast_fold) -> field {
ret {node:
return {node:
{mutbl: field.node.mutbl,
ident: fld.fold_ident(field.node.ident),
expr: fld.fold_expr(field.node.expr)},
@ -392,7 +394,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
let fold_mac = |x| fold_mac_(x, fld);
ret alt e {
return alt e {
expr_new(p, i, v) {
expr_new(fld.fold_expr(p),
fld.new_id(i),
@ -514,18 +516,18 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
// ...nor do modules
fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod {
ret {view_items: vec::map(m.view_items, |x| fld.fold_view_item(x)),
return {view_items: vec::map(m.view_items, |x| fld.fold_view_item(x)),
items: vec::filter_map(m.items, |x| fld.fold_item(x))};
}
fn noop_fold_foreign_mod(nm: foreign_mod, fld: ast_fold) -> foreign_mod {
ret {view_items: vec::map(nm.view_items, |x| fld.fold_view_item(x)),
return {view_items: vec::map(nm.view_items, |x| fld.fold_view_item(x)),
items: vec::map(nm.items, |x| fld.fold_foreign_item(x))}
}
fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
fn fold_variant_arg_(va: variant_arg, fld: ast_fold) -> variant_arg {
ret {ty: fld.fold_ty(va.ty), id: fld.new_id(va.id)};
return {ty: fld.fold_ty(va.ty), id: fld.new_id(va.id)};
}
let fold_variant_arg = |x| fold_variant_arg_(x, fld);
let args = vec::map(v.args, fold_variant_arg);
@ -537,7 +539,7 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
some(e) {some(fld.fold_expr(e))}
none {none}
};
ret {name: /* FIXME (#2543) */ copy v.name,
return {name: /* FIXME (#2543) */ copy v.name,
attrs: attrs,
args: args, id: fld.new_id(v.id),
disr_expr: de,
@ -545,18 +547,18 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
}
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident {
ret /* FIXME (#2543) */ copy i;
return /* FIXME (#2543) */ copy i;
}
fn noop_fold_path(&&p: path, fld: ast_fold) -> path {
ret {span: fld.new_span(p.span), global: p.global,
return {span: fld.new_span(p.span), global: p.global,
idents: vec::map(p.idents, |x| fld.fold_ident(x)),
rp: p.rp,
types: vec::map(p.types, |x| fld.fold_ty(x))};
}
fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
ret {is_mutbl: l.is_mutbl,
return {is_mutbl: l.is_mutbl,
ty: fld.fold_ty(l.ty),
pat: fld.fold_pat(l.pat),
init:
@ -573,15 +575,15 @@ fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
/* temporarily eta-expand because of a compiler bug with using `fn<T>` as a
value */
fn noop_map_exprs(f: fn@(&&@expr) -> @expr, es: ~[@expr]) -> ~[@expr] {
ret vec::map(es, f);
return vec::map(es, f);
}
fn noop_id(i: node_id) -> node_id { ret i; }
fn noop_id(i: node_id) -> node_id { return i; }
fn noop_span(sp: span) -> span { ret sp; }
fn noop_span(sp: span) -> span { return sp; }
fn default_ast_fold() -> ast_fold_precursor {
ret @{fold_crate: wrap(noop_fold_crate),
return @{fold_crate: wrap(noop_fold_crate),
fold_crate_directive: wrap(noop_fold_crate_directive),
fold_view_item: noop_fold_view_item,
fold_foreign_item: noop_fold_foreign_item,
@ -611,17 +613,17 @@ impl of ast_fold for ast_fold_precursor {
/* naturally, a macro to write these would be nice */
fn fold_crate(c: crate) -> crate {
let (n, s) = self.fold_crate(c.node, c.span, self as ast_fold);
ret {node: n, span: self.new_span(s)};
return {node: n, span: self.new_span(s)};
}
fn fold_crate_directive(&&c: @crate_directive) -> @crate_directive {
let (n, s) = self.fold_crate_directive(c.node, c.span,
self as ast_fold);
ret @{node: n,
return @{node: n,
span: self.new_span(s)};
}
fn fold_view_item(&&x: @view_item) ->
@view_item {
ret @{node: self.fold_view_item(x.node, self as ast_fold),
return @{node: self.fold_view_item(x.node, self as ast_fold),
attrs: vec::map(x.attrs, |a|
fold_attribute_(a, self as ast_fold)),
vis: x.vis,
@ -629,10 +631,10 @@ impl of ast_fold for ast_fold_precursor {
}
fn fold_foreign_item(&&x: @foreign_item)
-> @foreign_item {
ret self.fold_foreign_item(x, self as ast_fold);
return self.fold_foreign_item(x, self as ast_fold);
}
fn fold_item(&&i: @item) -> option<@item> {
ret self.fold_item(i, self as ast_fold);
return self.fold_item(i, self as ast_fold);
}
fn fold_class_item(&&ci: @class_member) -> @class_member {
@{node: alt ci.node {
@ -647,65 +649,65 @@ impl of ast_fold for ast_fold_precursor {
}
fn fold_item_underscore(i: item_) ->
item_ {
ret self.fold_item_underscore(i, self as ast_fold);
return self.fold_item_underscore(i, self as ast_fold);
}
fn fold_method(&&x: @method)
-> @method {
ret self.fold_method(x, self as ast_fold);
return self.fold_method(x, self as ast_fold);
}
fn fold_block(x: blk) -> blk {
let (n, s) = self.fold_block(x.node, x.span, self as ast_fold);
ret {node: n, span: self.new_span(s)};
return {node: n, span: self.new_span(s)};
}
fn fold_stmt(&&x: @stmt) -> @stmt {
let (n, s) = self.fold_stmt(x.node, x.span, self as ast_fold);
ret @{node: n, span: self.new_span(s)};
return @{node: n, span: self.new_span(s)};
}
fn fold_arm(x: arm) -> arm {
ret self.fold_arm(x, self as ast_fold);
return self.fold_arm(x, self as ast_fold);
}
fn fold_pat(&&x: @pat) -> @pat {
let (n, s) = self.fold_pat(x.node, x.span, self as ast_fold);
ret @{id: self.new_id(x.id),
return @{id: self.new_id(x.id),
node: n,
span: self.new_span(s)};
}
fn fold_decl(&&x: @decl) -> @decl {
let (n, s) = self.fold_decl(x.node, x.span, self as ast_fold);
ret @{node: n, span: self.new_span(s)};
return @{node: n, span: self.new_span(s)};
}
fn fold_expr(&&x: @expr) -> @expr {
let (n, s) = self.fold_expr(x.node, x.span, self as ast_fold);
ret @{id: self.new_id(x.id),
return @{id: self.new_id(x.id),
callee_id: self.new_id(x.callee_id),
node: n,
span: self.new_span(s)};
}
fn fold_ty(&&x: @ty) -> @ty {
let (n, s) = self.fold_ty(x.node, x.span, self as ast_fold);
ret @{id: self.new_id(x.id), node: n, span: self.new_span(s)};
return @{id: self.new_id(x.id), node: n, span: self.new_span(s)};
}
fn fold_mod(x: _mod) -> _mod {
ret self.fold_mod(x, self as ast_fold);
return self.fold_mod(x, self as ast_fold);
}
fn fold_foreign_mod(x: foreign_mod) ->
foreign_mod {
ret self.fold_foreign_mod(x, self as ast_fold);
return self.fold_foreign_mod(x, self as ast_fold);
}
fn fold_variant(x: variant) ->
variant {
let (n, s) = self.fold_variant(x.node, x.span, self as ast_fold);
ret {node: n, span: self.new_span(s)};
return {node: n, span: self.new_span(s)};
}
fn fold_ident(&&x: ident) -> ident {
ret self.fold_ident(x, self as ast_fold);
return self.fold_ident(x, self as ast_fold);
}
fn fold_path(&&x: @path) -> @path {
@self.fold_path(*x, self as ast_fold)
}
fn fold_local(&&x: @local) -> @local {
let (n, s) = self.fold_local(x.node, x.span, self as ast_fold);
ret @{node: n, span: self.new_span(s)};
return @{node: n, span: self.new_span(s)};
}
fn map_exprs(f: fn@(&&@expr) -> @expr, e: ~[@expr]) -> ~[@expr] {
self.map_exprs(f, e)

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