1
Fork 0

Convert to new closure syntax

This commit is contained in:
Brian Anderson 2012-06-30 16:19:07 -07:00
parent 13a8f54538
commit d1fc2b5995
394 changed files with 3253 additions and 3278 deletions

View file

@ -1007,11 +1007,11 @@ the function name.
~~~~
fn iter<T>(seq: ~[T], f: fn(T)) {
for seq.each {|elt| f(elt); }
for seq.each |elt| { f(elt); }
}
fn map<T, U>(seq: ~[T], f: fn(T) -> U) -> ~[U] {
let mut acc = ~[];
for seq.each {|elt| vec::push(acc, f(elt)); }
for seq.each |elt| { vec::push(acc, f(elt)); }
acc
}
~~~~
@ -1638,7 +1638,7 @@ task in a _failing state_.
~~~~
# let buildr = task::builder();
# task::unsupervise(buildr);
# do task::run(buildr) {||
# do task::run(buildr) || {
(~[1, 2, 3, 4])[0];
(~[mut 'x', 'y'])[1] = 'z';
@ -2069,7 +2069,7 @@ An example a for loop:
let v: ~[foo] = ~[a, b, c];
for v.each {|e|
for v.each |e| {
bar(e);
}
~~~~
@ -2276,7 +2276,7 @@ fn read_file_lines(path: str) -> ~[str] {
note path;
let r: [str];
let f: file = open_read(path);
lines(f) {|s|
lines(f) |s| {
r += ~[s];
}
ret r;
@ -3365,7 +3365,7 @@ An example of a `spawn` call:
let po = comm::port();
let ch = comm::chan(po);
do task::spawn {||
do task::spawn || {
// let task run, do other things
// ...
comm::send(ch, true);

View file

@ -851,9 +851,7 @@ full access to its environment.
fn call_closure_with_ten(b: fn(int)) { b(10); }
let x = 20;
call_closure_with_ten({|arg|
#info("x=%d, arg=%d", x, arg);
});
call_closure_with_ten(|arg| #info("x=%d, arg=%d", x, arg) );
~~~~
This defines a function that accepts a closure, and then calls it with
@ -910,7 +908,7 @@ that callers have the flexibility to pass whatever they want.
~~~~
fn call_twice(f: fn()) { f(); f(); }
call_twice({|| "I am a stack closure"; });
call_twice(|| { "I am a stack closure"; } );
call_twice(fn@() { "I am a boxed closure"; });
fn bare_function() { "I am a plain function"; }
call_twice(bare_function);
@ -926,7 +924,7 @@ them. Unique closures mostly exist for spawning new [tasks](#tasks).
### Do syntax
The compact syntax used for stack closures (`{|arg1, arg2| body}`) can
The compact syntax used for stack closures (`|arg1, arg2| body`) can
also be used to express boxed and unique closures in situations where
the closure style can be unambiguously derived from the context. Most
notably, when calling a higher-order function you do not have to use
@ -953,7 +951,7 @@ To run such an iteration, you could do this:
~~~~
# fn for_rev(v: ~[int], act: fn(int)) {}
for_rev(~[1, 2, 3], {|n| log(error, n); });
for_rev(~[1, 2, 3], |n| log(error, n) );
~~~~
Because this is such a common pattern Rust has a special form
@ -962,7 +960,7 @@ structure:
~~~~
# fn for_rev(v: [int], act: fn(int)) {}
do for_rev(~[1, 2, 3]) {|n|
do for_rev(~[1, 2, 3]) |n| {
log(error, n);
}
~~~~
@ -980,7 +978,7 @@ To allow breaking out of loops, many iteration functions, such as
`false` to break off iteration.
~~~~
vec::each(~[2, 4, 8, 5, 16], {|n|
vec::each(~[2, 4, 8, 5, 16], |n| {
if n % 2 != 0 {
io::println("found odd number!");
false
@ -994,7 +992,7 @@ return `true`, and `break` and `cont` can be used, much like in a
`while` loop, to explicitly return `false` or `true`.
~~~~
for vec::each(~[2, 4, 8, 5, 16]) {|n|
for vec::each(~[2, 4, 8, 5, 16]) |n| {
if n % 2 != 0 {
io::println("found odd number!");
break;
@ -1009,7 +1007,7 @@ function, not just the loop body.
~~~~
fn contains(v: ~[int], elt: int) -> bool {
for vec::each(v) {|x|
for vec::each(v) |x| {
if (x == elt) { ret true; }
}
false
@ -1478,7 +1476,7 @@ fn for_rev<T>(v: ~[T], act: fn(T)) {
fn map<T, U>(v: ~[T], f: fn(T) -> U) -> ~[U] {
let mut acc = ~[];
for v.each {|elt| vec::push(acc, f(elt)); }
for v.each |elt| { vec::push(acc, f(elt)); }
ret acc;
}
~~~~
@ -1956,7 +1954,7 @@ parameters.
# iface to_str { fn to_str() -> str; }
fn comma_sep<T: to_str>(elts: ~[T]) -> str {
let mut result = "", first = true;
for elts.each {|elt|
for elts.each |elt| {
if first { first = false; }
else { result += ", "; }
result += elt.to_str();
@ -1986,7 +1984,7 @@ iface seq<T> {
impl <T> of seq<T> for ~[T] {
fn len() -> uint { vec::len(self) }
fn iter(b: fn(T)) {
for self.each {|elt| b(elt); }
for self.each |elt| { b(elt); }
}
}
~~~~
@ -2006,7 +2004,7 @@ However, consider this function:
~~~~
# iface drawable { fn draw(); }
fn draw_all<T: drawable>(shapes: ~[T]) {
for shapes.each {|shape| shape.draw(); }
for shapes.each |shape| { shape.draw(); }
}
~~~~
@ -2020,7 +2018,7 @@ the function to be written simply like this:
~~~~
# iface drawable { fn draw(); }
fn draw_all(shapes: ~[drawable]) {
for shapes.each {|shape| shape.draw(); }
for shapes.each |shape| { shape.draw(); }
}
~~~~
@ -2105,7 +2103,7 @@ extern mod crypto {
fn as_hex(data: ~[u8]) -> str {
let mut acc = "";
for data.each {|byte| acc += #fmt("%02x", byte as uint); }
for data.each |byte| { acc += #fmt("%02x", byte as uint); }
ret acc;
}
@ -2338,7 +2336,7 @@ module `task`. Let's begin with the simplest one, `task::spawn()`:
~~~~
let some_value = 22;
do task::spawn {||
do task::spawn || {
io::println("This executes in the child task.");
io::println(#fmt("%d", some_value));
}
@ -2364,7 +2362,7 @@ in parallel. We might write something like:
# fn some_other_expensive_computation() {}
let port = comm::port::<int>();
let chan = comm::chan::<int>(port);
do task::spawn {||
do task::spawn || {
let result = some_expensive_computation();
comm::send(chan, result);
}
@ -2395,7 +2393,7 @@ The next statement actually spawns the child:
# fn some_expensive_computation() -> int { 42 }
# let port = comm::port::<int>();
# let chan = comm::chan::<int>(port);
do task::spawn {||
do task::spawn || {
let result = some_expensive_computation();
comm::send(chan, result);
}
@ -2458,7 +2456,7 @@ Here is the code for the parent task:
fn main() {
let from_child = comm::port();
let to_parent = comm::chan(from_child);
let to_child = do task::spawn_listener {|from_parent|
let to_child = do task::spawn_listener |from_parent| {
stringifier(from_parent, to_parent);
};
comm::send(to_child, 22u);

View file

@ -117,7 +117,7 @@ fn is_uuid(id: str) -> bool {
let parts = str::split_str(id, "-");
if vec::len(parts) == 5u {
let mut correct = 0u;
for vec::eachi(parts) { |i, part|
for vec::eachi(parts) |i, part| {
fn is_hex_digit(ch: char) -> bool {
('0' <= ch && ch <= '9') ||
('a' <= ch && ch <= 'f') ||
@ -222,7 +222,7 @@ fn load_link(mis: ~[@ast::meta_item]) -> (option<str>,
let mut name = none;
let mut vers = none;
let mut uuid = none;
for mis.each {|a|
for mis.each |a| {
alt a.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
alt *v {
@ -249,7 +249,7 @@ fn load_crate(filename: str) -> option<crate> {
let mut sigs = none;
let mut crate_type = none;
for c.node.attrs.each {|a|
for c.node.attrs.each |a| {
alt a.node.value.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) {
alt *v {
@ -291,7 +291,7 @@ fn load_crate(filename: str) -> option<crate> {
let mut attr_vers = "";
let mut attr_from = "";
for m.each { |item|
for m.each |item| {
alt attr::get_meta_item_value_str(item) {
some(value) {
let name = attr::get_meta_item_name(item);
@ -329,8 +329,8 @@ fn load_crate(filename: str) -> option<crate> {
mut deps: ~[]
};
let v = visit::mk_simple_visitor(@{
visit_view_item: {|a|goto_view_item(e, a)},
visit_item: {|a|goto_item(e, a)},
visit_view_item: |a| goto_view_item(e, a),
visit_item: |a| goto_item(e, a),
with *visit::default_simple_visitor()
});
@ -435,7 +435,7 @@ fn try_parse_sources(filename: str, sources: map::hashmap<str, source>) {
let c = io::read_whole_file_str(filename);
alt json::from_str(result::get(c)) {
ok(json::dict(j)) {
for j.each { |k, v|
for j.each |k, v| {
sources.insert(k, parse_source(k, v));
#debug("source: %s", k);
}
@ -501,7 +501,7 @@ fn load_one_source_package(src: source, p: map::hashmap<str, json::json>) {
let mut tags = ~[];
alt p.find("tags") {
some(json::list(js)) {
for (*js).each {|j|
for (*js).each |j| {
alt j {
json::string(j) { vec::grow(tags, 1u, *j); }
_ { }
@ -531,7 +531,7 @@ fn load_one_source_package(src: source, p: map::hashmap<str, json::json>) {
versions: ~[]
};
alt src.packages.position({ |pkg| pkg.uuid == uuid }) {
alt src.packages.position(|pkg| pkg.uuid == uuid ) {
some(idx) {
src.packages[idx] = newpkg;
log(debug, " updated package: " + src.name + "/" + name);
@ -573,7 +573,7 @@ fn load_source_packages(c: cargo, src: source) {
let pkgstr = io::read_whole_file_str(pkgfile);
alt json::from_str(result::get(pkgstr)) {
ok(json::list(js)) {
for (*js).each {|j|
for (*js).each |j| {
alt j {
json::dict(p) {
load_one_source_package(src, p);
@ -667,7 +667,7 @@ fn configure(opts: options) -> cargo {
need_dir(c.libdir);
need_dir(c.bindir);
for sources.each_key { |k|
for sources.each_key |k| {
let mut s = sources.get(k);
load_source_packages(c, s);
sources.insert(k, s);
@ -685,11 +685,11 @@ fn configure(opts: options) -> cargo {
}
fn for_each_package(c: cargo, b: fn(source, package)) {
for c.sources.each_value {|v|
for c.sources.each_value |v| {
// FIXME (#2280): this temporary shouldn't be
// necessary, but seems to be, for borrowing.
let pks = copy v.packages;
for vec::each(pks) {|p|
for vec::each(pks) |p| {
b(v, p);
}
}
@ -698,7 +698,7 @@ fn for_each_package(c: cargo, b: fn(source, package)) {
// Runs all programs in directory <buildpath>
fn run_programs(buildpath: str) {
let newv = os::list_dir_path(buildpath);
for newv.each {|ct|
for newv.each |ct| {
run::run_program(ct, ~[]);
}
}
@ -736,7 +736,7 @@ fn install_one_crate(c: cargo, path: str, cf: str) {
};
let newv = os::list_dir_path(buildpath);
let exec_suffix = os::exe_suffix();
for newv.each {|ct|
for newv.each |ct| {
if (exec_suffix != "" && str::ends_with(ct, exec_suffix)) ||
(exec_suffix == "" && !str::starts_with(path::basename(ct),
"lib")) {
@ -773,7 +773,7 @@ fn install_source(c: cargo, path: str) {
os::change_dir(path);
let mut cratefiles = ~[];
for os::walk_dir(".") {|p|
for os::walk_dir(".") |p| {
if str::ends_with(p, ".rc") {
vec::push(cratefiles, p);
}
@ -783,11 +783,11 @@ fn install_source(c: cargo, path: str) {
fail "this doesn't look like a rust package (no .rc files)";
}
for cratefiles.each {|cf|
for cratefiles.each |cf| {
alt load_crate(cf) {
none { cont; }
some(crate) {
for crate.deps.each { |query|
for crate.deps.each |query| {
// TODO: handle cyclic dependencies
let wd_base = c.workdir + path::path_sep();
@ -869,7 +869,7 @@ fn cargo_suggestion(c: cargo, fallback: fn())
fn install_uuid(c: cargo, wd: str, uuid: str) {
let mut ps = ~[];
for_each_package(c, { |s, p|
for_each_package(c, |s, p| {
if p.uuid == uuid {
vec::grow(ps, 1u, (s.name, copy p));
}
@ -879,13 +879,13 @@ fn install_uuid(c: cargo, wd: str, uuid: str) {
install_package(c, sname, wd, p);
ret;
} else if vec::len(ps) == 0u {
cargo_suggestion(c, { ||
cargo_suggestion(c, || {
error("can't find package: " + uuid);
});
ret;
}
error("found multiple packages:");
for ps.each {|elt|
for ps.each |elt| {
let (sname,p) = copy elt;
info(" " + sname + "/" + p.uuid + " (" + p.name + ")");
}
@ -893,7 +893,7 @@ fn install_uuid(c: cargo, wd: str, uuid: str) {
fn install_named(c: cargo, wd: str, name: str) {
let mut ps = ~[];
for_each_package(c, { |s, p|
for_each_package(c, |s, p| {
if p.name == name {
vec::grow(ps, 1u, (s.name, copy p));
}
@ -903,13 +903,13 @@ fn install_named(c: cargo, wd: str, name: str) {
install_package(c, sname, wd, p);
ret;
} else if vec::len(ps) == 0u {
cargo_suggestion(c, { ||
cargo_suggestion(c, || {
error("can't find package: " + name);
});
ret;
}
error("found multiple packages:");
for ps.each {|elt|
for ps.each |elt| {
let (sname,p) = copy elt;
info(" " + sname + "/" + p.uuid + " (" + p.name + ")");
}
@ -919,7 +919,7 @@ fn install_uuid_specific(c: cargo, wd: str, src: str, uuid: str) {
alt c.sources.find(src) {
some(s) {
let packages = copy s.packages;
if vec::any(packages, { |p|
if vec::any(packages, |p| {
if p.uuid == uuid {
install_package(c, src, wd, p);
true
@ -935,7 +935,7 @@ fn install_named_specific(c: cargo, wd: str, src: str, name: str) {
alt c.sources.find(src) {
some(s) {
let packages = copy s.packages;
if vec::any(packages, { |p|
if vec::any(packages, |p| {
if p.name == name {
install_package(c, src, wd, p);
true
@ -962,7 +962,7 @@ fn cmd_uninstall(c: cargo) {
// cache instead of looking for it (binaries can be uninstalled by
// name only)
if is_uuid(target) {
for os::list_dir(lib).each { |file|
for os::list_dir(lib).each |file| {
alt str::find_str(file, "-" + target + "-") {
some(idx) {
let full = path::normalize(path::connect(lib, file));
@ -979,7 +979,7 @@ fn cmd_uninstall(c: cargo) {
error("can't find package with uuid: " + target);
} else {
for os::list_dir(lib).each { |file|
for os::list_dir(lib).each |file| {
alt str::find_str(file, "lib" + target + "-") {
some(idx) {
let full = path::normalize(path::connect(lib,
@ -994,7 +994,7 @@ fn cmd_uninstall(c: cargo) {
none { cont; }
}
}
for os::list_dir(bin).each { |file|
for os::list_dir(bin).each |file| {
alt str::find_str(file, target) {
some(idx) {
let full = path::normalize(path::connect(bin, file));
@ -1065,7 +1065,7 @@ fn install_query(c: cargo, wd: str, target: str) {
// a bit of a hack. It should be cleaned up in the future.
if target == c.current_install {
for c.dep_cache.each { |k, _v|
for c.dep_cache.each |k, _v| {
c.dep_cache.remove(k);
}
@ -1101,7 +1101,7 @@ fn cmd_install(c: cargo) unsafe {
}
fn sync(c: cargo) {
for c.sources.each_key { |k|
for c.sources.each_key |k| {
let mut s = c.sources.get(k);
sync_one(c, s);
c.sources.insert(k, s);
@ -1464,15 +1464,13 @@ fn print_pkg(s: source, p: package) {
fn print_source(s: source) {
info(s.name + " (" + s.url + ")");
let pks = sort::merge_sort({ |a, b|
a < b
}, copy s.packages);
let pks = sort::merge_sort(|a, b| a < b, copy s.packages);
let l = vec::len(pks);
print(io::with_str_writer({ |writer|
print(io::with_str_writer(|writer| {
let mut list = " >> ";
do vec::iteri(pks) { |i, pk|
do vec::iteri(pks) |i, pk| {
if str::len(list) > 78u {
writer.write_line(list);
list = " >> ";
@ -1488,7 +1486,7 @@ fn cmd_list(c: cargo) {
sync(c);
if vec::len(c.opts.free) >= 3u {
do vec::iter_between(c.opts.free, 2u, vec::len(c.opts.free)) { |name|
do vec::iter_between(c.opts.free, 2u, vec::len(c.opts.free)) |name| {
if !valid_pkg_name(name) {
error(#fmt("'%s' is an invalid source name", name));
} else {
@ -1503,7 +1501,7 @@ fn cmd_list(c: cargo) {
}
}
} else {
for c.sources.each_value { |v|
for c.sources.each_value |v| {
print_source(v);
}
}
@ -1520,9 +1518,9 @@ fn cmd_search(c: cargo) {
let mut n = 0;
let name = c.opts.free[2];
let tags = vec::slice(c.opts.free, 3u, vec::len(c.opts.free));
for_each_package(c, { |s, p|
for_each_package(c, |s, p| {
if (str::contains(p.name, name) || name == "*") &&
vec::all(tags, { |t| vec::contains(p.tags, t) }) {
vec::all(tags, |t| vec::contains(p.tags, t) ) {
print_pkg(s, p);
n += 1;
}
@ -1569,7 +1567,7 @@ fn dump_sources(c: cargo) {
let hash = map::str_hash();
let root = json::dict(hash);
for c.sources.each { |k, v|
for c.sources.each |k, v| {
let chash = map::str_hash();
let child = json::dict(chash);
@ -1608,7 +1606,7 @@ fn copy_warn(srcfile: str, destfile: str) {
fn cmd_sources(c: cargo) {
if vec::len(c.opts.free) < 3u {
for c.sources.each_value { |v|
for c.sources.each_value |v| {
info(#fmt("%s (%s) via %s",
copy v.name, copy v.url, copy v.method));
}
@ -1619,7 +1617,7 @@ fn cmd_sources(c: cargo) {
alt action {
"clear" {
for c.sources.each_key { |k|
for c.sources.each_key |k| {
c.sources.remove(k);
}

View file

@ -90,7 +90,7 @@ fn verify(root: str, data: str, sig: str, keyfp: str) -> bool {
let p = gpg(~["--homedir", path, "--with-fingerprint", "--verify", sig,
data]);
let res = "Primary key fingerprint: " + keyfp;
for str::split_char(p.err, '\n').each {|line|
for str::split_char(p.err, '\n').each |line| {
if line == res { ret true; }
}
ret false;

View file

@ -136,7 +136,7 @@ fn test_opts(config: config) -> test::test_opts {
fn make_tests(config: config) -> ~[test::test_desc] {
#debug("making tests from %s", config.src_base);
let mut tests = ~[];
for os::list_dir_path(config.src_base).each {|file|
for os::list_dir_path(config.src_base).each |file| {
let file = file;
#debug("inspecting file %s", file);
if is_test(config, file) {
@ -155,11 +155,11 @@ fn is_test(config: config, testfile: str) -> bool {
let mut valid = false;
for valid_extensions.each {|ext|
for valid_extensions.each |ext| {
if str::ends_with(name, ext) { valid = true; }
}
for invalid_prefixes.each {|pre|
for invalid_prefixes.each |pre| {
if str::starts_with(name, pre) { valid = false; }
}
@ -181,9 +181,7 @@ fn make_test_name(config: config, testfile: str) -> str {
}
fn make_test_closure(config: config, testfile: str) -> test::test_fn {
ret {||
runtest::run(config, copy testfile);
};
fn~() { runtest::run(config, copy testfile) }
}
// Local Variables:

View file

@ -29,7 +29,7 @@ fn load_props(testfile: str) -> test_props {
let mut exec_env = ~[];
let mut compile_flags = option::none;
let mut pp_exact = option::none;
for iter_header(testfile) {|ln|
for iter_header(testfile) |ln| {
alt parse_error_pattern(ln) {
option::some(ep) { vec::push(error_patterns, ep) }
option::none { }
@ -43,11 +43,11 @@ fn load_props(testfile: str) -> test_props {
pp_exact = parse_pp_exact(ln, testfile);
}
do option::iter(parse_aux_build(ln)) {|ab|
do option::iter(parse_aux_build(ln)) |ab| {
vec::push(aux_builds, ab);
}
do option::iter(parse_exec_env(ln)) {|ee|
do option::iter(parse_exec_env(ln)) |ee| {
vec::push(exec_env, ee);
}
};
@ -62,7 +62,7 @@ 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|
for iter_header(testfile) |ln| {
if parse_name_directive(ln, "xfail-test") { ret true; }
if parse_name_directive(ln, xfail_target()) { ret true; }
if config.mode == common::mode_pretty &&
@ -104,7 +104,7 @@ fn parse_compile_flags(line: str) -> option<str> {
}
fn parse_exec_env(line: str) -> option<(str, str)> {
do parse_name_value_directive(line, "exec-env").map {|nv|
do parse_name_value_directive(line, "exec-env").map |nv| {
// nv is either FOO or FOO=BAR
let strs = str::splitn_char(nv, '=', 1u);
alt strs.len() {

View file

@ -13,7 +13,7 @@ fn target_env(lib_path: str, prog: str) -> ~[(str,str)] {
assert prog.ends_with(".exe");
let aux_path = prog.slice(0u, prog.len() - 4u) + ".libaux";
env = do vec::map(env) {|pair|
env = do vec::map(env) |pair| {
let (k,v) = pair;
if k == "PATH" { ("PATH", v + ";" + lib_path + ";" + aux_path) }
else { (k,v) }
@ -60,11 +60,11 @@ fn run(lib_path: str,
writeclose(pipe_in.out, input);
let p = comm::port();
let ch = comm::chan(p);
do task::spawn_sched(task::single_threaded) {||
do task::spawn_sched(task::single_threaded) || {
let errput = readclose(pipe_err.in);
comm::send(ch, (2, errput));
}
do task::spawn_sched(task::single_threaded) {||
do task::spawn_sched(task::single_threaded) || {
let output = readclose(pipe_out.in);
comm::send(ch, (1, output));
}

View file

@ -199,7 +199,7 @@ fn check_error_patterns(props: test_props,
let mut next_err_idx = 0u;
let mut next_err_pat = props.error_patterns[next_err_idx];
let mut done = false;
for str::split_char(procres.stderr, '\n').each {|line|
for str::split_char(procres.stderr, '\n').each |line| {
if str::contains(line, next_err_pat) {
#debug("found error pattern %s", next_err_pat);
next_err_idx += 1u;
@ -220,7 +220,7 @@ fn check_error_patterns(props: test_props,
fatal_procres(#fmt["error pattern '%s' not found!",
missing_patterns[0]], procres);
} else {
for missing_patterns.each {|pattern|
for missing_patterns.each |pattern| {
error(#fmt["error pattern '%s' not found!", pattern]);
}
fatal_procres("multiple error patterns not found", procres);
@ -239,7 +239,7 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
fatal("process did not return an error status");
}
let prefixes = vec::map(expected_errors, {|ee|
let prefixes = vec::map(expected_errors, |ee| {
#fmt("%s:%u:", testfile, ee.line)
});
@ -249,9 +249,9 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
// filename:line1:col1: line2:col2: *warning:* msg
// where line1:col1: is the starting point, line2:col2:
// is the ending point, and * represents ANSI color codes.
for str::split_char(procres.stderr, '\n').each {|line|
for str::split_char(procres.stderr, '\n').each |line| {
let mut was_expected = false;
for vec::eachi(expected_errors) {|i, ee|
for vec::eachi(expected_errors) |i, ee| {
if !found_flags[i] {
#debug["prefix=%s ee.kind=%s ee.msg=%s line=%s",
prefixes[i], ee.kind, ee.msg, line];
@ -277,7 +277,7 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
}
}
for uint::range(0u, vec::len(found_flags)) {|i|
for uint::range(0u, vec::len(found_flags)) |i| {
if !found_flags[i] {
let ee = expected_errors[i];
fatal_procres(#fmt["expected %s on line %u not found: %s",
@ -321,11 +321,11 @@ fn compose_and_run_compiler(
let extra_link_args = ~["-L", aux_output_dir_name(config, testfile)];
do vec::iter(props.aux_builds) {|rel_ab|
do vec::iter(props.aux_builds) |rel_ab| {
let abs_ab = path::connect(config.aux_base, rel_ab);
let aux_args =
make_compile_args(config, props, ~["--lib"] + extra_link_args,
{|a,b|make_lib_name(a, b, testfile)}, abs_ab);
|a,b| make_lib_name(a, b, testfile), abs_ab);
let auxres = compose_and_run(config, abs_ab, aux_args, ~[],
config.compile_lib_path, option::none);
if auxres.status != 0 {

View file

@ -25,7 +25,7 @@ fn find_rust_files(&files: ~[str], path: str) {
} else if os::path_is_dir(path)
&& !contains(path, "compile-fail")
&& !contains(path, "build") {
for os::list_dir_path(path).each {|p|
for os::list_dir_path(path).each |p| {
find_rust_files(files, p);
}
}
@ -139,8 +139,8 @@ fn steal(crate: ast::crate, tm: test_mode) -> stolen_stuff {
let exprs = @mut ~[];
let tys = @mut ~[];
let v = visit::mk_simple_visitor(@{
visit_expr: {|a|stash_expr_if(safe_to_steal_expr, exprs, a, tm)},
visit_ty: {|a|stash_ty_if(safe_to_steal_ty, tys, a, tm)}
visit_expr: |a| stash_expr_if(safe_to_steal_expr, exprs, a, tm),
visit_ty: |a| stash_ty_if(safe_to_steal_ty, tys, a, tm)
with *visit::default_simple_visitor()
});
visit::visit_crate(crate, (), v);
@ -187,10 +187,12 @@ fn replace_expr_in_crate(crate: ast::crate, i: uint,
fold::noop_fold_expr(original, fld)
}
}
let afp =
@{fold_expr: fold::wrap({|a,b|
fold_expr_rep(j, i, newexpr.node, a, b, tm)})
with *fold::default_ast_fold()};
let afp = @{
fold_expr: fold::wrap(|a,b| {
fold_expr_rep(j, i, newexpr.node, a, b, tm)
})
with *fold::default_ast_fold()
};
let af = fold::make_fold(afp);
let crate2: @ast::crate = @af.fold_crate(crate);
*crate2
@ -210,9 +212,10 @@ fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty,
newty_
} else { fold::noop_fold_ty(original, fld) }
}
let afp =
@{fold_ty: fold::wrap({|a,b|fold_ty_rep(j, i, newty.node, a, b, tm)})
with *fold::default_ast_fold()};
let afp = @{
fold_ty: fold::wrap(|a,b| fold_ty_rep(j, i, newty.node, a, b, tm) )
with *fold::default_ast_fold()
};
let af = fold::make_fold(afp);
let crate2: @ast::crate = @af.fold_crate(crate);
*crate2
@ -235,7 +238,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
filename: str, cx: context) {
let stolen = steal(crate, cx.mode);
let extra_exprs = vec::filter(common_exprs(),
{|a|safe_to_use_expr(a, cx.mode)});
|a| safe_to_use_expr(a, cx.mode) );
check_variants_T(crate, codemap, filename, "expr",
extra_exprs + stolen.exprs, pprust::expr_to_str,
replace_expr_in_crate, cx);
@ -259,23 +262,23 @@ fn check_variants_T<T: copy>(
let L = vec::len(things);
if L < 100u {
do under(uint::min(L, 20u)) {|i|
do under(uint::min(L, 20u)) |i| {
log(error, "Replacing... #" + uint::str(i));
do under(uint::min(L, 30u)) {|j|
do under(uint::min(L, 30u)) |j| {
log(error, "With... " + stringifier(@things[j]));
let crate2 = @replacer(crate, i, things[j], cx.mode);
// It would be best to test the *crate* for stability, but
// testing the string for stability is easier and ok for now.
let handler = diagnostic::mk_handler(none);
let str3 =
@as_str({|a|pprust::print_crate(
@as_str(|a|pprust::print_crate(
codemap,
diagnostic::mk_span_handler(handler, codemap),
crate2,
filename,
io::str_reader(""), a,
pprust::no_ann(),
false)});
false));
alt cx.mode {
tm_converge {
check_roundtrip_convergence(str3, 1u);
@ -421,14 +424,14 @@ fn parse_and_print(code: @str) -> str {
write_file(filename, *code);
let crate = parse::parse_crate_from_source_str(
filename, code, ~[], sess);
io::with_str_reader(*code, { |rdr|
as_str({|a|pprust::print_crate(sess.cm,
io::with_str_reader(*code, |rdr| {
as_str(|a| pprust::print_crate(sess.cm,
sess.span_diagnostic,
crate,
filename,
rdr, a,
pprust::no_ann(),
false)})
false) )
})
}
@ -441,7 +444,7 @@ fn has_raw_pointers(c: ast::crate) -> bool {
}
}
let v =
visit::mk_simple_visitor(@{visit_ty: {|a|visit_ty(has_rp, a)}
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;
@ -455,7 +458,7 @@ 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; } }
for dangerous_patterns.each |p| { if contains(code, p) { ret true; } }
ret false;
}
@ -463,7 +466,7 @@ 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; } }
for dangerous_patterns.each |p| { if contains(code, p) { ret true; } }
ret false;
}
@ -479,7 +482,7 @@ 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; } }
for confusing_patterns.each |p| { if contains(code, p) { ret true; } }
ret false;
}
@ -493,7 +496,7 @@ 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) { ret true; } }
ret false;
}
@ -527,7 +530,7 @@ fn check_roundtrip_convergence(code: @str, maxIters: uint) {
fn check_convergence(files: ~[str]) {
#error("pp convergence tests: %u files", vec::len(files));
for files.each {|file|
for files.each |file| {
if !file_might_not_converge(file) {
let s = @result::get(io::read_whole_file_str(file));
if !content_might_not_converge(*s) {
@ -541,7 +544,7 @@ fn check_convergence(files: ~[str]) {
}
fn check_variants(files: ~[str], cx: context) {
for files.each {|file|
for files.each |file| {
if cx.mode == tm_converge && file_might_not_converge(file) {
#error("Skipping convergence test based on\
file_might_not_converge");
@ -565,15 +568,15 @@ fn check_variants(files: ~[str], cx: context) {
parse::parse_crate_from_source_str(
file,
s, ~[], sess);
io::with_str_reader(*s, { |rdr|
io::with_str_reader(*s, |rdr| {
#error("%s",
as_str({|a|pprust::print_crate(sess.cm,
as_str(|a| pprust::print_crate(sess.cm,
sess.span_diagnostic,
crate,
file,
rdr, a,
pprust::no_ann(),
false)}))
false) ))
});
check_variants_of_ast(*crate, sess.cm, file, cx);
}

View file

@ -109,9 +109,7 @@ impl methods<T: send> for exclusive<T> {
unsafe::reinterpret_cast(self.data);
let r = {
let rec: &ex_data<T> = &(*ptr).data;
rec.lock.lock_cond({|c|
f(c, &rec.data)
})
rec.lock.lock_cond(|c| f(c, &rec.data))
};
unsafe::forget(ptr);
r
@ -135,7 +133,7 @@ fn shared_arc<T: send const>(-data: T) -> shared_arc<T> {
let a = arc::arc(data);
let p = port();
let c = chan(p);
do task::spawn() {|move a|
do task::spawn() |move a| {
let mut live = true;
let terminate = port();
let get = port();
@ -174,7 +172,7 @@ mod tests {
let p = port();
let c = chan(p);
do task::spawn() {||
do task::spawn() || {
let p = port();
c.send(chan(p));
@ -200,7 +198,7 @@ mod tests {
let p = port();
let c = chan(p);
do task::spawn() {||
do task::spawn() || {
let arc_v = get_arc(arc_c);
let v = *get(&arc_v);
assert v[2] == 3;
@ -221,20 +219,20 @@ mod tests {
let total = exclusive(~mut 0u);
for uint::range(0u, num_tasks) {|_i|
for uint::range(0u, num_tasks) |_i| {
let total = total.clone();
futures += ~[future::spawn({||
for uint::range(0u, count) {|_i|
do total.with {|_cond, count|
futures += ~[future::spawn(|| {
for uint::range(0u, count) |_i| {
do total.with |_cond, count| {
**count += 1u;
}
}
})];
};
for futures.each {|f| f.get() };
for futures.each |f| { f.get() }
do total.with {|_cond, total|
do total.with |_cond, total| {
assert **total == num_tasks * count
};
}

View file

@ -65,7 +65,7 @@ pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
#[test]
fn test_bool_from_str() {
do all_values { |v|
do all_values |v| {
assert some(v) == from_str(bool::to_str(v))
}
}
@ -78,7 +78,7 @@ fn test_bool_to_str() {
#[test]
fn test_bool_to_bit() {
do all_values { |v|
do all_values |v| {
assert to_bit(v) == if is_true(v) { 1u8 } else { 0u8 };
}
}

View file

@ -140,7 +140,7 @@ fn escape_unicode(c: char) -> str {
assert str::len(s) <= pad;
let mut out = "\\";
out += str::from_char(c);
for uint::range(str::len(s), pad) {|_i| out += "0"; }
for uint::range(str::len(s), pad) |_i| { out += "0"; }
out += s;
ret out;
}

View file

@ -98,7 +98,7 @@ class port_ptr<T:send> {
let po: *rust_port;
new(po: *rust_port) { self.po = po; }
drop unsafe {
do task::unkillable {||
do task::unkillable || {
// Once the port is detached it's guaranteed not to receive further
// messages
let yield = 0u;
@ -184,11 +184,11 @@ fn peek<T: send>(p: port<T>) -> bool { peek_((**p).po) }
#[doc(hidden)]
fn recv_chan<T: send>(ch: comm::chan<T>) -> T {
as_raw_port(ch, {|x|recv_(x)})
as_raw_port(ch, |x|recv_(x))
}
fn peek_chan<T: send>(ch: comm::chan<T>) -> bool {
as_raw_port(ch, {|x|peek_(x)})
as_raw_port(ch, |x|peek_(x))
}
#[doc = "Receive on a raw port pointer"]
@ -223,7 +223,7 @@ fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>)
let mut resport: *rust_port;
resport = rusti::init::<*rust_port>();
do vec::as_buf(ports) {|ports|
do vec::as_buf(ports) |ports| {
rustrt::rust_port_select(ptr::addr_of(resport), ports, n_ports,
yieldp);
}
@ -364,16 +364,16 @@ fn test_select2_rendezvous() {
let ch_a = chan(po_a);
let ch_b = chan(po_b);
do iter::repeat(10u) {||
do task::spawn {||
iter::repeat(10u, {|| task::yield() });
do iter::repeat(10u) || {
do task::spawn || {
iter::repeat(10u, || task::yield());
send(ch_a, "a");
};
assert select2(po_a, po_b) == either::left("a");
do task::spawn {||
iter::repeat(10u, {|| task::yield() });
do task::spawn || {
iter::repeat(10u, || task::yield());
send(ch_b, "b");
};
@ -391,14 +391,14 @@ fn test_select2_stress() {
let msgs = 100u;
let times = 4u;
do iter::repeat(times) {||
do task::spawn {||
do iter::repeat(msgs) {||
do iter::repeat(times) || {
do task::spawn || {
do iter::repeat(msgs) || {
send(ch_a, "a")
}
};
do task::spawn {||
do iter::repeat(msgs) {||
do task::spawn || {
do iter::repeat(msgs) || {
send(ch_b, "b")
}
};
@ -406,7 +406,7 @@ fn test_select2_stress() {
let mut as = 0;
let mut bs = 0;
do iter::repeat(msgs * times * 2u) {||
do iter::repeat(msgs * times * 2u) || {
alt check select2(po_a, po_b) {
either::left("a") { as += 1 }
either::right("b") { bs += 1 }
@ -440,9 +440,9 @@ fn test_recv_chan_wrong_task() {
let po = port();
let ch = chan(po);
send(ch, "flower");
assert result::is_err(task::try({||
assert result::is_err(task::try(||
recv_chan(ch)
}))
))
}
#[test]
@ -462,8 +462,8 @@ fn test_chan_peek() {
#[test]
fn test_listen() {
do listen {|parent|
do task::spawn {||
do listen |parent| {
do task::spawn || {
parent.send("oatmeal-salad");
}
assert parent.recv() == "oatmeal-salad";
@ -473,18 +473,18 @@ fn test_listen() {
#[test]
#[ignore(cfg(windows))]
fn test_port_detach_fail() {
do iter::repeat(100u) {||
do iter::repeat(100u) || {
let builder = task::builder();
task::unsupervise(builder);
do task::run(builder) {||
do task::run(builder) || {
let po = port();
let ch = po.chan();
do task::spawn {||
do task::spawn || {
fail;
}
do task::spawn {||
do task::spawn || {
ch.send(());
}
}

View file

@ -114,12 +114,12 @@ impl extensions<A> for dvec<A> {
"]
#[inline(always)]
fn swap(f: fn(-~[mut A]) -> ~[mut A]) {
self.borrow({ |v| self.return(f(v)) })
self.borrow(|v| self.return(f(v)))
}
#[doc = "Returns the number of elements currently in the dvec"]
fn len() -> uint {
do self.borrow { |v|
do self.borrow |v| {
let l = v.len();
self.return(v);
l
@ -134,7 +134,7 @@ impl extensions<A> for dvec<A> {
#[doc = "Remove and return the last element"]
fn pop() -> A {
do self.borrow { |v|
do self.borrow |v| {
let mut v <- v;
let result = vec::pop(v);
self.return(v);
@ -164,7 +164,7 @@ impl extensions<A> for dvec<A> {
#[doc = "Remove and return the first element"]
fn shift() -> A {
do self.borrow { |v|
do self.borrow |v| {
let mut v = vec::from_mut(v);
let result = vec::shift(v);
self.return(vec::to_mut(v));
@ -187,7 +187,7 @@ impl extensions<A:copy> for dvec<A> {
Appends elements from `from_idx` to `to_idx` (exclusive)
"]
fn push_slice(ts: &[const A], from_idx: uint, to_idx: uint) {
do self.swap { |v|
do self.swap |v| {
let mut v <- v;
let new_len = vec::len(v) + to_idx - from_idx;
vec::reserve(v, new_len);
@ -207,7 +207,7 @@ impl extensions<A:copy> for dvec<A> {
attempts to access this vector.
"]
fn append_iter<A, I:iter::base_iter<A>>(ts: I) {
do self.swap { |v|
do self.swap |v| {
let mut v = alt ts.size_hint() {
none { v }
some(h) {
@ -218,7 +218,7 @@ impl extensions<A:copy> for dvec<A> {
}
};
for ts.each { |t| vec::push(v, t) };
for ts.each |t| { vec::push(v, t) };
v
}
}
@ -229,7 +229,7 @@ impl extensions<A:copy> for dvec<A> {
See `unwrap()` if you do not wish to copy the contents.
"]
fn get() -> ~[A] {
do self.borrow { |v|
do self.borrow |v| {
let w = vec::from_mut(copy v);
self.return(v);
w
@ -259,7 +259,7 @@ impl extensions<A:copy> for dvec<A> {
growing the vector if necessary. New elements will be initialized
with `initval`"]
fn grow_set_elt(idx: uint, initval: A, val: A) {
do self.swap { |v|
do self.swap |v| {
let mut v <- v;
vec::grow_set(v, idx, initval, val);
v

View file

@ -25,7 +25,7 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
#[doc = "Extracts from a vector of either all the left values"];
let mut result: ~[T] = ~[];
for vec::each(eithers) {|elt|
for vec::each(eithers) |elt| {
alt elt { left(l) { vec::push(result, l); } _ {/* fallthrough */ } }
}
ret result;
@ -35,7 +35,7 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
#[doc = "Extracts from a vector of either all the right values"];
let mut result: ~[U] = ~[];
for vec::each(eithers) {|elt|
for vec::each(eithers) |elt| {
alt elt { right(r) { vec::push(result, r); } _ {/* fallthrough */ } }
}
ret result;
@ -52,7 +52,7 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
let mut lefts: ~[T] = ~[];
let mut rights: ~[U] = ~[];
for vec::each(eithers) {|elt|
for vec::each(eithers) |elt| {
alt elt {
left(l) { vec::push(lefts, l); }
right(r) { vec::push(rights, r); }

View file

@ -174,7 +174,7 @@ mod ct {
let curr: ~[flag] = ~[f];
ret {flags: vec::append(curr, rest), next: j};
}
let more = {|x|more_(x, s, i, lim)};
let more = |x| more_(x, s, i, lim);
let f = s[i];
ret if f == '-' as u8 {
more(flag_left_justify)

View file

@ -64,7 +64,7 @@ fn from_port<A:send>(-port: comm::port<A>) -> future<A> {
waiting for the result to be received on the port.
"];
do from_fn {||
do from_fn || {
comm::recv(port)
}
}
@ -93,7 +93,7 @@ fn spawn<A:send>(+blk: fn~() -> A) -> future<A> {
let mut po = comm::port();
let ch = comm::chan(po);
do task::spawn {||
do task::spawn || {
comm::send(ch, blk())
};
from_port(po)
@ -102,7 +102,7 @@ fn spawn<A:send>(+blk: fn~() -> A) -> future<A> {
fn get<A:copy>(future: future<A>) -> A {
#[doc = "Get the value of the future"];
do with(future) {|v| v }
do with(future) |v| { v }
}
fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B {
@ -150,18 +150,18 @@ fn test_iface_get() {
#[test]
fn test_with() {
let f = from_value("nail");
assert with(f, {|v| v}) == "nail";
assert with(f, |v| v) == "nail";
}
#[test]
fn test_iface_with() {
let f = from_value("kale");
assert f.with({|v| v}) == "kale";
assert f.with(|v| v) == "kale";
}
#[test]
fn test_spawn() {
let f = spawn({|| "bale" });
let f = spawn(|| "bale");
assert get(f) == "bale";
}
@ -169,6 +169,6 @@ fn test_spawn() {
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
fn test_futurefail() {
let f = spawn({|| fail });
let f = spawn(|| fail);
let _x: str = get(f);
}

View file

@ -93,8 +93,8 @@ fn from_str(s: str) -> option<T> { parse_buf(str::bytes(s), 10u) }
#[doc = "Convert to a string in a given base"]
fn to_str(n: T, radix: uint) -> str {
do to_str_bytes(n, radix) {|slice|
do vec::unpack_slice(slice) {|p, len|
do to_str_bytes(n, radix) |slice| {
do vec::unpack_slice(slice) |p, len| {
unsafe { str::unsafe::from_buf_len(p, len) }
}
}

View file

@ -195,7 +195,7 @@ impl of reader for *libc::FILE {
fn read_bytes(len: uint) -> ~[u8] {
let mut buf : ~[mut u8] = ~[mut];
vec::reserve(buf, len);
do vec::as_mut_buf(buf) {|b|
do vec::as_mut_buf(buf) |b| {
let read = libc::fread(b as *mut c_void, 1u as size_t,
len as size_t, self);
unsafe { vec::unsafe::set_len(buf, read as uint) };
@ -245,10 +245,10 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> reader {
fn stdin() -> reader { rustrt::rust_get_stdin() as reader }
fn file_reader(path: str) -> result<reader, str> {
let f = os::as_c_charp(path, {|pathbuf|
os::as_c_charp("r", {|modebuf|
let f = os::as_c_charp(path, |pathbuf| {
os::as_c_charp("r", |modebuf|
libc::fopen(pathbuf, modebuf)
})
)
});
ret if f as uint == 0u { result::err("error opening " + path) }
else {
@ -308,7 +308,7 @@ fn str_reader(s: str) -> reader {
}
fn with_str_reader<T>(s: str, f: fn(reader) -> T) -> T {
do str::as_bytes(s) { |bytes|
do str::as_bytes(s) |bytes| {
with_bytes_reader_between(bytes, 0u, str::len(s), f)
}
}
@ -334,7 +334,7 @@ impl <T: writer, C> of writer for {base: T, cleanup: C} {
impl of writer for *libc::FILE {
fn write(v: &[const u8]) {
do vec::unpack_const_slice(v) {|vbuf, len|
do vec::unpack_const_slice(v) |vbuf, len| {
let nout = libc::fwrite(vbuf as *c_void, len as size_t,
1u as size_t, self);
if nout < 1 as size_t {
@ -363,7 +363,7 @@ fn FILE_writer(f: *libc::FILE, cleanup: bool) -> writer {
impl of writer for fd_t {
fn write(v: &[const u8]) {
let mut count = 0u;
do vec::unpack_const_slice(v) {|vbuf, len|
do vec::unpack_const_slice(v) |vbuf, len| {
while count < len {
let vb = ptr::const_offset(vbuf, count) as *c_void;
let nout = libc::write(self, vb, len as size_t);
@ -412,7 +412,7 @@ fn mk_file_writer(path: str, flags: ~[fileflag])
fn wb() -> c_int { O_WRONLY as c_int }
let mut fflags: c_int = wb();
for vec::each(flags) {|f|
for vec::each(flags) |f| {
alt f {
append { fflags |= O_APPEND as c_int; }
create { fflags |= O_CREAT as c_int; }
@ -420,7 +420,7 @@ fn mk_file_writer(path: str, flags: ~[fileflag])
no_flag { }
}
}
let fd = do os::as_c_charp(path) {|pathbuf|
let fd = do os::as_c_charp(path) |pathbuf| {
libc::open(pathbuf, fflags,
(S_IRUSR | S_IWUSR) as c_int)
};
@ -514,78 +514,78 @@ impl writer_util for writer {
self.write_str(str::from_char(ch));
}
}
fn write_str(s: str/&) { str::byte_slice(s, {|v| self.write(v); }) }
fn write_str(s: str/&) { str::byte_slice(s, |v| self.write(v)) }
fn write_line(s: str/&) {
self.write_str(s);
self.write_str("\n"/&);
}
fn write_int(n: int) {
int::to_str_bytes(n, 10u, {|buf| self.write(buf) })
int::to_str_bytes(n, 10u, |buf| self.write(buf))
}
fn write_uint(n: uint) {
uint::to_str_bytes(false, n, 10u, {|buf| self.write(buf) })
uint::to_str_bytes(false, n, 10u, |buf| self.write(buf))
}
fn write_le_uint(n: uint, size: uint) {
u64_to_le_bytes(n as u64, size, {|v| self.write(v) })
u64_to_le_bytes(n as u64, size, |v| self.write(v))
}
fn write_le_int(n: int, size: uint) {
u64_to_le_bytes(n as u64, size, {|v| self.write(v) })
u64_to_le_bytes(n as u64, size, |v| self.write(v))
}
fn write_be_uint(n: uint, size: uint) {
u64_to_be_bytes(n as u64, size, {|v| self.write(v) })
u64_to_be_bytes(n as u64, size, |v| self.write(v))
}
fn write_be_int(n: int, size: uint) {
u64_to_be_bytes(n as u64, size, {|v| self.write(v) })
u64_to_be_bytes(n as u64, size, |v| self.write(v))
}
fn write_be_u64(n: u64) {
u64_to_be_bytes(n, 8u, {|v| self.write(v) })
u64_to_be_bytes(n, 8u, |v| self.write(v))
}
fn write_be_u32(n: u32) {
u64_to_be_bytes(n as u64, 4u, {|v| self.write(v) })
u64_to_be_bytes(n as u64, 4u, |v| self.write(v))
}
fn write_be_u16(n: u16) {
u64_to_be_bytes(n as u64, 2u, {|v| self.write(v) })
u64_to_be_bytes(n as u64, 2u, |v| self.write(v))
}
fn write_be_i64(n: i64) {
u64_to_be_bytes(n as u64, 8u, {|v| self.write(v) })
u64_to_be_bytes(n as u64, 8u, |v| self.write(v))
}
fn write_be_i32(n: i32) {
u64_to_be_bytes(n as u64, 4u, {|v| self.write(v) })
u64_to_be_bytes(n as u64, 4u, |v| self.write(v))
}
fn write_be_i16(n: i16) {
u64_to_be_bytes(n as u64, 2u, {|v| self.write(v) })
u64_to_be_bytes(n as u64, 2u, |v| self.write(v))
}
fn write_le_u64(n: u64) {
u64_to_le_bytes(n, 8u, {|v| self.write(v) })
u64_to_le_bytes(n, 8u, |v| self.write(v))
}
fn write_le_u32(n: u32) {
u64_to_le_bytes(n as u64, 4u, {|v| self.write(v) })
u64_to_le_bytes(n as u64, 4u, |v| self.write(v))
}
fn write_le_u16(n: u16) {
u64_to_le_bytes(n as u64, 2u, {|v| self.write(v) })
u64_to_le_bytes(n as u64, 2u, |v| self.write(v))
}
fn write_le_i64(n: i64) {
u64_to_le_bytes(n as u64, 8u, {|v| self.write(v) })
u64_to_le_bytes(n as u64, 8u, |v| self.write(v))
}
fn write_le_i32(n: i32) {
u64_to_le_bytes(n as u64, 4u, {|v| self.write(v) })
u64_to_le_bytes(n as u64, 4u, |v| self.write(v))
}
fn write_le_i16(n: i16) {
u64_to_le_bytes(n as u64, 2u, {|v| self.write(v) })
u64_to_le_bytes(n as u64, 2u, |v| self.write(v))
}
fn write_u8(n: u8) { self.write(&[n]) }
}
fn file_writer(path: str, flags: ~[fileflag]) -> result<writer, str> {
result::chain(mk_file_writer(path, flags), { |w| result::ok(w)})
result::chain(mk_file_writer(path, flags), |w| result::ok(w))
}
// FIXME: fileflags // #2004
fn buffered_file_writer(path: str) -> result<writer, str> {
let f = do os::as_c_charp(path) {|pathbuf|
do os::as_c_charp("w") {|modebuf|
let f = do os::as_c_charp(path) |pathbuf| {
do os::as_c_charp("w") |modebuf| {
libc::fopen(pathbuf, modebuf)
}
};
@ -672,7 +672,7 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) ->
}
fn read_whole_file_str(file: str) -> result<str, str> {
result::chain(read_whole_file(file), { |bytes|
result::chain(read_whole_file(file), |bytes| {
result::ok(str::from_bytes(bytes))
})
}
@ -680,7 +680,7 @@ fn read_whole_file_str(file: str) -> result<str, str> {
// FIXME (#2004): implement this in a low-level way. Going through the
// abstractions is pointless.
fn read_whole_file(file: str) -> result<~[u8], str> {
result::chain(file_reader(file), { |rdr|
result::chain(file_reader(file), |rdr| {
result::ok(rdr.read_whole_stream())
})
}
@ -804,7 +804,7 @@ mod tests {
assert(vec::len(res) == len);
}
assert(vec::slice(ivals, 0u, vec::len(res)) ==
vec::map(res, {|x| x as int}));
vec::map(res, |x| x as int));
}
let mut i = 0u;
while i < 8u {

View file

@ -7,7 +7,7 @@ Attempts to access this dvec during iteration will fail.
"]
fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
import dvec::extensions;
self.swap({ |v| vec::each(v, f); v })
self.swap(|v| { vec::each(v, f); v })
}
fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> {

View file

@ -5,21 +5,21 @@ iface base_iter<A> {
fn eachi<A,IA:base_iter<A>>(self: IA, blk: fn(uint, A) -> bool) {
let mut i = 0u;
for self.each {|a|
for self.each |a| {
if !blk(i, a) { break; }
i += 1u;
}
}
fn all<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool {
for self.each {|a|
for self.each |a| {
if !blk(a) { ret false; }
}
ret true;
}
fn any<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool {
for self.each {|a|
for self.each |a| {
if blk(a) { ret true; }
}
ret false;
@ -28,8 +28,8 @@ fn any<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool {
fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA,
prd: fn(A) -> bool) -> ~[A] {
let mut result = ~[];
self.size_hint().iter({|hint| vec::reserve(result, hint); });
for self.each {|a|
self.size_hint().iter(|hint| vec::reserve(result, hint));
for self.each |a| {
if prd(a) { vec::push(result, a); }
}
ret result;
@ -37,8 +37,8 @@ fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA,
fn map_to_vec<A:copy,B,IA:base_iter<A>>(self: IA, op: fn(A) -> B) -> ~[B] {
let mut result = ~[];
self.size_hint().iter({|hint| vec::reserve(result, hint); });
for self.each {|a|
self.size_hint().iter(|hint| vec::reserve(result, hint));
for self.each |a| {
vec::push(result, op(a));
}
ret result;
@ -48,8 +48,8 @@ fn flat_map_to_vec<A:copy,B:copy,IA:base_iter<A>,IB:base_iter<B>>(
self: IA, op: fn(A) -> IB) -> ~[B] {
let mut result = ~[];
for self.each {|a|
for op(a).each {|b|
for self.each |a| {
for op(a).each |b| {
vec::push(result, b);
}
}
@ -58,25 +58,25 @@ fn flat_map_to_vec<A:copy,B:copy,IA:base_iter<A>,IB:base_iter<B>>(
fn foldl<A,B,IA:base_iter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
let mut b <- b0;
for self.each {|a|
for self.each |a| {
b = blk(b, a);
}
ret b;
}
fn to_vec<A:copy,IA:base_iter<A>>(self: IA) -> ~[A] {
foldl::<A,~[A],IA>(self, ~[], {|r, a| vec::append(r, ~[a]) })
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(r, ~[a]))
}
fn contains<A,IA:base_iter<A>>(self: IA, x: A) -> bool {
for self.each {|a|
for self.each |a| {
if a == x { ret true; }
}
ret false;
}
fn count<A,IA:base_iter<A>>(self: IA, x: A) -> uint {
do foldl(self, 0u) {|count, value|
do foldl(self, 0u) |count, value| {
if value == x {
count + 1u
} else {
@ -88,7 +88,7 @@ fn count<A,IA:base_iter<A>>(self: IA, x: A) -> uint {
fn position<A,IA:base_iter<A>>(self: IA, f: fn(A) -> bool)
-> option<uint> {
let mut i = 0;
for self.each {|a|
for self.each |a| {
if f(a) { ret some(i); }
i += 1;
}
@ -108,7 +108,7 @@ fn repeat(times: uint, blk: fn()) {
}
fn min<A:copy,IA:base_iter<A>>(self: IA) -> A {
alt do foldl::<A,option<A>,IA>(self, none) {|a, b|
alt do foldl::<A,option<A>,IA>(self, none) |a, b| {
alt a {
some(a_) if a_ < b {
// FIXME (#2005): Not sure if this is successfully optimized to
@ -124,7 +124,7 @@ fn min<A:copy,IA:base_iter<A>>(self: IA) -> A {
}
fn max<A:copy,IA:base_iter<A>>(self: IA) -> A {
alt do foldl::<A,option<A>,IA>(self, none) {|a, b|
alt do foldl::<A,option<A>,IA>(self, none) |a, b| {
alt a {
some(a_) if a_ > b {
// FIXME (#2005): Not sure if this is successfully optimized to

View file

@ -31,7 +31,7 @@ fn chan<T: send>(p: port<T>) -> chan<T> {
fn send<T: send>(c: chan<T>, -x: T) {
let mut x <- some(x);
do (*c).with {|cond, data|
do (*c).with |cond, data| {
let mut xx = none;
xx <-> x;
(*data).push(option::unwrap(xx));
@ -40,7 +40,7 @@ fn send<T: send>(c: chan<T>, -x: T) {
}
fn recv<T: send>(p: port<T>) -> T {
do (*p).with {|cond, data|
do (*p).with |cond, data| {
if (*data).len() == 0u {
cond.wait();
}

View file

@ -133,10 +133,10 @@ fn test_unwrap_ptr() {
#[test]
fn test_unwrap_str() {
let x = "test";
let addr_x = str::as_buf(x, {|buf| ptr::addr_of(buf) });
let addr_x = str::as_buf(x, |buf| ptr::addr_of(buf));
let opt = some(x);
let y = unwrap(opt);
let addr_y = str::as_buf(y, {|buf| ptr::addr_of(buf) });
let addr_y = str::as_buf(y, |buf| ptr::addr_of(buf));
assert addr_x == addr_y;
}

View file

@ -53,7 +53,7 @@ native mod rustrt {
fn env() -> ~[(str,str)] {
let mut pairs = ~[];
for vec::each(rustrt::rust_env_pairs()) {|p|
for vec::each(rustrt::rust_env_pairs()) |p| {
let vs = str::splitn_char(p, '=', 1u);
assert vec::len(vs) == 2u;
vec::push(pairs, (vs[0], vs[1]));
@ -64,13 +64,13 @@ fn env() -> ~[(str,str)] {
const tmpbuf_sz : uint = 1000u;
fn as_c_charp<T>(s: str, f: fn(*c_char) -> T) -> T {
str::as_c_str(s, {|b| f(b as *c_char) })
str::as_c_str(s, |b| f(b as *c_char))
}
fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
-> option<str> {
let buf = vec::to_mut(vec::from_elem(tmpbuf_sz, 0u8 as c_char));
do vec::as_mut_buf(buf) { |b|
do vec::as_mut_buf(buf) |b| {
if f(b, tmpbuf_sz as size_t) unsafe {
some(str::unsafe::from_buf(b as *u8))
} else {
@ -95,7 +95,7 @@ mod win32 {
let mut done = false;
while !done {
let buf = vec::to_mut(vec::from_elem(n as uint, 0u16));
do vec::as_mut_buf(buf) {|b|
do vec::as_mut_buf(buf) |b| {
let k : dword = f(b, tmpbuf_sz as dword);
if k == (0 as dword) {
done = true;
@ -160,7 +160,7 @@ mod global_env {
fn get_global_env_chan() -> comm::chan<msg> {
let global_ptr = rustrt::rust_global_env_chan_ptr();
let builder_fn = {||
let builder_fn = || {
let builder = task::builder();
task::unsupervise(builder);
task::set_opts(builder, {
@ -182,7 +182,7 @@ mod global_env {
fn global_env_task(msg_po: comm::port<msg>) {
unsafe {
do priv::weaken_task {|weak_po|
do priv::weaken_task |weak_po| {
loop {
alt comm::select2(msg_po, weak_po) {
either::left(msg_getenv(n, resp_ch)) {
@ -220,8 +220,8 @@ mod global_env {
import libc::types::os::arch::extra::*;
import libc::funcs::extra::kernel32::*;
import win32::*;
do as_utf16_p(n) {|u|
do fill_utf16_buf_and_decode() {|buf, sz|
do as_utf16_p(n) |u| {
do fill_utf16_buf_and_decode() |buf, sz| {
GetEnvironmentVariableW(u, buf, sz)
}
}
@ -233,8 +233,8 @@ mod global_env {
// FIXME: remove this when export globs work properly. #1238
import libc::funcs::posix01::unistd::setenv;
do str::as_c_str(n) {|nbuf|
do str::as_c_str(v) {|vbuf|
do str::as_c_str(n) |nbuf| {
do str::as_c_str(v) |vbuf| {
setenv(nbuf, vbuf, 1i32);
}
}
@ -246,8 +246,8 @@ mod global_env {
// FIXME: remove imports when export globs work properly. #1238
import libc::funcs::extra::kernel32::*;
import win32::*;
do as_utf16_p(n) {|nbuf|
do as_utf16_p(v) {|vbuf|
do as_utf16_p(n) |nbuf| {
do as_utf16_p(v) |vbuf| {
SetEnvironmentVariableW(nbuf, vbuf);
}
}
@ -257,7 +257,7 @@ mod global_env {
}
fn fdopen(fd: c_int) -> *FILE {
ret do as_c_charp("r") {|modebuf|
ret do as_c_charp("r") |modebuf| {
libc::fdopen(fd, modebuf)
};
}
@ -370,7 +370,7 @@ fn self_exe_path() -> option<path> {
unsafe {
import libc::funcs::bsd44::*;
import libc::consts::os::extra::*;
do fill_charp_buf() {|buf, sz|
do fill_charp_buf() |buf, sz| {
let mib = ~[CTL_KERN as c_int,
KERN_PROC as c_int,
KERN_PROC_PATHNAME as c_int, -1 as c_int];
@ -384,8 +384,8 @@ fn self_exe_path() -> option<path> {
#[cfg(target_os = "linux")]
fn load_self() -> option<path> {
import libc::funcs::posix01::unistd::readlink;
do fill_charp_buf() {|buf, sz|
do as_c_charp("/proc/self/exe") { |proc_self_buf|
do fill_charp_buf() |buf, sz| {
do as_c_charp("/proc/self/exe") |proc_self_buf| {
readlink(proc_self_buf, buf, sz) != (-1 as ssize_t)
}
}
@ -395,7 +395,7 @@ fn self_exe_path() -> option<path> {
fn load_self() -> option<path> {
// FIXME: remove imports when export globs work properly. #1238
import libc::funcs::extra::*;
do fill_charp_buf() {|buf, sz|
do fill_charp_buf() |buf, sz| {
_NSGetExecutablePath(buf, ptr::mut_addr_of(sz as u32))
== (0 as c_int)
}
@ -407,12 +407,12 @@ fn self_exe_path() -> option<path> {
import libc::types::os::arch::extra::*;
import libc::funcs::extra::kernel32::*;
import win32::*;
do fill_utf16_buf_and_decode() {|buf, sz|
do fill_utf16_buf_and_decode() |buf, sz| {
GetModuleFileNameW(0u as dword, buf, sz)
}
}
do option::map(load_self()) {|pth|
do option::map(load_self()) |pth| {
path::dirname(pth) + path::path_sep()
}
}
@ -452,7 +452,7 @@ fn homedir() -> option<path> {
#[cfg(windows)]
fn secondary() -> option<path> {
do option::chain(getenv("USERPROFILE")) {|p|
do option::chain(getenv("USERPROFILE")) |p| {
if !str::is_empty(p) {
some(p)
} else {
@ -469,7 +469,7 @@ fn walk_dir(p: path, f: fn(path) -> bool) {
fn walk_dir_(p: path, f: fn(path) -> bool) -> bool {
let mut keepgoing = true;
do list_dir(p).each {|q|
do list_dir(p).each |q| {
let path = path::connect(p, q);
if !f(path) {
keepgoing = false;
@ -493,14 +493,14 @@ fn walk_dir(p: path, f: fn(path) -> bool) {
#[doc = "Indicates whether a path represents a directory"]
fn path_is_dir(p: path) -> bool {
do str::as_c_str(p) {|buf|
do str::as_c_str(p) |buf| {
rustrt::rust_path_is_dir(buf) != 0 as c_int
}
}
#[doc = "Indicates whether a path exists"]
fn path_exists(p: path) -> bool {
do str::as_c_str(p) {|buf|
do str::as_c_str(p) |buf| {
rustrt::rust_path_exists(buf) != 0 as c_int
}
}
@ -537,7 +537,7 @@ fn make_dir(p: path, mode: c_int) -> bool {
import libc::funcs::extra::kernel32::*;
import win32::*;
// FIXME: turn mode into something useful? #2623
do as_utf16_p(p) {|buf|
do as_utf16_p(p) |buf| {
CreateDirectoryW(buf, unsafe { unsafe::reinterpret_cast(0) })
!= (0 as BOOL)
}
@ -545,7 +545,7 @@ fn make_dir(p: path, mode: c_int) -> bool {
#[cfg(unix)]
fn mkdir(p: path, mode: c_int) -> bool {
do as_c_charp(p) {|c|
do as_c_charp(p) |c| {
libc::mkdir(c, mode as mode_t) == (0 as c_int)
}
}
@ -568,7 +568,7 @@ fn list_dir(p: path) -> ~[str] {
}
}
do rustrt::rust_list_files(star(p)).filter {|filename|
do rustrt::rust_list_files(star(p)).filter |filename| {
!str::eq(filename, ".") && !str::eq(filename, "..")
}
}
@ -585,7 +585,7 @@ fn list_dir_path(p: path) -> ~[str] {
&& p[pl - 1u] as char != path::consts::alt_path_sep) {
p += path::path_sep();
}
os::list_dir(p).map({|f| p + f})
os::list_dir(p).map(|f| p + f)
}
#[doc = "Removes a directory at the specified path"]
@ -598,14 +598,14 @@ 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|
ret 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|
ret do as_c_charp(p) |buf| {
libc::rmdir(buf) == (0 as c_int)
};
}
@ -620,14 +620,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|
ret 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|
ret do as_c_charp(p) |buf| {
libc::chdir(buf) == (0 as c_int)
};
}
@ -643,8 +643,8 @@ 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|
do as_utf16_p(to) {|top|
ret do as_utf16_p(from) |fromp| {
do as_utf16_p(to) |top| {
CopyFileW(fromp, top, (0 as BOOL)) != (0 as BOOL)
}
}
@ -652,16 +652,16 @@ fn copy_file(from: path, to: path) -> bool {
#[cfg(unix)]
fn do_copy_file(from: path, to: path) -> bool {
let istream = do as_c_charp(from) {|fromp|
do as_c_charp("rb") {|modebuf|
let istream = do as_c_charp(from) |fromp| {
do as_c_charp("rb") |modebuf| {
libc::fopen(fromp, modebuf)
}
};
if istream as uint == 0u {
ret false;
}
let ostream = do as_c_charp(to) {|top|
do as_c_charp("w+b") {|modebuf|
let ostream = do as_c_charp(to) |top| {
do as_c_charp("w+b") |modebuf| {
libc::fopen(top, modebuf)
}
};
@ -675,7 +675,7 @@ fn copy_file(from: path, to: path) -> bool {
let mut done = false;
let mut ok = true;
while !done {
do vec::as_mut_buf(buf) {|b|
do vec::as_mut_buf(buf) |b| {
let nread = libc::fread(b as *mut c_void, 1u as size_t,
bufsize as size_t,
istream);
@ -707,14 +707,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|
ret 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|
ret do as_c_charp(p) |buf| {
libc::unlink(buf) == (0 as c_int)
};
}
@ -850,7 +850,7 @@ mod tests {
fn test_env_getenv() {
let e = env();
assert vec::len(e) > 0u;
for vec::each(e) {|p|
for vec::each(e) |p| {
let (n, v) = p;
log(debug, n);
let v2 = getenv(n);
@ -894,7 +894,7 @@ mod tests {
setenv("HOME", "");
assert os::homedir() == none;
option::iter(oldhome, {|s| setenv("HOME", s)});
option::iter(oldhome, |s| setenv("HOME", s));
}
#[test]
@ -924,9 +924,9 @@ mod tests {
setenv("USERPROFILE", "/home/PaloAlto");
assert os::homedir() == some("/home/MountainView");
option::iter(oldhome, {|s| setenv("HOME", s)});
option::iter(oldhome, |s| setenv("HOME", s));
option::iter(olduserprofile,
{|s| setenv("USERPROFILE", s)});
|s| setenv("USERPROFILE", s));
}
// Issue #712
@ -939,7 +939,7 @@ mod tests {
// Just assuming that we've got some contents in the current directory
assert (vec::len(dirs) > 0u);
for vec::each(dirs) {|dir| log(debug, dir); }
for vec::each(dirs) |dir| { log(debug, dir); }
}
#[test]
@ -970,15 +970,15 @@ mod tests {
let out = tempdir + path::path_sep() + "out.txt";
/* Write the temp input file */
let ostream = do as_c_charp(in) {|fromp|
do as_c_charp("w+b") {|modebuf|
let ostream = do as_c_charp(in) |fromp| {
do as_c_charp("w+b") |modebuf| {
libc::fopen(fromp, modebuf)
}
};
assert (ostream as uint != 0u);
let s = "hello";
let mut buf = vec::to_mut(str::bytes(s) + ~[0 as u8]);
do vec::as_mut_buf(buf) {|b|
do vec::as_mut_buf(buf) |b| {
assert (libc::fwrite(b as *c_void, 1u as size_t,
(str::len(s) + 1u) as size_t, ostream)
== buf.len() as size_t)};

View file

@ -61,9 +61,9 @@ fn path_is_absolute(p: str) -> bool {
fn path_sep() -> str { ret str::from_char(consts::path_sep); }
fn split_dirname_basename (pp: path) -> {dirname: str, basename: str} {
alt str::rfind(pp, {|ch|
alt str::rfind(pp, |ch|
ch == consts::path_sep || ch == consts::alt_path_sep
}) {
) {
some(i) {
{dirname: str::slice(pp, 0u, i),
basename: str::slice(pp, i + 1u, str::len(pp))}
@ -145,7 +145,7 @@ the first element of the returned vector will be the drive letter
followed by a colon.
"]
fn split(p: path) -> ~[path] {
str::split_nonempty(p, {|c|
str::split_nonempty(p, |c| {
c == consts::path_sep || c == consts::alt_path_sep
})
}
@ -235,12 +235,11 @@ fn normalize(p: path) -> path {
ret s;
fn strip_dots(s: ~[path]) -> ~[path] {
vec::filter_map(s, { |elem|
vec::filter_map(s, |elem|
if elem == "." {
option::none
} else {
option::some(elem)
}
})
}

View file

@ -41,7 +41,7 @@ unsafe fn chan_from_global_ptr<T: send>(
let setup_po = comm::port();
let setup_ch = comm::chan(setup_po);
let setup_ch = do task::run_listener(builder()) {|setup_po|
let setup_ch = do task::run_listener(builder()) |setup_po| {
let po = comm::port::<T>();
let ch = comm::chan(po);
comm::send(setup_ch, ch);
@ -92,7 +92,7 @@ fn test_from_global_chan1() {
// Create the global channel, attached to a new task
let ch = unsafe {
do chan_from_global_ptr(globchanp, task::builder) {|po|
do chan_from_global_ptr(globchanp, task::builder) |po| {
let ch = comm::recv(po);
comm::send(ch, true);
let ch = comm::recv(po);
@ -106,7 +106,7 @@ fn test_from_global_chan1() {
// This one just reuses the previous channel
let ch = unsafe {
do chan_from_global_ptr(globchanp, task::builder) {|po|
do chan_from_global_ptr(globchanp, task::builder) |po| {
let ch = comm::recv(po);
comm::send(ch, false);
}
@ -121,7 +121,7 @@ fn test_from_global_chan1() {
#[test]
fn test_from_global_chan2() {
do iter::repeat(100u) {||
do iter::repeat(100u) || {
// The global channel
let globchan = 0u;
let globchanp = ptr::addr_of(globchan);
@ -131,13 +131,13 @@ fn test_from_global_chan2() {
// Spawn a bunch of tasks that all want to compete to
// create the global channel
for uint::range(0u, 10u) {|i|
do task::spawn {||
for uint::range(0u, 10u) |i| {
do task::spawn || {
let ch = unsafe {
do chan_from_global_ptr(
globchanp, task::builder) {|po|
globchanp, task::builder) |po| {
for uint::range(0u, 10u) {|_j|
for uint::range(0u, 10u) |_j| {
let ch = comm::recv(po);
comm::send(ch, {i});
}
@ -153,7 +153,7 @@ fn test_from_global_chan2() {
}
// There should be only one winner
let mut winners = 0u;
for uint::range(0u, 10u) {|_i|
for uint::range(0u, 10u) |_i| {
let res = comm::recv(resultpo);
if res { winners += 1u };
}
@ -200,9 +200,9 @@ unsafe fn weaken_task(f: fn(comm::port<()>)) {
#[test]
fn test_weaken_task_then_unweaken() {
do task::try {||
do task::try || {
unsafe {
do weaken_task {|_po|
do weaken_task |_po| {
}
}
};
@ -212,9 +212,9 @@ fn test_weaken_task_then_unweaken() {
fn test_weaken_task_wait() {
let builder = task::builder();
task::unsupervise(builder);
do task::run(builder) {||
do task::run(builder) || {
unsafe {
do weaken_task {|po|
do weaken_task |po| {
comm::recv(po);
}
}
@ -224,18 +224,18 @@ fn test_weaken_task_wait() {
#[test]
fn test_weaken_task_stress() {
// Create a bunch of weak tasks
do iter::repeat(100u) {||
do task::spawn {||
do iter::repeat(100u) || {
do task::spawn || {
unsafe {
do weaken_task {|_po|
do weaken_task |_po| {
}
}
}
let builder = task::builder();
task::unsupervise(builder);
do task::run(builder) {||
do task::run(builder) || {
unsafe {
do weaken_task {|po|
do weaken_task |po| {
// Wait for it to tell us to die
comm::recv(po);
}
@ -247,9 +247,9 @@ fn test_weaken_task_stress() {
#[test]
#[ignore(cfg(windows))]
fn test_weaken_task_fail() {
let res = do task::try {||
let res = do task::try || {
unsafe {
do weaken_task {|_po|
do weaken_task |_po| {
fail;
}
}

View file

@ -70,7 +70,7 @@ fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
#[doc = "Return the offset of the first null pointer in `buf`."]
#[inline(always)]
unsafe fn buf_len<T>(buf: **T) -> uint {
do position(buf) {|i| i == null() }
position(buf, |i| i == null())
}
#[doc = "Return the first offset `i` such that `f(buf[i]) == true`."]
@ -171,9 +171,9 @@ fn test_position() {
let s = "hello";
unsafe {
assert 2u == as_c_str(s, {|p| position(p, {|c| c == 'l' as c_char})});
assert 4u == as_c_str(s, {|p| position(p, {|c| c == 'o' as c_char})});
assert 5u == as_c_str(s, {|p| position(p, {|c| c == 0 as c_char })});
assert 2u == as_c_str(s, |p| position(p, |c| c == 'l' as c_char));
assert 4u == as_c_str(s, |p| position(p, |c| c == 'o' as c_char));
assert 5u == as_c_str(s, |p| position(p, |c| c == 0 as c_char));
}
}
@ -182,11 +182,11 @@ fn test_buf_len() {
let s0 = "hello";
let s1 = "there";
let s2 = "thing";
do str::as_c_str(s0) {|p0|
do str::as_c_str(s1) {|p1|
do str::as_c_str(s2) {|p2|
do str::as_c_str(s0) |p0| {
do str::as_c_str(s1) |p1| {
do str::as_c_str(s2) |p2| {
let v = ~[p0, p1, p2, null()];
do vec::as_buf(v) {|vp|
do vec::as_buf(v) |vp| {
assert unsafe { buf_len(vp) } == 3u;
}
}

View file

@ -152,7 +152,7 @@ impl extensions for rng {
#[doc = "Return a random byte string of the specified length"]
fn gen_bytes(len: uint) -> ~[u8] {
do vec::from_fn(len) {|_i|
do vec::from_fn(len) |_i| {
self.gen_u8()
}
}
@ -181,7 +181,7 @@ impl extensions for rng {
none if the sum of the weights is 0"]
fn choose_weighted_option<T:copy>(v: ~[weighted<T>]) -> option<T> {
let mut total = 0u;
for v.each {|item|
for v.each |item| {
total += item.weight;
}
if total == 0u {
@ -189,7 +189,7 @@ impl extensions for rng {
}
let chosen = self.gen_uint_range(0u, total);
let mut so_far = 0u;
for v.each {|item|
for v.each |item| {
so_far += item.weight;
if so_far > chosen {
ret some(item.item);
@ -202,8 +202,8 @@ impl extensions for rng {
the weight of the item determines how many copies there are"]
fn weighted_vec<T:copy>(v: ~[weighted<T>]) -> ~[T] {
let mut r = ~[];
for v.each {|item|
for uint::range(0u, item.weight) {|_i|
for v.each |item| {
for uint::range(0u, item.weight) |_i| {
vec::push(r, item.item);
}
}

View file

@ -254,7 +254,7 @@ fn map_vec<T,U:copy,V:copy>(
let mut vs: ~[V] = ~[];
vec::reserve(vs, vec::len(ts));
for vec::each(ts) {|t|
for vec::each(ts) |t| {
alt op(t) {
ok(v) { vec::push(vs, v); }
err(u) { ret err(u); }
@ -362,33 +362,33 @@ mod tests {
#[test]
fn test_impl_iter() {
let mut valid = false;
ok::<str, str>("a").iter({ |_x| valid = true; });
ok::<str, str>("a").iter(|_x| valid = true);
assert valid;
err::<str, str>("b").iter({ |_x| valid = false; });
err::<str, str>("b").iter(|_x| valid = false);
assert valid;
}
#[test]
fn test_impl_iter_err() {
let mut valid = true;
ok::<str, str>("a").iter_err({ |_x| valid = false; });
ok::<str, str>("a").iter_err(|_x| valid = false);
assert valid;
valid = false;
err::<str, str>("b").iter_err({ |_x| valid = true; });
err::<str, str>("b").iter_err(|_x| valid = true);
assert valid;
}
#[test]
fn test_impl_map() {
assert ok::<str, str>("a").map({ |_x| "b" }) == ok("b");
assert err::<str, str>("a").map({ |_x| "b" }) == err("a");
assert ok::<str, str>("a").map(|_x| "b") == ok("b");
assert err::<str, str>("a").map(|_x| "b") == err("a");
}
#[test]
fn test_impl_map_err() {
assert ok::<str, str>("a").map_err({ |_x| "b" }) == ok("a");
assert err::<str, str>("a").map_err({ |_x| "b" }) == err("b");
assert ok::<str, str>("a").map_err(|_x| "b") == ok("a");
assert err::<str, str>("a").map_err(|_x| "b") == err("b");
}
}

View file

@ -67,9 +67,9 @@ fn spawn_process(prog: str, args: ~[str],
dir: option<str>,
in_fd: c_int, out_fd: c_int, err_fd: c_int)
-> pid_t {
do with_argv(prog, args) {|argv|
do with_envp(env) { |envp|
do with_dirp(dir) { |dirp|
do with_argv(prog, args) |argv| {
do with_envp(env) |envp| {
do with_dirp(dir) |dirp| {
rustrt::rust_run_program(argv, envp, dirp,
in_fd, out_fd, err_fd)
}
@ -79,12 +79,12 @@ fn spawn_process(prog: str, args: ~[str],
fn with_argv<T>(prog: str, args: ~[str],
cb: fn(**libc::c_char) -> T) -> T {
let mut argptrs = str::as_c_str(prog, {|b| ~[b] });
let mut argptrs = str::as_c_str(prog, |b| ~[b]);
let mut tmps = ~[];
for vec::each(args) {|arg|
for vec::each(args) |arg| {
let t = @arg;
vec::push(tmps, t);
vec::push_all(argptrs, str::as_c_str(*t, {|b| ~[b] }));
vec::push_all(argptrs, str::as_c_str(*t, |b| ~[b]));
}
vec::push(argptrs, ptr::null());
vec::as_buf(argptrs, cb)
@ -100,16 +100,16 @@ fn with_envp<T>(env: option<~[(str,str)]>,
let mut tmps = ~[];
let mut ptrs = ~[];
for vec::each(es) {|e|
for vec::each(es) |e| {
let (k,v) = e;
let t = @(#fmt("%s=%s", k, v));
vec::push(tmps, t);
vec::push_all(ptrs, str::as_c_str(*t, {|b| ~[b]}));
vec::push_all(ptrs, str::as_c_str(*t, |b| ~[b]));
}
vec::push(ptrs, ptr::null());
vec::as_buf(ptrs, { |p|
vec::as_buf(ptrs, |p|
unsafe { cb(::unsafe::reinterpret_cast(p)) }
})
)
}
_ {
cb(ptr::null())
@ -127,7 +127,7 @@ fn with_envp<T>(env: option<~[(str,str)]>,
alt env {
some(es) if !vec::is_empty(es) {
let mut blk : ~[u8] = ~[];
for vec::each(es) {|e|
for vec::each(es) |e| {
let (k,v) = e;
let t = #fmt("%s=%s", k, v);
let mut v : ~[u8] = ::unsafe::reinterpret_cast(t);
@ -135,7 +135,7 @@ fn with_envp<T>(env: option<~[(str,str)]>,
::unsafe::forget(v);
}
blk += ~[0_u8];
vec::as_buf(blk, {|p| cb(::unsafe::reinterpret_cast(p)) })
vec::as_buf(blk, |p| cb(::unsafe::reinterpret_cast(p)))
}
_ {
cb(ptr::null())
@ -298,11 +298,11 @@ fn program_output(prog: str, args: ~[str]) ->
// clever way to do this.
let p = comm::port();
let ch = comm::chan(p);
do task::spawn_sched(task::single_threaded) {||
do task::spawn_sched(task::single_threaded) || {
let errput = readclose(pipe_err.in);
comm::send(ch, (2, errput));
};
do task::spawn_sched(task::single_threaded) {||
do task::spawn_sched(task::single_threaded) || {
let output = readclose(pipe_out.in);
comm::send(ch, (1, output));
};

View file

@ -18,7 +18,7 @@ fn walk_stack(visit: fn(frame) -> bool) {
#debug("beginning stack walk");
do frame_address { |frame_pointer|
do frame_address |frame_pointer| {
let mut frame_address: *word = unsafe {
reinterpret_cast(frame_pointer)
};
@ -44,7 +44,7 @@ fn walk_stack(visit: fn(frame) -> bool) {
#[test]
fn test_simple() {
for walk_stack { |_frame|
for walk_stack |_frame| {
}
}
@ -53,7 +53,7 @@ fn test_simple_deep() {
fn run(i: int) {
if i == 0 { ret }
for walk_stack { |_frame|
for walk_stack |_frame| {
unsafe {
breakpoint();
}

View file

@ -154,7 +154,7 @@ fn push_char(&s: str, ch: char) {
let new_len = len + nb;
reserve_at_least(s, new_len);
let off = len;
do as_buf(s) {|buf|
do as_buf(s) |buf| {
let buf: *mut u8 = ::unsafe::reinterpret_cast(buf);
if nb == 1u {
*ptr::mut_offset(buf, off) =
@ -208,7 +208,7 @@ fn push_char(&s: str, ch: char) {
*ptr::mut_offset(buf, off + nb) = 0u8;
}
do as_bytes(s) {|bytes|
do as_bytes(s) |bytes| {
let mut mut_bytes: ~[u8] = ::unsafe::reinterpret_cast(bytes);
vec::unsafe::set_len(mut_bytes, new_len + 1u);
::unsafe::forget(mut_bytes);
@ -228,7 +228,7 @@ pure fn from_chars(chs: &[const char]) -> str {
let mut buf = "";
unchecked {
reserve(buf, chs.len());
for vec::each(chs) {|ch| push_char(buf, ch); }
for vec::each(chs) |ch| { push_char(buf, ch); }
}
ret buf;
}
@ -236,7 +236,7 @@ pure fn from_chars(chs: &[const char]) -> str {
#[doc = "Concatenate a vector of strings"]
pure fn concat(v: &[const str]) -> str {
let mut s: str = "";
for vec::each(v) {|ss| s += ss; }
for vec::each(v) |ss| { s += ss; }
ret s;
}
@ -245,7 +245,7 @@ Concatenate a vector of strings, placing a given separator between each
"]
pure fn connect(v: &[const str], sep: str) -> str {
let mut s = "", first = true;
for vec::each(v) {|ss|
for vec::each(v) |ss| {
if first { first = false; } else { s += sep; }
s += ss;
}
@ -289,7 +289,7 @@ fn unshift_char(&s: str, ch: char) { s = from_char(ch) + s; }
#[doc = "Returns a string with leading whitespace removed"]
pure fn trim_left(+s: str) -> str {
alt find(s, {|c| !char::is_whitespace(c)}) {
alt find(s, |c| !char::is_whitespace(c)) {
none { "" }
some(first) {
if first == 0u { s }
@ -300,7 +300,7 @@ pure fn trim_left(+s: str) -> str {
#[doc = "Returns a string with trailing whitespace removed"]
pure fn trim_right(+s: str) -> str {
alt rfind(s, {|c| !char::is_whitespace(c)}) {
alt rfind(s, |c| !char::is_whitespace(c)) {
none { "" }
some(last) {
let {next, _} = char_range_at(s, last);
@ -336,7 +336,7 @@ Work with the string as a byte slice, not including trailing null.
"]
#[inline(always)]
pure fn byte_slice<T>(s: str/&, f: fn(v: &[u8]) -> T) -> T {
do unpack_slice(s) {|p,n|
do unpack_slice(s) |p,n| {
unsafe { vec::unsafe::form_slice(p, n-1u, f) }
}
}
@ -421,7 +421,7 @@ pure fn split_char_inner(s: str/&, sep: char, count: uint, allow_empty: bool)
}
result
} else {
splitn(s, {|cur| cur == sep}, count)
splitn(s, |cur| cur == sep, count)
}
}
@ -495,7 +495,7 @@ pure fn iter_matches(s: str/&a, sep: str/&b, f: fn(uint, uint)) {
pure fn iter_between_matches(s: str/&a, sep: str/&b, f: fn(uint, uint)) {
let mut last_end = 0u;
do iter_matches(s, sep) {|from, to|
do iter_matches(s, sep) |from, to| {
f(last_end, from);
last_end = to;
}
@ -513,7 +513,7 @@ assert [\"\", \"XXX\", \"YYY\", \"\"] == split_str(\".XXX.YYY.\", \".\")
"]
pure fn split_str(s: str/&a, sep: str/&b) -> ~[str] {
let mut result = ~[];
do iter_between_matches(s, sep) {|from, to|
do iter_between_matches(s, sep) |from, to| {
unsafe { vec::push(result, unsafe::slice_bytes(s, from, to)); }
}
result
@ -521,7 +521,7 @@ pure fn split_str(s: str/&a, sep: str/&b) -> ~[str] {
pure fn split_str_nonempty(s: str/&a, sep: str/&b) -> ~[str] {
let mut result = ~[];
do iter_between_matches(s, sep) {|from, to|
do iter_between_matches(s, sep) |from, to| {
if to > from {
unsafe { vec::push(result, unsafe::slice_bytes(s, from, to)); }
}
@ -539,7 +539,7 @@ Splits a string into a vector of the substrings separated by LF ('\\n')
and/or CR LF ('\\r\\n')
"]
pure fn lines_any(s: str/&) -> ~[str] {
vec::map(lines(s), {|s|
vec::map(lines(s), |s| {
let l = len(s);
let mut cp = s;
if l > 0u && s[l - 1u] == '\r' as u8 {
@ -553,21 +553,21 @@ pure fn lines_any(s: str/&) -> ~[str] {
Splits a string into a vector of the substrings separated by whitespace
"]
pure fn words(s: str/&) -> ~[str] {
split_nonempty(s, {|c| char::is_whitespace(c)})
split_nonempty(s, |c| char::is_whitespace(c))
}
#[doc = "Convert a string to lowercase. ASCII only"]
pure fn to_lower(s: str/&) -> str {
map(s, {|c|
unchecked{(libc::tolower(c as libc::c_char)) as char}
})
map(s,
|c| unchecked{(libc::tolower(c as libc::c_char)) as char}
)
}
#[doc = "Convert a string to uppercase. ASCII only"]
pure fn to_upper(s: str/&) -> str {
map(s, {|c|
unchecked{(libc::toupper(c as libc::c_char)) as char}
})
map(s,
|c| unchecked{(libc::toupper(c as libc::c_char)) as char}
)
}
#[doc = "
@ -585,7 +585,7 @@ The original string with all occurances of `from` replaced with `to`
"]
pure fn replace(s: str, from: str, to: str) -> str {
let mut result = "", first = true;
do iter_between_matches(s, from) {|start, end|
do iter_between_matches(s, from) |start, end| {
if first { first = false; } else { result += to; }
unsafe { result += unsafe::slice_bytes(s, start, end); }
}
@ -622,7 +622,7 @@ pure fn hash(&&s: str) -> uint {
// djb hash.
// FIXME: replace with murmur. (see #859 and #1616)
let mut u: uint = 5381u;
for each(s) {|c| u *= 33u; u += c as uint; }
for each(s) |c| { u *= 33u; u += c as uint; }
ret u;
}
@ -643,7 +643,7 @@ Return true if a predicate matches any character (and false if it
matches none or there are no characters)
"]
pure fn any(ss: str/&, pred: fn(char) -> bool) -> bool {
!all(ss, {|cc| !pred(cc)})
!all(ss, |cc| !pred(cc))
}
#[doc = "Apply a function to each character"]
@ -651,7 +651,7 @@ pure fn map(ss: str/&, ff: fn(char) -> char) -> str {
let mut result = "";
unchecked {
reserve(result, len(ss));
do chars_iter(ss) {|cc|
do chars_iter(ss) |cc| {
str::push_char(result, ff(cc));
}
}
@ -807,7 +807,7 @@ pure fn find_char_between(s: str/&, c: char, start: uint, end: uint)
}
ret none;
} else {
find_between(s, start, end, {|x| x == c})
find_between(s, start, end, |x| x == c)
}
}
@ -886,7 +886,7 @@ pure fn rfind_char_between(s: str/&, c: char, start: uint, end: uint)
}
ret none;
} else {
rfind_between(s, start, end, {|x| x == c})
rfind_between(s, start, end, |x| x == c)
}
}
@ -1051,7 +1051,7 @@ pure fn rfind_between(s: str/&, start: uint, end: uint, f: fn(char) -> bool)
// Utility used by various searching functions
pure fn match_at(haystack: str/&a, needle: str/&b, at: uint) -> bool {
let mut i = at;
for each(needle) {|c| if haystack[i] != c { ret false; } i += 1u; }
for each(needle) |c| { if haystack[i] != c { ret false; } i += 1u; }
ret true;
}
@ -1215,7 +1215,7 @@ fn is_alphanumeric(s: str/&) -> bool {
Returns the string length/size in bytes not counting the null terminator
"]
pure fn len(s: str/&) -> uint {
do unpack_slice(s) { |_p, n| n - 1u }
do unpack_slice(s) |_p, n| { n - 1u }
}
#[doc = "Returns the number of characters that a string holds"]
@ -1267,7 +1267,7 @@ pure fn is_utf16(v: &[const u16]) -> bool {
#[doc = "Converts to a vector of `u16` encoded as UTF-16"]
pure fn to_utf16(s: str/&) -> ~[u16] {
let mut u = ~[];
do chars_iter(s) {|cch|
do chars_iter(s) |cch| {
// Arithmetic with u32 literals is easier on the eyes than chars.
let mut ch = cch as u32;
@ -1316,7 +1316,7 @@ pure fn from_utf16(v: &[const u16]) -> str {
let mut buf = "";
unchecked {
reserve(buf, vec::len(v));
do utf16_chars(v) {|ch| push_char(buf, ch); }
utf16_chars(v, |ch| push_char(buf, ch));
}
ret buf;
}
@ -1539,7 +1539,7 @@ Loop through a substring, char by char
"]
pure fn any_between(s: str/&, start: uint, end: uint,
it: fn(char) -> bool) -> bool {
!all_between(s, start, end, {|c| !it(c)})
!all_between(s, start, end, |c| !it(c))
}
// UTF-8 tags and ranges
@ -1583,7 +1583,7 @@ Allows for unsafe manipulation of strings, which is useful for native
interop.
"]
pure fn as_buf<T>(s: str, f: fn(*u8) -> T) -> T {
as_bytes(s, { |v| unsafe { vec::as_buf(v, f) } })
as_bytes(s, |v| unsafe { vec::as_buf(v, f) })
}
#[doc = "
@ -1599,7 +1599,7 @@ let s = str::as_buf(\"PATH\", { |path_buf| libc::getenv(path_buf) });
~~~
"]
pure fn as_c_str<T>(s: str, f: fn(*libc::c_char) -> T) -> T {
as_buf(s, {|buf| f(buf as *libc::c_char) })
as_buf(s, |buf| f(buf as *libc::c_char))
}
@ -1671,7 +1671,7 @@ Returns the number of single-byte characters the string can hold without
reallocating
"]
pure fn capacity(&&s: str) -> uint {
do as_bytes(s) {|buf|
do as_bytes(s) |buf| {
let vcap = vec::capacity(buf);
assert vcap > 0u;
vcap - 1u
@ -1683,7 +1683,7 @@ pure fn escape_default(s: str/&) -> str {
let mut out: str = "";
unchecked {
reserve_at_least(out, str::len(s));
do chars_iter(s) {|c| out += char::escape_default(c); }
chars_iter(s, |c| out += char::escape_default(c));
}
ret out;
}
@ -1693,7 +1693,7 @@ pure fn escape_unicode(s: str/&) -> str {
let mut out: str = "";
unchecked {
reserve_at_least(out, str::len(s));
do chars_iter(s) {|c| out += char::escape_unicode(c); }
chars_iter(s, |c| out += char::escape_unicode(c));
}
ret out;
}
@ -1726,7 +1726,7 @@ mod unsafe {
unsafe fn from_buf_len(buf: *u8, len: uint) -> str {
let mut v: ~[u8] = ~[];
vec::reserve(v, len + 1u);
do vec::as_buf(v) {|b| ptr::memcpy(b, buf, len); }
vec::as_buf(v, |b| ptr::memcpy(b, buf, len));
vec::unsafe::set_len(v, len);
vec::push(v, 0u8);
@ -1777,14 +1777,14 @@ mod unsafe {
If end is greater than the length of the string.
"]
unsafe fn slice_bytes(s: str/&, begin: uint, end: uint) -> str {
do unpack_slice(s) { |sbuf, n|
do unpack_slice(s) |sbuf, n| {
assert (begin <= end);
assert (end <= n);
let mut v = ~[];
vec::reserve(v, end - begin + 1u);
unsafe {
do vec::as_buf(v) { |vbuf|
do vec::as_buf(v) |vbuf| {
let src = ptr::offset(sbuf, begin);
ptr::memcpy(vbuf, src, end - begin);
}
@ -1802,7 +1802,7 @@ mod unsafe {
#[doc = "Appends a vector of bytes to a string. (Not UTF-8 safe)."]
unsafe fn push_bytes(&s: str, bytes: ~[u8]) {
for vec::each(bytes) {|byte| rustrt::rust_str_push(s, byte); }
for vec::each(bytes) |byte| { rustrt::rust_str_push(s, byte); }
}
#[doc = "
@ -2037,7 +2037,7 @@ mod tests {
log(debug, "split_byte: " + s);
let v = split_char(s, c);
#debug("split_byte to: %?", v);
assert vec::all2(v, u, { |a,b| a == b });
assert vec::all2(v, u, |a,b| a == b);
}
t("abc.hello.there", '.', ~["abc", "hello", "there"]);
t(".hello.there", '.', ~["", "hello", "there"]);
@ -2067,7 +2067,7 @@ mod tests {
let v = splitn_char(s, c, n);
#debug("split_byte to: %?", v);
#debug("comparing vs. %?", u);
assert vec::all2(v, u, { |a,b| a == b });
assert vec::all2(v, u, |a,b| a == b);
}
t("abc.hello.there", '.', 0u, ~["abc.hello.there"]);
t("abc.hello.there", '.', 1u, ~["abc", "hello.there"]);
@ -2149,7 +2149,7 @@ mod tests {
fn test_split() {
let data = "ประเทศไทย中华Việt Nam";
assert ~["ประเทศไทย中", "Việt Nam"]
== split (data, {|cc| cc == '华'});
== split (data, |cc| cc == '华');
assert ~["", "", "XXX", "YYY", ""]
== split("zzXXXzYYYz", char::is_lowercase);
@ -2157,9 +2157,9 @@ mod tests {
assert ~["zz", "", "", "z", "", "", "z"]
== split("zzXXXzYYYz", char::is_uppercase);
assert ~["",""] == split("z", {|cc| cc == 'z'});
assert ~[""] == split("", {|cc| cc == 'z'});
assert ~["ok"] == split("ok", {|cc| cc == 'z'});
assert ~["",""] == split("z", |cc| cc == 'z');
assert ~[""] == split("", |cc| cc == 'z');
assert ~["ok"] == split("ok", |cc| cc == 'z');
}
#[test]
@ -2284,9 +2284,9 @@ mod tests {
#[test]
fn test_to_lower() {
assert "" == map("", {|c| libc::tolower(c as c_char) as char});
assert "" == map("", |c| libc::tolower(c as c_char) as char);
assert "ymca" == map("YMCA",
{|c| libc::tolower(c as c_char) as char});
|c| libc::tolower(c as c_char) as char);
}
#[test]
@ -2574,13 +2574,13 @@ mod tests {
#[should_fail]
fn test_as_bytes_fail() {
// Don't double free
do as_bytes("") {|_bytes| fail }
as_bytes::<()>("", |_bytes| fail );
}
#[test]
fn test_as_buf() {
let a = "Abcdefg";
let b = as_buf(a, {|buf|
let b = as_buf(a, |buf| {
assert unsafe { *buf } == 65u8;
100
});
@ -2590,7 +2590,7 @@ mod tests {
#[test]
fn test_as_buf_small() {
let a = "A";
let b = as_buf(a, {|buf|
let b = as_buf(a, |buf| {
assert unsafe { *buf } == 65u8;
100
});
@ -2601,7 +2601,7 @@ mod tests {
fn test_as_buf2() {
unsafe {
let s = "hello";
let sb = as_buf(s, {|b| b });
let sb = as_buf(s, |b| b);
let s_cstr = unsafe::from_buf(sb);
assert (eq(s_cstr, s));
}
@ -2647,7 +2647,7 @@ mod tests {
#[test]
fn test_chars_iter() {
let mut i = 0;
do chars_iter("x\u03c0y") {|ch|
do chars_iter("x\u03c0y") |ch| {
alt check i {
0 { assert ch == 'x'; }
1 { assert ch == '\u03c0'; }
@ -2656,14 +2656,14 @@ mod tests {
i += 1;
}
do chars_iter("") {|_ch| fail; } // should not fail
chars_iter("", |_ch| fail ); // should not fail
}
#[test]
fn test_bytes_iter() {
let mut i = 0;
do bytes_iter("xyz") {|bb|
do bytes_iter("xyz") |bb| {
alt check i {
0 { assert bb == 'x' as u8; }
1 { assert bb == 'y' as u8; }
@ -2672,7 +2672,7 @@ mod tests {
i += 1;
}
do bytes_iter("") {|bb| assert bb == 0u8; }
bytes_iter("", |bb| assert bb == 0u8);
}
#[test]
@ -2681,7 +2681,7 @@ mod tests {
let mut ii = 0;
do split_char_iter(data, ' ') {|xx|
do split_char_iter(data, ' ') |xx| {
alt ii {
0 { assert "\nMary" == xx; }
1 { assert "had" == xx; }
@ -2699,7 +2699,7 @@ mod tests {
let mut ii = 0;
do splitn_char_iter(data, ' ', 2u) {|xx|
do splitn_char_iter(data, ' ', 2u) |xx| {
alt ii {
0 { assert "\nMary" == xx; }
1 { assert "had" == xx; }
@ -2716,7 +2716,7 @@ mod tests {
let mut ii = 0;
do words_iter(data) {|ww|
do words_iter(data) |ww| {
alt ii {
0 { assert "Mary" == ww; }
1 { assert "had" == ww; }
@ -2727,7 +2727,7 @@ mod tests {
ii += 1;
}
do words_iter("") {|_x| fail; } // should not fail
words_iter("", |_x| fail); // should not fail
}
#[test]
@ -2736,7 +2736,7 @@ mod tests {
let mut ii = 0;
do lines_iter(lf) {|x|
do lines_iter(lf) |x| {
alt ii {
0 { assert "" == x; }
1 { assert "Mary had a little lamb" == x; }
@ -2750,9 +2750,8 @@ mod tests {
#[test]
fn test_map() {
assert "" == map("", {|c| libc::toupper(c as c_char) as char});
assert "YMCA" == map("ymca", {|c| libc::toupper(c as c_char)
as char});
assert "" == map("", |c| libc::toupper(c as c_char) as char);
assert "YMCA" == map("ymca", |c| libc::toupper(c as c_char) as char);
}
#[test]
@ -2819,7 +2818,7 @@ mod tests {
0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16,
0x000a_u16 ]) ];
for vec::each(pairs) {|p|
for vec::each(pairs) |p| {
let (s, u) = p;
assert to_utf16(s) == u;
assert from_utf16(u) == s;
@ -2832,7 +2831,7 @@ mod tests {
fn test_each_char() {
let s = "abc";
let mut found_b = false;
for each_char(s) {|ch|
for each_char(s) |ch| {
if ch == 'b' {
found_b = true;
break;
@ -2844,7 +2843,7 @@ mod tests {
#[test]
fn test_unpack_slice() {
let a = "hello";
do unpack_slice(a) {|buf, len|
do unpack_slice(a) |buf, len| {
unsafe {
assert a[0] == 'h' as u8;
assert *buf == 'h' as u8;

View file

@ -183,16 +183,16 @@ mod tests {
let lock = arc::arc(create_lock());
let lock2 = arc::clone(&lock);
do task::spawn {|move lock2|
do task::spawn |move lock2| {
let lock = arc::get(&lock2);
do (*lock).lock_cond {|c|
do (*lock).lock_cond |c| {
c.wait();
}
}
let mut signaled = false;
while !signaled {
do (*arc::get(&lock)).lock_cond {|c|
do (*arc::get(&lock)).lock_cond |c| {
signaled = c.signal()
}
}

View file

@ -295,7 +295,7 @@ fn future_result(builder: builder) -> future::future<task_result> {
with get_opts(builder)
});
do future::from_fn {||
do future::from_fn || {
alt comm::recv(po) {
exit(_, result) { result }
}
@ -307,7 +307,7 @@ fn future_task(builder: builder) -> future::future<task> {
let mut po = comm::port();
let ch = comm::chan(po);
do add_wrapper(builder) {|body|
do add_wrapper(builder) |body| {
fn~() {
comm::send(ch, get_task());
body();
@ -342,7 +342,7 @@ fn run_listener<A:send>(-builder: builder,
let setup_po = comm::port();
let setup_ch = comm::chan(setup_po);
do run(builder) {||
do run(builder) || {
let po = comm::port();
let mut ch = comm::chan(po);
comm::send(setup_ch, ch);
@ -439,7 +439,7 @@ fn try<T:send>(+f: fn~() -> T) -> result<T,()> {
let mut builder = builder();
unsupervise(builder);
let result = future_result(builder);
do run(builder) {||
do run(builder) || {
comm::send(ch, f());
}
alt future::get(result) {
@ -540,7 +540,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) {
};
assert !new_task.is_null();
do option::iter(opts.notify_chan) {|c|
do option::iter(opts.notify_chan) |c| {
// FIXME (#1087): Would like to do notification in Rust
rustrt::rust_task_config_notify(new_task, c);
}
@ -615,7 +615,7 @@ crust fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe {
assert !map_ptr.is_null();
// Get and keep the single reference that was created at the beginning.
let map: task_local_map = unsafe::reinterpret_cast(map_ptr);
for (*map).each {|entry|
for (*map).each |entry| {
alt entry {
// Finaliser drops data. We drop the finaliser implicitly here.
some((_key, data, finalise_fn)) { finalise_fn(data); }
@ -657,10 +657,10 @@ unsafe fn key_to_key_value<T>(key: local_data_key<T>) -> *libc::c_void {
unsafe fn local_data_lookup<T>(map: task_local_map, key: local_data_key<T>)
-> option<(uint, *libc::c_void, fn@(+*libc::c_void))> {
let key_value = key_to_key_value(key);
let map_pos = (*map).position({|entry|
let map_pos = (*map).position(|entry|
alt entry { some((k,_,_)) { k == key_value } none { false } }
});
do map_pos.map {|index|
);
do map_pos.map |index| {
// .get() is guaranteed because of "none { false }" above.
let (_, data_ptr, finaliser) = (*map)[index].get();
(index, data_ptr, finaliser)
@ -671,7 +671,7 @@ unsafe fn local_get_helper<T>(task: *rust_task, key: local_data_key<T>,
do_pop: bool) -> option<@T> {
let map = get_task_local_map(task);
// Interpret our findings from the map
do local_data_lookup(map, key).map {|result|
do local_data_lookup(map, key).map |result| {
// A reference count magically appears on 'data' out of thin air.
// 'data' has the reference we originally stored it with. We either
// need to erase it from the map or artificially bump the count.
@ -718,7 +718,7 @@ unsafe fn local_set<T>(task: *rust_task, key: local_data_key<T>, -data: @T) {
}
none {
// Find an empty slot. If not, grow the vector.
alt (*map).position({|x| x == none}) {
alt (*map).position(|x| x == none) {
some(empty_index) {
(*map).set_elt(empty_index, new_entry);
}
@ -799,7 +799,7 @@ native mod rustrt {
fn test_spawn_raw_simple() {
let po = comm::port();
let ch = comm::chan(po);
do spawn_raw(default_task_opts()) {||
do spawn_raw(default_task_opts()) || {
comm::send(ch, ());
}
comm::recv(po);
@ -812,7 +812,7 @@ fn test_spawn_raw_unsupervise() {
supervise: false
with default_task_opts()
};
do spawn_raw(opts) {||
do spawn_raw(opts) || {
fail;
}
}
@ -829,7 +829,7 @@ fn test_spawn_raw_notify() {
notify_chan: some(notify_ch)
with default_task_opts()
};
do spawn_raw(opts) {||
do spawn_raw(opts) || {
comm::send(task_ch, get_task());
}
let task_ = comm::recv(task_po);
@ -840,7 +840,7 @@ fn test_spawn_raw_notify() {
notify_chan: some(notify_ch)
with default_task_opts()
};
do spawn_raw(opts) {||
do spawn_raw(opts) || {
comm::send(task_ch, get_task());
fail;
}
@ -853,7 +853,7 @@ fn test_run_basic() {
let po = comm::port();
let ch = comm::chan(po);
let buildr = builder();
do run(buildr) {||
do run(buildr) || {
comm::send(ch, ());
}
comm::recv(po);
@ -864,13 +864,13 @@ fn test_add_wrapper() {
let po = comm::port();
let ch = comm::chan(po);
let buildr = builder();
do add_wrapper(buildr) {|body|
do add_wrapper(buildr) |body| {
fn~() {
body();
comm::send(ch, ());
}
}
do run(buildr) {||}
do run(buildr) || { }
comm::recv(po);
}
@ -879,13 +879,13 @@ fn test_add_wrapper() {
fn test_future_result() {
let buildr = builder();
let result = future_result(buildr);
do run(buildr) {||}
do run(buildr) || { }
assert future::get(result) == success;
let buildr = builder();
let result = future_result(buildr);
unsupervise(buildr);
do run(buildr) {|| fail }
do run(buildr) || { fail }
assert future::get(result) == failure;
}
@ -895,7 +895,7 @@ fn test_future_task() {
let ch = comm::chan(po);
let buildr = builder();
let task1 = future_task(buildr);
do run(buildr) {|| comm::send(ch, get_task()) }
do run(buildr) || { comm::send(ch, get_task()) }
assert future::get(task1) == comm::recv(po);
}
@ -903,7 +903,7 @@ fn test_future_task() {
fn test_spawn_listiner_bidi() {
let po = comm::port();
let ch = comm::chan(po);
let ch = do spawn_listener {|po|
let ch = do spawn_listener |po| {
// Now the child has a port called 'po' to read from and
// an environment-captured channel called 'ch'.
let res = comm::recv(po);
@ -918,7 +918,7 @@ fn test_spawn_listiner_bidi() {
#[test]
fn test_try_success() {
alt do try {||
alt do try || {
"Success!"
} {
result::ok("Success!") { }
@ -929,7 +929,7 @@ fn test_try_success() {
#[test]
#[ignore(cfg(windows))]
fn test_try_fail() {
alt do try {||
alt do try || {
fail
} {
result::err(()) { }
@ -941,7 +941,7 @@ fn test_try_fail() {
#[should_fail]
#[ignore(cfg(windows))]
fn test_spawn_sched_no_threads() {
do spawn_sched(manual_threads(0u)) {|| };
do spawn_sched(manual_threads(0u)) || { }
}
#[test]
@ -952,7 +952,7 @@ fn test_spawn_sched() {
fn f(i: int, ch: comm::chan<()>) {
let parent_sched_id = rustrt::rust_get_sched_id();
do spawn_sched(single_threaded) {||
do spawn_sched(single_threaded) || {
let child_sched_id = rustrt::rust_get_sched_id();
assert parent_sched_id != child_sched_id;
@ -973,9 +973,9 @@ fn test_spawn_sched_childs_on_same_sched() {
let po = comm::port();
let ch = comm::chan(po);
do spawn_sched(single_threaded) {||
do spawn_sched(single_threaded) || {
let parent_sched_id = rustrt::rust_get_sched_id();
do spawn {||
do spawn || {
let child_sched_id = rustrt::rust_get_sched_id();
// This should be on the same scheduler
assert parent_sched_id == child_sched_id;
@ -1002,7 +1002,7 @@ fn test_spawn_sched_blocking() {
// Testing that a task in one scheduler can block in foreign code
// without affecting other schedulers
do iter::repeat(20u) {||
do iter::repeat(20u) || {
let start_po = comm::port();
let start_ch = comm::chan(start_po);
@ -1011,7 +1011,7 @@ fn test_spawn_sched_blocking() {
let lock = testrt::rust_dbg_lock_create();
do spawn_sched(single_threaded) {||
do spawn_sched(single_threaded) || {
testrt::rust_dbg_lock_lock(lock);
comm::send(start_ch, ());
@ -1038,7 +1038,7 @@ fn test_spawn_sched_blocking() {
let setup_ch = comm::chan(setup_po);
let parent_po = comm::port();
let parent_ch = comm::chan(parent_po);
do spawn {||
do spawn || {
let child_po = comm::port();
comm::send(setup_ch, comm::chan(child_po));
pingpong(child_po, parent_ch);
@ -1063,7 +1063,7 @@ fn avoid_copying_the_body(spawnfn: fn(+fn~())) {
let x = ~1;
let x_in_parent = ptr::addr_of(*x) as uint;
do spawnfn {||
do spawnfn || {
let x_in_child = ptr::addr_of(*x) as uint;
comm::send(ch, x_in_child);
}
@ -1079,7 +1079,7 @@ fn test_avoid_copying_the_body_spawn() {
#[test]
fn test_avoid_copying_the_body_spawn_listener() {
do avoid_copying_the_body {|f|
do avoid_copying_the_body |f| {
spawn_listener(fn~(move f, _po: comm::port<int>) {
f();
});
@ -1088,9 +1088,9 @@ fn test_avoid_copying_the_body_spawn_listener() {
#[test]
fn test_avoid_copying_the_body_run() {
do avoid_copying_the_body {|f|
do avoid_copying_the_body |f| {
let buildr = builder();
do run(buildr) {||
do run(buildr) || {
f();
}
}
@ -1098,7 +1098,7 @@ fn test_avoid_copying_the_body_run() {
#[test]
fn test_avoid_copying_the_body_run_listener() {
do avoid_copying_the_body {|f|
do avoid_copying_the_body |f| {
let buildr = builder();
run_listener(buildr, fn~(move f, _po: comm::port<int>) {
f();
@ -1108,8 +1108,8 @@ fn test_avoid_copying_the_body_run_listener() {
#[test]
fn test_avoid_copying_the_body_try() {
do avoid_copying_the_body {|f|
do try {||
do avoid_copying_the_body |f| {
do try || {
f()
};
}
@ -1117,10 +1117,10 @@ fn test_avoid_copying_the_body_try() {
#[test]
fn test_avoid_copying_the_body_future_task() {
do avoid_copying_the_body {|f|
do avoid_copying_the_body |f| {
let buildr = builder();
future_task(buildr);
do run(buildr) {||
do run(buildr) || {
f();
}
}
@ -1128,10 +1128,10 @@ fn test_avoid_copying_the_body_future_task() {
#[test]
fn test_avoid_copying_the_body_unsupervise() {
do avoid_copying_the_body {|f|
do avoid_copying_the_body |f| {
let buildr = builder();
unsupervise(buildr);
do run(buildr) {||
do run(buildr) || {
f();
}
}
@ -1151,7 +1151,7 @@ fn test_osmain() {
let po = comm::port();
let ch = comm::chan(po);
do run(buildr) {||
do run(buildr) || {
comm::send(ch, ());
}
comm::recv(po);
@ -1166,12 +1166,12 @@ fn test_unkillable() {
let ch = po.chan();
// We want to do this after failing
do spawn {||
do spawn || {
iter::repeat(10u, yield);
ch.send(());
}
do spawn {||
do spawn || {
yield();
// We want to fail after the unkillable task
// blocks on recv
@ -1179,7 +1179,7 @@ fn test_unkillable() {
}
unsafe {
do unkillable {||
do unkillable || {
let p = ~0;
let pp: *uint = unsafe::transmute(p);
@ -1198,7 +1198,7 @@ fn test_unkillable() {
fn test_tls_multitask() unsafe {
fn my_key(+_x: @str) { }
local_data_set(my_key, @"parent data");
do task::spawn {||
do task::spawn || {
assert local_data_get(my_key) == none; // TLS shouldn't carry over.
local_data_set(my_key, @"child data");
assert *(local_data_get(my_key).get()) == "child data";
@ -1230,13 +1230,13 @@ fn test_tls_pop() unsafe {
#[test]
fn test_tls_modify() unsafe {
fn my_key(+_x: @str) { }
local_data_modify(my_key, {|data|
local_data_modify(my_key, |data| {
alt data {
some(@val) { fail "unwelcome value: " + val }
none { some(@"first data") }
}
});
local_data_modify(my_key, {|data|
local_data_modify(my_key, |data| {
alt data {
some(@"first data") { some(@"next data") }
some(@val) { fail "wrong value: " + val }
@ -1254,7 +1254,7 @@ fn test_tls_crust_automorestack_memorial_bug() unsafe {
// something within a rust stack segment. Then a subsequent upcall (esp.
// for logging, think vsnprintf) would run on a stack smaller than 1 MB.
fn my_key(+_x: @str) { }
do task::spawn {||
do task::spawn || {
unsafe { local_data_set(my_key, @"hax"); }
}
}
@ -1264,7 +1264,7 @@ fn test_tls_multiple_types() unsafe {
fn str_key(+_x: @str) { }
fn box_key(+_x: @@()) { }
fn int_key(+_x: @int) { }
do task::spawn{||
do task::spawn || {
local_data_set(str_key, @"string data");
local_data_set(box_key, @@());
local_data_set(int_key, @42);
@ -1276,7 +1276,7 @@ fn test_tls_overwrite_multiple_types() unsafe {
fn str_key(+_x: @str) { }
fn box_key(+_x: @@()) { }
fn int_key(+_x: @int) { }
do task::spawn{||
do task::spawn || {
local_data_set(str_key, @"string data");
local_data_set(int_key, @42);
// This could cause a segfault if overwriting-destruction is done with
@ -1294,7 +1294,7 @@ fn test_tls_cleanup_on_failure() unsafe {
fn int_key(+_x: @int) { }
local_data_set(str_key, @"parent data");
local_data_set(box_key, @@());
do task::spawn{|| // spawn_linked
do task::spawn || { // spawn_linked
local_data_set(str_key, @"string data");
local_data_set(box_key, @@());
local_data_set(int_key, @42);

View file

@ -59,7 +59,7 @@ impl <A: to_str copy, B: to_str copy, C: to_str copy> of to_str for (A, B, C){
impl <A: to_str> of to_str for ~[A] {
fn to_str() -> str {
let mut acc = "[", first = true;
for vec::each(self) {|elt|
for vec::each(self) |elt| {
if first { first = false; }
else { acc += ", "; }
acc += elt.to_str();

View file

@ -131,8 +131,8 @@ Convert to a string in a given base
Fails if `radix` < 2 or `radix` > 16
"]
fn to_str(num: T, radix: uint) -> str {
do to_str_bytes(false, num, radix) {|slice|
do vec::unpack_slice(slice) {|p, len|
do to_str_bytes(false, num, radix) |slice| {
do vec::unpack_slice(slice) |p, len| {
unsafe { str::unsafe::from_buf_len(p, len) }
}
}
@ -177,7 +177,7 @@ fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
// in-bounds, no extra cost.
unsafe {
do vec::unpack_slice(buf) {|p, len|
do vec::unpack_slice(buf) |p, len| {
let mp = p as *mut u8;
let mut i = len;
let mut n = num;

View file

@ -103,12 +103,12 @@ type init_op<T> = fn(uint) -> T;
#[doc = "Returns true if a vector contains no elements"]
pure fn is_empty<T>(v: &[const T]) -> bool {
unpack_const_slice(v, {|_p, len| len == 0u})
unpack_const_slice(v, |_p, len| len == 0u)
}
#[doc = "Returns true if a vector contains some elements"]
pure fn is_not_empty<T>(v: &[const T]) -> bool {
unpack_const_slice(v, {|_p, len| len > 0u})
unpack_const_slice(v, |_p, len| len > 0u)
}
#[doc = "Returns true if two vectors have the same length"]
@ -169,7 +169,7 @@ pure fn capacity<T>(&&v: ~[const T]) -> uint {
#[doc = "Returns the length of a vector"]
#[inline(always)]
pure fn len<T>(&&v: &[const T]) -> uint {
unpack_const_slice(v, { |_p, len| len})
unpack_const_slice(v, |_p, len| len)
}
#[doc = "
@ -266,7 +266,7 @@ pure fn slice<T: copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
pure fn view<T: copy>(v: &[const T], start: uint, end: uint) -> &a.[T] {
assert (start <= end);
assert (end <= len(v));
do unpack_slice(v) {|p, _len|
do unpack_slice(v) |p, _len| {
unsafe {
::unsafe::reinterpret_cast(
(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
@ -387,7 +387,7 @@ fn shift<T>(&v: ~[T]) -> T {
let vv = unsafe::to_ptr(vv);
rr <- *vv;
for uint::range(1u, ln) {|i|
for uint::range(1u, ln) |i| {
let r <- *ptr::offset(vv, i);
push(v, r);
}
@ -455,16 +455,14 @@ fn push_slow<T>(&v: ~[const T], +initval: T) {
// Unchecked vector indexing
#[inline(always)]
unsafe fn ref<T: copy>(v: &[const T], i: uint) -> T {
unpack_slice(v, {|p, _len|
*ptr::offset(p, i)
})
unpack_slice(v, |p, _len| *ptr::offset(p, i))
}
#[inline(always)]
fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
reserve(v, v.len() + rhs.len());
for uint::range(0u, rhs.len()) {|i|
for uint::range(0u, rhs.len()) |i| {
push(v, unsafe { ref(rhs, i) })
}
}
@ -473,8 +471,8 @@ fn push_all<T: copy>(&v: ~[const T], rhs: &[const T]) {
fn push_all_move<T>(&v: ~[const T], -rhs: ~[const T]) {
reserve(v, v.len() + rhs.len());
unsafe {
do unpack_slice(rhs) {|p, len|
for uint::range(0, len) {|i|
do unpack_slice(rhs) |p, len| {
for uint::range(0, len) |i| {
let x <- *ptr::offset(p, i);
push(v, x);
}
@ -578,7 +576,7 @@ Apply a function to each element of a vector and return the results
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)); } }
for each(v) |elem| { unsafe { push(result, f(elem)); } }
ret result;
}
@ -588,7 +586,7 @@ Apply a function to each element of a vector and return the results
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)); } }
for eachi(v) |i, elem| { unsafe { push(result, f(i, elem)); } }
ret result;
}
@ -598,7 +596,7 @@ of each result vector
"]
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)); } }
for each(v) |elem| { unchecked{ push_all_move(result, f(elem)); } }
ret result;
}
@ -627,7 +625,7 @@ the resulting vector.
pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> option<U>)
-> ~[U] {
let mut result = ~[];
for each(v) {|elem|
for each(v) |elem| {
alt f(elem) {
none {/* no-op */ }
some(result_elem) { unsafe { push(result, result_elem); } }
@ -645,7 +643,7 @@ only those elements for which `f` returned true.
"]
pure fn filter<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[T] {
let mut result = ~[];
for each(v) {|elem|
for each(v) |elem| {
if f(elem) { unsafe { push(result, elem); } }
}
ret result;
@ -658,7 +656,7 @@ Flattens a vector of vectors of T into a single vector of T.
"]
pure fn concat<T: copy>(v: &[[T]/~]) -> ~[T] {
let mut r = ~[];
for each(v) {|inner| unsafe { push_all(r, inner); } }
for each(v) |inner| { unsafe { push_all(r, inner); } }
ret r;
}
@ -668,7 +666,7 @@ Concatenate a vector of vectors, placing a given separator between each
pure fn connect<T: copy>(v: &[[T]/~], sep: T) -> ~[T] {
let mut r: ~[T] = ~[];
let mut first = true;
for each(v) {|inner|
for each(v) |inner| {
if first { first = false; } else { unsafe { push(r, sep); } }
unchecked { push_all(r, inner) };
}
@ -678,7 +676,7 @@ pure fn connect<T: copy>(v: &[[T]/~], sep: T) -> ~[T] {
#[doc = "Reduce a vector from left to right"]
pure fn foldl<T: copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
let mut accum = z;
do iter(v) { |elt|
do iter(v) |elt| {
accum = p(accum, elt);
}
ret accum;
@ -687,7 +685,7 @@ pure fn foldl<T: copy, U>(z: T, v: &[U], p: fn(T, U) -> T) -> T {
#[doc = "Reduce a vector from right to left"]
pure fn foldr<T, U: copy>(v: &[T], z: U, p: fn(T, U) -> U) -> U {
let mut accum = z;
do riter(v) { |elt|
do riter(v) |elt| {
accum = p(elt, accum);
}
ret accum;
@ -699,7 +697,7 @@ Return true if a predicate matches any elements
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; } }
for each(v) |elem| { if f(elem) { ret true; } }
ret false;
}
@ -726,7 +724,7 @@ Return true if a predicate matches all elements
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; } }
for each(v) |elem| { if !f(elem) { ret false; } }
ret true;
}
@ -736,7 +734,7 @@ Return true if a predicate matches all elements
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; } }
for eachi(v) |i, elem| { if !f(i, elem) { ret false; } }
ret true;
}
@ -756,14 +754,14 @@ pure fn all2<T, U>(v0: &[T], v1: &[U],
#[doc = "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; } }
for each(v) |elt| { if x == elt { ret true; } }
ret false;
}
#[doc = "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; } }
for each(v) |elt| { if x == elt { cnt += 1u; } }
ret cnt;
}
@ -787,7 +785,7 @@ is returned. If `f` matches no elements then none is returned.
"]
pure fn find_between<T: copy>(v: &[T], start: uint, end: uint,
f: fn(T) -> bool) -> option<T> {
option::map(position_between(v, start, end, f), { |i| v[i] })
option::map(position_between(v, start, end, f), |i| v[i])
}
#[doc = "
@ -810,12 +808,12 @@ the element is returned. If `f` matches no elements then none is returned.
"]
pure fn rfind_between<T: copy>(v: &[T], start: uint, end: uint,
f: fn(T) -> bool) -> option<T> {
option::map(rposition_between(v, start, end, f), { |i| v[i] })
option::map(rposition_between(v, start, end, f), |i| v[i])
}
#[doc = "Find the first index containing a matching value"]
pure fn position_elem<T>(v: &[T], x: T) -> option<uint> {
position(v, { |y| x == y })
position(v, |y| x == y)
}
#[doc = "
@ -847,7 +845,7 @@ pure fn position_between<T>(v: &[T], start: uint, end: uint,
#[doc = "Find the last index containing a matching value"]
pure fn rposition_elem<T>(v: &[T], x: T) -> option<uint> {
rposition(v, { |y| x == y })
rposition(v, |y| x == y)
}
#[doc = "
@ -894,7 +892,7 @@ of the i-th tuple of the input vector.
"]
pure fn unzip<T: copy, U: copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
let mut as = ~[], bs = ~[];
for each(v) {|p|
for each(v) |p| {
let (a, b) = p;
unchecked {
vec::push(as, a);
@ -974,7 +972,7 @@ element's value.
*/
#[inline(always)]
pure fn iter_between<T>(v: &[T], start: uint, end: uint, f: fn(T)) {
do unpack_slice(v) { |base_ptr, len|
do unpack_slice(v) |base_ptr, len| {
assert start <= end;
assert end <= len;
unsafe {
@ -996,7 +994,7 @@ Return true to continue, false to break.
"]
#[inline(always)]
pure fn each<T>(v: &[const T], f: fn(T) -> bool) {
do vec::unpack_slice(v) {|p, n|
do vec::unpack_slice(v) |p, n| {
let mut n = n;
let mut p = p;
while n > 0u {
@ -1016,7 +1014,7 @@ Return true to continue, false to break.
"]
#[inline(always)]
pure fn eachi<T>(v: &[const T], f: fn(uint, T) -> bool) {
do vec::unpack_slice(v) {|p, n|
do vec::unpack_slice(v) |p, n| {
let mut i = 0u;
let mut p = p;
while i < n {
@ -1039,7 +1037,7 @@ Both vectors must have the same length
#[inline]
fn iter2<U, T>(v1: &[U], v2: &[T], f: fn(U, T)) {
assert len(v1) == len(v2);
for uint::range(0u, len(v1)) {|i|
for uint::range(0u, len(v1)) |i| {
f(v1[i], v2[i])
}
}
@ -1064,7 +1062,7 @@ Iterates over vector `v` and, for each element, calls function `f` with the
element's value.
"]
pure fn riter<T>(v: &[T], f: fn(T)) {
riteri(v, { |_i, v| f(v) })
riteri(v, |_i, v| f(v))
}
#[doc ="
@ -1102,7 +1100,7 @@ pure fn permute<T: copy>(v: &[T], put: fn(~[T])) {
let mut rest = slice(v, 0u, i);
unchecked {
push_all(rest, view(v, i+1u, ln));
permute(rest, {|permutation|
permute(rest, |permutation| {
put(append(~[elt], permutation))
})
}
@ -1114,7 +1112,7 @@ pure fn permute<T: copy>(v: &[T], put: fn(~[T])) {
pure fn windowed<TT: copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
let mut ww = ~[];
assert 1u <= nn;
vec::iteri (xx, {|ii, _x|
vec::iteri (xx, |ii, _x| {
let len = vec::len(xx);
if ii+nn <= len unchecked {
vec::push(ww, vec::slice(xx, ii, ii+nn));
@ -1130,11 +1128,11 @@ Allows for unsafe manipulation of vector contents, which is useful for native
interop.
"]
fn as_buf<E,T>(v: &[E], f: fn(*E) -> T) -> T {
unpack_slice(v, { |buf, _len| f(buf) })
unpack_slice(v, |buf, _len| f(buf))
}
fn as_mut_buf<E,T>(v: &[mut E], f: fn(*mut E) -> T) -> T {
unpack_mut_slice(v, { |buf, _len| f(buf) })
unpack_mut_slice(v, |buf, _len| f(buf))
}
#[doc = "
@ -1474,7 +1472,7 @@ mod u8 {
it out. -- tjc */
let mut u: uint = 5381u;
vec::iter(s, { |c| u *= 33u; u += c as uint; });
vec::iter(s, |c| {u *= 33u; u += c as uint;});
ret u;
}
}
@ -1841,21 +1839,21 @@ mod tests {
#[test]
fn test_iter_empty() {
let mut i = 0;
iter::<int>(~[], { |_v| i += 1 });
iter::<int>(~[], |_v| i += 1);
assert i == 0;
}
#[test]
fn test_iter_nonempty() {
let mut i = 0;
iter(~[1, 2, 3], { |v| i += v });
iter(~[1, 2, 3], |v| i += v);
assert i == 6;
}
#[test]
fn test_iteri() {
let mut i = 0;
iteri(~[1, 2, 3], { |j, v|
iteri(~[1, 2, 3], |j, v| {
if i == 0 { assert v == 1; }
assert j + 1u == v as uint;
i += v;
@ -1866,14 +1864,14 @@ mod tests {
#[test]
fn test_riter_empty() {
let mut i = 0;
riter::<int>(~[], { |_v| i += 1 });
riter::<int>(~[], |_v| i += 1);
assert i == 0;
}
#[test]
fn test_riter_nonempty() {
let mut i = 0;
riter(~[1, 2, 3], { |v|
riter(~[1, 2, 3], |v| {
if i == 0 { assert v == 3; }
i += v
});
@ -1883,7 +1881,7 @@ mod tests {
#[test]
fn test_riteri() {
let mut i = 0;
riteri(~[0, 1, 2], { |j, v|
riteri(~[0, 1, 2], |j, v| {
if i == 0 { assert v == 2; }
assert j == v as uint;
i += v;
@ -1896,19 +1894,19 @@ mod tests {
let mut results: ~[~[int]];
results = ~[];
permute(~[], {|v| vec::push(results, v); });
permute(~[], |v| vec::push(results, v));
assert results == ~[~[]];
results = ~[];
permute(~[7], {|v| results += ~[v]; });
permute(~[7], |v| results += ~[v]);
assert results == ~[~[7]];
results = ~[];
permute(~[1,1], {|v| results += ~[v]; });
permute(~[1,1], |v| results += ~[v]);
assert results == ~[~[1,1],~[1,1]];
results = ~[];
permute(~[5,2,0], {|v| results += ~[v]; });
permute(~[5,2,0], |v| results += ~[v]);
assert results ==
~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]];
}

View file

@ -45,7 +45,7 @@ fn process(v0: bitv, v1: bitv, op: fn(uint, uint) -> uint) -> bool {
assert (vec::len(v0.storage) == len);
assert (v0.nbits == v1.nbits);
let mut changed = false;
for uint::range(0u, len) {|i|
for uint::range(0u, len) |i| {
let w0 = v0.storage[i];
let w1 = v1.storage[i];
let w = op(w0, w1);
@ -89,7 +89,7 @@ fn assign(v0: bitv, v1: bitv) -> bool {
fn clone(v: bitv) -> bitv {
let storage = vec::to_mut(vec::from_elem(v.nbits / uint_bits + 1u, 0u));
let len = vec::len(v.storage);
for uint::range(0u, len) {|i| storage[i] = v.storage[i]; };
for uint::range(0u, len) |i| { storage[i] = v.storage[i]; };
ret @{storage: storage, nbits: v.nbits};
}
@ -113,22 +113,22 @@ contain identical elements.
fn equal(v0: bitv, v1: bitv) -> bool {
if v0.nbits != v1.nbits { ret false; }
let len = vec::len(v1.storage);
for uint::iterate(0u, len) {|i|
for uint::iterate(0u, len) |i| {
if v0.storage[i] != v1.storage[i] { ret false; }
}
}
#[doc = "Set all bits to 0"]
#[inline(always)]
fn clear(v: bitv) { for each_storage(v) {|w| w = 0u } }
fn clear(v: bitv) { for each_storage(v) |w| { w = 0u } }
#[doc = "Set all bits to 1"]
#[inline(always)]
fn set_all(v: bitv) { for each_storage(v) {|w| w = !0u } }
fn set_all(v: bitv) { for each_storage(v) |w| { w = !0u } }
#[doc = "Invert all bits"]
#[inline(always)]
fn invert(v: bitv) { for each_storage(v) {|w| w = !w } }
fn invert(v: bitv) { for each_storage(v) |w| { w = !w } }
#[doc = "
Calculate the difference between two bitvectors
@ -163,14 +163,14 @@ fn set(v: bitv, i: uint, x: bool) {
#[doc = "Returns true if all bits are 1"]
fn is_true(v: bitv) -> bool {
for each(v) {|i| if !i { ret false; } }
for each(v) |i| { if !i { ret false; } }
ret true;
}
#[doc = "Returns true if all bits are 0"]
fn is_false(v: bitv) -> bool {
for each(v) {|i| if i { ret false; } }
for each(v) |i| { if i { ret false; } }
ret true;
}
@ -184,7 +184,7 @@ Converts the bitvector to a vector of uint with the same length.
Each uint in the resulting vector has either value 0u or 1u.
"]
fn to_vec(v: bitv) -> ~[uint] {
let sub = {|x|init_to_vec(v, x)};
let sub = |x| init_to_vec(v, x);
ret vec::from_fn::<uint>(v.nbits, sub);
}
@ -199,7 +199,7 @@ fn each(v: bitv, f: fn(bool) -> bool) {
#[inline(always)]
fn each_storage(v: bitv, op: fn(&uint) -> bool) {
for uint::range(0u, vec::len(v.storage)) {|i|
for uint::range(0u, vec::len(v.storage)) |i| {
let mut w = v.storage[i];
let b = !op(w);
v.storage[i] = w;
@ -215,7 +215,7 @@ is either '0' or '1'.
"]
fn to_str(v: bitv) -> str {
let mut rs = "";
for each(v) {|i| if i { rs += "1"; } else { rs += "0"; } }
for each(v) |i| { if i { rs += "1"; } else { rs += "0"; } }
ret rs;
}

View file

@ -140,7 +140,7 @@ mod tests {
assert mem as int != 0;
ret unsafe { c_vec_with_dtor(mem as *mut u8, n as uint,
{||free(mem)}) };
||free(mem)) };
}
#[test]

View file

@ -57,7 +57,7 @@ fn create<T: copy>() -> t<T> {
self.lo = self.elts.len() - 1u;
} else { self.lo -= 1u; }
if self.lo == self.hi {
self.elts.swap({ |v| grow(self.nelts, oldlo, v) });
self.elts.swap(|v| grow(self.nelts, oldlo, v));
self.lo = self.elts.len() - 1u;
self.hi = self.nelts;
}
@ -66,7 +66,7 @@ fn create<T: copy>() -> t<T> {
}
fn add_back(t: T) {
if self.lo == self.hi && self.nelts != 0u {
self.elts.swap({ |v| grow(self.nelts, self.lo, v) });
self.elts.swap(|v| grow(self.nelts, self.lo, v));
self.lo = 0u;
self.hi = self.nelts;
}
@ -292,7 +292,7 @@ mod tests {
two(17, 42));
#debug("*** test parameterized: taggypar<int>");
let eq4: eqfn<taggypar<int>> = {|x,y|taggypareq::<int>(x, y)};
let eq4: eqfn<taggypar<int>> = |x,y| taggypareq::<int>(x, y);
test_parameterized::<taggypar<int>>(eq4, onepar::<int>(1),
twopar::<int>(1, 2),
threepar::<int>(1, 2, 3),

View file

@ -222,19 +222,19 @@ impl writer for writer {
}
fn wr_tagged_u64(tag_id: uint, v: u64) {
do io::u64_to_be_bytes(v, 8u) {|v|
do io::u64_to_be_bytes(v, 8u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
fn wr_tagged_u32(tag_id: uint, v: u32) {
do io::u64_to_be_bytes(v as u64, 4u) {|v|
do io::u64_to_be_bytes(v as u64, 4u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
fn wr_tagged_u16(tag_id: uint, v: u16) {
do io::u64_to_be_bytes(v as u64, 2u) {|v|
do io::u64_to_be_bytes(v as u64, 2u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
@ -244,19 +244,19 @@ impl writer for writer {
}
fn wr_tagged_i64(tag_id: uint, v: i64) {
do io::u64_to_be_bytes(v as u64, 8u) {|v|
do io::u64_to_be_bytes(v as u64, 8u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
fn wr_tagged_i32(tag_id: uint, v: i32) {
do io::u64_to_be_bytes(v as u64, 4u) {|v|
do io::u64_to_be_bytes(v as u64, 4u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
fn wr_tagged_i16(tag_id: uint, v: i16) {
do io::u64_to_be_bytes(v as u64, 2u) {|v|
do io::u64_to_be_bytes(v as u64, 2u) |v| {
self.wr_tagged_bytes(tag_id, v);
}
}
@ -355,7 +355,7 @@ impl serializer of serialization::serializer for ebml::writer {
fn emit_enum_variant_arg(_idx: uint, f: fn()) { f() }
fn emit_vec(len: uint, f: fn()) {
do self.wr_tag(es_vec as uint) {||
do self.wr_tag(es_vec as uint) || {
self._emit_tagged_uint(es_vec_len, len);
f()
}
@ -482,7 +482,7 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
#debug["read_enum_variant()"];
let idx = self._next_uint(es_enum_vid);
#debug[" idx=%u", idx];
do self.push_doc(self.next_doc(es_enum_body)) {||
do self.push_doc(self.next_doc(es_enum_body)) || {
f(idx)
}
}
@ -494,7 +494,7 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
fn read_vec<T:copy>(f: fn(uint) -> T) -> T {
#debug["read_vec()"];
do self.push_doc(self.next_doc(es_vec)) {||
do self.push_doc(self.next_doc(es_vec)) || {
let len = self._next_uint(es_vec_len);
#debug[" len=%u", len];
f(len)
@ -549,14 +549,14 @@ fn test_option_int() {
}
fn serialize_0<S: serialization::serializer>(s: S, v: option<int>) {
do s.emit_enum("core::option::t") {||
do s.emit_enum("core::option::t") || {
alt v {
none {
s.emit_enum_variant("core::option::none", 0u, 0u, {||});
s.emit_enum_variant("core::option::none", 0u, 0u, || { } );
}
some(v0) {
do s.emit_enum_variant("core::option::some", 1u, 1u) {||
s.emit_enum_variant_arg(0u, {|| serialize_1(s, v0) });
do s.emit_enum_variant("core::option::some", 1u, 1u) || {
s.emit_enum_variant_arg(0u, || serialize_1(s, v0));
}
}
}
@ -568,12 +568,12 @@ fn test_option_int() {
}
fn deserialize_0<S: serialization::deserializer>(s: S) -> option<int> {
do s.read_enum("core::option::t") {||
do s.read_enum_variant {|i|
do s.read_enum("core::option::t") || {
do s.read_enum_variant |i| {
alt check i {
0u { none }
1u {
let v0 = do s.read_enum_variant_arg(0u) {||
let v0 = do s.read_enum_variant_arg(0u) || {
deserialize_1(s)
};
some(v0)

View file

@ -145,7 +145,7 @@ fn name_str(nm: name) -> str {
}
fn find_opt(opts: ~[opt], nm: name) -> option<uint> {
vec::position(opts, { |opt| opt.name == nm })
vec::position(opts, |opt| opt.name == nm)
}
#[doc = "
@ -228,7 +228,7 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe {
}
}
let mut name_pos = 0u;
for vec::each(names) {|nm|
for vec::each(names) |nm| {
name_pos += 1u;
let optid = alt find_opt(opts, nm) {
some(id) { id }
@ -297,7 +297,7 @@ fn opt_present(m: match, nm: str) -> bool {
#[doc = "Returns true if any of several options were matched"]
fn opts_present(m: match, names: ~[str]) -> bool {
for vec::each(names) {|nm|
for vec::each(names) |nm| {
alt find_opt(m.opts, mkname(nm)) {
some(_) { ret true; }
_ { }
@ -323,7 +323,7 @@ Fails if the no option was provided from the given list, or if the no such
option took an argument
"]
fn opts_str(m: match, names: ~[str]) -> str {
for vec::each(names) {|nm|
for vec::each(names) |nm| {
alt opt_val(m, nm) {
val(s) { ret s }
_ { }
@ -340,7 +340,7 @@ Used when an option accepts multiple values.
"]
fn opt_strs(m: match, nm: str) -> ~[str] {
let mut acc: ~[str] = ~[];
for vec::each(opt_vals(m, nm)) {|v|
for vec::each(opt_vals(m, nm)) |v| {
alt v { val(s) { vec::push(acc, s); } _ { } }
}
ret acc;

View file

@ -54,7 +54,7 @@ fn to_writer(wr: io::writer, j: json) {
list(v) {
wr.write_char('[');
let mut first = true;
for (*v).each { |item|
for (*v).each |item| {
if !first {
wr.write_str(", ");
}
@ -71,7 +71,7 @@ fn to_writer(wr: io::writer, j: json) {
wr.write_str("{ ");
let mut first = true;
for d.each { |key, value|
for d.each |key, value| {
if !first {
wr.write_str(", ");
}
@ -90,7 +90,7 @@ fn to_writer(wr: io::writer, j: json) {
fn escape_str(s: str) -> str {
let mut escaped = "\"";
do str::chars_iter(s) { |c|
do str::chars_iter(s) |c| {
alt c {
'"' { escaped += "\\\""; }
'\\' { escaped += "\\\\"; }
@ -110,7 +110,7 @@ fn escape_str(s: str) -> str {
#[doc = "Serializes a json value into a string"]
fn to_str(j: json) -> str {
io::with_str_writer({ |wr| to_writer(wr, j) })
io::with_str_writer(|wr| to_writer(wr, j))
}
type parser = {
@ -186,7 +186,7 @@ impl parser for parser {
}
fn parse_ident(ident: str, value: json) -> result<json, error> {
if str::all(ident, { |c| c == self.next_char() }) {
if str::all(ident, |c| c == self.next_char()) {
self.bump();
ok(value)
} else {
@ -487,7 +487,7 @@ fn eq(value0: json, value1: json) -> bool {
(dict(d0), dict(d1)) {
if d0.size() == d1.size() {
let mut equal = true;
for d0.each { |k, v0|
for d0.each |k, v0| {
alt d1.find(k) {
some(v1) {
if !eq(v0, v1) { equal = false; } }
@ -598,13 +598,13 @@ impl <A: to_json copy, B: to_json copy, C: to_json copy>
}
impl <A: to_json> of to_json for ~[A] {
fn to_json() -> json { list(@self.map({ |elt| elt.to_json() })) }
fn to_json() -> json { list(@self.map(|elt| elt.to_json())) }
}
impl <A: to_json copy> of to_json for hashmap<str, A> {
fn to_json() -> json {
let d = map::str_hash();
for self.each() { |key, value|
for self.each() |key, value| {
d.insert(copy key, value.to_json());
}
dict(d)
@ -635,7 +635,7 @@ mod tests {
fn mk_dict(items: ~[(str, json)]) -> json {
let d = map::str_hash();
do vec::iter(items) { |item|
do vec::iter(items) |item| {
let (key, value) = copy item;
d.insert(key, value);
};

View file

@ -11,7 +11,7 @@ enum list<T> {
#[doc = "Create a list from a vector"]
fn from_vec<T: copy>(v: ~[T]) -> @list<T> {
vec::foldr(v, @nil::<T>, { |h, t| @cons(h, t) })
vec::foldr(v, @nil::<T>, |h, t| @cons(h, t))
}
#[doc = "
@ -29,7 +29,7 @@ accumulated result.
"]
fn foldl<T: copy, U>(z: T, ls: @list<U>, f: fn(T, U) -> T) -> T {
let mut accum: T = z;
do iter(ls) {|elt| accum = f(accum, elt);}
do iter(ls) |elt| { accum = f(accum, elt);}
accum
}
@ -55,7 +55,7 @@ fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> option<T> {
#[doc = "Returns true if a list contains an element with the given value"]
fn has<T: copy>(ls: @list<T>, elt: T) -> bool {
for each(ls) { |e|
for each(ls) |e| {
if e == elt { ret true; }
}
ret false;
@ -77,7 +77,7 @@ pure fn is_not_empty<T: copy>(ls: @list<T>) -> bool {
#[doc = "Returns the length of a list"]
fn len<T>(ls: @list<T>) -> uint {
let mut count = 0u;
iter(ls, {|_e| count += 1u;});
iter(ls, |_e| count += 1u);
count
}

View file

@ -151,7 +151,7 @@ mod chained {
let n_old_chains = vec::len(self.chains);
let n_new_chains: uint = uint::next_power_of_two(n_old_chains+1u);
let new_chains = chains(n_new_chains);
for self.each_entry {|entry|
for self.each_entry |entry| {
let idx = entry.hash % n_new_chains;
entry.next = new_chains[idx];
new_chains[idx] = present(entry);
@ -256,14 +256,14 @@ mod chained {
}
fn each(blk: fn(K,V) -> bool) {
for self.each_entry { |entry|
for self.each_entry |entry| {
if !blk(entry.key, copy entry.value) { break; }
}
}
fn each_key(blk: fn(K) -> bool) { self.each({ |k, _v| blk(k)}) }
fn each_key(blk: fn(K) -> bool) { self.each(|k, _v| blk(k)) }
fn each_value(blk: fn(V) -> bool) { self.each({ |_k, v| blk(v)}) }
fn each_value(blk: fn(V) -> bool) { self.each(|_k, v| blk(v)) }
}
fn chains<K,V>(nchains: uint) -> ~[mut chain<K,V>] {
@ -302,7 +302,7 @@ fn str_hash<V: copy>() -> hashmap<str, V> {
#[doc = "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)});
ret hashmap(|x: @str| str::hash(*x), |x,y| str::eq(*x,*y));
}
#[doc = "Construct a hashmap for byte string keys"]
@ -332,7 +332,7 @@ Convert a set into a vector.
"]
fn vec_from_set<T: copy>(s: set<T>) -> ~[T] {
let mut v = ~[];
do s.each_key() {|k|
do s.each_key() |k| {
vec::push(v, k);
true
};
@ -343,7 +343,7 @@ fn vec_from_set<T: copy>(s: set<T>) -> ~[T] {
fn hash_from_vec<K: const copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>,
items: ~[(K, V)]) -> hashmap<K, V> {
let map = hashmap(hasher, eqer);
do vec::iter(items) { |item|
do vec::iter(items) |item| {
let (key, value) = item;
map.insert(key, value);
}

View file

@ -88,7 +88,7 @@ fn md4_str(msg: ~[u8]) -> str {
f(a); f(b); f(c); f(d);
}
let mut result = "";
do app(a, b, c, d) {|u|
do app(a, b, c, d) |u| {
let mut i = 0u32;
while i < 4u32 {
let byte = (u >> (i * 8u32)) as u8;

View file

@ -66,7 +66,7 @@ j Fails if the string is not a valid IPv4 address
}
}
fn try_parse_addr(ip: str) -> result::result<ip_addr,parse_addr_err> {
let parts = vec::map(str::split_char(ip, '.'), {|s|
let parts = vec::map(str::split_char(ip, '.'), |s| {
alt uint::from_str(s) {
some(n) if n <= 255u { n }
_ { 256u }

View file

@ -48,7 +48,7 @@ class tcp_socket {
};
let close_data_ptr = ptr::addr_of(close_data);
let stream_handle_ptr = (*(self.socket_data)).stream_handle_ptr;
do iotask::interact((*(self.socket_data)).iotask) {|loop_ptr|
do iotask::interact((*(self.socket_data)).iotask) |loop_ptr| {
log(debug, #fmt("interact dtor for tcp_socket stream %? loop %?",
stream_handle_ptr, loop_ptr));
uv::ll::set_data_for_uv_handle(stream_handle_ptr,
@ -72,7 +72,7 @@ class tcp_conn_port {
let server_stream_ptr = ptr::addr_of((*conn_data_ptr).server_stream);
let stream_closed_po = (*(self.conn_data)).stream_closed_po;
let iotask = (*conn_data_ptr).iotask;
do iotask::interact(iotask) {|loop_ptr|
do iotask::interact(iotask) |loop_ptr| {
log(debug, #fmt("dtor for tcp_conn_port loop: %?",
loop_ptr));
uv::ll::close(server_stream_ptr, tcp_nl_close_cb);
@ -131,7 +131,7 @@ fn connect(input_ip: ip::ip_addr, port: uint,
// we can send into the interact cb to be handled in libuv..
log(debug, #fmt("stream_handle_ptr outside interact %?",
stream_handle_ptr));
do iotask::interact(iotask) {|loop_ptr|
do iotask::interact(iotask) |loop_ptr| {
log(debug, "in interact cb for tcp client connect..");
log(debug, #fmt("stream_handle_ptr in interact %?",
stream_handle_ptr));
@ -251,7 +251,7 @@ value as the `err` variant
fn write_future(sock: tcp_socket, raw_write_data: ~[u8])
-> future<result::result<(), tcp_err_data>> unsafe {
let socket_data_ptr = ptr::addr_of(*(sock.socket_data));
do future_spawn {||
do future_spawn || {
write_common_impl(socket_data_ptr, raw_write_data)
}
}
@ -340,7 +340,7 @@ read attempt. Pass `0u` to wait indefinitely
fn read_future(sock: tcp_socket, timeout_msecs: uint)
-> future<result::result<~[u8],tcp_err_data>> {
let socket_data = ptr::addr_of(*(sock.socket_data));
do future_spawn {||
do future_spawn || {
read_common_impl(socket_data, timeout_msecs)
}
}
@ -387,7 +387,7 @@ fn new_listener(host_ip: ip::ip_addr, port: uint, backlog: uint,
let setup_po = comm::port::<option<tcp_err_data>>();
let setup_ch = comm::chan(setup_po);
do iotask::interact(iotask) {|loop_ptr|
do iotask::interact(iotask) |loop_ptr| {
let tcp_addr = ipv4_ip_addr_to_sockaddr_in(host_ip,
port);
alt uv::ll::tcp_init(loop_ptr, server_stream_ptr) {
@ -488,7 +488,7 @@ fn conn_recv_spawn(server_port: tcp_conn_port,
let new_conn_po = (*(server_port.conn_data)).new_conn_po;
let iotask = (*(server_port.conn_data)).iotask;
let new_conn_result = comm::recv(new_conn_po);
do task::spawn {||
do task::spawn || {
let sock_create_result = alt new_conn_result {
ok(client_stream_ptr) {
conn_port_new_tcp_socket(client_stream_ptr, iotask)
@ -709,7 +709,7 @@ fn listen_for_conn(host_ip: ip::ip_addr, port: uint, backlog: uint,
let setup_po = comm::port::<option<tcp_err_data>>();
let setup_ch = comm::chan(setup_po);
do iotask::interact(iotask) {|loop_ptr|
do iotask::interact(iotask) |loop_ptr| {
let tcp_addr = ipv4_ip_addr_to_sockaddr_in(host_ip,
port);
alt uv::ll::tcp_init(loop_ptr, server_stream_ptr) {
@ -755,7 +755,7 @@ fn listen_for_conn(host_ip: ip::ip_addr, port: uint, backlog: uint,
none {
on_establish_cb(kill_ch);
let kill_result = comm::recv(kill_po);
do iotask::interact(iotask) {|loop_ptr|
do iotask::interact(iotask) |loop_ptr| {
log(debug, #fmt("tcp::listen post-kill recv hl interact %?",
loop_ptr));
(*server_data_ptr).active = false;
@ -861,7 +861,7 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) ->
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
let stop_po = comm::port::<option<tcp_err_data>>();
let stop_ch = comm::chan(stop_po);
do iotask::interact((*socket_data).iotask) {|loop_ptr|
do iotask::interact((*socket_data).iotask) |loop_ptr| {
log(debug, "in interact cb for tcp::read_stop");
alt uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) {
0i32 {
@ -893,7 +893,7 @@ fn read_start_common_impl(socket_data: *tcp_socket_data)
let start_po = comm::port::<option<uv::ll::uv_err_data>>();
let start_ch = comm::chan(start_po);
log(debug, "in tcp::read_start before interact loop");
do iotask::interact((*socket_data).iotask) {|loop_ptr|
do iotask::interact((*socket_data).iotask) |loop_ptr| {
log(debug, #fmt("in tcp::read_start interact cb %?", loop_ptr));
alt uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t,
on_alloc_cb,
@ -935,7 +935,7 @@ fn write_common_impl(socket_data_ptr: *tcp_socket_data,
result_ch: comm::chan(result_po)
};
let write_data_ptr = ptr::addr_of(write_data);
do iotask::interact((*socket_data_ptr).iotask) {|loop_ptr|
do iotask::interact((*socket_data_ptr).iotask) |loop_ptr| {
log(debug, #fmt("in interact cb for tcp::write %?", loop_ptr));
alt uv::ll::write(write_req_ptr,
stream_handle_ptr,
@ -979,8 +979,8 @@ fn conn_port_new_tcp_socket(
iotask : iotask
};
let client_socket_data_ptr = ptr::addr_of(*client_socket_data);
do comm::listen {|cont_ch|
do iotask::interact(iotask) {|loop_ptr|
do comm::listen |cont_ch| {
do iotask::interact(iotask) |loop_ptr| {
log(debug, #fmt("in interact cb 4 conn_port_new_tcp.. loop %?",
loop_ptr));
uv::ll::set_data_for_uv_handle(stream_handle_ptr,
@ -1332,8 +1332,8 @@ mod test {
let cont_po = comm::port::<()>();
let cont_ch = comm::chan(cont_po);
// server
do task::spawn_sched(task::manual_threads(1u)) {||
let actual_req = do comm::listen {|server_ch|
do task::spawn_sched(task::manual_threads(1u)) || {
let actual_req = do comm::listen |server_ch| {
run_tcp_test_server(
server_ip,
server_port,
@ -1347,7 +1347,7 @@ mod test {
comm::recv(cont_po);
// client
log(debug, "server started, firing up client..");
let actual_resp = do comm::listen {|client_ch|
let actual_resp = do comm::listen |client_ch| {
run_tcp_test_client(
server_ip,
server_port,
@ -1376,8 +1376,8 @@ mod test {
let cont_po = comm::port::<()>();
let cont_ch = comm::chan(cont_po);
// server
do task::spawn_sched(task::manual_threads(1u)) {||
let actual_req = do comm::listen {|server_ch|
do task::spawn_sched(task::manual_threads(1u)) || {
let actual_req = do comm::listen |server_ch| {
run_tcp_test_server_listener(
server_ip,
server_port,
@ -1391,7 +1391,7 @@ mod test {
comm::recv(cont_po);
// client
log(debug, "server started, firing up client..");
let actual_resp = do comm::listen {|client_ch|
let actual_resp = do comm::listen |client_ch| {
run_tcp_test_client(
server_ip,
server_port,
@ -1413,23 +1413,21 @@ mod test {
cont_ch: comm::chan<()>,
iotask: iotask) -> str {
do task::spawn_sched(task::manual_threads(1u)) {||
do task::spawn_sched(task::manual_threads(1u)) || {
let server_ip_addr = ip::v4::parse_addr(server_ip);
let listen_result =
listen_for_conn(server_ip_addr, server_port, 128u,
iotask,
iotask, |kill_ch| {
// on_establish_cb -- called when listener is set up
{|kill_ch|
log(debug, #fmt("establish_cb %?",
kill_ch));
comm::send(cont_ch, ());
},
}, |new_conn, kill_ch| {
// risky to run this on the loop, but some users
// will want the POWER
{|new_conn, kill_ch|
log(debug, "SERVER: new connection!");
do comm::listen {|cont_ch|
do task::spawn_sched(task::manual_threads(1u)) {||
do comm::listen |cont_ch| {
do task::spawn_sched(task::manual_threads(1u)) || {
log(debug, "SERVER: starting worker for new req");
let accept_result = accept(new_conn);
@ -1492,7 +1490,7 @@ mod test {
cont_ch: comm::chan<()>,
iotask: iotask) -> str {
do task::spawn_sched(task::manual_threads(1u)) {||
do task::spawn_sched(task::manual_threads(1u)) || {
let server_ip_addr = ip::v4::parse_addr(server_ip);
let new_listener_result =
new_listener(server_ip_addr, server_port, 128u, iotask);

View file

@ -41,9 +41,9 @@ fn map_slices<A: copy send, B: copy send>(
while base < len {
let end = uint::min(len, base + items_per_task);
// FIXME: why is the ::<A, ()> annotation required here? (#2617)
do vec::unpack_slice::<A, ()>(xs) {|p, _len|
do vec::unpack_slice::<A, ()>(xs) |p, _len| {
let f = f();
let f = do future_spawn() {|copy base|
let f = do future_spawn() |copy base| {
unsafe {
let len = end - base;
let slice = (ptr::offset(p, base),
@ -66,7 +66,7 @@ fn map_slices<A: copy send, B: copy send>(
log(info, #fmt("num_tasks: %?", (num_tasks, futures.len())));
assert(num_tasks == futures.len());
let r = do futures.map() {|ys|
let r = do futures.map() |ys| {
ys.get()
};
assert(r.len() == futures.len());
@ -76,7 +76,7 @@ fn map_slices<A: copy send, B: copy send>(
#[doc="A parallel version of map."]
fn map<A: copy send, B: copy send>(xs: ~[A], f: fn~(A) -> B) -> ~[B] {
vec::concat(map_slices(xs, {||
vec::concat(map_slices(xs, || {
fn~(_base: uint, slice : &[A], copy f) -> ~[B] {
vec::map(slice, f)
}
@ -86,9 +86,9 @@ fn map<A: copy send, B: copy send>(xs: ~[A], f: fn~(A) -> B) -> ~[B] {
#[doc="A parallel version of mapi."]
fn mapi<A: copy send, B: copy send>(xs: ~[A],
f: fn~(uint, A) -> B) -> ~[B] {
let slices = map_slices(xs, {||
let slices = map_slices(xs, || {
fn~(base: uint, slice : &[A], copy f) -> ~[B] {
vec::mapi(slice, {|i, x|
vec::mapi(slice, |i, x| {
f(i + base, x)
})
}
@ -105,10 +105,10 @@ In this case, f is a function that creates functions to run over the
inner elements. This is to skirt the need for copy constructors."]
fn mapi_factory<A: copy send, B: copy send>(
xs: ~[A], f: fn() -> fn~(uint, A) -> B) -> ~[B] {
let slices = map_slices(xs, {||
let slices = map_slices(xs, || {
let f = f();
fn~(base: uint, slice : &[A], move f) -> ~[B] {
vec::mapi(slice, {|i, x|
vec::mapi(slice, |i, x| {
f(i + base, x)
})
}
@ -121,20 +121,20 @@ fn mapi_factory<A: copy send, B: copy send>(
#[doc="Returns true if the function holds for all elements in the vector."]
fn alli<A: copy send>(xs: ~[A], f: fn~(uint, A) -> bool) -> bool {
do vec::all(map_slices(xs, {||
do vec::all(map_slices(xs, || {
fn~(base: uint, slice : &[A], copy f) -> bool {
vec::alli(slice, {|i, x|
vec::alli(slice, |i, x| {
f(i + base, x)
})
}
})) {|x| x }
})) |x| { x }
}
#[doc="Returns true if the function holds for any elements in the vector."]
fn any<A: copy send>(xs: ~[A], f: fn~(A) -> bool) -> bool {
do vec::any(map_slices(xs, {||
do vec::any(map_slices(xs, || {
fn~(_base : uint, slice: &[A], copy f) -> bool {
vec::any(slice, f)
}
})) {|x| x }
})) |x| { x }
}

View file

@ -158,13 +158,13 @@ fn concat(v: ~[rope]) -> rope {
let mut len = vec::len(v);
if len == 0u { ret node::empty; }
let ropes = vec::to_mut(vec::from_elem(len, v[0]));
for uint::range(1u, len) {|i|
for uint::range(1u, len) |i| {
ropes[i] = v[i];
}
//Merge progresively
while len > 1u {
for uint::range(0u, len/2u) {|i|
for uint::range(0u, len/2u) |i| {
ropes[i] = append_rope(ropes[2u*i], ropes[2u*i+1u]);
}
if len%2u != 0u {
@ -397,7 +397,7 @@ Loop through a rope, char by char, until the end.
* it - A block to execute with each consecutive character of the rope.
"]
fn iter_chars(rope: rope, it: fn(char)) {
do loop_chars(rope) {|x|
do loop_chars(rope) |x| {
it(x);
true
};
@ -1038,11 +1038,11 @@ mod node {
}
fn loop_chars(node: @node, it: fn(char) -> bool) -> bool {
ret loop_leaves(node, {|leaf|
ret loop_leaves(node,|leaf| {
str::all_between(*leaf.content,
leaf.byte_offset,
leaf.byte_len, it)
})
});
}
#[doc ="
@ -1350,19 +1350,19 @@ mod tests {
fn char_at1() {
//Generate a large rope
let mut r = of_str(@ "123456789");
for uint::range(0u, 10u){|_i|
for uint::range(0u, 10u) |_i| {
r = append_rope(r, r);
}
//Copy it in the slowest possible way
let mut r2 = empty();
for uint::range(0u, char_len(r)){|i|
for uint::range(0u, char_len(r)) |i| {
r2 = append_char(r2, char_at(r, i));
}
assert eq(r, r2);
let mut r3 = empty();
for uint::range(0u, char_len(r)){|i|
for uint::range(0u, char_len(r)) |i| {
r3 = prepend_char(r3, char_at(r, char_len(r) - i - 1u));
}
assert eq(r, r3);
@ -1383,7 +1383,7 @@ mod tests {
//Generate a reasonable rope
let chunk = of_str(@ "123456789");
let mut r = empty();
for uint::range(0u, 10u){|_i|
for uint::range(0u, 10u) |_i| {
r = append_rope(r, chunk);
}

View file

@ -84,9 +84,9 @@ iface deserializer {
// In some cases, these should eventually be coded as traits.
fn emit_from_vec<S: serializer, T>(s: S, v: ~[T], f: fn(T)) {
do s.emit_vec(vec::len(v)) {||
do vec::iteri(v) {|i,e|
do s.emit_vec_elt(i) {||
do s.emit_vec(vec::len(v)) || {
do vec::iteri(v) |i,e| {
do s.emit_vec_elt(i) || {
f(e)
}
}
@ -94,9 +94,9 @@ fn emit_from_vec<S: serializer, T>(s: S, v: ~[T], f: fn(T)) {
}
fn read_to_vec<D: deserializer, T: copy>(d: D, f: fn() -> T) -> ~[T] {
do d.read_vec {|len|
do vec::from_fn(len) {|i|
do d.read_vec_elt(i) {|| f() }
do d.read_vec |len| {
do vec::from_fn(len) |i| {
d.read_vec_elt(i, || f())
}
}
}
@ -234,16 +234,16 @@ fn deserialize_bool<D: deserializer>(d: D) -> bool {
}
fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) {
do s.emit_enum("option") {||
do s.emit_enum("option") || {
alt v {
none {
do s.emit_enum_variant("none", 0u, 0u) {||
do s.emit_enum_variant("none", 0u, 0u) || {
}
}
some(v) {
do s.emit_enum_variant("some", 1u, 1u) {||
do s.emit_enum_variant_arg(0u) {||
do s.emit_enum_variant("some", 1u, 1u) || {
do s.emit_enum_variant_arg(0u) || {
st(v)
}
}
@ -254,14 +254,14 @@ fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) {
fn deserialize_option<D: deserializer,T: copy>(d: D, st: fn() -> T)
-> option<T> {
do d.read_enum("option") {||
do d.read_enum_variant {|i|
do d.read_enum("option") || {
do d.read_enum_variant |i| {
alt check i {
0u { // none
none
}
1u { // some(v)
some(d.read_enum_variant_arg(0u, {||
some(d.read_enum_variant_arg(0u, || {
st()
}))
}

View file

@ -63,7 +63,7 @@ fn sha1() -> sha1 {
fn add_input(st: sha1state, msg: ~[u8]) {
/* FIXME: Should be typestate precondition (#2345) */
assert (!st.computed);
for vec::each(msg) {|element|
for vec::each(msg) |element| {
st.msg_block[st.msg_block_idx] = element;
st.msg_block_idx += 1u;
st.len_low += 8u32;
@ -160,7 +160,7 @@ fn sha1() -> sha1 {
fn mk_result(st: sha1state) -> ~[u8] {
if !st.computed { pad_msg(st); st.computed = true; }
let mut rs: ~[u8] = ~[];
for vec::each(st.h) {|hpart|
for vec::each(st.h) |hpart| {
let a = (hpart >> 24u32 & 0xFFu32) as u8;
let b = (hpart >> 16u32 & 0xFFu32) as u8;
let c = (hpart >> 8u32 & 0xFFu32) as u8;
@ -237,7 +237,7 @@ fn sha1() -> sha1 {
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); }
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
ret s;
}
}
@ -326,7 +326,7 @@ mod tests {
// Test that it works when accepting the message all at once
let sh = sha1::sha1();
for vec::each(tests) {|t|
for vec::each(tests) |t| {
sh.input_str(t.input);
let out = sh.result();
check_vec_eq(t.output, out);
@ -335,7 +335,7 @@ mod tests {
// Test that it works when accepting the message in pieces
for vec::each(tests) {|t|
for vec::each(tests) |t| {
let len = str::len(t.input);
let mut left = len;
while left > 0u {

View file

@ -58,7 +58,7 @@ fn contains_key<T: copy>(self: smallintmap<T>, key: uint) -> bool {
impl <V: copy> of map::map<uint, V> for smallintmap<V> {
fn size() -> uint {
let mut sz = 0u;
for self.v.each {|item|
for self.v.each |item| {
alt item { some(_) { sz += 1u; } _ {} }
}
sz
@ -102,7 +102,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
}
}
fn each_value(it: fn(V) -> bool) {
self.each({|_i, v| it(v)});
self.each(|_i, v| it(v));
}
}

View file

@ -155,7 +155,7 @@ This is an unstable sort.
"]
fn quick_sort3<T: copy ord eq>(arr: ~[mut T]) {
if len::<T>(arr) == 0u { ret; }
qsort3::<T>({ |x, y| x.lt(y) }, { |x, y| x.eq(y) }, arr, 0,
qsort3::<T>(|x, y| x.lt(y), |x, y| x.eq(y), arr, 0,
(len::<T>(arr) as int) - 1);
}
@ -251,7 +251,7 @@ mod test_qsort {
let immut_names = vec::from_mut(names);
let pairs = vec::zip(expected, immut_names);
for vec::each(pairs) {|p|
for vec::each(pairs) |p| {
let (a, b) = p;
#debug("%d %d", a, b);
assert (a == b);

View file

@ -37,7 +37,7 @@ fn color_supported() -> bool {
"screen-bce", "xterm-256color"];
ret alt os::getenv("TERM") {
option::some(env) {
for vec::each(supported_terms) {|term|
for vec::each(supported_terms) |term| {
if str::eq(term, env) { ret true; }
}
false

View file

@ -162,7 +162,7 @@ fn run_tests_console(opts: test_opts,
mut ignored: 0u,
mut failures: ~[]};
run_tests(opts, tests, {|x|callback(x, st)});
run_tests(opts, tests, |x| callback(x, st));
assert (st.passed + st.failed + st.ignored == st.total);
let success = st.failed == 0u;
@ -216,9 +216,9 @@ fn run_tests_console(opts: test_opts,
fn print_failures(st: console_test_state) {
st.out.write_line("\nfailures:");
let failures = copy st.failures;
let failures = vec::map(failures, {|test| test.name});
let failures = vec::map(failures, |test| test.name);
let failures = sort::merge_sort(str::le, failures);
for vec::each(failures) {|name|
for vec::each(failures) |name| {
st.out.write_line(#fmt[" %s", name]);
}
}
@ -349,7 +349,7 @@ fn filter_tests(opts: test_opts,
} else { ret option::none; }
}
let filter = {|x|filter_fn(x, filter_str)};
let filter = |x| filter_fn(x, filter_str);
vec::filter_map(filtered, filter)
};
@ -367,7 +367,7 @@ fn filter_tests(opts: test_opts,
} else { ret option::none; }
};
vec::filter_map(filtered, {|x|filter(x)})
vec::filter_map(filtered, |x| filter(x))
};
// Sort the tests alphabetically
@ -376,7 +376,7 @@ fn filter_tests(opts: test_opts,
fn lteq(t1: test_desc, t2: test_desc) -> bool {
str::le(t1.name, t2.name)
}
sort::merge_sort({|x,y|lteq(x, y)}, filtered)
sort::merge_sort(|x,y| lteq(x, y), filtered)
};
ret filtered;
@ -390,7 +390,7 @@ fn run_test(+test: test_desc, monitor_ch: comm::chan<monitor_msg>) {
ret;
}
do task::spawn {||
do task::spawn || {
let testfn = copy test.fn;
let mut builder = task::builder();
let result_future = task::future_result(builder);
@ -529,7 +529,7 @@ mod tests {
{
let testfn = fn~() { };
let mut tests = ~[];
for vec::each(names) {|name|
for vec::each(names) |name| {
let test = {name: name, fn: copy testfn, ignore: false,
should_fail: false};
tests += ~[test];
@ -547,7 +547,7 @@ mod tests {
let pairs = vec::zip(expected, filtered);
for vec::each(pairs) {|p| let (a, b) = copy p; assert (a == b.name); }
for vec::each(pairs) |p| { let (a, b) = copy p; assert (a == b.name); }
}
}

View file

@ -142,7 +142,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
fn match_str(s: str, pos: uint, needle: str) -> bool {
let mut i = pos;
for str::each(needle) {|ch|
for str::each(needle) |ch| {
if s[i] != ch {
ret false;
}
@ -283,21 +283,21 @@ fn strptime(s: str, format: str) -> result<tm, str> {
}
'c' {
parse_type(s, pos, 'a', tm)
.chain({ |pos| parse_char(s, pos, ' ') })
.chain({ |pos| parse_type(s, pos, 'b', tm) })
.chain({ |pos| parse_char(s, pos, ' ') })
.chain({ |pos| parse_type(s, pos, 'e', tm) })
.chain({ |pos| parse_char(s, pos, ' ') })
.chain({ |pos| parse_type(s, pos, 'T', tm) })
.chain({ |pos| parse_char(s, pos, ' ') })
.chain({ |pos| parse_type(s, pos, 'Y', tm) })
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'b', tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'e', tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'T', tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'Y', tm))
}
'D' | 'x' {
parse_type(s, pos, 'm', tm)
.chain({ |pos| parse_char(s, pos, '/') })
.chain({ |pos| parse_type(s, pos, 'd', tm) })
.chain({ |pos| parse_char(s, pos, '/') })
.chain({ |pos| parse_type(s, pos, 'y', tm) })
.chain(|pos| parse_char(s, pos, '/'))
.chain(|pos| parse_type(s, pos, 'd', tm))
.chain(|pos| parse_char(s, pos, '/'))
.chain(|pos| parse_type(s, pos, 'y', tm))
}
'd' {
alt match_digits(s, pos, 2u, false) {
@ -313,10 +313,10 @@ fn strptime(s: str, format: str) -> result<tm, str> {
}
'F' {
parse_type(s, pos, 'Y', tm)
.chain({ |pos| parse_char(s, pos, '-') })
.chain({ |pos| parse_type(s, pos, 'm', tm) })
.chain({ |pos| parse_char(s, pos, '-') })
.chain({ |pos| parse_type(s, pos, 'd', tm) })
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'm', tm))
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'd', tm))
}
'H' {
// FIXME (#2350): range check.
@ -398,17 +398,17 @@ fn strptime(s: str, format: str) -> result<tm, str> {
}
'R' {
parse_type(s, pos, 'H', tm)
.chain({ |pos| parse_char(s, pos, ':') })
.chain({ |pos| parse_type(s, pos, 'M', tm) })
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'M', tm))
}
'r' {
parse_type(s, pos, 'I', tm)
.chain({ |pos| parse_char(s, pos, ':') })
.chain({ |pos| parse_type(s, pos, 'M', tm) })
.chain({ |pos| parse_char(s, pos, ':') })
.chain({ |pos| parse_type(s, pos, 'S', tm) })
.chain({ |pos| parse_char(s, pos, ' ') })
.chain({ |pos| parse_type(s, pos, 'p', tm) })
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'M', tm))
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'S', tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'p', tm))
}
'S' {
// FIXME (#2350): range check.
@ -424,10 +424,10 @@ fn strptime(s: str, format: str) -> result<tm, str> {
//'s' {}
'T' | 'X' {
parse_type(s, pos, 'H', tm)
.chain({ |pos| parse_char(s, pos, ':') })
.chain({ |pos| parse_type(s, pos, 'M', tm) })
.chain({ |pos| parse_char(s, pos, ':') })
.chain({ |pos| parse_type(s, pos, 'S', tm) })
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'M', tm))
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'S', tm))
}
't' { parse_char(s, pos, '\t') }
'u' {
@ -443,10 +443,10 @@ fn strptime(s: str, format: str) -> result<tm, str> {
}
'v' {
parse_type(s, pos, 'e', tm)
.chain({ |pos| parse_char(s, pos, '-') })
.chain({ |pos| parse_type(s, pos, 'b', tm) })
.chain({ |pos| parse_char(s, pos, '-') })
.chain({ |pos| parse_type(s, pos, 'Y', tm) })
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'b', tm))
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'Y', tm))
}
//'W' {}
'w' {
@ -526,7 +526,7 @@ fn strptime(s: str, format: str) -> result<tm, str> {
}
}
do io::with_str_reader(format) { |rdr|
do io::with_str_reader(format) |rdr| {
let tm = {
mut tm_sec: 0_i32,
mut tm_min: 0_i32,
@ -738,7 +738,7 @@ fn strftime(format: str, tm: tm) -> str {
let mut buf = "";
do io::with_str_reader(format) { |rdr|
do io::with_str_reader(format) |rdr| {
while !rdr.eof() {
alt rdr.read_char() {
'%' { buf += parse_type(rdr.read_char(), tm); }
@ -1002,7 +1002,7 @@ mod tests {
}
}
do [
[
"Sunday",
"Monday",
"Tuesday",
@ -1010,9 +1010,9 @@ mod tests {
"Thursday",
"Friday",
"Saturday"
]/_.iter { |day| assert test(day, "%A"); }
]/_.iter(|day| assert test(day, "%A"));
do [
[
"Sun",
"Mon",
"Tue",
@ -1020,9 +1020,9 @@ mod tests {
"Thu",
"Fri",
"Sat"
]/_.iter { |day| assert test(day, "%a"); }
]/_.iter(|day| assert test(day, "%a"));
do [
[
"January",
"February",
"March",
@ -1035,9 +1035,9 @@ mod tests {
"October",
"November",
"December"
]/_.iter { |day| assert test(day, "%B"); }
]/_.iter(|day| assert test(day, "%B"));
do [
[
"Jan",
"Feb",
"Mar",
@ -1050,7 +1050,7 @@ mod tests {
"Oct",
"Nov",
"Dec"
]/_.iter { |day| assert test(day, "%b"); }
]/_.iter(|day| assert test(day, "%b"));
assert test("19", "%C");
assert test("Fri Feb 13 23:31:30 2009", "%c");

View file

@ -31,7 +31,7 @@ fn delayed_send<T: copy send>(iotask: iotask,
let timer_done_ch_ptr = ptr::addr_of(timer_done_ch);
let timer = uv::ll::timer_t();
let timer_ptr = ptr::addr_of(timer);
do iotask::interact(iotask) {|loop_ptr|
do iotask::interact(iotask) |loop_ptr| {
let init_result = uv::ll::timer_init(loop_ptr, timer_ptr);
if (init_result == 0i32) {
let start_result = uv::ll::timer_start(
@ -105,11 +105,11 @@ fn recv_timeout<T: copy send>(iotask: iotask,
delayed_send(iotask, msecs, timeout_ch, ());
// FIXME: This could be written clearer (#2618)
either::either(
{|left_val|
|left_val| {
log(debug, #fmt("recv_time .. left_val %?",
left_val));
none
}, {|right_val|
}, |right_val| {
some(right_val)
}, comm::select2(timeout_po, wait_po)
)
@ -151,7 +151,7 @@ mod test {
#[test]
fn test_gl_timer_sleep_stress1() {
let hl_loop = uv::global_loop::get();
do iter::repeat(200u) {||
do iter::repeat(200u) || {
sleep(hl_loop, 1u);
}
}
@ -171,14 +171,14 @@ mod test {
};
do iter::repeat(repeat) {||
do iter::repeat(repeat) || {
for spec.each {|spec|
for spec.each |spec| {
let (times, maxms) = spec;
do task::spawn {||
do task::spawn || {
import rand::*;
let rng = rng();
do iter::repeat(times) {||
do iter::repeat(times) || {
sleep(hl_loop, rng.next() as uint % maxms);
}
comm::send(ch, ());
@ -186,7 +186,7 @@ mod test {
}
}
do iter::repeat(repeat * spec.len()) {||
do iter::repeat(repeat * spec.len()) || {
comm::recv(po)
}
}
@ -204,14 +204,14 @@ mod test {
let mut failures = 0;
let hl_loop = uv::global_loop::get();
do iter::repeat(times as uint) {||
do iter::repeat(times as uint) || {
task::yield();
let expected = rand::rng().gen_str(16u);
let test_po = comm::port::<str>();
let test_ch = comm::chan(test_po);
do task::spawn() {||
do task::spawn() || {
delayed_send(hl_loop, 1u, test_ch, expected);
};
@ -231,12 +231,12 @@ mod test {
let mut failures = 0;
let hl_loop = uv::global_loop::get();
do iter::repeat(times as uint) {||
do iter::repeat(times as uint) || {
let expected = rand::rng().gen_str(16u);
let test_po = comm::port::<str>();
let test_ch = comm::chan(test_po);
do task::spawn() {||
do task::spawn() || {
delayed_send(hl_loop, 1000u, test_ch, expected);
};

View file

@ -125,7 +125,7 @@ mod tests {
fn t(n: @mut int, &&k: int, &&_v: ()) {
assert (*n == k); *n += 1;
}
traverse(m, {|x,y|t(n, x, y)});
traverse(m, |x,y| t(n, x, y));
}
#[test]

View file

@ -40,7 +40,7 @@ fn get_monitor_task_gl() -> iotask unsafe {
#debug("ENTERING global_loop::get() loop chan: %?",
monitor_loop_chan_ptr);
let builder_fn = {||
let builder_fn = || {
let builder = task::builder();
task::set_opts(builder, {
supervise: false,
@ -57,11 +57,11 @@ fn get_monitor_task_gl() -> iotask unsafe {
type monchan = chan<iotask>;
let monitor_ch = do chan_from_global_ptr::<monchan>(monitor_loop_chan_ptr,
builder_fn) {|msg_po|
builder_fn) |msg_po| {
#debug("global monitor task starting");
// As a weak task the runtime will notify us when to exit
do weaken_task() {|weak_exit_po|
do weaken_task() |weak_exit_po| {
#debug("global monitor task is now weak");
let hl_loop = spawn_loop();
loop {
@ -87,7 +87,7 @@ fn get_monitor_task_gl() -> iotask unsafe {
// once we have a chan to the monitor loop, we ask it for
// the libuv loop's async handle
do listen { |fetch_ch|
do listen |fetch_ch| {
monitor_ch.send(fetch_ch);
fetch_ch.recv()
}
@ -95,11 +95,11 @@ fn get_monitor_task_gl() -> iotask unsafe {
fn spawn_loop() -> iotask unsafe {
let builder = task::builder();
do task::add_wrapper(builder) {|task_body|
do task::add_wrapper(builder) |task_body| {
fn~(move task_body) {
// The I/O loop task also needs to be weak so it doesn't keep
// the runtime alive
do weaken_task {|weak_exit_po|
do weaken_task |weak_exit_po| {
#debug("global libuv task is now weak %?", weak_exit_po);
task_body();
@ -129,7 +129,7 @@ mod test {
log(debug, "in simple timer cb");
ll::timer_stop(timer_ptr);
let hl_loop = get_gl();
do iotask::interact(hl_loop) {|_loop_ptr|
do iotask::interact(hl_loop) |_loop_ptr| {
log(debug, "closing timer");
ll::close(timer_ptr, simple_timer_close_cb);
log(debug, "about to deref exit_ch_ptr");
@ -146,7 +146,7 @@ mod test {
exit_ch_ptr));
let timer_handle = ll::timer_t();
let timer_ptr = ptr::addr_of(timer_handle);
do iotask::interact(iotask) {|loop_ptr|
do iotask::interact(iotask) |loop_ptr| {
log(debug, "user code inside interact loop!!!");
let init_status = ll::timer_init(loop_ptr, timer_ptr);
if(init_status == 0i32) {
@ -174,7 +174,7 @@ mod test {
let hl_loop = get_gl();
let exit_po = comm::port::<()>();
let exit_ch = comm::chan(exit_po);
task::spawn_sched(task::manual_threads(1u), {||
task::spawn_sched(task::manual_threads(1u), || {
impl_uv_hl_simple_timer(hl_loop);
comm::send(exit_ch, ());
});
@ -191,13 +191,13 @@ mod test {
let exit_po = comm::port::<()>();
let exit_ch = comm::chan(exit_po);
let cycles = 5000u;
do iter::repeat(cycles) {||
task::spawn_sched(task::manual_threads(1u), {||
do iter::repeat(cycles) || {
task::spawn_sched(task::manual_threads(1u), || {
impl_uv_hl_simple_timer(hl_loop);
comm::send(exit_ch, ());
});
};
do iter::repeat(cycles) {||
do iter::repeat(cycles) || {
comm::recv(exit_po);
};
log(debug, "test_stress_gl_uv_global_loop_high_level_global_timer"+

View file

@ -39,9 +39,9 @@ fn spawn_iotask(-builder: task::builder) -> iotask {
with get_opts(builder)
});
do listen {|iotask_ch|
do listen |iotask_ch| {
do run(copy(builder)) {||
do run(copy(builder)) || {
#debug("entering libuv task");
run_loop(iotask_ch);
#debug("libuv task exiting");
@ -211,7 +211,7 @@ mod test {
exit_ch: exit_ch
};
let ah_data_ptr = ptr::addr_of(ah_data);
do interact(iotask) {|loop_ptr|
do interact(iotask) |loop_ptr| {
ll::async_init(loop_ptr, ah_ptr, async_handle_cb);
ll::set_data_for_uv_handle(ah_ptr, ah_data_ptr as *libc::c_void);
ll::async_send(ah_ptr);
@ -224,7 +224,7 @@ mod test {
unsafe fn spawn_test_loop(exit_ch: comm::chan<()>) -> iotask {
let iotask_port = comm::port::<iotask>();
let iotask_ch = comm::chan(iotask_port);
do task::spawn_sched(task::manual_threads(1u)) {||
do task::spawn_sched(task::manual_threads(1u)) || {
run_loop(iotask_ch);
exit_ch.send(());
};
@ -255,13 +255,13 @@ mod test {
// called, at least.
let work_exit_po = comm::port::<()>();
let work_exit_ch = comm::chan(work_exit_po);
do iter::repeat(7u) {||
do task::spawn_sched(task::manual_threads(1u)) {||
do iter::repeat(7u) || {
do task::spawn_sched(task::manual_threads(1u)) || {
impl_uv_iotask_async(iotask);
comm::send(work_exit_ch, ());
};
};
do iter::repeat(7u) {||
do iter::repeat(7u) || {
comm::recv(work_exit_po);
};
log(debug, "sending teardown_loop msg..");

View file

@ -1262,7 +1262,7 @@ mod test {
let continue_chan = comm::chan::<bool>(continue_port);
let continue_chan_ptr = ptr::addr_of(continue_chan);
do task::spawn_sched(task::manual_threads(1u)) {||
do task::spawn_sched(task::manual_threads(1u)) || {
impl_uv_tcp_server(bind_ip, port,
kill_server_msg,
server_resp_msg,
@ -1275,7 +1275,7 @@ mod test {
comm::recv(continue_port);
log(debug, "received on continue port, set up tcp client");
do task::spawn_sched(task::manual_threads(1u)) {||
do task::spawn_sched(task::manual_threads(1u)) || {
impl_uv_tcp_request(request_ip, port,
kill_server_msg,
ptr::addr_of(client_chan));

View file

@ -11,7 +11,7 @@ type path = ~[path_elt];
/* FIXMEs that say "bad" are as per #2543 */
fn path_to_str_with_sep(p: path, sep: str) -> str {
let strs = do vec::map(p) {|e|
let strs = do vec::map(p) |e| {
alt e {
path_mod(s) { /* FIXME (#2543) */ copy *s }
path_name(s) { /* FIXME (#2543) */ copy *s }
@ -119,7 +119,7 @@ fn map_decoded_item(diag: span_handler,
fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
sp: codemap::span, id: node_id, cx: ctx, v: vt) {
for decl.inputs.each {|a|
for decl.inputs.each |a| {
cx.map.insert(a.id,
node_arg(/* FIXME (#2543) */
copy a, cx.local_id));
@ -156,7 +156,7 @@ fn map_block(b: blk, cx: ctx, v: vt) {
}
fn number_pat(cx: ctx, pat: @pat) {
do ast_util::walk_pat(pat) {|p|
do ast_util::walk_pat(pat) |p| {
alt p.node {
pat_ident(_, _) {
cx.map.insert(p.id, node_local(cx.local_id));
@ -190,13 +190,13 @@ fn map_item(i: @item, cx: ctx, v: vt) {
alt i.node {
item_impl(_, _, _, _, ms) {
let impl_did = ast_util::local_def(i.id);
for ms.each {|m|
for ms.each |m| {
map_method(impl_did, extend(cx, i.ident), m,
cx);
}
}
item_enum(vs, _, _) {
for vs.each {|v|
for vs.each |v| {
cx.map.insert(v.node.id, node_variant(
/* FIXME (#2543) */ copy v, i,
extend(cx, i.ident)));
@ -207,7 +207,7 @@ fn map_item(i: @item, cx: ctx, v: vt) {
either::left(msg) { cx.diag.span_fatal(i.span, msg); }
either::right(abi) { abi }
};
for nm.items.each {|nitem|
for nm.items.each |nitem| {
cx.map.insert(nitem.id,
node_foreign_item(nitem, abi,
/* FIXME (#2543) */
@ -218,12 +218,12 @@ fn map_item(i: @item, cx: ctx, v: vt) {
let (_, ms) = ast_util::split_class_items(items);
// Map iface refs to their parent classes. This is
// so we can find the self_ty
do vec::iter(ifces) {|p| cx.map.insert(p.id,
do vec::iter(ifces) |p| { cx.map.insert(p.id,
node_item(i, item_path)); };
let d_id = ast_util::local_def(i.id);
let p = extend(cx, i.ident);
// only need to handle methods
do vec::iter(ms) {|m| map_method(d_id, p, m, cx); }
do vec::iter(ms) |m| { map_method(d_id, p, m, cx); }
}
_ { }
}
@ -240,7 +240,7 @@ fn map_item(i: @item, cx: ctx, v: vt) {
fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {
alt vi.node {
view_item_export(vps) {
for vps.each {|vp|
for vps.each |vp| {
let (id, name) = alt vp.node {
view_path_simple(nm, _, id) {
(id, /* FIXME (#2543) */ copy nm)

View file

@ -25,7 +25,7 @@ pure fn path_name(p: @path) -> str { path_name_i(p.idents) }
pure fn path_name_i(idents: ~[ident]) -> str {
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
str::connect(idents.map({|i|*i}), "::")
str::connect(idents.map(|i|*i), "::")
}
pure fn path_to_ident(p: @path) -> ident { vec::last(p.idents) }
@ -152,11 +152,11 @@ pure fn float_ty_to_str(t: float_ty) -> str {
fn is_exported(i: ident, m: _mod) -> bool {
let mut local = false;
let mut parent_enum : option<ident> = none;
for m.items.each {|it|
for m.items.each |it| {
if it.ident == i { local = true; }
alt it.node {
item_enum(variants, _, _) {
for variants.each {|v|
for variants.each |v| {
if v.node.name == i {
local = true;
parent_enum = some(/* FIXME (#2543) */ copy it.ident);
@ -168,11 +168,11 @@ fn is_exported(i: ident, m: _mod) -> bool {
if local { break; }
}
let mut has_explicit_exports = false;
for m.view_items.each {|vi|
for m.view_items.each |vi| {
alt vi.node {
view_item_export(vps) {
has_explicit_exports = true;
for vps.each {|vp|
for vps.each |vp| {
alt vp.node {
ast::view_path_simple(id, _, _) {
if id == i { ret true; }
@ -187,7 +187,7 @@ 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; }
for ids.each {|id|
for ids.each |id| {
if id.node.name == i { ret true; }
}
} else {
@ -288,14 +288,16 @@ type ivar = {ident: ident, ty: @ty, cm: class_mutability,
id: node_id, vis: visibility};
fn public_methods(ms: ~[@method]) -> ~[@method] {
vec::filter(ms, {|m| alt m.vis {
vec::filter(ms,
|m| alt m.vis {
public { true }
_ { false }}})
_ { false }
})
}
fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) {
let mut vs = ~[], ms = ~[];
for cs.each {|c|
for cs.each |c| {
alt c.node {
instance_var(i, t, cm, id, vis) {
vec::push(vs, {ident: /* FIXME (#2543) */ copy i,
@ -408,7 +410,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
alt vi.node {
view_item_use(_, _, id) { vfn(id) }
view_item_import(vps) | view_item_export(vps) {
do vec::iter(vps) {|vp|
do vec::iter(vps) |vp| {
alt vp.node {
view_path_simple(_, _, id) { vfn(id) }
view_path_glob(_, id) { vfn(id) }
@ -426,7 +428,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
visit_item: fn@(i: @item) {
vfn(i.id);
alt i.node {
item_enum(vs, _, _) { for vs.each {|v| vfn(v.node.id); } }
item_enum(vs, _, _) { for vs.each |v| { vfn(v.node.id); } }
_ {}
}
},
@ -473,7 +475,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
},
visit_ty_params: fn@(ps: ~[ty_param]) {
vec::iter(ps, {|p| vfn(p.id) })
vec::iter(ps, |p| vfn(p.id))
},
visit_constr: fn@(_p: @path, _sp: span, id: node_id) {
@ -486,33 +488,33 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
alt fk {
visit::fk_ctor(nm, tps, self_id, parent_id) {
vec::iter(tps, {|tp| vfn(tp.id)});
vec::iter(tps, |tp| vfn(tp.id));
vfn(id);
vfn(self_id);
vfn(parent_id.node);
}
visit::fk_dtor(tps, self_id, parent_id) {
vec::iter(tps, {|tp| vfn(tp.id)});
vec::iter(tps, |tp| vfn(tp.id));
vfn(id);
vfn(self_id);
vfn(parent_id.node);
}
visit::fk_item_fn(_, tps) {
vec::iter(tps, {|tp| vfn(tp.id)});
vec::iter(tps, |tp| vfn(tp.id));
}
visit::fk_method(_, tps, m) {
vfn(m.self_id);
vec::iter(tps, {|tp| vfn(tp.id)});
vec::iter(tps, |tp| vfn(tp.id));
}
visit::fk_anon(_, capture_clause)
| visit::fk_fn_block(capture_clause) {
for vec::each(*capture_clause) {|clause|
for vec::each(*capture_clause) |clause| {
vfn(clause.id);
}
}
}
do vec::iter(d.inputs) {|arg|
do vec::iter(d.inputs) |arg| {
vfn(arg.id)
}
},
@ -536,7 +538,7 @@ fn visit_ids_for_inlined_item(item: inlined_item, vfn: fn@(node_id)) {
fn compute_id_range(visit_ids_fn: fn(fn@(node_id))) -> id_range {
let min = @mut int::max_value;
let max = @mut int::min_value;
do visit_ids_fn { |id|
do visit_ids_fn |id| {
*min = int::min(*min, id);
*max = int::max(*max, id + 1);
}
@ -544,7 +546,7 @@ fn compute_id_range(visit_ids_fn: fn(fn@(node_id))) -> id_range {
}
fn compute_id_range_for_inlined_item(item: inlined_item) -> id_range {
compute_id_range({ |f| visit_ids_for_inlined_item(item, f) })
compute_id_range(|f| visit_ids_for_inlined_item(item, f))
}
pure fn is_item_impl(item: @ast::item) -> bool {
@ -558,8 +560,12 @@ fn walk_pat(pat: @pat, it: fn(@pat)) {
it(pat);
alt pat.node {
pat_ident(pth, some(p)) { walk_pat(p, it); }
pat_rec(fields, _) { for fields.each {|f| walk_pat(f.pat, it); } }
pat_enum(_, some(s)) | pat_tup(s) { for s.each {|p| walk_pat(p, it); } }
pat_rec(fields, _) {
for fields.each |f| { walk_pat(f.pat, it); }
}
pat_enum(_, some(s)) | pat_tup(s) {
for s.each |p| { walk_pat(p, it); }
}
pat_box(s) | pat_uniq(s) { walk_pat(s, it); }
pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _)
| pat_enum(_, _) {}

View file

@ -77,7 +77,7 @@ fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value }
// Get the meta_items from inside a vector of attributes
fn attr_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
let mut mitems = ~[];
for attrs.each {|a| vec::push(mitems, attr_meta(a)); }
for attrs.each |a| { vec::push(mitems, attr_meta(a)); }
ret mitems;
}
@ -179,7 +179,7 @@ comparison is performed structurally.
fn contains(haystack: ~[@ast::meta_item], needle: @ast::meta_item) -> bool {
#debug("looking for %s",
print::pprust::meta_item_to_str(*needle));
for haystack.each {|item|
for haystack.each |item| {
#debug("looking in %s",
print::pprust::meta_item_to_str(*item));
if eq(item, needle) { #debug("found it!"); ret true; }
@ -289,8 +289,7 @@ fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ast::ident) ->
~[@ast::meta_item] {
ret vec::filter_map(items, {
|item|
ret vec::filter_map(items, |item| {
if get_meta_item_name(item) != name {
option::some(/* FIXME (#2543) */ copy item)
} else {
@ -301,7 +300,7 @@ fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: ast::ident) ->
fn find_linkage_attrs(attrs: ~[ast::attribute]) -> ~[ast::attribute] {
let mut found = ~[];
for find_attrs_by_name(attrs, "link").each {|attr|
for find_attrs_by_name(attrs, "link").each |attr| {
alt attr.node.value.node {
ast::meta_list(_, _) { vec::push(found, attr) }
_ { #debug("ignoring link attribute that has incorrect type"); }
@ -315,7 +314,7 @@ From a list of crate attributes get only the meta_items that impact crate
linkage
"]
fn find_linkage_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
do find_linkage_attrs(attrs).flat_map {|attr|
do find_linkage_attrs(attrs).flat_map |attr| {
alt check attr.node.value.node {
ast::meta_list(_, items) { /* FIXME (#2543) */ copy items }
}
@ -351,7 +350,7 @@ enum inline_attr {
#[doc = "True if something like #[inline] is found in the list of attrs."]
fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr {
// TODO---validate the usage of #[inline] and #[inline(always)]
do vec::foldl(ia_none, attrs) {|ia,attr|
do vec::foldl(ia_none, attrs) |ia,attr| {
alt attr.node.value.node {
ast::meta_word(@"inline") { ia_hint }
ast::meta_list(@"inline", items) {
@ -370,7 +369,7 @@ fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr {
fn require_unique_names(diagnostic: span_handler,
metas: ~[@ast::meta_item]) {
let map = map::str_hash();
for metas.each {|meta|
for metas.each |meta| {
let name = get_meta_item_name(meta);
// FIXME: How do I silence the warnings? --pcw (#2619)

View file

@ -185,7 +185,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
let lo = lookup_char_pos(cm, sp.lo);
let hi = lookup_char_pos(cm, sp.hi);
let mut lines = ~[];
for uint::range(lo.line - 1u, hi.line as uint) {|i|
for uint::range(lo.line - 1u, hi.line as uint) |i| {
vec::push(lines, i);
};
ret @{file: lo.file, lines: lines};
@ -224,7 +224,7 @@ fn get_snippet(cm: codemap::codemap, fidx: uint, lo: uint, hi: uint) -> str
}
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 { ret 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

@ -207,7 +207,7 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
elided = true;
}
// Print the offending lines
for display_lines.each {|line|
for display_lines.each |line| {
io::stderr().write_str(#fmt["%s:%u ", fm.name, line + 1u]);
let s = codemap::get_line(fm, line as int) + "\n";
io::stderr().write_str(s);
@ -249,11 +249,9 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
}
fn print_macro_backtrace(cm: codemap::codemap, sp: span) {
do option::iter (sp.expn_info) {|ei|
let ss = option::map_default(ei.callie.span, @"", {
|span|
@codemap::span_to_str(span, cm)
});
do option::iter (sp.expn_info) |ei| {
let ss = option::map_default(ei.callie.span, @"",
|span| @codemap::span_to_str(span, cm));
print_diagnostic(*ss, note,
#fmt("in expansion of #%s", ei.callie.name));
let ss = codemap::span_to_str(ei.call_site, cm);

View file

@ -100,7 +100,7 @@ fn expand(cx: ext_ctxt,
with *item}
}
do vec::flat_map(in_items) {|in_item|
do vec::flat_map(in_items) |in_item| {
alt in_item.node {
ast::item_ty(ty, tps, _) {
vec::append(~[filter_attrs(in_item)],
@ -151,7 +151,7 @@ impl helpers for ext_ctxt {
fn ty_fn(span: span,
-input_tys: ~[@ast::ty],
-output: @ast::ty) -> @ast::ty {
let args = do vec::map(input_tys) {|ty|
let args = do vec::map(input_tys) |ty| {
{mode: ast::expl(ast::by_ref),
ty: ty,
ident: @"",
@ -237,12 +237,12 @@ impl helpers for ext_ctxt {
fn lambda(blk: ast::blk) -> @ast::expr {
let ext_cx = self;
let blk_e = self.expr(blk.span, ast::expr_block(blk));
#ast{ {|| $(blk_e) } }
#ast{ || $(blk_e) }
}
fn clone_folder() -> fold::ast_fold {
fold::make_fold(@{
new_id: {|_id| self.next_id()}
new_id: |_id| self.next_id()
with *fold::default_ast_fold()
})
}
@ -272,7 +272,7 @@ impl helpers for ext_ctxt {
}
let fld = fold::make_fold(@{
new_span: {|a|repl_sp(a, ast_util::dummy_sp(), span)}
new_span: |a| repl_sp(a, ast_util::dummy_sp(), span)
with *fold::default_ast_fold()
});
@ -294,11 +294,11 @@ fn ser_path(cx: ext_ctxt, tps: ser_tps_map, path: @ast::path,
ast::expr_path(
cx.helper_path(path, "serialize")));
let ty_args = do vec::map(path.types) {|ty|
let ty_args = do vec::map(path.types) |ty| {
let sv_stmts = ser_ty(cx, tps, ty, cx.clone(s), #ast{ __v });
let sv = cx.expr(path.span,
ast::expr_block(cx.blk(path.span, sv_stmts)));
cx.at(ty.span, #ast{ {|__v| $(sv)} })
cx.at(ty.span, #ast{ |__v| $(sv) })
};
~[cx.stmt(
@ -316,14 +316,14 @@ fn ser_variant(cx: ext_ctxt,
bodyfn: fn(-@ast::expr, ast::blk) -> @ast::expr,
argfn: fn(-@ast::expr, uint, ast::blk) -> @ast::expr)
-> ast::arm {
let vnames = do vec::from_fn(vec::len(tys)) {|i|
let vnames = do vec::from_fn(vec::len(tys)) |i| {
@#fmt["__v%u", i]
};
let pats = do vec::from_fn(vec::len(tys)) {|i|
let pats = do vec::from_fn(vec::len(tys)) |i| {
cx.binder_pat(tys[i].span, vnames[i])
};
let pat: @ast::pat = @{id: cx.next_id(), node: pfn(pats), span: span};
let stmts = do vec::from_fn(vec::len(tys)) {|i|
let stmts = do vec::from_fn(vec::len(tys)) |i| {
let v = cx.var_ref(span, vnames[i]);
let arg_blk =
cx.blk(
@ -376,7 +376,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
}
ast::ty_rec(flds) {
let fld_stmts = do vec::from_fn(vec::len(flds)) {|fidx|
let fld_stmts = do vec::from_fn(vec::len(flds)) |fidx| {
let fld = flds[fidx];
let vf = cx.expr(fld.span,
ast::expr_field(cx.clone(v),
@ -412,17 +412,17 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
cx, tps, tys, ty.span, s,
// Generate pattern (v1, v2, v3)
{|pats| ast::pat_tup(pats)},
|pats| ast::pat_tup(pats),
// Generate body s.emit_tup(3, {|| blk })
{|-s, blk|
|-s, blk| {
let sz = cx.lit_uint(ty.span, vec::len(tys));
let body = cx.lambda(blk);
#ast{ $(s).emit_tup($(sz), $(body)) }
},
// Generate s.emit_tup_elt(i, {|| blk })
{|-s, i, blk|
|-s, i, blk| {
let idx = cx.lit_uint(ty.span, i);
let body = cx.lambda(blk);
#ast{ $(s).emit_tup_elt($(idx), $(body)) }
@ -473,7 +473,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
cx.at(ty.span, #ast{ __e })))));
~[#ast(stmt){
std::serialization::emit_from_vec($(s), $(v), {|__e| $(ser_e) })
std::serialization::emit_from_vec($(s), $(v), |__e| $(ser_e))
}]
}
@ -491,17 +491,17 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
-> @ast::item {
let ext_cx = cx; // required for #ast
let tp_types = vec::map(tps, {|tp| cx.ty_path(span, ~[tp.ident], ~[])});
let tp_types = vec::map(tps, |tp| cx.ty_path(span, ~[tp.ident], ~[]));
let v_ty = cx.ty_path(span, ~[name], tp_types);
let tp_inputs =
vec::map(tps, {|tp|
vec::map(tps, |tp|
{mode: ast::expl(ast::by_ref),
ty: cx.ty_fn(span,
~[cx.ty_path(span, ~[tp.ident], ~[])],
cx.ty_nil(span)),
ident: @("__s" + *tp.ident),
id: cx.next_id()}});
id: cx.next_id()});
#debug["tp_inputs = %?", tp_inputs];
@ -518,7 +518,7 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
tp_inputs);
let tps_map = map::str_hash();
do vec::iter2(tps, tp_inputs) {|tp, arg|
do vec::iter2(tps, tp_inputs) |tp, arg| {
let arg_ident = arg.ident;
tps_map.insert(
*tp.ident,
@ -539,7 +539,7 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
vec::append(~[{ident: @"__S",
id: cx.next_id(),
bounds: ser_bnds}],
vec::map(tps, {|tp| cx.clone_ty_param(tp) }));
vec::map(tps, |tp| cx.clone_ty_param(tp)));
let ser_output: @ast::ty = @{id: cx.next_id(),
node: ast::ty_nil,
@ -575,7 +575,7 @@ fn deser_path(cx: ext_ctxt, tps: deser_tps_map, path: @ast::path,
ast::expr_path(
cx.helper_path(path, "deserialize")));
let ty_args = do vec::map(path.types) {|ty|
let ty_args = do vec::map(path.types) |ty| {
let dv_expr = deser_ty(cx, tps, ty, cx.clone(d));
cx.lambda(cx.expr_blk(dv_expr))
};
@ -618,7 +618,7 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
}
ast::ty_rec(flds) {
let fields = do vec::from_fn(vec::len(flds)) {|fidx|
let fields = do vec::from_fn(vec::len(flds)) |fidx| {
let fld = flds[fidx];
let d = cx.clone(d);
let f = cx.lit_str(fld.span, fld.node.ident);
@ -647,7 +647,7 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
// d.read_tup_elt(2u, {||...}))
// }
let arg_exprs = do vec::from_fn(vec::len(tys)) {|i|
let arg_exprs = do vec::from_fn(vec::len(tys)) |i| {
let idx = cx.lit_uint(ty.span, i);
let body = deser_lambda(cx, tps, tys[i], cx.clone(d));
#ast{ $(d).read_tup_elt($(idx), $(body)) }
@ -703,17 +703,17 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
-> @ast::item {
let ext_cx = cx; // required for #ast
let tp_types = vec::map(tps, {|tp| cx.ty_path(span, ~[tp.ident], ~[])});
let tp_types = vec::map(tps, |tp| cx.ty_path(span, ~[tp.ident], ~[]));
let v_ty = cx.ty_path(span, ~[name], tp_types);
let tp_inputs =
vec::map(tps, {|tp|
vec::map(tps, |tp|
{mode: ast::expl(ast::by_ref),
ty: cx.ty_fn(span,
~[],
cx.ty_path(span, ~[tp.ident], ~[])),
ident: @("__d" + *tp.ident),
id: cx.next_id()}});
id: cx.next_id()});
#debug["tp_inputs = %?", tp_inputs];
@ -725,7 +725,7 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
tp_inputs);
let tps_map = map::str_hash();
do vec::iter2(tps, tp_inputs) {|tp, arg|
do vec::iter2(tps, tp_inputs) |tp, arg| {
let arg_ident = arg.ident;
tps_map.insert(
*tp.ident,
@ -745,7 +745,7 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
vec::append(~[{ident: @"__D",
id: cx.next_id(),
bounds: deser_bnds}],
vec::map(tps, {|tp|
vec::map(tps, |tp| {
let cloned = cx.clone_ty_param(tp);
{bounds: @(vec::append(*cloned.bounds,
~[ast::bound_copy]))
@ -774,8 +774,8 @@ fn ty_fns(cx: ext_ctxt, name: ast::ident,
let span = ty.span;
~[
mk_ser_fn(cx, span, name, tps, {|a,b,c,d|ser_ty(a, b, ty, c, d)}),
mk_deser_fn(cx, span, name, tps, {|a,b,c|deser_ty(a, b, ty, c)})
mk_ser_fn(cx, span, name, tps, |a,b,c,d| ser_ty(a, b, ty, c, d)),
mk_deser_fn(cx, span, name, tps, |a,b,c| deser_ty(a, b, ty, c))
]
}
@ -783,17 +783,17 @@ fn ser_enum(cx: ext_ctxt, tps: ser_tps_map, e_name: ast::ident,
e_span: span, variants: ~[ast::variant],
-s: @ast::expr, -v: @ast::expr) -> ~[@ast::stmt] {
let ext_cx = cx;
let arms = do vec::from_fn(vec::len(variants)) {|vidx|
let arms = do vec::from_fn(vec::len(variants)) |vidx| {
let variant = variants[vidx];
let v_span = variant.span;
let v_name = variant.node.name;
let variant_tys = vec::map(variant.node.args, {|a| a.ty });
let variant_tys = vec::map(variant.node.args, |a| a.ty);
ser_variant(
cx, tps, variant_tys, v_span, cx.clone(s),
// Generate pattern var(v1, v2, v3)
{|pats|
|pats| {
if vec::is_empty(pats) {
ast::pat_ident(cx.path(v_span, ~[v_name]), none)
} else {
@ -803,7 +803,7 @@ fn ser_enum(cx: ext_ctxt, tps: ser_tps_map, e_name: ast::ident,
// Generate body s.emit_enum_variant("foo", 0u,
// 3u, {|| blk })
{|-s, blk|
|-s, blk| {
let v_name = cx.lit_str(v_span, v_name);
let v_id = cx.lit_uint(v_span, vidx);
let sz = cx.lit_uint(v_span, vec::len(variant_tys));
@ -815,7 +815,7 @@ fn ser_enum(cx: ext_ctxt, tps: ser_tps_map, e_name: ast::ident,
},
// Generate s.emit_enum_variant_arg(i, {|| blk })
{|-s, i, blk|
|-s, i, blk| {
let idx = cx.lit_uint(v_span, i);
let body = cx.lambda(blk);
#ast[expr]{
@ -832,13 +832,13 @@ fn deser_enum(cx: ext_ctxt, tps: deser_tps_map, e_name: ast::ident,
e_span: span, variants: ~[ast::variant],
-d: @ast::expr) -> @ast::expr {
let ext_cx = cx;
let arms: ~[ast::arm] = do vec::from_fn(vec::len(variants)) {|vidx|
let arms: ~[ast::arm] = do vec::from_fn(vec::len(variants)) |vidx| {
let variant = variants[vidx];
let v_span = variant.span;
let v_name = variant.node.name;
let tys = vec::map(variant.node.args, {|a| a.ty });
let tys = vec::map(variant.node.args, |a| a.ty);
let arg_exprs = do vec::from_fn(vec::len(tys)) {|i|
let arg_exprs = do vec::from_fn(vec::len(tys)) |i| {
let idx = cx.lit_uint(v_span, i);
let body = deser_lambda(cx, tps, tys[i], cx.clone(d));
#ast{ $(d).read_enum_variant_arg($(idx), $(body)) }
@ -866,7 +866,7 @@ fn deser_enum(cx: ext_ctxt, tps: deser_tps_map, e_name: ast::ident,
let e_name = cx.lit_str(e_span, e_name);
let alt_expr = cx.expr(e_span,
ast::expr_alt(#ast{__i}, arms, ast::alt_check));
let var_lambda = #ast{ {|__i| $(alt_expr)} };
let var_lambda = #ast{ |__i| $(alt_expr) };
let read_var = #ast{ $(cx.clone(d)).read_enum_variant($(var_lambda)) };
let read_lambda = cx.lambda(cx.expr_blk(read_var));
#ast{ $(d).read_enum($(e_name), $(read_lambda)) }
@ -877,8 +877,8 @@ fn enum_fns(cx: ext_ctxt, e_name: ast::ident, e_span: span,
-> ~[@ast::item] {
~[
mk_ser_fn(cx, e_span, e_name, tps,
{|a,b,c,d|ser_enum(a, b, e_name, e_span, variants, c, d)}),
|a,b,c,d| ser_enum(a, b, e_name, e_span, variants, c, d)),
mk_deser_fn(cx, e_span, e_name, tps,
{|a,b,c|deser_enum(a, b, e_name, e_span, variants, c)})
|a,b,c| deser_enum(a, b, e_name, e_span, variants, c))
]
}

View file

@ -81,7 +81,7 @@ fn mk_rec_e(cx: ext_ctxt, sp: span,
fields: ~[{ident: ast::ident, ex: @ast::expr}]) ->
@ast::expr {
let mut astfields: ~[ast::field] = ~[];
for fields.each {|field|
for fields.each |field| {
let ident = field.ident;
let val = field.ex;
let astfield =

View file

@ -4,7 +4,7 @@ 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_no_max(cx,sp,arg,1u,"concat_idents");
let mut res = "";
for args.each {|e|
for args.each |e| {
res += *expr_to_ident(cx, e, "expected an ident");
}

View file

@ -47,7 +47,7 @@ fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos {
}
fn count_names(ms: &[matcher]) -> uint {
vec::foldl(0u, ms, {|ct, m|
vec::foldl(0u, ms, |ct, m| {
ct + alt m.node {
mtc_tok(_) { 0u }
mtc_rep(more_ms, _, _) { count_names(more_ms) }
@ -57,7 +57,7 @@ fn count_names(ms: &[matcher]) -> uint {
fn new_matcher_pos(ms: ~[matcher], sep: option<token>) -> matcher_pos {
~{elts: ms, sep: sep, mut idx: 0u, mut up: matcher_pos_up(none),
matches: copy vec::from_fn(count_names(ms), {|_i| dvec::dvec()}) }
matches: copy vec::from_fn(count_names(ms), |_i| dvec::dvec()) }
}
/* logically, an arb_depth should contain only one kind of nonterminal */
@ -106,7 +106,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
// I bet this is a perf problem: we're preemptively
// doing a lot of array work that will get thrown away
// most of the time.
for ei.matches.eachi() { |idx, elt|
for ei.matches.eachi() |idx, elt| {
new_pos.matches[idx].push(@seq(elt.get()));
}
@ -145,7 +145,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
}
let matches = vec::map(ei.matches, // fresh, same size:
{|_m| dvec::<@arb_depth>()});
|_m| dvec::<@arb_depth>());
let ei_t <- ei;
vec::push(cur_eis, ~{
elts: matchers, sep: sep, mut idx: 0u,
@ -165,7 +165,7 @@ 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 {
let ret_val = vec::map(eof_eis[0u].matches, {|dv| dv.pop()});
let ret_val = vec::map(eof_eis[0u].matches, |dv| dv.pop());
ret ret_val; /* success */
} else if eof_eis.len() > 1u {
rdr.fatal("Ambiguity: multiple successful parses");
@ -175,7 +175,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
} else {
if (bb_eis.len() > 0u && next_eis.len() > 0u)
|| bb_eis.len() > 1u {
let nts = str::connect(vec::map(bb_eis, {|ei|
let nts = str::connect(vec::map(bb_eis, |ei| {
alt ei.elts[ei.idx].node
{ mtc_bb(_,name,_) { *name } _ { fail; } }
}), " or ");

View file

@ -100,8 +100,8 @@ fn expand_mod_items(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
// For each item, look through the attributes. If any of them are
// decorated with "item decorators", then use that function to transform
// the item into a new set of items.
let new_items = do vec::flat_map(module.items) {|item|
do vec::foldr(item.attrs, ~[item]) {|attr, items|
let new_items = do vec::flat_map(module.items) |item| {
do vec::foldr(item.attrs, ~[item]) |attr, items| {
let mname = alt attr.node.value.node {
ast::meta_word(n) { n }
ast::meta_name_value(n, _) { n }
@ -164,10 +164,10 @@ fn expand_crate(parse_sess: parse::parse_sess,
let afp = default_ast_fold();
let cx: ext_ctxt = mk_ctxt(parse_sess, cfg);
let f_pre =
@{fold_expr: {|a,b,c|expand_expr(exts, cx, a, b, c, afp.fold_expr)},
fold_mod: {|a,b|expand_mod_items(exts, cx, a, b, afp.fold_mod)},
fold_item: {|a,b|expand_item(cx, a, b, afp.fold_item)},
new_span: {|a|new_span(cx, a)}
@{fold_expr: |a,b,c| expand_expr(exts, cx, a, b, c, afp.fold_expr),
fold_mod: |a,b| expand_mod_items(exts, cx, a, b, afp.fold_mod),
fold_item: |a,b| expand_item(cx, a, b, afp.fold_item),
new_span: |a|new_span(cx, a)
with *afp};
let f = make_fold(f_pre);
let cm = parse_expr_from_source_str("<core-macros>",

View file

@ -51,7 +51,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
fn make_rt_conv_expr(cx: ext_ctxt, sp: span, cnv: conv) -> @ast::expr {
fn make_flags(cx: ext_ctxt, sp: span, flags: ~[flag]) -> @ast::expr {
let mut tmp_expr = make_rt_path_expr(cx, sp, @"flag_none");
for flags.each {|f|
for flags.each |f| {
let fstr = alt f {
flag_left_justify { "flag_left_justify" }
flag_left_zero_pad { "flag_left_zero_pad" }
@ -136,7 +136,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
option::none { }
_ { cx.span_unimpl(sp, unsupported); }
}
for cnv.flags.each {|f|
for cnv.flags.each |f| {
alt f {
flag_left_justify { }
flag_sign_always {
@ -191,7 +191,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
some(p) { log(debug, "param: " + int::to_str(p, 10u)); }
_ { #debug("param: none"); }
}
for c.flags.each {|f|
for c.flags.each |f| {
alt f {
flag_left_justify { #debug("flag: left justify"); }
flag_left_zero_pad { #debug("flag: left zero pad"); }
@ -246,7 +246,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
let mut n = 0u;
let mut piece_exprs = ~[];
let nargs = args.len();
for pieces.each {|pc|
for pieces.each |pc| {
alt pc {
piece_string(s) {
vec::push(piece_exprs, mk_str(cx, fmt_sp, s));

View file

@ -7,7 +7,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
cx.print_backtrace();
io::stdout().write_line(
str::connect(vec::map(args,
{|&&ex| print::pprust::expr_to_str(ex)}), ", ")
|&&ex| print::pprust::expr_to_str(ex)), ", ")
);
//trivial expression

View file

@ -97,17 +97,15 @@ impl of qq_helper for @ast::pat {
fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
{
let v = @{visit_expr: {|node, &&cx, v|
visit_aq(node, "from_expr", cx, v)},
visit_ty: {|node, &&cx, v|
visit_aq(node, "from_ty", cx, v)}
let v = @{visit_expr: |node, &&cx, v| visit_aq(node, "from_expr", cx, v),
visit_ty: |node, &&cx, v| visit_aq(node, "from_ty", cx, v)
with *default_visitor()};
let cx = @{lo:lo, gather: dvec()};
node.visit(cx, mk_vt(v));
// FIXME (#2250): Maybe this is an overkill (merge_sort), it might
// be better to just keep the gather array in sorted order.
do cx.gather.swap { |v|
vec::to_mut(std::sort::merge_sort({|a,b| a.lo < b.lo}, v))
do cx.gather.swap |v| {
vec::to_mut(std::sort::merge_sort(|a,b| a.lo < b.lo, v))
};
ret cx;
}
@ -132,7 +130,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span,
-> @ast::expr
{
let mut what = "expr";
do option::iter(arg) {|arg|
do option::iter(arg) |arg| {
let args: ~[@ast::expr] =
alt arg.node {
ast::expr_vec(elts, _) { elts }
@ -193,7 +191,7 @@ fn finish<T: qq_helper>
let qcx = gather_anti_quotes(sp.lo, node);
let cx = qcx;
for uint::range(1u, cx.gather.len()) {|i|
for uint::range(1u, cx.gather.len()) |i| {
assert cx.gather[i-1u].lo < cx.gather[i].lo;
// ^^ check that the vector is sorted
assert cx.gather[i-1u].hi <= cx.gather[i].lo;
@ -205,7 +203,7 @@ fn finish<T: qq_helper>
let mut state = active;
let mut i = 0u, j = 0u;
let g_len = cx.gather.len();
do str::chars_iter(*str) {|ch|
do str::chars_iter(*str) |ch| {
if (j < g_len && i == cx.gather[j].lo) {
assert ch == '$';
let repl = #fmt("$%u ", j);
@ -229,14 +227,11 @@ fn finish<T: qq_helper>
let cx = ecx;
let cfg_call = {||
mk_call_(cx, sp, mk_access(cx, sp, ~[@"ext_cx"], @"cfg"), ~[])
};
let cfg_call = || mk_call_(
cx, sp, mk_access(cx, sp, ~[@"ext_cx"], @"cfg"), ~[]);
let parse_sess_call = {||
mk_call_(cx, sp,
mk_access(cx, sp, ~[@"ext_cx"], @"parse_sess"), ~[])
};
let parse_sess_call = || mk_call_(
cx, sp, mk_access(cx, sp, ~[@"ext_cx"], @"parse_sess"), ~[]);
let pcall = mk_call(cx,sp,
~[@"syntax", @"parse", @"parser",
@ -259,7 +254,7 @@ fn finish<T: qq_helper>
rcall = mk_call(cx,sp,
~[@"syntax", @"ext", @"qquote", @"replace"],
~[pcall,
mk_uniq_vec_e(cx,sp, qcx.gather.map_to_vec({|g|
mk_uniq_vec_e(cx,sp, qcx.gather.map_to_vec(|g| {
mk_call(cx,sp,
~[@"syntax", @"ext",
@"qquote", @g.constr],
@ -275,10 +270,10 @@ fn replace<T>(node: T, repls: ~[fragment], ff: fn (ast_fold, T) -> T)
-> T
{
let aft = default_ast_fold();
let f_pre = @{fold_expr: {|a,b,c|replace_expr(repls, a, b, c,
aft.fold_expr)},
fold_ty: {|a,b,c|replace_ty(repls, a, b, c,
aft.fold_ty)}
let f_pre = @{fold_expr: |a,b,c|replace_expr(repls, a, b, c,
aft.fold_expr),
fold_ty: |a,b,c|replace_ty(repls, a, b, c,
aft.fold_ty)
with *aft};
ret ff(make_fold(f_pre), node);
}

View file

@ -74,7 +74,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) ->
{pre: ~[@expr], rep: option<@expr>, post: ~[@expr]} {
let mut idx: uint = 0u;
let mut res = none;
for elts.each {|elt|
for elts.each |elt| {
alt elt.node {
expr_mac(m) {
alt m.node {
@ -103,7 +103,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) ->
fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: ~[T]) ->
option<~[U]> {
let mut res = ~[];
for v.each {|elem|
for v.each |elem| {
alt f(elem) { none { ret none; } some(fv) { vec::push(res, fv); } }
}
ret some(res);
@ -113,7 +113,7 @@ fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
alt ad {
leaf(x) { ret f(x); }
seq(ads, span) {
alt option_flatten_map({|x| a_d_map(x, f)}, *ads) {
alt option_flatten_map(|x| a_d_map(x, f), *ads) {
none { ret none; }
some(ts) { ret some(seq(@ts, span)); }
}
@ -128,7 +128,7 @@ fn compose_sels(s1: selector, s2: selector) -> selector {
some(matches) { a_d_map(matches, s2) }
}
}
ret {|x|scomp(s1, s2, x)};
ret { |x| scomp(s1, s2, x) };
}
@ -164,11 +164,11 @@ selectors. */
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|
for b.literal_ast_matchers.each |sel| {
alt sel(match_expr(e)) { none { ret none; } _ { } }
}
let mut never_mind: bool = false;
for b.real_binders.each {|key, val|
for b.real_binders.each |key, val| {
alt val(match_expr(e)) {
none { never_mind = true; }
some(mtc) { res.insert(key, mtc); }
@ -190,22 +190,22 @@ fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr {
}
let afp = default_ast_fold();
let f_pre =
@{fold_ident: {|x,y|transcribe_ident(cx, b, idx_path, x, y)},
fold_path: {|x,y|transcribe_path(cx, b, idx_path, x, y)},
fold_expr: {|x,y,z|
@{fold_ident: |x,y|transcribe_ident(cx, b, idx_path, x, y),
fold_path: |x,y|transcribe_path(cx, b, idx_path, x, y),
fold_expr: |x,y,z|
transcribe_expr(cx, b, idx_path, x, y, z, afp.fold_expr)
},
fold_ty: {|x,y,z|
,
fold_ty: |x,y,z|
transcribe_type(cx, b, idx_path,
x, y, z, afp.fold_ty)
},
fold_block: {|x,y,z|
,
fold_block: |x,y,z|
transcribe_block(cx, b, idx_path, x, y, z, afp.fold_block)
},
map_exprs: {|x,y|
,
map_exprs: |x,y|
transcribe_exprs(cx, b, idx_path, x, y)
},
new_id: {|x|new_id(x, cx)}
,
new_id: |x|new_id(x, cx)
with *afp};
let f = make_fold(f_pre);
let result = f.fold_expr(body);
@ -217,7 +217,7 @@ fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr {
fn follow(m: arb_depth<matchable>, idx_path: @mut ~[uint]) ->
arb_depth<matchable> {
let mut res: arb_depth<matchable> = m;
for vec::each(*idx_path) {|idx|
for vec::each(*idx_path) |idx| {
res = alt res {
leaf(_) { ret res;/* end of the line */ }
seq(new_ms, _) { new_ms[idx] }
@ -255,11 +255,11 @@ fn free_vars(b: bindings, e: @expr, it: fn(ident)) {
// using fold is a hack: we want visit, but it doesn't hit idents ) :
// solve this with macros
let f_pre =
@{fold_ident: {|x,y|mark_ident(x, y, b, idents)}
@{fold_ident: |x,y|mark_ident(x, y, b, idents)
with *default_ast_fold()};
let f = make_fold(f_pre);
f.fold_expr(e); // ignore result
for idents.each_key {|x| it(x); };
for idents.each_key |x| { it(x); };
}
@ -276,7 +276,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
let mut repeat: option<{rep_count: uint, name: ident}> = none;
/* we need to walk over all the free vars in lockstep, except for
the leaves, which are just duplicated */
do free_vars(b, repeat_me) {|fv|
do free_vars(b, repeat_me) |fv| {
let cur_pos = follow(b.get(fv), idx_path);
alt cur_pos {
leaf(_) { }
@ -481,7 +481,7 @@ fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
_ { cx.bug("broken traversal in p_t_s_r") }
}
}
b.literal_ast_matchers.push({|x|select(cx, x, e)});
b.literal_ast_matchers.push(|x| select(cx, x, e));
}
}
}
@ -523,7 +523,7 @@ fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
if b.real_binders.contains_key(p_id) {
cx.span_fatal(p.span, "duplicate binding identifier");
}
b.real_binders.insert(p_id, compose_sels(s, {|x|select(cx, x)}));
b.real_binders.insert(p_id, compose_sels(s, |x| select(cx, x)));
}
none { }
}
@ -568,7 +568,7 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) {
_ { none }
}
}
let final_step = {|x|select_pt_1(cx, x, select_pt_2)};
let final_step = |x| select_pt_1(cx, x, select_pt_2);
b.real_binders.insert(id, compose_sels(s, final_step));
}
none { no_des(cx, pth.span, "under `#<>`"); }
@ -588,7 +588,7 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) {
_ { none }
}
}
let final_step = {|x|select_pt_1(cx, x, select_pt_2)};
let final_step = |x| select_pt_1(cx, x, select_pt_2);
b.real_binders.insert(id, compose_sels(s, final_step));
}
none { no_des(cx, blk.span, "under `#{}`"); }
@ -625,7 +625,7 @@ fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector,
}
}
p_t_s_rec(cx, match_expr(repeat_me),
compose_sels(s, {|x|select(cx, repeat_me, offset, x)}), b);
compose_sels(s, |x| select(cx, repeat_me, offset, x)), b);
}
@ -649,7 +649,7 @@ fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector,
}
}
b.literal_ast_matchers.push(
compose_sels(s, {|x|len_select(cx, x, at_least, len)}));
compose_sels(s, |x| len_select(cx, x, at_least, len)));
}
fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool,
@ -670,7 +670,7 @@ fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: ~[@expr], _repeat_after: bool,
}
}
p_t_s_rec(cx, match_expr(elts[idx]),
compose_sels(s, {|x, copy idx|select(cx, x, idx)}), b);
compose_sels(s, |x, copy idx| select(cx, x, idx)), b);
idx += 1u;
}
}
@ -681,7 +681,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
let mut macro_name: option<@str> = none;
let mut clauses: ~[@clause] = ~[];
for args.each {|arg|
for args.each |arg| {
alt arg.node {
expr_vec(elts, mutbl) {
if vec::len(elts) != 2u {
@ -745,9 +745,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)
};
let ext = |a,b,c,d, move clauses| generic_extension(a,b,c,d,clauses);
ret {ident:
alt macro_name {
@ -766,7 +764,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
some(arg) { arg }
none { cx.span_fatal(sp, "macro must have arguments")}
};
for clauses.each {|c|
for clauses.each |c| {
alt use_selectors_to_bind(c.params, arg) {
some(bindings) { ret transcribe(cx, bindings, c.body); }
none { cont; }

View file

@ -50,7 +50,7 @@ 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_lit(cx, sp, ast::lit_str(
@str::connect(cx.mod_path().map({|x|*x}), "::")));
@str::connect(cx.mod_path().map(|x|*x), "::")));
}
fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
@ -88,7 +88,7 @@ fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
alt io::read_whole_file(res_rel_file(cx, sp, file)) {
result::ok(src) {
let u8_exprs = vec::map(src, { |char: u8|
let u8_exprs = vec::map(src, |char: u8| {
mk_lit(cx, sp, ast::lit_uint(char as u64, ast::ty_u8))
});
ret mk_uniq_vec_e(cx, sp, u8_exprs);

View file

@ -87,7 +87,7 @@ fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
alt mi.node {
meta_word(id) { meta_word(fld.fold_ident(id)) }
meta_list(id, mis) {
let fold_meta_item = {|x|fold_meta_item_(x, fld)};
let fold_meta_item = |x|fold_meta_item_(x, fld);
meta_list(/* FIXME: (#2543) */ copy id,
vec::map(mis, fold_meta_item))
}
@ -131,7 +131,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)}),
ret {inputs: vec::map(decl.inputs, |x| fold_arg_(x, fld) ),
output: fld.fold_ty(decl.output),
purity: decl.purity,
cf: decl.cf,
@ -148,16 +148,16 @@ fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound {
fn fold_ty_param(tp: ty_param, fld: ast_fold) -> ty_param {
{ident: /* FIXME (#2543) */ copy tp.ident,
id: fld.new_id(tp.id),
bounds: @vec::map(*tp.bounds, {|x|fold_ty_param_bound(x, fld)})}
bounds: @vec::map(*tp.bounds, |x| fold_ty_param_bound(x, fld) )}
}
fn fold_ty_params(tps: ~[ty_param], fld: ast_fold) -> ~[ty_param] {
vec::map(tps, {|x|fold_ty_param(x, fld)})
vec::map(tps, |x| fold_ty_param(x, fld) )
}
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)};
let fold_meta_item = |x| fold_meta_item_(x, fld);
let fold_attribute = |x| fold_attribute_(x, fld);
ret {directives: vec::map(c.directives, fld.fold_crate_directive),
module: fld.fold_mod(c.module),
@ -188,8 +188,8 @@ fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ {
fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
-> @foreign_item {
let fold_arg = {|x|fold_arg_(x, fld)};
let fold_attribute = {|x|fold_attribute_(x, fld)};
let fold_arg = |x| fold_arg_(x, fld);
let fold_attribute = |x| fold_attribute_(x, fld);
ret @{ident: fld.fold_ident(ni.ident),
attrs: vec::map(ni.attrs, fold_attribute),
@ -211,7 +211,7 @@ fn noop_fold_foreign_item(&&ni: @foreign_item, fld: ast_fold)
}
fn noop_fold_item(&&i: @item, fld: ast_fold) -> @item {
let fold_attribute = {|x|fold_attribute_(x, fld)};
let fold_attribute = |x| fold_attribute_(x, fld);
ret @{ident: fld.fold_ident(i.ident),
attrs: vec::map(i.attrs, fold_attribute),
@ -255,7 +255,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
let ctor_body = fld.fold_block(ctor.node.body);
let ctor_decl = fold_fn_decl(ctor.node.dec, fld);
let ctor_id = fld.new_id(ctor.node.id);
let dtor = do option::map(m_dtor) {|dtor|
let dtor = do option::map(m_dtor) |dtor| {
let dtor_body = fld.fold_block(dtor.node.body);
let dtor_id = fld.new_id(dtor.node.id);
{node: {body: dtor_body,
@ -263,7 +263,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
with dtor}};
item_class(
/* FIXME (#2543) */ copy typms,
vec::map(ifaces, {|p| fold_iface_ref(p, fld) }),
vec::map(ifaces, |p| fold_iface_ref(p, fld)),
vec::map(items, fld.fold_class_item),
{node: {body: ctor_body,
dec: ctor_decl,
@ -273,7 +273,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
item_impl(tps, rp, ifce, ty, methods) {
item_impl(fold_ty_params(tps, fld),
rp,
ifce.map({ |p| fold_iface_ref(p, fld) }),
ifce.map(|p| fold_iface_ref(p, fld)),
fld.fold_ty(ty),
vec::map(methods, fld.fold_method))
}
@ -333,11 +333,11 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
pat_lit(e) { pat_lit(fld.fold_expr(e)) }
pat_enum(pth, pats) {
pat_enum(fld.fold_path(pth), option::map(pats,
{|pats| vec::map(pats, fld.fold_pat)}))
|pats| vec::map(pats, fld.fold_pat)))
}
pat_rec(fields, etc) {
let mut fs = ~[];
for fields.each {|f|
for fields.each |f| {
vec::push(fs,
{ident: /* FIXME (#2543) */ copy f.ident,
pat: fld.fold_pat(f.pat)});
@ -376,9 +376,9 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
expr: fld.fold_expr(field.node.expr)},
span: fld.new_span(field.span)};
}
let fold_field = {|x|fold_field_(x, fld)};
let fold_field = |x| fold_field_(x, fld);
let fold_mac = {|x|fold_mac_(x, fld)};
let fold_mac = |x| fold_mac_(x, fld);
ret alt e {
expr_new(p, i, v) {
@ -426,13 +426,13 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
expr_fn(proto, decl, body, captures) {
expr_fn(proto, fold_fn_decl(decl, fld),
fld.fold_block(body),
@((*captures).map({|cap_item|
@((*captures).map(|cap_item| {
@({id: fld.new_id((*cap_item).id)
with *cap_item})})))
}
expr_fn_block(decl, body, captures) {
expr_fn_block(fold_fn_decl(decl, fld), fld.fold_block(body),
@((*captures).map({|cap_item|
@((*captures).map(|cap_item| {
@({id: fld.new_id((*cap_item).id)
with *cap_item})})))
}
@ -474,7 +474,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
}
fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
let fold_mac = {|x|fold_mac_(x, fld)};
let fold_mac = |x| fold_mac_(x, fld);
fn fold_mt(mt: mt, fld: ast_fold) -> mt {
{ty: fld.fold_ty(mt.ty), mutbl: mt.mutbl}
}
@ -490,9 +490,9 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
ty_vec(mt) {ty_vec(fold_mt(mt, fld))}
ty_ptr(mt) {ty_ptr(fold_mt(mt, fld))}
ty_rptr(region, mt) {ty_rptr(region, fold_mt(mt, fld))}
ty_rec(fields) {ty_rec(vec::map(fields, {|f| fold_field(f, fld)}))}
ty_rec(fields) {ty_rec(vec::map(fields, |f| fold_field(f, fld)))}
ty_fn(proto, decl) {ty_fn(proto, fold_fn_decl(decl, fld))}
ty_tup(tys) {ty_tup(vec::map(tys, {|ty| fld.fold_ty(ty)}))}
ty_tup(tys) {ty_tup(vec::map(tys, |ty| fld.fold_ty(ty)))}
ty_path(path, id) {ty_path(fld.fold_path(path), fld.new_id(id))}
ty_constr(ty, constrs) {ty_constr(fld.fold_ty(ty),
vec::map(constrs, fld.fold_ty_constr))}
@ -527,10 +527,10 @@ 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)};
}
let fold_variant_arg = {|x|fold_variant_arg_(x, fld)};
let fold_variant_arg = |x| fold_variant_arg_(x, fld);
let args = vec::map(v.args, fold_variant_arg);
let fold_attribute = {|x|fold_attribute_(x, fld)};
let fold_attribute = |x| fold_attribute_(x, fld);
let attrs = vec::map(v.attrs, fold_attribute);
let de = alt v.disr_expr {
@ -624,8 +624,8 @@ impl of ast_fold for ast_fold_precursor {
fn fold_view_item(&&x: @view_item) ->
@view_item {
ret @{node: self.fold_view_item(x.node, self as ast_fold),
attrs: vec::map(x.attrs, {|a|
fold_attribute_(a, self as ast_fold)}),
attrs: vec::map(x.attrs, |a|
fold_attribute_(a, self as ast_fold)),
vis: x.vis,
span: self.new_span(x.span)};
}

View file

@ -37,8 +37,8 @@ fn new_parse_sess(demitter: option<emitter>) -> parse_sess {
ret @{cm: cm,
mut next_id: 1,
span_diagnostic: mk_span_handler(mk_handler(demitter), cm),
interner: @interner::mk::<@str>({|x|str::hash(*x)},
{|x,y|str::eq(*x, *y)}),
interner: @interner::mk::<@str>(|x| str::hash(*x),
|x,y| str::eq(*x, *y)),
mut chpos: 0u, mut byte_pos: 0u};
}
@ -47,8 +47,8 @@ fn new_parse_sess_special_handler(sh: span_handler, cm: codemap::codemap)
ret @{cm: cm,
mut next_id: 1,
span_diagnostic: sh,
interner: @interner::mk::<@str>({|x|str::hash(*x)},
{|x,y|str::eq(*x, *y)}),
interner: @interner::mk::<@str>(|x| str::hash(*x),
|x,y| str::eq(*x, *y)),
mut chpos: 0u, mut byte_pos: 0u};
}

View file

@ -114,7 +114,7 @@ impl parser_attr for parser {
fn parse_meta_seq() -> ~[@ast::meta_item] {
ret self.parse_seq(token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
{|p| p.parse_meta_item()}).node;
|p| p.parse_meta_item()).node;
}
fn parse_optional_meta() -> ~[@ast::meta_item] {

View file

@ -173,8 +173,8 @@ fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
{cmnts: ~[cmnt], lits: ~[lit]} {
let src = @str::from_bytes(srdr.read_whole_stream());
let itr = @interner::mk::<@str>(
{|x|str::hash(*x)},
{|x,y|str::eq(*x, *y)}
|x| str::hash(*x),
|x,y| str::eq(*x, *y)
);
let rdr = lexer::new_low_level_string_reader
(span_diagnostic, codemap::new_filemap(path, src, 0u, 0u), itr);

View file

@ -12,7 +12,7 @@ fn eval_crate_directives(cx: ctx,
prefix: str,
&view_items: ~[@ast::view_item],
&items: ~[@ast::item]) {
for cdirs.each {|sub_cdir|
for cdirs.each |sub_cdir| {
eval_crate_directive(cx, sub_cdir, prefix, view_items, items);
}
}

View file

@ -162,7 +162,7 @@ class parser {
fn parse_ty_fn_decl(purity: ast::purity) -> fn_decl {
let inputs = do self.parse_unspanned_seq(
token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA)) { |p|
seq_sep_trailing_disallowed(token::COMMA)) |p| {
let mode = p.parse_arg_mode();
let name = if is_plain_ident(p.token)
&& p.look_ahead(1u) == token::COLON {
@ -188,7 +188,7 @@ class parser {
fn parse_ty_methods() -> ~[ty_method] {
do self.parse_unspanned_seq(token::LBRACE, token::RBRACE,
seq_sep_none()) { |p|
seq_sep_none()) |p| {
let attrs = p.parse_outer_attributes();
let flo = p.span.lo;
let pur = p.parse_fn_purity();
@ -220,7 +220,7 @@ class parser {
// otherwise, fail
fn ident_index(args: ~[arg], i: ident) -> uint {
let mut j = 0u;
for args.each {|a| if a.ident == i { ret j; } j += 1u; }
for args.each |a| { if a.ident == i { ret j; } j += 1u; }
self.fatal("unbound variable `" + *i + "` in constraint arg");
}
@ -256,7 +256,7 @@ class parser {
let args = self.parse_unspanned_seq(
token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
{|p| p.parse_constr_arg(fn_args)});
|p| p.parse_constr_arg(fn_args));
ret @spanned(lo, self.span.hi,
{path: path, args: args, id: self.get_id()});
}
@ -267,7 +267,7 @@ class parser {
let args: ~[@ty_constr_arg] = self.parse_unspanned_seq(
token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
{|p| p.parse_type_constr_arg()});
|p| p.parse_type_constr_arg());
let hi = self.span.lo;
let tc: ty_constr_ = {path: path, args: args, id: self.get_id()};
ret @spanned(lo, hi, tc);
@ -286,7 +286,7 @@ class parser {
}
fn parse_type_constraints() -> ~[@ty_constr] {
ret self.parse_constrs({|p| p.parse_constr_in_type()});
ret self.parse_constrs(|p| p.parse_constr_in_type());
}
fn parse_ret_ty() -> (ret_style, @ty) {
@ -397,7 +397,7 @@ class parser {
let elems = self.parse_unspanned_seq(
token::LBRACE, token::RBRACE,
seq_sep_trailing_allowed(token::COMMA),
{|p| p.parse_ty_field()});
|p| p.parse_ty_field());
if vec::len(elems) == 0u {
self.unexpected_last(token::RBRACE);
}
@ -495,11 +495,11 @@ class parser {
}
fn parse_arg_or_capture_item() -> arg_or_capture_item {
self.parse_capture_item_or({|p| p.parse_arg() })
self.parse_capture_item_or(|p| p.parse_arg())
}
fn parse_fn_block_arg() -> arg_or_capture_item {
do self.parse_capture_item_or {|p|
do self.parse_capture_item_or |p| {
let m = p.parse_arg_mode();
let i = p.parse_value_ident();
let t = if p.eat(token::COLON) {
@ -594,8 +594,8 @@ class parser {
}
fn parse_path_without_tps() -> @path {
self.parse_path_without_tps_({|p| p.parse_ident()},
{|p| p.parse_ident()})
self.parse_path_without_tps_(|p| p.parse_ident(),
|p| p.parse_ident())
}
fn parse_path_without_tps_(
@ -623,8 +623,8 @@ class parser {
}
fn parse_value_path() -> @path {
self.parse_path_without_tps_({|p| p.parse_ident()},
{|p| p.parse_value_ident()})
self.parse_path_without_tps_(|p| p.parse_ident(),
|p| p.parse_value_ident())
}
fn parse_path_with_tps(colons: bool) -> @path {
@ -658,7 +658,7 @@ class parser {
let tps = {
if self.token == token::LT {
self.parse_seq_lt_gt(some(token::COMMA),
{|p| p.parse_ty(false)})
|p| p.parse_ty(false))
} else {
{node: ~[], span: path.span}
}
@ -820,7 +820,7 @@ class parser {
let mutbl = self.parse_mutability();
let es = self.parse_seq_to_end(
token::RBRACKET, seq_sep_trailing_allowed(token::COMMA),
{|p| p.parse_expr()});
|p| p.parse_expr());
hi = self.span.hi;
ex = expr_vec(es, mutbl);
} else if self.token == token::POUND
@ -968,10 +968,10 @@ class parser {
let es =
if self.token == token::LPAREN {
self.parse_unspanned_seq(token::LPAREN, token::RPAREN,
sep, {|p| p.parse_expr()})
sep, |p| p.parse_expr())
} else {
self.parse_unspanned_seq(token::LBRACKET, token::RBRACKET,
sep, {|p| p.parse_expr()})
sep, |p| p.parse_expr())
};
let hi = self.span.hi;
e = some(self.mk_expr(lo, hi, expr_vec(es, m_imm)));
@ -1019,7 +1019,7 @@ class parser {
let tys = if self.eat(token::MOD_SEP) {
self.expect(token::LT);
self.parse_seq_to_gt(some(token::COMMA),
{|p| p.parse_ty(false)})
|p| p.parse_ty(false))
} else { ~[] };
e = self.mk_pexpr(lo, hi, expr_field(self.to_expr(e),
self.get_str(i),
@ -1036,7 +1036,7 @@ class parser {
let es = self.parse_unspanned_seq(
token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
{|p| p.parse_expr()});
|p| p.parse_expr());
hi = self.span.hi;
let nd = expr_call(self.to_expr(e), es, false);
@ -1095,7 +1095,7 @@ class parser {
vec::append(
self.parse_seq_to_before_end(
ket, seq_sep_none(),
{|p| p.parse_token_tree()}),
|p| p.parse_token_tree()),
~[parse_tt_flat(self, true)])))
}
_ { parse_tt_flat(self, false) }
@ -1106,7 +1106,7 @@ class parser {
fn parse_tt_mac_demo() -> @expr {
let ms = self.parse_seq(token::LBRACE, token::RBRACE,
common::seq_sep_none(),
{|p| p.parse_matcher(@mut 0u)}).node;
|p| p.parse_matcher(@mut 0u)).node;
let tt = self.parse_token_tree();
alt tt {
tt_delim(tts) {
@ -1131,7 +1131,7 @@ class parser {
self.bump();
let ms = (self.parse_seq(token::LPAREN, token::RPAREN,
common::seq_sep_none(),
{|p| p.parse_matcher(name_idx)}).node);
|p| p.parse_matcher(name_idx)).node);
if ms.len() == 0u {
self.fatal("repetition body must be nonempty");
}
@ -1350,7 +1350,7 @@ class parser {
// the future, just have to change parse_arg to parse_fn_block_arg.
let (decl, capture_clause) =
self.parse_fn_decl(impure_fn,
{|p| p.parse_arg_or_capture_item()});
|p| p.parse_arg_or_capture_item());
let body = self.parse_block();
ret self.mk_expr(lo, body.span.hi,
@ -1367,7 +1367,7 @@ class parser {
// `|args| { ... }` like in `do` expressions
fn parse_lambda_block_expr() -> @expr {
self.parse_lambda_expr_({||
self.parse_lambda_expr_(|| {
let blk = self.parse_block();
self.mk_expr(blk.span.lo, blk.span.hi, expr_block(blk))
})
@ -1375,7 +1375,7 @@ class parser {
// `|args| expr`
fn parse_lambda_expr() -> @expr {
self.parse_lambda_expr_({|| self.parse_expr()})
self.parse_lambda_expr_(|| self.parse_expr())
}
fn parse_lambda_expr_(parse_body: fn&() -> @expr) -> @expr {
@ -1645,7 +1645,7 @@ class parser {
args = self.parse_unspanned_seq(
token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
{|p| p.parse_pat()});
|p| p.parse_pat());
hi = self.span.hi;
}
}
@ -1891,7 +1891,7 @@ class parser {
fn parse_ty_params() -> ~[ty_param] {
if self.eat(token::LT) {
self.parse_seq_to_gt(some(token::COMMA), {|p| p.parse_ty_param()})
self.parse_seq_to_gt(some(token::COMMA), |p| p.parse_ty_param())
} else { ~[] }
}
@ -1913,7 +1913,7 @@ class parser {
let mut constrs = ~[];
if self.token == token::COLON {
self.bump();
constrs = self.parse_constrs({|p| p.parse_ty_constr(inputs) });
constrs = self.parse_constrs(|p| p.parse_ty_constr(inputs));
}
let (ret_style, ret_ty) = self.parse_ret_ty();
ret ({inputs: inputs,
@ -1931,7 +1931,7 @@ class parser {
self.parse_unspanned_seq(
token::BINOP(token::OR), token::BINOP(token::OR),
seq_sep_trailing_disallowed(token::COMMA),
{|p| p.parse_fn_block_arg()})
|p| p.parse_fn_block_arg())
}
};
let output = if self.eat(token::RARROW) {
@ -1966,7 +1966,7 @@ class parser {
fn parse_item_fn(purity: purity) -> item_info {
let t = self.parse_fn_header();
let (decl, _) = self.parse_fn_decl(purity, {|p| p.parse_arg()});
let (decl, _) = self.parse_fn_decl(purity, |p| p.parse_arg());
let (inner_attrs, body) = self.parse_inner_attrs_and_block(true);
(t.ident, item_fn(decl, t.tps, body), some(inner_attrs))
}
@ -1991,7 +1991,7 @@ class parser {
let lo = self.span.lo, pur = self.parse_fn_purity();
let ident = self.parse_method_name();
let tps = self.parse_ty_params();
let (decl, _) = self.parse_fn_decl(pur, {|p| p.parse_arg()});
let (decl, _) = self.parse_fn_decl(pur, |p| p.parse_arg());
let (inner_attrs, body) = self.parse_inner_attrs_and_block(true);
let attrs = vec::append(attrs, inner_attrs);
@{ident: ident, attrs: attrs, tps: tps, decl: decl, body: body,
@ -2066,7 +2066,7 @@ class parser {
@{span: s, global: false, idents: ~[i],
rp: a_r,
types: vec::map(typarams, {|tp|
types: vec::map(typarams, |tp| {
@{id: self.get_id(),
node: ty_path(ident_to_path(s, tp.ident), self.get_id()),
span: s}})
@ -2081,7 +2081,7 @@ class parser {
fn parse_iface_ref_list() -> ~[@iface_ref] {
self.parse_seq_to_before_end(
token::LBRACE, seq_sep_trailing_disallowed(token::COMMA),
{|p| p.parse_iface_ref()})
|p| p.parse_iface_ref())
}
fn parse_item_class() -> item_info {
@ -2108,7 +2108,7 @@ class parser {
members(mms) { ms = vec::append(ms, mms); }
}
}
let actual_dtor = do option::map(the_dtor) {|dtor|
let actual_dtor = do option::map(the_dtor) |dtor| {
let (d_body, d_s) = dtor;
{node: {id: self.get_id(),
self_id: self.get_id(),
@ -2151,7 +2151,7 @@ class parser {
fn parse_ctor(result_ty: ast::ty_) -> class_contents {
// FIXME (#2660): Can ctors/dtors have attrs?
let lo = self.last_span.lo;
let (decl_, _) = self.parse_fn_decl(impure_fn, {|p| p.parse_arg()});
let (decl_, _) = self.parse_fn_decl(impure_fn, |p| p.parse_arg());
let decl = {output: @{id: self.get_id(),
node: result_ty, span: decl_.output.span}
with decl_};
@ -2253,7 +2253,7 @@ class parser {
purity: purity) -> @foreign_item {
let lo = self.last_span.lo;
let t = self.parse_fn_header();
let (decl, _) = self.parse_fn_decl(purity, {|p| p.parse_arg()});
let (decl, _) = self.parse_fn_decl(purity, |p| p.parse_arg());
let mut hi = self.span.hi;
self.expect(token::SEMI);
ret @{ident: t.ident,
@ -2368,8 +2368,8 @@ class parser {
let arg_tys = self.parse_unspanned_seq(
token::LPAREN, token::RPAREN,
seq_sep_trailing_disallowed(token::COMMA),
{|p| p.parse_ty(false)});
for arg_tys.each {|ty|
|p| p.parse_ty(false));
for arg_tys.each |ty| {
vec::push(args, {ty: ty, id: self.get_id()});
}
} else if self.eat(token::EQ) {
@ -2515,7 +2515,7 @@ class parser {
let idents = self.parse_unspanned_seq(
token::LBRACE, token::RBRACE,
seq_sep_trailing_allowed(token::COMMA),
{|p| p.parse_path_list_ident()});
|p| p.parse_path_list_ident());
let path = @{span: mk_sp(lo, self.span.hi),
global: false, idents: path,
rp: none, types: ~[]};

View file

@ -238,10 +238,10 @@ in positions that might otherwise contain _value identifiers_.
"]
fn keyword_table() -> hashmap<str, ()> {
let keywords = str_hash();
for contextual_keyword_table().each_key {|word|
for contextual_keyword_table().each_key |word| {
keywords.insert(word, ());
}
for restricted_keyword_table().each_key {|word|
for restricted_keyword_table().each_key |word| {
keywords.insert(word, ());
}
keywords
@ -263,7 +263,7 @@ fn contextual_keyword_table() -> hashmap<str, ()> {
/* temp */
"sep", "many", "at_least_one", "parse"
];
for keys.each {|word|
for keys.each |word| {
words.insert(word, ());
}
words
@ -301,7 +301,7 @@ fn restricted_keyword_table() -> hashmap<str, ()> {
"unchecked", "unsafe",
"while"
];
for keys.each {|word|
for keys.each |word| {
words.insert(word, ());
}
words

View file

@ -105,7 +105,7 @@ fn typarams_to_str(tps: ~[ast::ty_param]) -> str {
}
fn path_to_str(&&p: @ast::path) -> str {
ret to_str(p, {|a,b|print_path(a, b, false)});
ret to_str(p, |a,b| print_path(a, b, false));
}
fn fun_to_str(decl: ast::fn_decl, name: ast::ident,
@ -260,7 +260,7 @@ fn synth_comment(s: ps, text: str) {
fn commasep<IN>(s: ps, b: breaks, elts: ~[IN], op: fn(ps, IN)) {
box(s, 0u, b);
let mut first = true;
for elts.each {|elt|
for elts.each |elt| {
if first { first = false; } else { word_space(s, ","); }
op(s, elt);
}
@ -273,7 +273,7 @@ fn commasep_cmnt<IN>(s: ps, b: breaks, elts: ~[IN], op: fn(ps, IN),
box(s, 0u, b);
let len = vec::len::<IN>(elts);
let mut i = 0u;
for elts.each {|elt|
for elts.each |elt| {
maybe_print_comment(s, get_span(elt).hi);
op(s, elt);
i += 1u;
@ -294,19 +294,19 @@ fn commasep_exprs(s: ps, b: breaks, exprs: ~[@ast::expr]) {
fn print_mod(s: ps, _mod: ast::_mod, attrs: ~[ast::attribute]) {
print_inner_attributes(s, attrs);
for _mod.view_items.each {|vitem|
for _mod.view_items.each |vitem| {
print_view_item(s, vitem);
}
for _mod.items.each {|item| print_item(s, item); }
for _mod.items.each |item| { print_item(s, item); }
}
fn print_foreign_mod(s: ps, nmod: ast::foreign_mod,
attrs: ~[ast::attribute]) {
print_inner_attributes(s, attrs);
for nmod.view_items.each {|vitem|
for nmod.view_items.each |vitem| {
print_view_item(s, vitem);
}
for nmod.items.each {|item| print_foreign_item(s, item); }
for nmod.items.each |item| { print_foreign_item(s, item); }
}
fn print_region(s: ps, region: @ast::region) {
@ -481,7 +481,7 @@ fn print_item(s: ps, &&item: @ast::item) {
end(s);
} else {
bopen(s);
for variants.each {|v|
for variants.each |v| {
space_if_not_bol(s);
maybe_print_comment(s, v.span.lo);
print_outer_attributes(s, v.node.attrs);
@ -501,8 +501,8 @@ fn print_item(s: ps, &&item: @ast::item) {
print_type_params(s, tps);
if vec::len(ifaces) != 0u {
word_space(s, ":");
commasep(s, inconsistent, ifaces, {|s, p|
print_path(s, p.path, false)});
commasep(s, inconsistent, ifaces, |s, p|
print_path(s, p.path, false));
}
bopen(s);
hardbreak_if_not_bol(s);
@ -511,13 +511,13 @@ fn print_item(s: ps, &&item: @ast::item) {
print_fn_args_and_ret(s, ctor.node.dec, ~[]);
space(s.s);
print_block(s, ctor.node.body);
do option::iter(m_dtor) {|dtor|
do option::iter(m_dtor) |dtor| {
hardbreak_if_not_bol(s);
maybe_print_comment(s, dtor.span.lo);
head(s, "drop");
print_block(s, dtor.node.body);
}
for items.each {|ci|
for items.each |ci| {
/*
FIXME (#1893): collect all private items and print
them in a single "priv" section
@ -565,7 +565,7 @@ fn print_item(s: ps, &&item: @ast::item) {
print_region_param(s, rp);
print_type_params(s, tps);
space(s.s);
option::iter(ifce, {|p|
option::iter(ifce, |p| {
word_nbsp(s, "of");
print_path(s, p.path, false);
space(s.s);
@ -574,7 +574,7 @@ fn print_item(s: ps, &&item: @ast::item) {
print_type(s, ty);
space(s.s);
bopen(s);
for methods.each {|meth|
for methods.each |meth| {
print_method(s, meth);
}
bclose(s, item.span);
@ -586,7 +586,7 @@ fn print_item(s: ps, &&item: @ast::item) {
print_type_params(s, tps);
word(s.s, " ");
bopen(s);
for methods.each {|meth| print_ty_method(s, meth); }
for methods.each |meth| { print_ty_method(s, meth); }
bclose(s, item.span);
}
}
@ -632,7 +632,7 @@ fn print_method(s: ps, meth: @ast::method) {
fn print_outer_attributes(s: ps, attrs: ~[ast::attribute]) {
let mut count = 0;
for attrs.each {|attr|
for attrs.each |attr| {
alt attr.node.style {
ast::attr_outer { print_attribute(s, attr); count += 1; }
_ {/* fallthrough */ }
@ -643,7 +643,7 @@ fn print_outer_attributes(s: ps, attrs: ~[ast::attribute]) {
fn print_inner_attributes(s: ps, attrs: ~[ast::attribute]) {
let mut count = 0;
for attrs.each {|attr|
for attrs.each |attr| {
alt attr.node.style {
ast::attr_inner {
print_attribute(s, attr);
@ -719,8 +719,8 @@ fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type,
print_inner_attributes(s, attrs);
for blk.node.view_items.each {|vi| print_view_item(s, vi); }
for blk.node.stmts.each {|st|
for blk.node.view_items.each |vi| { print_view_item(s, vi); }
for blk.node.stmts.each |st| {
print_stmt(s, *st);
}
alt blk.node.expr {
@ -796,7 +796,7 @@ fn print_mac(s: ps, m: ast::mac) {
some(@{node: ast::expr_vec(_, _), _}) { }
_ { word(s.s, " "); }
}
option::iter(arg, {|a|print_expr(s, a)});
option::iter(arg, |a| print_expr(s, a));
// FIXME: extension 'body' (#2339)
}
ast::mac_embed_type(ty) {
@ -943,12 +943,12 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
print_maybe_parens_discrim(s, expr);
space(s.s);
bopen(s);
for arms.each {|arm|
for arms.each |arm| {
space(s.s);
cbox(s, alt_indent_unit);
ibox(s, 0u);
let mut first = true;
for arm.pats.each {|p|
for arm.pats.each |p| {
if first {
first = false;
} else { space(s.s); word_space(s, "|"); }
@ -1135,8 +1135,8 @@ fn print_decl(s: ps, decl: @ast::decl) {
word_nbsp(s, "let");
// if any are mut, all are mut
if vec::any(locs, {|l| l.node.is_mutbl }) {
assert vec::all(locs, {|l| l.node.is_mutbl });
if vec::any(locs, |l| l.node.is_mutbl) {
assert vec::all(locs, |l| l.node.is_mutbl);
word_nbsp(s, "mut");
}
@ -1176,7 +1176,7 @@ fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) {
maybe_print_comment(s, path.span.lo);
if path.global { word(s.s, "::"); }
let mut first = true;
for path.idents.each {|id|
for path.idents.each |id| {
if first { first = false; } else { word(s.s, "::"); }
word(s.s, *id);
}
@ -1278,7 +1278,7 @@ fn print_fn_args(s: ps, decl: ast::fn_decl,
commasep(s, inconsistent, decl.inputs, print_arg);
if cap_items.is_not_empty() {
let mut first = decl.inputs.is_empty();
for cap_items.each { |cap_item|
for cap_items.each |cap_item| {
if first { first = false; } else { word_space(s, ","); }
if cap_item.is_move { word_nbsp(s, "move") }
else { word_nbsp(s, "copy") }
@ -1292,7 +1292,7 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl,
popen(s);
print_fn_args(s, decl, cap_items);
pclose(s);
word(s.s, constrs_str(decl.constraints, {|c|
word(s.s, constrs_str(decl.constraints, |c| {
ast_fn_constr_to_str(decl, c)
}));
@ -1336,7 +1336,7 @@ fn print_arg_mode(s: ps, m: ast::mode) {
fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
if vec::len(*bounds) > 0u {
word(s.s, ":");
for vec::each(*bounds) {|bound|
for vec::each(*bounds) |bound| {
nbsp(s);
alt bound {
ast::bound_copy { word(s.s, "copy"); }
@ -1404,7 +1404,7 @@ fn print_view_path(s: ps, &&vp: @ast::view_path) {
ast::view_path_list(path, idents, _) {
print_path(s, path, false);
word(s.s, "::{");
do commasep(s, inconsistent, idents) {|s, w|
do commasep(s, inconsistent, idents) |s, w| {
word(s.s, *w.node.name)
}
word(s.s, "}");
@ -1627,7 +1627,7 @@ fn print_comment(s: ps, cmnt: comments::cmnt) {
}
comments::isolated {
pprust::hardbreak_if_not_bol(s);
for cmnt.lines.each {|line|
for cmnt.lines.each |line| {
// Don't print empty lines because they will end up as trailing
// whitespace
if str::is_not_empty(line) { word(s.s, line); }
@ -1641,7 +1641,7 @@ fn print_comment(s: ps, cmnt: comments::cmnt) {
hardbreak(s.s);
} else {
ibox(s, 0u);
for cmnt.lines.each {|line|
for cmnt.lines.each |line| {
if str::is_not_empty(line) { word(s.s, line); }
hardbreak(s.s);
}
@ -1691,7 +1691,7 @@ fn constr_args_to_str<T>(f: fn@(T) -> str,
str {
let mut comma = false;
let mut s = "(";
for args.each {|a|
for args.each |a| {
if comma { s += ", "; } else { comma = true; }
s += constr_arg_to_str::<T>(f, a.node);
}
@ -1719,7 +1719,7 @@ fn ast_ty_fn_constr_to_str(&&c: @ast::constr) -> str {
}
fn ast_fn_constr_to_str(decl: ast::fn_decl, &&c: @ast::constr) -> str {
let arg_to_str = {|a|fn_arg_idx_to_str(decl, a)};
let arg_to_str = |a| fn_arg_idx_to_str(decl, a);
ret path_to_str(c.node.path) +
constr_args_to_str(arg_to_str, c.node.args);
}
@ -1734,7 +1734,7 @@ fn ty_constr_to_str(&&c: @ast::ty_constr) -> str {
fn constrs_str<T>(constrs: ~[T], elt: fn(T) -> str) -> str {
let mut s = "", colon = true;
for constrs.each {|c|
for constrs.each |c| {
if colon { s += " : "; colon = false; } else { s += ", "; }
s += elt(c);
}

View file

@ -64,22 +64,22 @@ type visitor<E> =
visit_class_item: fn@(@class_member, E, vt<E>)};
fn default_visitor<E>() -> visitor<E> {
ret @{visit_mod: {|a,b,c,d,e|visit_mod::<E>(a, b, c, d, e)},
visit_view_item: {|a,b,c|visit_view_item::<E>(a, b, c)},
visit_foreign_item: {|a,b,c|visit_foreign_item::<E>(a, b, c)},
visit_item: {|a,b,c|visit_item::<E>(a, b, c)},
visit_local: {|a,b,c|visit_local::<E>(a, b, c)},
visit_block: {|a,b,c|visit_block::<E>(a, b, c)},
visit_stmt: {|a,b,c|visit_stmt::<E>(a, b, c)},
visit_arm: {|a,b,c|visit_arm::<E>(a, b, c)},
visit_pat: {|a,b,c|visit_pat::<E>(a, b, c)},
visit_decl: {|a,b,c|visit_decl::<E>(a, b, c)},
visit_expr: {|a,b,c|visit_expr::<E>(a, b, c)},
visit_ty: {|a,b,c|skip_ty::<E>(a, b, c)},
visit_ty_params: {|a,b,c|visit_ty_params::<E>(a, b, c)},
visit_constr: {|a,b,c,d,e|visit_constr::<E>(a, b, c, d, e)},
visit_fn: {|a,b,c,d,e,f,g|visit_fn::<E>(a, b, c, d, e, f, g)},
visit_class_item: {|a,b,c|visit_class_item::<E>(a, b, c)}};
ret @{visit_mod: |a,b,c,d,e|visit_mod::<E>(a, b, c, d, e),
visit_view_item: |a,b,c|visit_view_item::<E>(a, b, c),
visit_foreign_item: |a,b,c|visit_foreign_item::<E>(a, b, c),
visit_item: |a,b,c|visit_item::<E>(a, b, c),
visit_local: |a,b,c|visit_local::<E>(a, b, c),
visit_block: |a,b,c|visit_block::<E>(a, b, c),
visit_stmt: |a,b,c|visit_stmt::<E>(a, b, c),
visit_arm: |a,b,c|visit_arm::<E>(a, b, c),
visit_pat: |a,b,c|visit_pat::<E>(a, b, c),
visit_decl: |a,b,c|visit_decl::<E>(a, b, c),
visit_expr: |a,b,c|visit_expr::<E>(a, b, c),
visit_ty: |a,b,c|skip_ty::<E>(a, b, c),
visit_ty_params: |a,b,c|visit_ty_params::<E>(a, b, c),
visit_constr: |a,b,c,d,e|visit_constr::<E>(a, b, c, d, e),
visit_fn: |a,b,c,d,e,f,g|visit_fn::<E>(a, b, c, d, e, f, g),
visit_class_item: |a,b,c|visit_class_item::<E>(a, b, c)};
}
fn visit_crate<E>(c: crate, e: E, v: vt<E>) {
@ -90,7 +90,7 @@ fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) {
alt cd.node {
cdir_src_mod(_, _) { }
cdir_dir_mod(_, cdirs, _) {
for cdirs.each {|cdir|
for cdirs.each |cdir| {
visit_crate_directive(cdir, e, v);
}
}
@ -100,8 +100,8 @@ fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) {
}
fn visit_mod<E>(m: _mod, _sp: span, _id: node_id, e: E, v: vt<E>) {
for m.view_items.each {|vi| v.visit_view_item(vi, e, v); }
for m.items.each {|i| v.visit_item(i, e, v); }
for m.view_items.each |vi| { v.visit_view_item(vi, e, v); }
for m.items.each |i| { v.visit_item(i, e, v); }
}
fn visit_view_item<E>(_vi: @view_item, _e: E, _v: vt<E>) { }
@ -122,8 +122,8 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
}
item_mod(m) { v.visit_mod(m, i.span, i.id, e, v); }
item_foreign_mod(nm) {
for nm.view_items.each {|vi| v.visit_view_item(vi, e, v); }
for nm.items.each {|ni| v.visit_foreign_item(ni, e, v); }
for nm.view_items.each |vi| { v.visit_view_item(vi, e, v); }
for nm.items.each |ni| { v.visit_foreign_item(ni, e, v); }
}
item_ty(t, tps, rp) {
v.visit_ty(t, e, v);
@ -131,34 +131,34 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
}
item_enum(variants, tps, _) {
v.visit_ty_params(tps, e, v);
for variants.each {|vr|
for vr.node.args.each {|va| v.visit_ty(va.ty, e, v); }
for variants.each |vr| {
for vr.node.args.each |va| { v.visit_ty(va.ty, e, v); }
}
}
item_impl(tps, _rp, ifce, ty, methods) {
v.visit_ty_params(tps, e, v);
option::iter(ifce, {|p| visit_path(p.path, e, v)});
option::iter(ifce, |p| visit_path(p.path, e, v));
v.visit_ty(ty, e, v);
for methods.each {|m|
for methods.each |m| {
visit_method_helper(m, e, v)
}
}
item_class(tps, ifaces, members, ctor, m_dtor, _) {
v.visit_ty_params(tps, e, v);
for members.each {|m|
for members.each |m| {
v.visit_class_item(m, e, v);
}
for ifaces.each {|p| visit_path(p.path, e, v); }
for ifaces.each |p| { visit_path(p.path, e, v); }
visit_class_ctor_helper(ctor, i.ident, tps,
ast_util::local_def(i.id), e, v);
do option::iter(m_dtor) {|dtor|
do option::iter(m_dtor) |dtor| {
visit_class_dtor_helper(dtor, tps,
ast_util::local_def(i.id), e, v)};
}
item_iface(tps, _rp, methods) {
v.visit_ty_params(tps, e, v);
for methods.each {|m|
for m.decl.inputs.each {|a| v.visit_ty(a.ty, e, v); }
for methods.each |m| {
for m.decl.inputs.each |a| { v.visit_ty(a.ty, e, v); }
v.visit_ty_params(m.tps, e, v);
v.visit_ty(m.decl.output, e, v);
}
@ -186,12 +186,12 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
v.visit_ty(mt.ty, e, v);
}
ty_rec(flds) {
for flds.each {|f| v.visit_ty(f.node.mt.ty, e, v); }
for flds.each |f| { v.visit_ty(f.node.mt.ty, e, v); }
}
ty_tup(ts) { for ts.each {|tt| v.visit_ty(tt, e, v); } }
ty_tup(ts) { for ts.each |tt| { v.visit_ty(tt, e, v); } }
ty_fn(_, decl) {
for decl.inputs.each {|a| v.visit_ty(a.ty, e, v); }
for decl.constraints.each {|c|
for decl.inputs.each |a| { v.visit_ty(a.ty, e, v); }
for decl.constraints.each |c| {
v.visit_constr(c.node.path, c.span, c.node.id, e, v);
}
v.visit_ty(decl.output, e, v);
@ -202,7 +202,7 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
}
ty_constr(t, cs) {
v.visit_ty(t, e, v);
for cs.each {|tc|
for cs.each |tc| {
v.visit_constr(tc.node.path, tc.span, tc.node.id, e, v);
}
}
@ -220,26 +220,26 @@ fn visit_constr<E>(_operator: @path, _sp: span, _id: node_id, _e: E,
}
fn visit_path<E>(p: @path, e: E, v: vt<E>) {
for p.types.each {|tp| v.visit_ty(tp, e, v); }
for p.types.each |tp| { v.visit_ty(tp, e, v); }
}
fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
alt p.node {
pat_enum(path, children) {
visit_path(path, e, v);
do option::iter(children) {|children|
for children.each {|child| v.visit_pat(child, e, v); }}
do option::iter(children) |children| {
for children.each |child| { v.visit_pat(child, e, v); }}
}
pat_rec(fields, _) {
for fields.each {|f| v.visit_pat(f.pat, e, v); }
for fields.each |f| { v.visit_pat(f.pat, e, v); }
}
pat_tup(elts) { for elts.each {|elt| v.visit_pat(elt, e, v); } }
pat_tup(elts) { for elts.each |elt| { v.visit_pat(elt, e, v); } }
pat_box(inner) | pat_uniq(inner) {
v.visit_pat(inner, e, v);
}
pat_ident(path, inner) {
visit_path(path, e, v);
do option::iter(inner) {|subpat| v.visit_pat(subpat, e, v)};
do option::iter(inner) |subpat| { v.visit_pat(subpat, e, v)};
}
pat_lit(ex) { v.visit_expr(ex, e, v); }
pat_range(e1, e2) { v.visit_expr(e1, e, v); v.visit_expr(e2, e, v); }
@ -257,8 +257,8 @@ fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) {
}
fn visit_ty_params<E>(tps: ~[ty_param], e: E, v: vt<E>) {
for tps.each {|tp|
for vec::each(*tp.bounds) {|bound|
for tps.each |tp| {
for vec::each(*tp.bounds) |bound| {
alt bound {
bound_iface(t) { v.visit_ty(t, e, v); }
bound_copy | bound_send | bound_const { }
@ -268,8 +268,8 @@ fn visit_ty_params<E>(tps: ~[ty_param], e: E, v: vt<E>) {
}
fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) {
for fd.inputs.each {|a| v.visit_ty(a.ty, e, v); }
for fd.constraints.each {|c|
for fd.inputs.each |a| { v.visit_ty(a.ty, e, v); }
for fd.constraints.each |c| {
v.visit_constr(c.node.path, c.span, c.node.id, e, v);
}
v.visit_ty(fd.output, e, v);
@ -311,8 +311,8 @@ fn visit_fn<E>(fk: fn_kind, decl: fn_decl, body: blk, _sp: span,
}
fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) {
for b.node.view_items.each {|vi| v.visit_view_item(vi, e, v); }
for b.node.stmts.each {|s| v.visit_stmt(s, e, v); }
for b.node.view_items.each |vi| { v.visit_view_item(vi, e, v); }
for b.node.stmts.each |s| { v.visit_stmt(s, e, v); }
visit_expr_opt(b.node.expr, e, v);
}
@ -327,7 +327,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
alt d.node {
decl_local(locs) {
for locs.each {|loc| v.visit_local(loc, e, v); }
for locs.each |loc| { v.visit_local(loc, e, v); }
}
decl_item(it) { v.visit_item(it, e, v); }
}
@ -338,13 +338,13 @@ fn visit_expr_opt<E>(eo: option<@expr>, e: E, v: vt<E>) {
}
fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) {
for exprs.each {|ex| v.visit_expr(ex, e, v); }
for exprs.each |ex| { v.visit_expr(ex, e, v); }
}
fn visit_mac<E>(m: mac, e: E, v: vt<E>) {
alt m.node {
ast::mac_invoc(pth, arg, body) {
option::map(arg, {|arg| v.visit_expr(arg, e, v)}); }
option::map(arg, |arg| v.visit_expr(arg, e, v)); }
ast::mac_invoc_tt(pth, tt) { /* no user-serviceable parts inside */ }
ast::mac_embed_type(ty) { v.visit_ty(ty, e, v); }
ast::mac_embed_block(blk) { v.visit_block(blk, e, v); }
@ -363,10 +363,10 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
expr_vstore(x, _) { v.visit_expr(x, e, v); }
expr_vec(es, _) { visit_exprs(es, e, v); }
expr_rec(flds, base) {
for flds.each {|f| v.visit_expr(f.node.expr, e, v); }
for flds.each |f| { v.visit_expr(f.node.expr, e, v); }
visit_expr_opt(base, e, v);
}
expr_tup(elts) { for elts.each {|el| v.visit_expr(el, e, v); } }
expr_tup(elts) { for elts.each |el| { v.visit_expr(el, e, v); } }
expr_call(callee, args, _) {
visit_exprs(args, e, v);
v.visit_expr(callee, e, v);
@ -393,7 +393,7 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
expr_loop(b) { v.visit_block(b, e, v); }
expr_alt(x, arms, _) {
v.visit_expr(x, e, v);
for arms.each {|a| v.visit_arm(a, e, v); }
for arms.each |a| { v.visit_arm(a, e, v); }
}
expr_fn(proto, decl, body, cap_clause) {
v.visit_fn(fk_anon(proto, cap_clause), decl, body,
@ -414,7 +414,7 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
}
expr_field(x, _, tys) {
v.visit_expr(x, e, v);
for tys.each {|tp| v.visit_ty(tp, e, v); }
for tys.each |tp| { v.visit_ty(tp, e, v); }
}
expr_index(a, b) { v.visit_expr(a, e, v); v.visit_expr(b, e, v); }
expr_path(p) { visit_path(p, e, v); }
@ -431,7 +431,7 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
}
fn visit_arm<E>(a: arm, e: E, v: vt<E>) {
for a.pats.each {|p| v.visit_pat(p, e, v); }
for a.pats.each |p| { v.visit_pat(p, e, v); }
visit_expr_opt(a.guard, e, v);
v.visit_block(a.body, e, v);
}
@ -551,9 +551,9 @@ fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
visit_fn(fk, decl, body, sp, id, e, v);
}
let visit_ty = if v.visit_ty == simple_ignore_ty {
{|a,b,c| skip_ty(a, b, c)}
|a,b,c| skip_ty(a, b, c)
} else {
{|a,b,c| v_ty(v.visit_ty, a, b, c)}
|a,b,c| v_ty(v.visit_ty, a, b, c)
};
fn v_class_item(f: fn@(@class_member),
cm: @class_member, &&e: (),
@ -561,33 +561,28 @@ fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
f(cm);
visit_class_item(cm, e, v);
}
ret mk_vt(@{visit_mod: {|a,b,c,d,e|v_mod(v.visit_mod, a, b, c, d, e)},
visit_view_item: {|a,b,c|
v_view_item(v.visit_view_item, a, b, c)
},
ret mk_vt(@{visit_mod: |a,b,c,d,e|v_mod(v.visit_mod, a, b, c, d, e),
visit_view_item: |a,b,c|
v_view_item(v.visit_view_item, a, b, c),
visit_foreign_item:
{|a,b,c|v_foreign_item(v.visit_foreign_item, a, b, c)},
visit_item: {|a,b,c|v_item(v.visit_item, a, b, c)},
visit_local: {|a,b,c|v_local(v.visit_local, a, b, c)},
visit_block: {|a,b,c|v_block(v.visit_block, a, b, c)},
visit_stmt: {|a,b,c|v_stmt(v.visit_stmt, a, b, c)},
visit_arm: {|a,b,c|v_arm(v.visit_arm, a, b, c)},
visit_pat: {|a,b,c|v_pat(v.visit_pat, a, b, c)},
visit_decl: {|a,b,c|v_decl(v.visit_decl, a, b, c)},
visit_expr: {|a,b,c|v_expr(v.visit_expr, a, b, c)},
|a,b,c|v_foreign_item(v.visit_foreign_item, a, b, c),
visit_item: |a,b,c|v_item(v.visit_item, a, b, c),
visit_local: |a,b,c|v_local(v.visit_local, a, b, c),
visit_block: |a,b,c|v_block(v.visit_block, a, b, c),
visit_stmt: |a,b,c|v_stmt(v.visit_stmt, a, b, c),
visit_arm: |a,b,c|v_arm(v.visit_arm, a, b, c),
visit_pat: |a,b,c|v_pat(v.visit_pat, a, b, c),
visit_decl: |a,b,c|v_decl(v.visit_decl, a, b, c),
visit_expr: |a,b,c|v_expr(v.visit_expr, a, b, c),
visit_ty: visit_ty,
visit_ty_params: {|a,b,c|
v_ty_params(v.visit_ty_params, a, b, c)
},
visit_constr: {|a,b,c,d,e|
v_constr(v.visit_constr, a, b, c, d, e)
},
visit_fn: {|a,b,c,d,e,f,g|
v_fn(v.visit_fn, a, b, c, d, e, f, g)
},
visit_class_item: {|a,b,c|
visit_ty_params: |a,b,c|
v_ty_params(v.visit_ty_params, a, b, c),
visit_constr: |a,b,c,d,e|
v_constr(v.visit_constr, a, b, c, d, e),
visit_fn: |a,b,c,d,e,f,g|
v_fn(v.visit_fn, a, b, c, d, e, f, g),
visit_class_item: |a,b,c|
v_class_item(v.visit_class_item, a, b, c)
}
});
}

View file

@ -69,16 +69,14 @@ mod write {
output_type_bitcode {
if opts.optimize != 0u {
let filename = mk_intermediate_name(output, "no-opt.bc");
str::as_c_str(filename,
{|buf|
str::as_c_str(filename, |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf)
});
}
}
_ {
let filename = mk_intermediate_name(output, "bc");
str::as_c_str(filename,
{|buf|
str::as_c_str(filename, |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf)
});
}
@ -151,8 +149,7 @@ mod write {
let filename = mk_intermediate_name(output, "opt.bc");
llvm::LLVMRunPassManager(pm.llpm, llmod);
str::as_c_str(filename,
{|buf|
str::as_c_str(filename, |buf| {
llvm::LLVMWriteBitcodeToFile(llmod, buf)
});
pm = mk_pass_manager();
@ -161,8 +158,8 @@ mod write {
if opts.output_type == output_type_assembly {
let _: () = str::as_c_str(
sess.targ_cfg.target_strs.target_triple,
{|buf_t|
str::as_c_str(output, {|buf_o|
|buf_t| {
str::as_c_str(output, |buf_o| {
llvm::LLVMRustWriteOutputFile(
pm.llpm,
llmod,
@ -170,7 +167,9 @@ mod write {
buf_o,
lib::llvm::AssemblyFile as c_uint,
CodeGenOptLevel,
true)})});
true)
})
});
}
@ -178,11 +177,10 @@ mod write {
// This .o is needed when an exe is built
if opts.output_type == output_type_object ||
opts.output_type == output_type_exe {
let _: () =
str::as_c_str(
let _: () = str::as_c_str(
sess.targ_cfg.target_strs.target_triple,
{|buf_t|
str::as_c_str(output, {|buf_o|
|buf_t| {
str::as_c_str(output, |buf_o| {
llvm::LLVMRustWriteOutputFile(
pm.llpm,
llmod,
@ -190,17 +188,18 @@ mod write {
buf_o,
lib::llvm::ObjectFile as c_uint,
CodeGenOptLevel,
true)})});
true)
})
});
}
} else {
// If we aren't saving temps then just output the file
// type corresponding to the '-c' or '-S' flag used
let _: () =
str::as_c_str(
let _: () = str::as_c_str(
sess.targ_cfg.target_strs.target_triple,
{|buf_t|
str::as_c_str(output, {|buf_o|
|buf_t| {
str::as_c_str(output, |buf_o| {
llvm::LLVMRustWriteOutputFile(
pm.llpm,
llmod,
@ -208,7 +207,9 @@ mod write {
buf_o,
FileType as c_uint,
CodeGenOptLevel,
true)})});
true)
})
});
}
// Clean up and return
@ -219,14 +220,14 @@ mod write {
if opts.output_type == output_type_llvm_assembly {
// Given options "-S --emit-llvm": output LLVM assembly
str::as_c_str(output, {|buf_o|
str::as_c_str(output, |buf_o| {
llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o)});
} else {
// If only a bitcode file is asked for by using the '--emit-llvm'
// flag, then output it here
llvm::LLVMRunPassManager(pm.llpm, llmod);
str::as_c_str(output,
{|buf| llvm::LLVMWriteBitcodeToFile(llmod, buf) });
|buf| llvm::LLVMWriteBitcodeToFile(llmod, buf) );
}
llvm::LLVMDisposeModule(llmod);
@ -301,7 +302,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
let mut cmh_items: ~[@ast::meta_item] = ~[];
let linkage_metas = attr::find_linkage_metas(c.node.attrs);
attr::require_unique_names(sess.diagnostic(), linkage_metas);
for linkage_metas.each {|meta|
for linkage_metas.each |meta| {
if *attr::get_meta_item_name(meta) == "name" {
alt attr::get_meta_item_value_str(meta) {
some(v) { name = some(v); }
@ -332,7 +333,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
let cmh_items = attr::sort_meta_items(metas.cmh_items);
sha.reset();
for cmh_items.each {|m_|
for cmh_items.each |m_| {
let m = m_;
alt m.node {
ast::meta_name_value(key, value) {
@ -347,7 +348,7 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
}
}
for dep_hashes.each {|dh|
for dep_hashes.each |dh| {
sha.input_str(len_and_str(*dh));
}
@ -443,7 +444,7 @@ fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> str {
// gas doesn't!
fn sanitize(s: str) -> str {
let mut result = "";
do str::chars_iter(s) {|c|
do str::chars_iter(s) |c| {
alt c {
'@' { result += "_sbox_"; }
'~' { result += "_ubox_"; }
@ -479,7 +480,7 @@ fn mangle(ss: path) -> str {
let mut n = "_ZN"; // Begin name-sequence.
for ss.each {|s|
for ss.each |s| {
alt s { path_name(s) | path_mod(s) {
let sani = sanitize(*s);
n += #fmt["%u%s", str::len(sani), sani];
@ -593,7 +594,7 @@ fn link_binary(sess: session,
// # Crate linking
let cstore = sess.cstore;
for cstore::get_used_crate_files(cstore).each {|cratepath|
for cstore::get_used_crate_files(cstore).each |cratepath| {
if str::ends_with(cratepath, ".rlib") {
vec::push(cc_args, cratepath);
cont;
@ -606,7 +607,7 @@ fn link_binary(sess: session,
}
let ula = cstore::get_used_link_args(cstore);
for ula.each {|arg| vec::push(cc_args, arg); }
for ula.each |arg| { vec::push(cc_args, arg); }
// # Native library linking
@ -617,11 +618,11 @@ fn link_binary(sess: session,
// forces to make sure that library can be found at runtime.
let addl_paths = sess.opts.addl_lib_search_paths;
for addl_paths.each {|path| vec::push(cc_args, "-L" + path); }
for addl_paths.each |path| { vec::push(cc_args, "-L" + path); }
// The names of the native libraries
let used_libs = cstore::get_used_libraries(cstore);
for used_libs.each {|l| vec::push(cc_args, "-l" + l); }
for used_libs.each |l| { vec::push(cc_args, "-l" + l); }
if sess.building_library {
vec::push(cc_args, lib_cmd);

View file

@ -45,7 +45,7 @@ fn get_sysroot_absolute_rt_lib(sess: session::session) -> path::path {
}
fn rpaths_to_flags(rpaths: ~[str]) -> ~[str] {
vec::map(rpaths, { |rpath| #fmt("-Wl,-rpath,%s",rpath)})
vec::map(rpaths, |rpath| #fmt("-Wl,-rpath,%s",rpath) )
}
fn get_rpaths(os: session::os, cwd: path::path, sysroot: path::path,
@ -55,7 +55,7 @@ fn get_rpaths(os: session::os, cwd: path::path, sysroot: path::path,
#debug("sysroot: %s", sysroot);
#debug("output: %s", output);
#debug("libs:");
for libs.each {|libpath|
for libs.each |libpath| {
#debug(" %s", libpath);
}
#debug("target_triple: %s", target_triple);
@ -74,7 +74,7 @@ fn get_rpaths(os: session::os, cwd: path::path, sysroot: path::path,
fn log_rpaths(desc: str, rpaths: ~[str]) {
#debug("%s rpaths:", desc);
for rpaths.each {|rpath|
for rpaths.each |rpath| {
#debug(" %s", rpath);
}
}
@ -96,7 +96,7 @@ fn get_rpaths_relative_to_output(os: session::os,
cwd: path::path,
output: path::path,
libs: ~[path::path]) -> ~[str] {
vec::map(libs, {|a|
vec::map(libs, |a| {
check not_win32(os);
get_rpath_relative_to_output(os, cwd, output, a)
})
@ -142,7 +142,7 @@ fn get_relative_to(abs1: path::path, abs2: path::path) -> path::path {
}
let mut path = ~[];
for uint::range(start_idx, len1 - 1u) {|_i| vec::push(path, ".."); };
for uint::range(start_idx, len1 - 1u) |_i| { vec::push(path, ".."); };
vec::push_all(path, vec::view(split2, start_idx, len2 - 1u));
@ -154,7 +154,7 @@ fn get_relative_to(abs1: path::path, abs2: path::path) -> path::path {
}
fn get_absolute_rpaths(cwd: path::path, libs: ~[path::path]) -> ~[str] {
vec::map(libs, {|a|get_absolute_rpath(cwd, a)})
vec::map(libs, |a| get_absolute_rpath(cwd, a) )
}
fn get_absolute_rpath(cwd: path::path, &&lib: path::path) -> str {
@ -185,7 +185,7 @@ fn get_install_prefix_rpath(cwd: path::path, target_triple: str) -> str {
fn minimize_rpaths(rpaths: ~[str]) -> ~[str] {
let set = map::str_hash::<()>();
let mut minimized = ~[];
for rpaths.each {|rpath|
for rpaths.each |rpath| {
if !set.contains_key(rpath) {
vec::push(minimized, rpath);
set.insert(rpath, ());

View file

@ -36,15 +36,15 @@ fn declare_upcalls(targ_cfg: @session::config,
tys: ~[TypeRef], rv: TypeRef) ->
ValueRef {
let mut arg_tys: ~[TypeRef] = ~[];
for tys.each {|t| vec::push(arg_tys, t); }
for tys.each |t| { vec::push(arg_tys, t); }
let fn_ty = T_fn(arg_tys, rv);
ret base::decl_cdecl_fn(llmod, prefix + name, fn_ty);
}
fn nothrow(f: ValueRef) -> ValueRef {
base::set_no_unwind(f); f
}
let d = {|a,b,c|decl(llmod, "upcall_", a, b, c)};
let dv = {|a,b|decl(llmod, "upcall_", a, b, T_void())};
let d = |a,b,c| decl(llmod, "upcall_", a, b, c);
let dv = |a,b| decl(llmod, "upcall_", a, b, T_void());
let int_t = T_int(targ_cfg);
let size_t = T_size_t(targ_cfg);

View file

@ -82,7 +82,7 @@ fn parse_cfgspecs(cfgspecs: ~[str]) -> ast::crate_cfg {
// varieties of meta_item here. At the moment we just support the
// meta_word variant.
let mut words = ~[];
for cfgspecs.each {|s| vec::push(words, attr::mk_word_item(@s)); }
for cfgspecs.each |s| { vec::push(words, attr::mk_word_item(@s)); }
ret words;
}
@ -131,95 +131,111 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
-> {crate: @ast::crate, tcx: option<ty::ctxt>} {
let time_passes = sess.time_passes();
let mut crate = time(time_passes, "parsing",
{||parse_input(sess, cfg, input)});
||parse_input(sess, cfg, input) );
if upto == cu_parse { ret {crate: crate, tcx: none}; }
sess.building_library = session::building_library(
sess.opts.crate_type, crate, sess.opts.test);
crate =
time(time_passes, "configuration",
{|copy crate|front::config::strip_unconfigured_items(crate)});
crate =
time(time_passes, "maybe building test harness",
{|copy crate|front::test::modify_for_testing(sess, crate)});
crate =
time(time_passes, "expansion",
{|copy crate|syntax::ext::expand::expand_crate(
sess.parse_sess, sess.opts.cfg, crate)});
crate = time(time_passes, "configuration", |copy crate| {
front::config::strip_unconfigured_items(crate)
});
crate = time(time_passes, "maybe building test harness", |copy crate| {
front::test::modify_for_testing(sess, crate)
});
crate = time(time_passes, "expansion", |copy crate| {
syntax::ext::expand::expand_crate(
sess.parse_sess, sess.opts.cfg, crate)
});
if upto == cu_expand { ret {crate: crate, tcx: none}; }
crate =
time(time_passes, "intrinsic injection", {|copy crate|
crate = time(time_passes, "intrinsic injection", |copy crate| {
front::intrinsic_inject::inject_intrinsic(sess, crate)
});
crate =
time(time_passes, "core injection", {|copy crate|
crate = time(time_passes, "core injection", |copy crate| {
front::core_inject::maybe_inject_libcore_ref(sess, crate)
});
time(time_passes, "building warning settings table", {|copy crate|
time(time_passes, "building warning settings table", |copy crate| {
lint::build_settings_crate(sess, crate)
});
let ast_map =
time(time_passes, "ast indexing", {|copy crate|
let ast_map = time(time_passes, "ast indexing", |copy crate| {
syntax::ast_map::map_crate(sess.diagnostic(), *crate)
});
time(time_passes, "external crate/lib resolution", {|copy crate|
time(time_passes, "external crate/lib resolution", |copy crate| {
creader::read_crates(
sess.diagnostic(), *crate, sess.cstore,
sess.filesearch,
session::sess_os_to_meta_os(sess.targ_cfg.os),
sess.opts.static)
});
let {def_map, exp_map, impl_map} =
time(time_passes, "resolution", {|copy crate|
let { def_map, exp_map, impl_map
} = time(time_passes, "resolution", |copy crate| {
resolve::resolve_crate(sess, ast_map, crate)
});
let freevars =
time(time_passes, "freevar finding", {|copy crate|
let freevars = time(time_passes, "freevar finding", |copy crate| {
freevars::annotate_freevars(def_map, crate)
});
let region_map =
time(time_passes, "region resolution", {|copy crate|
let region_map = time(time_passes, "region resolution", |copy crate| {
middle::region::resolve_crate(sess, def_map, crate)
});
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars, region_map);
let (method_map, vtable_map) =
time(time_passes, "typechecking", {|copy crate|
let ( method_map, vtable_map
) = time(time_passes, "typechecking", |copy crate| {
typeck::check_crate(ty_cx, impl_map, crate)
});
time(time_passes, "const checking", {|copy crate|
time(time_passes, "const checking", |copy crate| {
middle::check_const::check_crate(
sess, crate, ast_map, def_map, method_map, ty_cx)
});
if upto == cu_typeck { ret {crate: crate, tcx: some(ty_cx)}; }
time(time_passes, "block-use checking",
{|copy crate|middle::block_use::check_crate(ty_cx, crate)});
time(time_passes, "loop checking",
{|copy crate|middle::check_loop::check_crate(ty_cx, crate)});
time(time_passes, "alt checking",
{|copy crate|middle::check_alt::check_crate(ty_cx, crate)});
let last_use_map =
time(time_passes, "liveness checking", {|copy crate|
time(time_passes, "block-use checking", |copy crate| {
middle::block_use::check_crate(ty_cx, crate)
});
time(time_passes, "loop checking", |copy crate| {
middle::check_loop::check_crate(ty_cx, crate)
});
time(time_passes, "alt checking", |copy crate| {
middle::check_alt::check_crate(ty_cx, crate)
});
let last_use_map = time(time_passes, "liveness checking", |copy crate| {
middle::liveness::check_crate(ty_cx, method_map, crate)
});
time(time_passes, "typestate checking",
{|copy crate|middle::tstate::ck::check_crate(ty_cx, crate)});
let (root_map, mutbl_map) = time(
time_passes, "borrow checking",
{|copy crate|middle::borrowck::check_crate(ty_cx, method_map,
last_use_map, crate)});
time(time_passes, "kind checking", {|copy crate|
time(time_passes, "typestate checking", |copy crate| {
middle::tstate::ck::check_crate(ty_cx, crate)
});
let ( root_map, mutbl_map
) = time(time_passes, "borrow checking", |copy crate| {
middle::borrowck::check_crate(ty_cx, method_map,
last_use_map, crate)
});
time(time_passes, "kind checking", |copy crate| {
kind::check_crate(ty_cx, method_map, last_use_map, crate)
});
time(time_passes, "lint checking",
{|copy crate|lint::check_crate(ty_cx, crate)});
time(time_passes, "lint checking", |copy crate| {
lint::check_crate(ty_cx, crate)
});
if upto == cu_no_trans { ret {crate: crate, tcx: some(ty_cx)}; }
let outputs = option::get(outputs);
@ -229,13 +245,14 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
impl_map: impl_map, method_map: method_map,
vtable_map: vtable_map};
let (llmod, link_meta) =
time(time_passes, "translation",
{|copy crate|trans::base::trans_crate(
sess, crate, ty_cx, outputs.obj_filename,
exp_map, maps)});
time(time_passes, "LLVM passes",
{||link::write::run_passes(sess, llmod, outputs.obj_filename)});
let (llmod, link_meta) = time(time_passes, "translation", |copy crate| {
trans::base::trans_crate(sess, crate, ty_cx, outputs.obj_filename,
exp_map, maps)
});
time(time_passes, "LLVM passes", || {
link::write::run_passes(sess, llmod, outputs.obj_filename)
});
let stop_after_codegen =
sess.opts.output_type != link::output_type_exe ||
@ -243,9 +260,11 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
if stop_after_codegen { ret {crate: crate, tcx: some(ty_cx)}; }
time(time_passes, "linking",
{||link::link_binary(sess, outputs.obj_filename,
outputs.out_filename, link_meta)});
time(time_passes, "linking", || {
link::link_binary(sess, outputs.obj_filename,
outputs.out_filename, link_meta)
});
ret {crate: crate, tcx: some(ty_cx)};
}
@ -313,7 +332,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
let ann = alt ppm {
ppm_typed {
{pre: ann_paren_for_expr,
post: {|a|ann_typed_post(option::get(tcx), a)}}
post: |a| ann_typed_post(option::get(tcx), a) }
}
ppm_identified | ppm_expanded_identified {
{pre: ann_paren_for_expr, post: ann_identified_post}
@ -322,7 +341,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
};
let is_expanded = upto != cu_parse;
let src = codemap::get_filemap(sess.codemap, source_name(input)).src;
do io::with_str_reader(*src) { |rdr|
do io::with_str_reader(*src) |rdr| {
pprust::print_crate(sess.codemap, sess.span_diagnostic, crate,
source_name(input),
rdr, io::stdout(), ann, is_expanded);
@ -417,7 +436,7 @@ fn build_session_options(match: getopts::match,
let lint_flags = vec::append(getopts::opt_strs(match, "W"),
getopts::opt_strs(match, "warn"));
let lint_dict = lint::get_lint_dict();
let lint_opts = do vec::map(lint_flags) {|flag|
let lint_opts = do vec::map(lint_flags) |flag| {
alt lint::lookup_lint(lint_dict, flag) {
(flag, none) {
early_error(demitter, #fmt("unknown warning: %s", flag))
@ -429,9 +448,9 @@ fn build_session_options(match: getopts::match,
let mut debugging_opts = 0u;
let debug_flags = getopts::opt_strs(match, "Z");
let debug_map = session::debugging_opts_map();
for debug_flags.each { |debug_flag|
for debug_flags.each |debug_flag| {
let mut this_bit = 0u;
for debug_map.each { |pair|
for debug_map.each |pair| {
let (name, _, bit) = pair;
if name == debug_flag { this_bit = bit; break; }
}

View file

@ -80,7 +80,7 @@ Options:
fn describe_warnings() {
let lint_dict = lint::get_lint_dict();
let mut max_key = 0u;
for lint_dict.each_key {|k| max_key = uint::max(k.len(), max_key); }
for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); }
fn padded(max: uint, s: str) -> str {
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
}
@ -89,7 +89,7 @@ fn describe_warnings() {
padded(max_key, "name"), "default", "meaning"));
io::println(#fmt(" %s %7.7s %s\n",
padded(max_key, "----"), "-------", "-------"));
for lint_dict.each {|k, v|
for lint_dict.each |k, v| {
let k = str::replace(k, "_", "-");
io::println(#fmt(" %s %7.7s %s",
padded(max_key, k),
@ -103,7 +103,7 @@ fn describe_warnings() {
fn describe_debug_flags() {
io::println(#fmt("\nAvailable debug options:\n"));
for session::debugging_opts_map().each { |pair|
for session::debugging_opts_map().each |pair| {
let (name, desc, _) = pair;
io::println(#fmt(" -Z%-20s -- %s", name, desc));
}
@ -169,7 +169,7 @@ fn run_compiler(args: ~[str], demitter: diagnostic::emitter) {
let pretty =
option::map(getopts::opt_default(match, "pretty",
"normal"),
{|a|parse_pretty(sess, a)});
|a| parse_pretty(sess, a) );
alt pretty {
some::<pp_mode>(ppm) { pretty_print_input(sess, cfg, input, ppm); ret; }
none::<pp_mode> {/* continue */ }
@ -211,7 +211,7 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
let p = comm::port();
let ch = comm::chan(p);
alt do task::try {||
alt do task::try || {
// The 'diagnostics emitter'. Every error, warning, etc. should
// go through this function.
@ -248,7 +248,7 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
"try running with RUST_LOG=rustc=0,::rt::backtrace \
to get further details and report the results \
to github.com/mozilla/rust/issues"
]/_.each {|note|
]/_.each |note| {
diagnostic::emit(none, note, diagnostic::note)
}
}
@ -259,7 +259,7 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
}
fn main(args: ~[str]) {
do monitor {|demitter|
do monitor |demitter| {
run_compiler(args, demitter);
}
}

View file

@ -13,7 +13,7 @@ type ctxt = @{
// Support conditional compilation by transforming the AST, stripping out
// any items that do not belong in the current configuration
fn strip_unconfigured_items(crate: @ast::crate) -> @ast::crate {
do strip_items(crate) {|attrs|
do strip_items(crate) |attrs| {
in_cfg(crate.node.config, attrs)
}
}
@ -24,9 +24,9 @@ fn strip_items(crate: @ast::crate, in_cfg: in_cfg_pred)
let ctxt = @{in_cfg: in_cfg};
let precursor =
@{fold_mod: {|a,b|fold_mod(ctxt, a, b)},
fold_block: fold::wrap({|a,b|fold_block(ctxt, a, b)}),
fold_foreign_mod: {|a,b|fold_foreign_mod(ctxt, a, b)}
@{fold_mod: |a,b| fold_mod(ctxt, a, b),
fold_block: fold::wrap(|a,b| fold_block(ctxt, a, b) ),
fold_foreign_mod: |a,b| fold_foreign_mod(ctxt, a, b)
with *fold::default_ast_fold()};
let fold = fold::make_fold(precursor);
@ -41,7 +41,7 @@ fn filter_item(cx: ctxt, &&item: @ast::item) ->
fn fold_mod(cx: ctxt, m: ast::_mod, fld: fold::ast_fold) ->
ast::_mod {
let filter = {|a|filter_item(cx, a)};
let filter = |a| filter_item(cx, a);
let filtered_items = vec::filter_map(m.items, filter);
ret {view_items: vec::map(m.view_items, fld.fold_view_item),
items: vec::map(filtered_items, fld.fold_item)};
@ -56,7 +56,7 @@ fn filter_foreign_item(cx: ctxt, &&item: @ast::foreign_item) ->
fn fold_foreign_mod(cx: ctxt, nm: ast::foreign_mod,
fld: fold::ast_fold) -> ast::foreign_mod {
let filter = {|a|filter_foreign_item(cx, a)};
let filter = |a| filter_foreign_item(cx, a);
let filtered_items = vec::filter_map(nm.items, filter);
ret {view_items: vec::map(nm.view_items, fld.fold_view_item),
items: filtered_items};
@ -81,7 +81,7 @@ fn filter_stmt(cx: ctxt, &&stmt: @ast::stmt) ->
fn fold_block(cx: ctxt, b: ast::blk_, fld: fold::ast_fold) ->
ast::blk_ {
let filter = {|a|filter_stmt(cx, a)};
let filter = |a| filter_stmt(cx, a);
let filtered_stmts = vec::filter_map(b.stmts, filter);
ret {view_items: b.view_items,
stmts: vec::map(filtered_stmts, fld.fold_stmt),
@ -113,12 +113,12 @@ fn metas_in_cfg(cfg: ast::crate_cfg, metas: ~[@ast::meta_item]) -> bool {
// so we can match against them. This is the list of configurations for
// which the item is valid
let cfg_metas = vec::concat(vec::filter_map(cfg_metas,
{|&&i| attr::get_meta_item_list(i)}));
|&&i| attr::get_meta_item_list(i) ));
let has_cfg_metas = vec::len(cfg_metas) > 0u;
if !has_cfg_metas { ret true; }
for cfg_metas.each {|cfg_mi|
for cfg_metas.each |cfg_mi| {
if attr::contains(cfg, cfg_mi) { ret true; }
}

View file

@ -45,9 +45,9 @@ fn generate_test_harness(sess: session::session,
testfns: dvec()};
let precursor =
@{fold_crate: fold::wrap({|a,b|fold_crate(cx, a, b)}),
fold_item: {|a,b|fold_item(cx, a, b)},
fold_mod: {|a,b|fold_mod(cx, a, b)} with *fold::default_ast_fold()};
@{fold_crate: fold::wrap(|a,b| fold_crate(cx, a, b) ),
fold_item: |a,b| fold_item(cx, a, b),
fold_mod: |a,b| fold_mod(cx, a, b) with *fold::default_ast_fold()};
let fold = fold::make_fold(precursor);
let res = @fold.fold_crate(*crate);
@ -57,7 +57,7 @@ fn generate_test_harness(sess: session::session,
fn strip_test_functions(crate: @ast::crate) -> @ast::crate {
// When not compiling with --test we should not compile the
// #[test] functions
do config::strip_items(crate) {|attrs|
do config::strip_items(crate) |attrs| {
!attr::contains_name(attr::attr_metas(attrs), "test")
}
}
@ -147,7 +147,7 @@ fn is_ignored(cx: test_ctxt, i: @ast::item) -> bool {
let ignoreattrs = attr::find_attrs_by_name(i.attrs, "ignore");
let ignoreitems = attr::attr_metas(ignoreattrs);
let cfg_metas = vec::concat(vec::filter_map(ignoreitems,
{|&&i| attr::get_meta_item_list(i)}));
|&&i| attr::get_meta_item_list(i) ));
ret if vec::is_not_empty(ignoreitems) {
config::metas_in_cfg(cx.crate.node.config, cfg_metas)
} else {
@ -278,7 +278,7 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
#debug("building test vector from %u tests", cx.testfns.len());
let mut descs = ~[];
for cx.testfns.each {|test|
for cx.testfns.each |test| {
vec::push(descs, mk_test_desc_rec(cx, test));
}

View file

@ -1029,7 +1029,7 @@ fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) ->
tys: ~[TypeRef]) -> str {
let mut s: str = "";
let mut first: bool = true;
for tys.each {|t|
for tys.each |t| {
if first { first = false; } else { s += ", "; }
s += type_to_str_inner(names, outer, t);
}
@ -1079,7 +1079,7 @@ fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) ->
}
Pointer {
let mut i: uint = 0u;
for outer0.each {|tout|
for outer0.each |tout| {
i += 1u;
if tout as int == ty as int {
let n: uint = vec::len::<TypeRef>(outer0) - i;
@ -1133,7 +1133,7 @@ type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
fn mk_target_data(string_rep: str) -> target_data {
let lltd =
str::as_c_str(string_rep, {|buf| llvm::LLVMCreateTargetData(buf) });
str::as_c_str(string_rep, |buf| llvm::LLVMCreateTargetData(buf) );
ret {lltd: lltd, dtor: @target_data_res(lltd)};
}

View file

@ -128,7 +128,7 @@ fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); }
fn hash_path(&&s: str) -> uint {
let mut h = 5381u;
for str::each(s) {|ch| h = (h << 5u) + h ^ (ch as uint); }
for str::each(s) |ch| { h = (h << 5u) + h ^ (ch as uint); }
ret h;
}

View file

@ -31,8 +31,8 @@ fn read_crates(diag: span_handler, crate: ast::crate,
mut next_crate_num: 1};
let v =
visit::mk_simple_visitor(@{visit_view_item:
{|a|visit_view_item(e, a)},
visit_item: {|a|visit_item(e, a)}
|a| visit_view_item(e, a),
visit_item: |a| visit_item(e, a)
with *visit::default_simple_visitor()});
visit::visit_crate(crate, (), v);
dump_crates(e.crate_cache);
@ -48,14 +48,14 @@ type cache_entry = {
fn dump_crates(crate_cache: dvec<cache_entry>) {
#debug("resolved crates:");
for crate_cache.each {|entry|
for crate_cache.each |entry| {
#debug("cnum: %?", entry.cnum);
#debug("span: %?", entry.span);
#debug("hash: %?", entry.hash);
let attrs = ~[
attr::mk_attr(attr::mk_list_item(@"link", *entry.metas))
];
for attr::find_linkage_attrs(attrs).each {|attr|
for attr::find_linkage_attrs(attrs).each |attr| {
#debug("meta: %s", pprust::attr_to_str(attr));
}
}
@ -68,7 +68,7 @@ fn warn_if_multiple_versions(diag: span_handler,
if crate_cache.len() != 0u {
let name = loader::crate_name_from_metas(*crate_cache.last().metas);
let {lefts: matches, rights: non_matches} =
partition(crate_cache.map_to_vec({|entry|
partition(crate_cache.map_to_vec(|entry| {
let othername = loader::crate_name_from_metas(*entry.metas);
if name == othername {
left(entry)
@ -82,7 +82,7 @@ fn warn_if_multiple_versions(diag: span_handler,
if matches.len() != 1u {
diag.handler().warn(
#fmt("using multiple versions of crate `%s`", *name));
for matches.each {|match|
for matches.each |match| {
diag.span_note(match.span, "used here");
let attrs = ~[
attr::mk_attr(attr::mk_list_item(@"link", *match.metas))
@ -147,7 +147,7 @@ fn visit_item(e: env, i: @ast::item) {
e.diag.span_fatal(i.span, "library '" + *foreign_name +
"' already added: can't specify link_args.");
}
for link_args.each {|a|
for link_args.each |a| {
alt attr::get_meta_item_value_str(attr::attr_meta(a)) {
some(linkarg) {
cstore::add_used_link_args(cstore, *linkarg);
@ -178,7 +178,7 @@ fn metas_with_ident(ident: ast::ident,
fn existing_match(e: env, metas: ~[@ast::meta_item], hash: str) ->
option<int> {
for e.crate_cache.each {|c|
for e.crate_cache.each |c| {
if loader::metadata_matches(*c.metas, metas)
&& (hash.is_empty() || *c.hash == hash) {
ret some(c.cnum);
@ -246,7 +246,7 @@ fn resolve_crate_deps(e: env, cdata: @~[u8]) -> cstore::cnum_map {
// The map from crate numbers in the crate we're resolving to local crate
// numbers
let cnum_map = int_hash::<ast::crate_num>();
for decoder::get_crate_deps(cdata).each {|dep|
for decoder::get_crate_deps(cdata).each |dep| {
let extrn_cnum = dep.cnum;
let cname = dep.name;
let cmetas = metas_with(dep.vers, @"vers", ~[]);

View file

@ -42,7 +42,7 @@ fn lookup_defs(cstore: cstore::cstore, cnum: ast::crate_num,
path: ~[ast::ident]) -> ~[ast::def] {
let mut result = ~[];
#debug("lookup_defs: path = %? cnum = %?", path, cnum);
for resolve_path(cstore, cnum, path).each {|elt|
for resolve_path(cstore, cnum, path).each |elt| {
let (c, data, def) = elt;
vec::push(result, decoder::lookup_def(c, data, def));
}
@ -66,7 +66,7 @@ fn resolve_path(cstore: cstore::cstore, cnum: ast::crate_num,
#debug("resolve_path %s in crates[%d]:%s",
ast_util::path_name_i(path), cnum, cm.name);
let mut result = ~[];
for decoder::resolve_path(path, cm.data).each {|def|
for decoder::resolve_path(path, cm.data).each |def| {
if def.crate == ast::local_crate {
vec::push(result, (cnum, cm.data, def));
} else {
@ -120,7 +120,7 @@ fn get_impls_for_mod(cstore: cstore::cstore, def: ast::def_id,
name: option<ast::ident>)
-> @~[@decoder::_impl] {
let cdata = cstore::get_crate_data(cstore, def.crate);
do decoder::get_impls_for_mod(cdata, def.node, name) {|cnum|
do decoder::get_impls_for_mod(cdata, def.node, name) |cnum| {
cstore::get_crate_data(cstore, cnum)
}
}
@ -151,13 +151,13 @@ fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
#debug("Looking up %?", class_id);
let class_doc = expect(tcx.diag,
decoder::maybe_find_item(class_id.node, all_items),
{|| #fmt("get_field_type: class ID %? not found",
class_id)});
|| #fmt("get_field_type: class ID %? not found",
class_id) );
#debug("looking up %? : %?", def, class_doc);
let the_field = expect(tcx.diag,
decoder::maybe_find_item(def.node, class_doc),
{|| #fmt("get_field_type: in class %?, field ID %? not found",
class_id, def)});
|| #fmt("get_field_type: in class %?, field ID %? not found",
class_id, def) );
#debug("got field data %?", the_field);
let ty = decoder::item_type(def, the_field, tcx, cdata);
ret {bounds: @~[], rp: ast::rp_none, ty: ty};

View file

@ -96,7 +96,7 @@ fn get_crate_vers(cstore: cstore, cnum: ast::crate_num) -> @str {
fn set_crate_data(cstore: cstore, cnum: ast::crate_num,
data: crate_metadata) {
p(cstore).metas.insert(cnum, data);
do vec::iter(decoder::get_crate_module_paths(data.data)) {|dp|
do vec::iter(decoder::get_crate_module_paths(data.data)) |dp| {
let (did, path) = dp;
let d = {crate: cnum, node: did.node};
p(cstore).mod_path_map.insert(d, @path);
@ -108,7 +108,7 @@ fn have_crate_data(cstore: cstore, cnum: ast::crate_num) -> bool {
}
fn iter_crate_data(cstore: cstore, i: fn(ast::crate_num, crate_metadata)) {
for p(cstore).metas.each {|k,v| i(k, v);};
for p(cstore).metas.each |k,v| { i(k, v);};
}
fn add_used_crate_file(cstore: cstore, lib: str) {
@ -157,7 +157,7 @@ fn get_dep_hashes(cstore: cstore) -> ~[@str] {
type crate_hash = {name: @str, hash: @str};
let mut result = ~[];
for p(cstore).use_crate_map.each_value {|cnum|
for p(cstore).use_crate_map.each_value |cnum| {
let cdata = cstore::get_crate_data(cstore, cnum);
let hash = decoder::get_crate_hash(cdata.data);
#debug("Add hash[%s]: %s", cdata.name, *hash);
@ -168,7 +168,7 @@ fn get_dep_hashes(cstore: cstore) -> ~[@str] {
}
let sorted = std::sort::merge_sort(lteq, result);
#debug("sorted:");
for sorted.each {|x|
for sorted.each |x| {
#debug(" hash[%s]: %s", *x.name, *x.hash);
}
fn mapper(ch: crate_hash) -> @str { ret ch.hash; }
@ -178,7 +178,7 @@ fn get_dep_hashes(cstore: cstore) -> ~[@str] {
fn get_path(cstore: cstore, d: ast::def_id) -> ~[ast::ident] {
// let f = bind str::split_str(_, "::");
option::map_default(p(cstore).mod_path_map.find(d), ~[],
{|ds| str::split_str(*ds, "::").map({|x|@x})})
|ds| str::split_str(*ds, "::").map(|x| @x ) )
}
// Local Variables:
// mode: rust

View file

@ -64,7 +64,7 @@ fn lookup_hash(d: ebml::doc, eq_fn: fn@(~[u8]) -> bool, hash: uint) ->
let mut result: ~[ebml::doc] = ~[];
let belt = tag_index_buckets_bucket_elt;
do ebml::tagged_docs(bucket, belt) {|elt|
do ebml::tagged_docs(bucket, belt) |elt| {
let pos = io::u64_from_be_bytes(*elt.data, elt.start, 4u) as uint;
if eq_fn(vec::slice::<u8>(*elt.data, elt.start + 4u, elt.end)) {
vec::push(result, ebml::doc_at(d.data, pos).doc);
@ -77,7 +77,7 @@ fn maybe_find_item(item_id: int, items: ebml::doc) -> option<ebml::doc> {
fn eq_item(bytes: ~[u8], item_id: int) -> bool {
ret io::u64_from_be_bytes(bytes, 0u, 4u) as int == item_id;
}
let eqer = {|a|eq_item(a, item_id)};
let eqer = |a| eq_item(a, item_id);
let found = lookup_hash(items, eqer, hash_node_id(item_id));
if vec::len(found) == 0u {
ret option::none::<ebml::doc>;
@ -110,7 +110,7 @@ fn item_symbol(item: ebml::doc) -> str {
fn item_parent_item(d: ebml::doc) -> option<ast::def_id> {
let mut found = none;
do ebml::tagged_docs(d, tag_items_data_parent_item) {|did|
do ebml::tagged_docs(d, tag_items_data_parent_item) |did| {
found = some(parse_def_id(ebml::doc_data(did)));
}
found
@ -123,9 +123,10 @@ fn class_member_id(d: ebml::doc, cdata: cmd) -> ast::def_id {
fn field_mutability(d: ebml::doc) -> ast::class_mutability {
// Use maybe_get_doc in case it's a method
option::map_default(ebml::maybe_get_doc(d, tag_class_mut),
option::map_default(
ebml::maybe_get_doc(d, tag_class_mut),
ast::class_immutable,
{|d|
|d| {
alt ebml::doc_as_u8(d) as char {
'm' { ast::class_mutable }
_ { ast::class_immutable }
@ -134,14 +135,14 @@ fn field_mutability(d: ebml::doc) -> ast::class_mutability {
}
fn variant_disr_val(d: ebml::doc) -> option<int> {
do option::chain(ebml::maybe_get_doc(d, tag_disr_val)) {|val_doc|
do option::chain(ebml::maybe_get_doc(d, tag_disr_val)) |val_doc| {
int::parse_buf(ebml::doc_data(val_doc), 10u)
}
}
fn doc_type(doc: ebml::doc, tcx: ty::ctxt, cdata: cmd) -> ty::t {
let tp = ebml::get_doc(doc, tag_items_data_item_type);
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx, {|did|
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx, |did| {
translate_def_id(cdata, did)
})
}
@ -157,7 +158,7 @@ fn item_type(item_id: ast::def_id, item: ebml::doc,
fn item_impl_iface(item: ebml::doc, tcx: ty::ctxt, cdata: cmd)
-> option<ty::t> {
let mut result = none;
do ebml::tagged_docs(item, tag_impl_iface) {|ity|
do ebml::tagged_docs(item, tag_impl_iface) |ity| {
result = some(doc_type(ity, tcx, cdata));
};
result
@ -166,8 +167,8 @@ fn item_impl_iface(item: ebml::doc, tcx: ty::ctxt, cdata: cmd)
fn item_ty_param_bounds(item: ebml::doc, tcx: ty::ctxt, cdata: cmd)
-> @~[ty::param_bounds] {
let mut bounds = ~[];
do ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds) {|p|
let bd = parse_bounds_data(p.data, p.start, cdata.cnum, tcx, {|did|
do ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds) |p| {
let bd = parse_bounds_data(p.data, p.start, cdata.cnum, tcx, |did| {
translate_def_id(cdata, did)
});
vec::push(bounds, bd);
@ -190,14 +191,14 @@ fn item_ty_region_param(item: ebml::doc) -> ast::region_param {
fn item_ty_param_count(item: ebml::doc) -> uint {
let mut n = 0u;
ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds,
{|_p| n += 1u; });
|_p| n += 1u );
n
}
fn enum_variant_ids(item: ebml::doc, cdata: cmd) -> ~[ast::def_id] {
let mut ids: ~[ast::def_id] = ~[];
let v = tag_items_data_item_variant;
do ebml::tagged_docs(item, v) {|p|
do ebml::tagged_docs(item, v) |p| {
let ext = parse_def_id(ebml::doc_data(p));
vec::push(ids, {crate: cdata.cnum, node: ext.node});
};
@ -213,10 +214,10 @@ fn resolve_path(path: ~[ast::ident], data: @~[u8]) -> ~[ast::def_id] {
let s = ast_util::path_name_i(path);
let md = ebml::doc(data);
let paths = ebml::get_doc(md, tag_paths);
let eqer = {|a|eq_item(a, s)};
let eqer = |a| eq_item(a, s);
let mut result: ~[ast::def_id] = ~[];
#debug("resolve_path: looking up %s", s);
for lookup_hash(paths, eqer, hash_path(s)).each {|doc|
for lookup_hash(paths, eqer, hash_path(s)).each |doc| {
let did_doc = ebml::get_doc(doc, tag_def_id);
vec::push(result, parse_def_id(ebml::doc_data(did_doc)));
}
@ -232,7 +233,7 @@ fn item_path(item_doc: ebml::doc) -> ast_map::path {
let mut result = ~[];
vec::reserve(result, len);
do ebml::docs(path_doc) {|tag, elt_doc|
do ebml::docs(path_doc) |tag, elt_doc| {
if tag == tag_path_elt_mod {
let str = ebml::doc_as_str(elt_doc);
vec::push(result, ast_map::path_mod(@str));
@ -306,7 +307,7 @@ fn get_impl_method(cdata: cmd, id: ast::node_id,
name: ast::ident) -> ast::def_id {
let items = ebml::get_doc(ebml::doc(cdata.data), tag_items);
let mut found = none;
do ebml::tagged_docs(find_item(id, items), tag_item_impl_method) {|mid|
do ebml::tagged_docs(find_item(id, items), tag_item_impl_method) |mid| {
let m_did = parse_def_id(ebml::doc_data(mid));
if item_name(find_item(m_did.node, items)) == name {
found = some(translate_def_id(cdata, m_did));
@ -323,7 +324,7 @@ fn get_class_method(cdata: cmd, id: ast::node_id,
some(it) { it }
none { fail (#fmt("get_class_method: class id not found \
when looking up method %s", *name)) }};
do ebml::tagged_docs(cls_items, tag_item_iface_method) {|mid|
do ebml::tagged_docs(cls_items, tag_item_iface_method) |mid| {
let m_did = class_member_id(mid, cdata);
if item_name(mid) == name {
found = some(m_did);
@ -343,7 +344,7 @@ fn class_dtor(cdata: cmd, id: ast::node_id) -> option<ast::def_id> {
none { fail (#fmt("class_dtor: class id not found \
when looking up dtor for %d", id)); }
};
do ebml::tagged_docs(cls_items, tag_item_dtor) {|doc|
do ebml::tagged_docs(cls_items, tag_item_dtor) |doc| {
let doc1 = ebml::get_doc(doc, tag_def_id);
let did = parse_def_id(ebml::doc_data(doc1));
found = some(translate_def_id(cdata, did));
@ -399,7 +400,7 @@ fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
let mut infos: ~[ty::variant_info] = ~[];
let variant_ids = enum_variant_ids(item, cdata);
let mut disr_val = 0;
for variant_ids.each {|did|
for variant_ids.each |did| {
let item = find_item(did.node, items);
let ctor_ty = item_type({crate: cdata.cnum, node: id}, item,
tcx, cdata);
@ -407,7 +408,7 @@ fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
let mut arg_tys: ~[ty::t] = ~[];
alt ty::get(ctor_ty).struct {
ty::ty_fn(f) {
for f.inputs.each {|a| vec::push(arg_tys, a.ty); }
for f.inputs.each |a| { vec::push(arg_tys, a.ty); }
}
_ { /* Nullary enum variant. */ }
}
@ -429,7 +430,7 @@ type _impl = {did: ast::def_id, ident: ast::ident, methods: ~[@method_info]};
fn item_impl_methods(cdata: cmd, item: ebml::doc, base_tps: uint)
-> ~[@method_info] {
let mut rslt = ~[];
do ebml::tagged_docs(item, tag_item_impl_method) {|doc|
do ebml::tagged_docs(item, tag_item_impl_method) |doc| {
let m_did = parse_def_id(ebml::doc_data(doc));
let mth_item = lookup_item(m_did.node, cdata.data);
vec::push(rslt, @{did: translate_def_id(cdata, m_did),
@ -447,7 +448,7 @@ fn get_impls_for_mod(cdata: cmd, m_id: ast::node_id,
let data = cdata.data;
let mod_item = lookup_item(m_id, data);
let mut result = ~[];
do ebml::tagged_docs(mod_item, tag_mod_impl) {|doc|
do ebml::tagged_docs(mod_item, tag_mod_impl) |doc| {
let did = parse_def_id(ebml::doc_data(doc));
let local_did = translate_def_id(cdata, did);
// The impl may be defined in a different crate. Ask the caller
@ -473,7 +474,7 @@ fn get_iface_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
let data = cdata.data;
let item = lookup_item(id, data);
let mut result = ~[];
do ebml::tagged_docs(item, tag_item_iface_method) {|mth|
do ebml::tagged_docs(item, tag_item_iface_method) |mth| {
let bounds = item_ty_param_bounds(mth, tcx, cdata);
let name = item_name(mth);
let ty = doc_type(mth, tcx, cdata);
@ -498,7 +499,7 @@ fn get_class_members(cdata: cmd, id: ast::node_id,
let data = cdata.data;
let item = lookup_item(id, data);
let mut result = ~[];
do ebml::tagged_docs(item, tag_item_field) {|an_item|
do ebml::tagged_docs(item, tag_item_field) |an_item| {
let f = item_family(an_item);
if p(f) {
let name = item_name(an_item);
@ -520,7 +521,7 @@ pure fn family_to_visibility(family: char) -> ast::visibility {
/* 'g' for public field, 'j' for private field */
fn get_class_fields(cdata: cmd, id: ast::node_id) -> ~[ty::field_ty] {
get_class_members(cdata, id, {|f| f == 'g' || f == 'j'})
get_class_members(cdata, id, |f| f == 'g' || f == 'j')
}
fn family_has_type_params(fam_ch: char) -> bool {
@ -578,12 +579,12 @@ fn item_family_to_str(fam: char) -> str {
fn get_meta_items(md: ebml::doc) -> ~[@ast::meta_item] {
let mut items: ~[@ast::meta_item] = ~[];
do ebml::tagged_docs(md, tag_meta_item_word) {|meta_item_doc|
do ebml::tagged_docs(md, tag_meta_item_word) |meta_item_doc| {
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
let n = str::from_bytes(ebml::doc_data(nd));
vec::push(items, attr::mk_word_item(@n));
};
do ebml::tagged_docs(md, tag_meta_item_name_value) {|meta_item_doc|
do ebml::tagged_docs(md, tag_meta_item_name_value) |meta_item_doc| {
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
let vd = ebml::get_doc(meta_item_doc, tag_meta_item_value);
let n = str::from_bytes(ebml::doc_data(nd));
@ -592,7 +593,7 @@ fn get_meta_items(md: ebml::doc) -> ~[@ast::meta_item] {
// but currently the encoder just drops them
vec::push(items, attr::mk_name_value_item_str(@n, v));
};
do ebml::tagged_docs(md, tag_meta_item_list) {|meta_item_doc|
do ebml::tagged_docs(md, tag_meta_item_list) |meta_item_doc| {
let nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
let n = str::from_bytes(ebml::doc_data(nd));
let subitems = get_meta_items(meta_item_doc);
@ -605,7 +606,7 @@ fn get_attributes(md: ebml::doc) -> ~[ast::attribute] {
let mut attrs: ~[ast::attribute] = ~[];
alt ebml::maybe_get_doc(md, tag_attributes) {
option::some(attrs_d) {
do ebml::tagged_docs(attrs_d, tag_attribute) {|attr_doc|
do ebml::tagged_docs(attrs_d, tag_attribute) |attr_doc| {
let meta_items = get_meta_items(attr_doc);
// Currently it's only possible to have a single meta item on
// an attribute
@ -622,7 +623,7 @@ fn get_attributes(md: ebml::doc) -> ~[ast::attribute] {
}
fn list_meta_items(meta_items: ebml::doc, out: io::writer) {
for get_meta_items(meta_items).each {|mi|
for get_meta_items(meta_items).each |mi| {
out.write_str(#fmt["%s\n", pprust::meta_item_to_str(*mi)]);
}
}
@ -630,7 +631,7 @@ fn list_meta_items(meta_items: ebml::doc, out: io::writer) {
fn list_crate_attributes(md: ebml::doc, hash: @str, out: io::writer) {
out.write_str(#fmt("=Crate Attributes (%s)=\n", *hash));
for get_attributes(md).each {|attr|
for get_attributes(md).each |attr| {
out.write_str(#fmt["%s\n", pprust::attribute_to_str(attr)]);
}
@ -652,7 +653,7 @@ fn get_crate_deps(data: @~[u8]) -> ~[crate_dep] {
fn docstr(doc: ebml::doc, tag_: uint) -> str {
str::from_bytes(ebml::doc_data(ebml::get_doc(doc, tag_)))
}
do ebml::tagged_docs(depsdoc, tag_crate_dep) {|depdoc|
do ebml::tagged_docs(depsdoc, tag_crate_dep) |depdoc| {
vec::push(deps, {cnum: crate_num,
name: @docstr(depdoc, tag_crate_dep_name),
vers: @docstr(depdoc, tag_crate_dep_vers),
@ -665,7 +666,7 @@ fn get_crate_deps(data: @~[u8]) -> ~[crate_dep] {
fn list_crate_deps(data: @~[u8], out: io::writer) {
out.write_str("=External Dependencies=\n");
for get_crate_deps(data).each {|dep|
for get_crate_deps(data).each |dep| {
out.write_str(#fmt["%d %s-%s-%s\n",
dep.cnum, *dep.name, *dep.hash, *dep.vers]);
}
@ -691,7 +692,7 @@ fn get_crate_vers(data: @~[u8]) -> @str {
fn list_crate_items(bytes: @~[u8], md: ebml::doc, out: io::writer) {
out.write_str("=Items=\n");
let items = ebml::get_doc(md, tag_items);
do iter_crate_items(bytes) {|path, did|
do iter_crate_items(bytes) |path, did| {
out.write_str(#fmt["%s (%s)\n", path, describe_def(items, did)]);
}
out.write_str("\n");
@ -702,9 +703,9 @@ fn iter_crate_items(bytes: @~[u8], proc: fn(str, ast::def_id)) {
let paths = ebml::get_doc(md, tag_paths);
let index = ebml::get_doc(paths, tag_index);
let bs = ebml::get_doc(index, tag_index_buckets);
do ebml::tagged_docs(bs, tag_index_buckets_bucket) {|bucket|
do ebml::tagged_docs(bs, tag_index_buckets_bucket) |bucket| {
let et = tag_index_buckets_bucket_elt;
do ebml::tagged_docs(bucket, et) {|elt|
do ebml::tagged_docs(bucket, et) |elt| {
let data = read_path(elt);
let {tag:_, doc:def} = ebml::doc_at(bytes, data.pos);
let did_doc = ebml::get_doc(def, tag_def_id);
@ -723,7 +724,7 @@ fn get_crate_module_paths(bytes: @~[u8]) -> ~[(ast::def_id, str)] {
// fowarded path due to renamed import or reexport
let mut res = ~[];
let mods = map::str_hash();
do iter_crate_items(bytes) {|path, did|
do iter_crate_items(bytes) |path, did| {
let m = mod_of_path(path);
if str::is_not_empty(m) {
// if m has a sub-item, it must be a module
@ -734,7 +735,7 @@ fn get_crate_module_paths(bytes: @~[u8]) -> ~[(ast::def_id, str)] {
// unified later by using the mods map
vec::push(res, (did, path));
}
ret do vec::filter(res) {|x|
ret do vec::filter(res) |x| {
let (_, xp) = x;
mods.contains_key(xp)
}

View file

@ -87,20 +87,20 @@ fn encode_name_and_def_id(ebml_w: ebml::writer, nm: ident,
}
fn encode_region_param(ebml_w: ebml::writer, rp: region_param) {
do ebml_w.wr_tag(tag_region_param) {||
do ebml_w.wr_tag(tag_region_param) || {
serialize_region_param(ebml_w, rp)
}
}
fn encode_named_def_id(ebml_w: ebml::writer, name: ident, id: def_id) {
do ebml_w.wr_tag(tag_paths_data_item) {||
do ebml_w.wr_tag(tag_paths_data_item) || {
encode_name(ebml_w, name);
encode_def_id(ebml_w, id);
}
}
fn encode_mutability(ebml_w: ebml::writer, mt: class_mutability) {
do ebml_w.wr_tag(tag_class_mut) {||
do ebml_w.wr_tag(tag_class_mut) || {
ebml_w.writer.write(&[alt mt { class_immutable { 'i' }
class_mutable { 'm' } } as u8]);
}
@ -110,9 +110,9 @@ type entry<T> = {val: T, pos: uint};
fn encode_enum_variant_paths(ebml_w: ebml::writer, variants: ~[variant],
path: ~[ident], &index: ~[entry<str>]) {
for variants.each {|variant|
for variants.each |variant| {
add_to_index(ebml_w, path, index, variant.node.name);
do ebml_w.wr_tag(tag_paths_data_item) {||
do ebml_w.wr_tag(tag_paths_data_item) || {
encode_name(ebml_w, variant.node.name);
encode_def_id(ebml_w, local_def(variant.node.id));
}
@ -130,7 +130,7 @@ fn add_to_index(ebml_w: ebml::writer, path: &[ident], &index: ~[entry<str>],
fn encode_foreign_module_item_paths(ebml_w: ebml::writer, nmod: foreign_mod,
path: ~[ident], &index: ~[entry<str>]) {
for nmod.items.each {|nitem|
for nmod.items.each |nitem| {
add_to_index(ebml_w, path, index, nitem.ident);
encode_named_def_id(ebml_w, nitem.ident, local_def(nitem.id));
}
@ -138,7 +138,7 @@ fn encode_foreign_module_item_paths(ebml_w: ebml::writer, nmod: foreign_mod,
fn encode_class_item_paths(ebml_w: ebml::writer,
items: ~[@class_member], path: ~[ident], &index: ~[entry<str>]) {
for items.each {|it|
for items.each |it| {
alt ast_util::class_member_visibility(it) {
private { cont; }
public {
@ -156,7 +156,7 @@ fn encode_class_item_paths(ebml_w: ebml::writer,
fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
module: _mod, path: ~[ident],
&index: ~[entry<str>]) {
for module.items.each {|it|
for module.items.each |it| {
if !reachable(ecx, it.id) ||
!ast_util::is_exported(it.ident, module) { cont; }
if !ast_util::is_item_impl(it) {
@ -170,7 +170,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
encode_named_def_id(ebml_w, it.ident, local_def(it.id));
}
item_mod(_mod) {
do ebml_w.wr_tag(tag_paths_data_mod) {||
do ebml_w.wr_tag(tag_paths_data_mod) || {
encode_name_and_def_id(ebml_w, it.ident, it.id);
encode_module_item_paths(ebml_w, ecx, _mod,
vec::append_one(path, it.ident),
@ -178,7 +178,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
}
}
item_foreign_mod(nmod) {
do ebml_w.wr_tag(tag_paths_data_mod) {||
do ebml_w.wr_tag(tag_paths_data_mod) || {
encode_name_and_def_id(ebml_w, it.ident, it.id);
encode_foreign_module_item_paths(
ebml_w, nmod,
@ -186,15 +186,15 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
}
}
item_ty(_, tps, _) {
do ebml_w.wr_tag(tag_paths_data_item) {||
do ebml_w.wr_tag(tag_paths_data_item) || {
encode_name_and_def_id(ebml_w, it.ident, it.id);
}
}
item_class(_, _, items, ctor, m_dtor, _) {
do ebml_w.wr_tag(tag_paths_data_item) {||
do ebml_w.wr_tag(tag_paths_data_item) || {
encode_name_and_def_id(ebml_w, it.ident, it.id);
}
do ebml_w.wr_tag(tag_paths) {||
do ebml_w.wr_tag(tag_paths) || {
// We add the same ident twice: for the
// class and for its ctor
add_to_index(ebml_w, path, index, it.ident);
@ -206,13 +206,13 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
}
}
item_enum(variants, _, _) {
do ebml_w.wr_tag(tag_paths_data_item) {||
do ebml_w.wr_tag(tag_paths_data_item) || {
encode_name_and_def_id(ebml_w, it.ident, it.id);
}
encode_enum_variant_paths(ebml_w, variants, path, index);
}
item_iface(*) {
do ebml_w.wr_tag(tag_paths_data_item) {||
do ebml_w.wr_tag(tag_paths_data_item) || {
encode_name_and_def_id(ebml_w, it.ident, it.id);
}
}
@ -240,7 +240,7 @@ fn encode_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, crate: @crate)
fn encode_reexport_paths(ebml_w: ebml::writer,
ecx: @encode_ctxt, &index: ~[entry<str>]) {
for ecx.reexports.each {|reexport|
for ecx.reexports.each |reexport| {
let (path, def_id) = reexport;
vec::push(index, {val: path, pos: ebml_w.writer.tell()});
ebml_w.start_tag(tag_paths_data_item);
@ -265,9 +265,9 @@ fn encode_type_param_bounds(ebml_w: ebml::writer, ecx: @encode_ctxt,
let ty_str_ctxt = @{diag: ecx.diag,
ds: def_to_str,
tcx: ecx.tcx,
reachable: {|a|reachable(ecx, a)},
reachable: |a| reachable(ecx, a),
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
for params.each {|param|
for params.each |param| {
ebml_w.start_tag(tag_items_data_item_ty_param_bounds);
let bs = ecx.tcx.ty_param_bounds.get(param.id);
tyencode::enc_bounds(ebml_w.writer, ty_str_ctxt, bs);
@ -286,7 +286,7 @@ fn write_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
@{diag: ecx.diag,
ds: def_to_str,
tcx: ecx.tcx,
reachable: {|a|reachable(ecx, a)},
reachable: |a| reachable(ecx, a),
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
}
@ -335,7 +335,7 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
let mut disr_val = 0;
let mut i = 0;
let vi = ty::enum_variants(ecx.tcx, {crate: local_crate, node: id});
for variants.each {|variant|
for variants.each |variant| {
vec::push(*index, {val: variant.node.id, pos: ebml_w.writer.tell()});
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(variant.node.id));
@ -372,9 +372,9 @@ fn encode_path(ebml_w: ebml::writer,
ebml_w.wr_tagged_str(tag, *name);
}
do ebml_w.wr_tag(tag_path) {||
do ebml_w.wr_tag(tag_path) || {
ebml_w.wr_tagged_u32(tag_path_len, (vec::len(path) + 1u) as u32);
do vec::iter(path) {|pe| encode_path_elt(ebml_w, pe); }
do vec::iter(path) |pe| { encode_path_elt(ebml_w, pe); }
encode_path_elt(ebml_w, name);
}
}
@ -386,7 +386,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
encode_family(ebml_w, 'm');
encode_name(ebml_w, name);
let impls = ecx.impl_map(id);
for impls.each {|i|
for impls.each |i| {
let (ident, did) = i;
if ast_util::is_exported(ident, md) {
ebml_w.start_tag(tag_mod_impl);
@ -432,7 +432,7 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
may have fields with the same name */
let index = @mut ~[];
let tcx = ecx.tcx;
for items.each {|ci|
for items.each |ci| {
/* We encode both private and public fields -- need to include
private fields to get the offsets right */
alt ci.node {
@ -547,7 +547,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
index: @mut ~[entry<int>]) {
vec::push(*index, {val: item.id, pos: ebml_w.writer.tell()});
}
let add_to_index = {|copy ebml_w|add_to_index_(item, ebml_w, index)};
let add_to_index = |copy ebml_w| add_to_index_(item, ebml_w, index);
alt item.node {
item_const(_, _) {
@ -602,13 +602,13 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
}
item_enum(variants, tps, rp) {
add_to_index();
do ebml_w.wr_tag(tag_items_data_item) {||
do ebml_w.wr_tag(tag_items_data_item) || {
encode_def_id(ebml_w, local_def(item.id));
encode_family(ebml_w, 't');
encode_type_param_bounds(ebml_w, ecx, tps);
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
encode_name(ebml_w, item.ident);
for variants.each {|v|
for variants.each |v| {
encode_variant_id(ebml_w, local_def(v.node.id));
}
ecx.encode_inlined_item(ecx, ebml_w, path, ii_item(item));
@ -626,7 +626,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
let idx = encode_info_for_class(ecx, ebml_w, item.id, path, tps,
items, index);
/* Encode the dtor */
do option::iter(m_dtor) {|dtor|
do option::iter(m_dtor) |dtor| {
vec::push(*index, {val: dtor.node.id, pos: ebml_w.writer.tell()});
encode_info_for_fn(ecx, ebml_w, dtor.node.id, @(*item.ident
+ "_dtor"), path, if tps.len() > 0u {
@ -646,13 +646,13 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_name(ebml_w, item.ident);
encode_path(ebml_w, path, ast_map::path_name(item.ident));
encode_region_param(ebml_w, rp);
for ifaces.each {|t|
for ifaces.each |t| {
encode_iface_ref(ebml_w, ecx, t);
}
/* Encode the dtor */
/* Encode id for dtor */
do option::iter(m_dtor) {|dtor|
do ebml_w.wr_tag(tag_item_dtor) {||
do option::iter(m_dtor) |dtor| {
do ebml_w.wr_tag(tag_item_dtor) || {
encode_def_id(ebml_w, local_def(dtor.node.id));
}
};
@ -661,14 +661,14 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
for methods, write all the stuff get_iface_method
needs to know*/
let (fs,ms) = ast_util::split_class_items(items);
for fs.each {|f|
for fs.each |f| {
ebml_w.start_tag(tag_item_field);
encode_visibility(ebml_w, f.vis);
encode_name(ebml_w, f.ident);
encode_def_id(ebml_w, local_def(f.id));
ebml_w.end_tag();
}
for ms.each {|m|
for ms.each |m| {
alt m.vis {
private { /* do nothing */ }
public {
@ -703,12 +703,12 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_type_param_bounds(ebml_w, ecx, tps);
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
encode_name(ebml_w, item.ident);
for methods.each {|m|
for methods.each |m| {
ebml_w.start_tag(tag_item_impl_method);
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id))));
ebml_w.end_tag();
}
do option::iter(ifce) {|t|
do option::iter(ifce) |t| {
encode_iface_ref(ebml_w, ecx, t)
};
encode_path(ebml_w, path, ast_map::path_name(item.ident));
@ -716,7 +716,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
let impl_path = vec::append_one(path,
ast_map::path_name(item.ident));
for methods.each {|m|
for methods.each |m| {
vec::push(*index, {val: m.id, pos: ebml_w.writer.tell()});
encode_info_for_method(ecx, ebml_w, impl_path,
should_inline(m.attrs), item.id, m,
@ -733,7 +733,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
encode_name(ebml_w, item.ident);
let mut i = 0u;
for vec::each(*ty::iface_methods(tcx, local_def(item.id))) {|mty|
for vec::each(*ty::iface_methods(tcx, local_def(item.id))) |mty| {
ebml_w.start_tag(tag_item_iface_method);
encode_name(ebml_w, mty.ident);
encode_type_param_bounds(ebml_w, ecx, ms[i].tps);
@ -782,8 +782,8 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer,
encode_info_for_mod(ecx, ebml_w, crate.node.module,
crate_node_id, ~[], @"");
visit::visit_crate(*crate, (), visit::mk_vt(@{
visit_expr: {|_e, _cx, _v|},
visit_item: {|i, cx, v, copy ebml_w|
visit_expr: |_e, _cx, _v| { },
visit_item: |i, cx, v, copy ebml_w| {
visit::visit_item(i, cx, v);
alt check ecx.tcx.items.get(i.id) {
ast_map::node_item(_, pt) {
@ -806,7 +806,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer,
}
}
},
visit_foreign_item: {|ni, cx, v, copy ebml_w|
visit_foreign_item: |ni, cx, v, copy ebml_w| {
visit::visit_foreign_item(ni, cx, v);
alt check ecx.tcx.items.get(ni.id) {
ast_map::node_foreign_item(_, abi, pt) {
@ -827,14 +827,14 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer,
fn create_index<T: copy>(index: ~[entry<T>], hash_fn: fn@(T) -> uint) ->
~[@~[entry<T>]] {
let mut buckets: ~[@mut ~[entry<T>]] = ~[];
for uint::range(0u, 256u) {|_i| vec::push(buckets, @mut ~[]); };
for index.each {|elt|
for uint::range(0u, 256u) |_i| { vec::push(buckets, @mut ~[]); };
for index.each |elt| {
let h = hash_fn(elt.val);
vec::push(*buckets[h % 256u], elt);
}
let mut buckets_frozen = ~[];
for buckets.each {|bucket|
for buckets.each |bucket| {
vec::push(buckets_frozen, @*bucket);
}
ret buckets_frozen;
@ -846,10 +846,10 @@ fn encode_index<T>(ebml_w: ebml::writer, buckets: ~[@~[entry<T>]],
ebml_w.start_tag(tag_index);
let mut bucket_locs: ~[uint] = ~[];
ebml_w.start_tag(tag_index_buckets);
for buckets.each {|bucket|
for buckets.each |bucket| {
vec::push(bucket_locs, ebml_w.writer.tell());
ebml_w.start_tag(tag_index_buckets_bucket);
for vec::each(*bucket) {|elt|
for vec::each(*bucket) |elt| {
ebml_w.start_tag(tag_index_buckets_bucket_elt);
writer.write_be_uint(elt.pos, 4u);
write_fn(writer, elt.val);
@ -859,7 +859,7 @@ fn encode_index<T>(ebml_w: ebml::writer, buckets: ~[@~[entry<T>]],
}
ebml_w.end_tag();
ebml_w.start_tag(tag_index_table);
for bucket_locs.each {|pos| writer.write_be_uint(pos, 4u); }
for bucket_locs.each |pos| { writer.write_be_uint(pos, 4u); }
ebml_w.end_tag();
ebml_w.end_tag();
}
@ -899,7 +899,7 @@ fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) {
ebml_w.start_tag(tag_meta_item_name);
ebml_w.writer.write(str::bytes(*name));
ebml_w.end_tag();
for items.each {|inner_item|
for items.each |inner_item| {
encode_meta_item(ebml_w, *inner_item);
}
ebml_w.end_tag();
@ -909,7 +909,7 @@ fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) {
fn encode_attributes(ebml_w: ebml::writer, attrs: ~[attribute]) {
ebml_w.start_tag(tag_attributes);
for attrs.each {|attr|
for attrs.each |attr| {
ebml_w.start_tag(tag_attribute);
encode_meta_item(ebml_w, attr.node.value);
ebml_w.end_tag();
@ -948,7 +948,7 @@ fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> ~[attribute] {
let mut attrs: ~[attribute] = ~[];
let mut found_link_attr = false;
for crate.node.attrs.each {|attr|
for crate.node.attrs.each |attr| {
vec::push(
attrs,
if *attr::get_attr_name(attr) != "link" {
@ -977,7 +977,7 @@ fn encode_crate_deps(ebml_w: ebml::writer, cstore: cstore::cstore) {
// Pull the cnums and name,vers,hash out of cstore
let mut deps: ~[mut numdep] = ~[mut];
do cstore::iter_crate_data(cstore) {|key, val|
do cstore::iter_crate_data(cstore) |key, val| {
let dep = {cnum: key, name: @val.name,
vers: decoder::get_crate_vers(val.data),
hash: decoder::get_crate_hash(val.data)};
@ -990,7 +990,7 @@ fn encode_crate_deps(ebml_w: ebml::writer, cstore: cstore::cstore) {
// Sanity-check the crate numbers
let mut expected_cnum = 1;
for deps.each {|n|
for deps.each |n| {
assert (n.cnum == expected_cnum);
expected_cnum += 1;
}
@ -1004,7 +1004,7 @@ fn encode_crate_deps(ebml_w: ebml::writer, cstore: cstore::cstore) {
// FIXME (#2166): This is not nearly enough to support correct versioning
// but is enough to get transitive crate dependencies working.
ebml_w.start_tag(tag_crate_deps);
for get_ordered_deps(cstore).each {|dep|
for get_ordered_deps(cstore).each |dep| {
encode_crate_dep(ebml_w, dep);
}
ebml_w.end_tag();
@ -1081,7 +1081,7 @@ fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> str {
let cx = @{diag: tcx.diag,
ds: def_to_str,
tcx: tcx,
reachable: {|_id| false},
reachable: |_id| false,
abbrevs: tyencode::ac_no_abbrevs};
let buf = io::mem_buffer();
tyencode::enc_ty(io::mem_buffer_writer(buf), cx, t);

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