~~~~
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
}
~~~~
~~~~
# 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';
let v: ~[foo] = ~[a, b, c];
-for v.each {|e|
+for v.each |e| {
bar(e);
}
~~~~
note path;
let r: [str];
let f: file = open_read(path);
- lines(f) {|s|
+ lines(f) |s| {
r += ~[s];
}
ret r;
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);
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
~~~~
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);
### 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
~~~~
# 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
~~~~
# 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);
}
~~~~
`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
`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;
~~~~
fn contains(v: ~[int], elt: int) -> bool {
- for vec::each(v) {|x|
+ for vec::each(v) |x| {
if (x == elt) { ret true; }
}
false
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;
}
~~~~
# 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();
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); }
}
}
~~~~
~~~~
# iface drawable { fn draw(); }
fn draw_all<T: drawable>(shapes: ~[T]) {
- for shapes.each {|shape| shape.draw(); }
+ for shapes.each |shape| { shape.draw(); }
}
~~~~
~~~~
# iface drawable { fn draw(); }
fn draw_all(shapes: ~[drawable]) {
- for shapes.each {|shape| shape.draw(); }
+ for shapes.each |shape| { shape.draw(); }
}
~~~~
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;
}
~~~~
let some_value = 22;
-do task::spawn {||
+do task::spawn || {
io::println("This executes in the child task.");
io::println(#fmt("%d", some_value));
}
# 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);
}
# 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);
}
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);
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') ||
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 {
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 {
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);
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()
});
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);
}
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); }
_ { }
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);
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);
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);
}
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);
}
}
// 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, ~[]);
}
}
};
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")) {
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);
}
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();
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));
}
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 + ")");
}
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));
}
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 + ")");
}
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
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
// 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));
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,
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));
// 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);
}
}
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);
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 = " >> ";
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 {
}
}
} else {
- for c.sources.each_value { |v|
+ for c.sources.each_value |v| {
print_source(v);
}
}
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;
}
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);
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));
}
alt action {
"clear" {
- for c.sources.each_key { |k|
+ for c.sources.each_key |k| {
c.sources.remove(k);
}
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;
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) {
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; }
}
}
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:
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 { }
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);
}
};
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 &&
}
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() {
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) }
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));
}
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;
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);
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)
});
// 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];
}
}
- 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",
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 {
} 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);
}
}
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);
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
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
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);
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);
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) )
})
}
}
}
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;
"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;
}
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;
}
"\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;
}
];
- for confusing_files.each {|f| if contains(filename, f) { ret true; } }
+ for confusing_files.each |f| { if contains(filename, f) { ret true; } }
ret false;
}
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) {
}
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");
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);
}
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
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();
let p = port();
let c = chan(p);
- do task::spawn() {||
+ do task::spawn() || {
let p = port();
c.send(chan(p));
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;
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
};
}
#[test]
fn test_bool_from_str() {
- do all_values { |v|
+ do all_values |v| {
assert some(v) == from_str(bool::to_str(v))
}
}
#[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 };
}
}
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;
}
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;
#[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"]
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);
}
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");
};
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")
}
};
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 }
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]
#[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";
#[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(());
}
}
"]
#[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
#[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);
#[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));
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);
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) {
}
};
- for ts.each { |t| vec::push(v, t) };
+ for ts.each |t| { vec::push(v, t) };
v
}
}
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
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
#[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;
#[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;
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); }
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)
waiting for the result to be received on the port.
"];
- do from_fn {||
+ do from_fn || {
comm::recv(port)
}
}
let mut po = comm::port();
let ch = comm::chan(po);
- do task::spawn {||
+ do task::spawn || {
comm::send(ch, blk())
};
from_port(po)
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 {
#[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";
}
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
fn test_futurefail() {
- let f = spawn({|| fail });
+ let f = spawn(|| fail);
let _x: str = get(f);
}
#[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) }
}
}
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) };
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 {
}
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)
}
}
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 {
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);
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; }
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)
};
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)
}
};
}
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))
})
}
// 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())
})
}
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 {
"]
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> {
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;
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;
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;
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);
}
}
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 {
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;
}
}
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
}
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
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));
}
fn recv<T: send>(p: port<T>) -> T {
- do (*p).with {|cond, data|
+ do (*p).with |cond, data| {
if (*data).len() == 0u {
cond.wait();
}
#[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;
}
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]));
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 {
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;
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, {
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)) {
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)
}
}
// 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);
}
}
// 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);
}
}
}
fn fdopen(fd: c_int) -> *FILE {
- ret do as_c_charp("r") {|modebuf|
+ ret do as_c_charp("r") |modebuf| {
libc::fdopen(fd, modebuf)
};
}
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];
#[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)
}
}
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)
}
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()
}
}
#[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 {
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;
#[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
}
}
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)
}
#[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)
}
}
}
}
- do rustrt::rust_list_files(star(p)).filter {|filename|
+ do rustrt::rust_list_files(star(p)).filter |filename| {
!str::eq(filename, ".") && !str::eq(filename, "..")
}
}
&& 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"]
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)
};
}
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)
};
}
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)
}
}
#[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)
}
};
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);
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)
};
}
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);
setenv("HOME", "");
assert os::homedir() == none;
- option::iter(oldhome, {|s| setenv("HOME", s)});
+ option::iter(oldhome, |s| setenv("HOME", s));
}
#[test]
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
// 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]
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)};
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))}
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
})
}
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)
- }
- })
+ })
}
fn rollup_doubledots(s: ~[path]) -> ~[path] {
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);
// 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);
// 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);
}
#[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);
// 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});
}
}
// 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 };
}
#[test]
fn test_weaken_task_then_unweaken() {
- do task::try {||
+ do task::try || {
unsafe {
- do weaken_task {|_po|
+ do weaken_task |_po| {
}
}
};
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);
}
}
#[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);
}
#[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;
}
}
#[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`."]
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));
}
}
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;
}
}
#[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()
}
}
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 {
}
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);
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);
}
}
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); }
#[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");
}
}
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)
}
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)
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())
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);
::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())
// 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));
};
#debug("beginning stack walk");
- do frame_address { |frame_pointer|
+ do frame_address |frame_pointer| {
let mut frame_address: *word = unsafe {
reinterpret_cast(frame_pointer)
};
#[test]
fn test_simple() {
- for walk_stack { |_frame|
+ for walk_stack |_frame| {
}
}
fn run(i: int) {
if i == 0 { ret }
- for walk_stack { |_frame|
+ for walk_stack |_frame| {
unsafe {
breakpoint();
}
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) =
*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);
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;
}
#[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;
}
"]
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;
}
#[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 }
#[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);
"]
#[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) }
}
}
}
result
} else {
- splitn(s, {|cur| cur == sep}, count)
+ splitn(s, |cur| cur == sep, count)
}
}
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;
}
"]
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
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)); }
}
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 {
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 = "
"]
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); }
}
// 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;
}
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"]
let mut result = "";
unchecked {
reserve(result, len(ss));
- do chars_iter(ss) {|cc|
+ do chars_iter(ss) |cc| {
str::push_char(result, ff(cc));
}
}
}
ret none;
} else {
- find_between(s, start, end, {|x| x == c})
+ find_between(s, start, end, |x| x == c)
}
}
}
ret none;
} else {
- rfind_between(s, start, end, {|x| x == c})
+ rfind_between(s, start, end, |x| x == c)
}
}
// 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;
}
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"]
#[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;
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;
}
"]
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
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 = "
~~~
"]
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))
}
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
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;
}
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;
}
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);
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);
}
#[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 = "
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"]);
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"]);
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);
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]
#[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]
#[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
});
#[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
});
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));
}
#[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'; }
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; }
i += 1;
}
- do bytes_iter("") {|bb| assert bb == 0u8; }
+ bytes_iter("", |bb| assert bb == 0u8);
}
#[test]
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; }
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; }
let mut ii = 0;
- do words_iter(data) {|ww|
+ do words_iter(data) |ww| {
alt ii {
0 { assert "Mary" == ww; }
1 { assert "had" == ww; }
ii += 1;
}
- do words_iter("") {|_x| fail; } // should not fail
+ words_iter("", |_x| fail); // should not fail
}
#[test]
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; }
#[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]
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;
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;
#[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;
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()
}
}
with get_opts(builder)
});
- do future::from_fn {||
+ do future::from_fn || {
alt comm::recv(po) {
exit(_, result) { result }
}
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();
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);
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) {
};
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);
}
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); }
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)
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.
}
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);
}
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);
supervise: false
with default_task_opts()
};
- do spawn_raw(opts) {||
+ do spawn_raw(opts) || {
fail;
}
}
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);
notify_chan: some(notify_ch)
with default_task_opts()
};
- do spawn_raw(opts) {||
+ do spawn_raw(opts) || {
comm::send(task_ch, get_task());
fail;
}
let po = comm::port();
let ch = comm::chan(po);
let buildr = builder();
- do run(buildr) {||
+ do run(buildr) || {
comm::send(ch, ());
}
comm::recv(po);
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);
}
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;
}
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);
}
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);
#[test]
fn test_try_success() {
- alt do try {||
+ alt do try || {
"Success!"
} {
result::ok("Success!") { }
#[test]
#[ignore(cfg(windows))]
fn test_try_fail() {
- alt do try {||
+ alt do try || {
fail
} {
result::err(()) { }
#[should_fail]
#[ignore(cfg(windows))]
fn test_spawn_sched_no_threads() {
- do spawn_sched(manual_threads(0u)) {|| };
+ do spawn_sched(manual_threads(0u)) || { }
}
#[test]
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;
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;
// 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);
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, ());
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);
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);
}
#[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();
});
#[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();
}
}
#[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();
#[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()
};
}
#[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();
}
}
#[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();
}
}
let po = comm::port();
let ch = comm::chan(po);
- do run(buildr) {||
+ do run(buildr) || {
comm::send(ch, ());
}
comm::recv(po);
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
}
unsafe {
- do unkillable {||
+ do unkillable || {
let p = ~0;
let pp: *uint = unsafe::transmute(p);
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";
#[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 }
// 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"); }
}
}
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);
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
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);
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();
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) }
}
}
// 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;
#[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"]
#[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 = "
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>()))
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);
}
// 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) })
}
}
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);
}
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;
}
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;
}
"]
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;
}
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); } }
"]
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;
"]
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;
}
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) };
}
#[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;
#[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;
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;
}
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;
}
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;
}
#[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;
}
"]
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 = "
"]
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 = "
#[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 = "
"]
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);
*/
#[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 {
"]
#[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 {
"]
#[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 {
#[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])
}
}
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 ="
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))
})
}
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));
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 = "
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;
}
}
#[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;
#[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
});
#[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;
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]];
}
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);
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};
}
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
#[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;
}
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);
}
#[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;
"]
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;
}
assert mem as int != 0;
ret unsafe { c_vec_with_dtor(mem as *mut u8, n as uint,
- {||free(mem)}) };
+ ||free(mem)) };
}
#[test]
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;
}
}
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;
}
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),
}
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);
}
}
}
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);
}
}
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()
}
#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)
}
}
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)
}
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));
}
}
}
}
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)
}
fn find_opt(opts: ~[opt], nm: name) -> option<uint> {
- vec::position(opts, { |opt| opt.name == nm })
+ vec::position(opts, |opt| opt.name == nm)
}
#[doc = "
}
}
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 }
#[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; }
_ { }
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 }
_ { }
"]
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;
list(v) {
wr.write_char('[');
let mut first = true;
- for (*v).each { |item|
+ for (*v).each |item| {
if !first {
wr.write_str(", ");
}
wr.write_str("{ ");
let mut first = true;
- for d.each { |key, value|
+ for d.each |key, value| {
if !first {
wr.write_str(", ");
}
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 += "\\\\"; }
#[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 = {
}
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 {
(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; } }
}
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)
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);
};
#[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 = "
"]
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
}
#[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;
#[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
}
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);
}
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>] {
#[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"]
"]
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
};
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);
}
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;
}
}
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 }
};
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,
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);
// 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));
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)
}
}
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)
}
}
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) {
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)
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) {
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;
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 {
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,
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,
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,
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,
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,
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,
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,
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,
- // on_establish_cb -- called when listener is set up
- {|kill_ch|
+ iotask, |kill_ch| {
+ // on_establish_cb -- called when listener is set up
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);
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);
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),
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());
#[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)
}
#[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)
})
}
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)
})
}
#[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 }
}
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 {
* 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
};
}
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 ="
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);
//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);
}
// 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)
}
}
}
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())
}
}
}
}
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)
}
}
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()
}))
}
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;
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;
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;
}
}
// 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);
// 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 {
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
}
}
fn each_value(it: fn(V) -> bool) {
- self.each({|_i, v| it(v)});
+ self.each(|_i, v| it(v));
}
}
"]
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);
}
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);
"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
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;
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]);
}
}
} 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)
};
} else { ret option::none; }
};
- vec::filter_map(filtered, {|x|filter(x)})
+ vec::filter_map(filtered, |x| filter(x))
};
// Sort the tests alphabetically
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;
ret;
}
- do task::spawn {||
+ do task::spawn || {
let testfn = copy test.fn;
let mut builder = task::builder();
let result_future = task::future_result(builder);
{
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];
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); }
}
}
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;
}
}
'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) {
}
'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.
}
'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.
//'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' {
}
'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' {
}
}
- 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,
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); }
}
}
- do [
+ [
"Sunday",
"Monday",
"Tuesday",
"Thursday",
"Friday",
"Saturday"
- ]/_.iter { |day| assert test(day, "%A"); }
+ ]/_.iter(|day| assert test(day, "%A"));
- do [
+ [
"Sun",
"Mon",
"Tue",
"Thu",
"Fri",
"Sat"
- ]/_.iter { |day| assert test(day, "%a"); }
+ ]/_.iter(|day| assert test(day, "%a"));
- do [
+ [
"January",
"February",
"March",
"October",
"November",
"December"
- ]/_.iter { |day| assert test(day, "%B"); }
+ ]/_.iter(|day| assert test(day, "%B"));
- do [
+ [
"Jan",
"Feb",
"Mar",
"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");
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(
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)
)
#[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);
}
}
};
- 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, ());
}
}
- do iter::repeat(repeat * spec.len()) {||
+ do iter::repeat(repeat * spec.len()) || {
comm::recv(po)
}
}
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);
};
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);
};
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]
#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,
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 {
// 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()
}
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();
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");
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) {
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, ());
});
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"+
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");
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);
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(());
};
// 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..");
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,
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));
/* 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 }
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));
}
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));
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)));
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) */
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); }
}
_ { }
}
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)
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) }
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);
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; }
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 {
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,
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) }
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); } }
_ {}
}
},
},
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) {
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)
}
},
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);
}
}
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 {
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(_, _) {}
// 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;
}
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; }
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 {
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"); }
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 }
}
#[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) {
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)
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};
}
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");
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);
}
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);
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)],
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: @"",
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()
})
}
}
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()
});
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(
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(
}
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),
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)) }
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))
}]
}
-> @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];
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,
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,
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))
};
}
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);
// 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)) }
-> @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];
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,
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]))
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))
]
}
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 {
// 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));
},
// 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]{
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)) }
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)) }
-> ~[@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))
]
}
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 =
_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");
}
}
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) }
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 */
// 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()));
}
}
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,
/* 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");
} 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 ");
// 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 }
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>",
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" }
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 {
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"); }
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));
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
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;
}
-> @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 }
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;
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);
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",
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],
-> 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);
}
{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 {
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);
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)); }
}
some(matches) { a_d_map(matches, s2) }
}
}
- ret {|x|scomp(s1, s2, x)};
+ ret { |x| scomp(s1, s2, x) };
}
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); }
}
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);
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] }
// 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); };
}
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(_) { }
_ { 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));
}
}
}
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 { }
}
_ { 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 `#<>`"); }
_ { 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 `#{}`"); }
}
}
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);
}
}
}
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,
}
}
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;
}
}
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 {
}
}
- 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 {
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; }
-> @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,
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);
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))
}
}
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,
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),
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),
}
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),
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,
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,
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))
}
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)});
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) {
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})})))
}
}
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}
}
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))}
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 {
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)};
}
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};
}
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};
}
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] {
{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);
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);
}
}
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 {
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();
// 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");
}
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()});
}
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);
}
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) {
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);
}
}
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) {
}
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_(
}
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 {
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}
}
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
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)));
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),
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);
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) }
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) {
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");
}
// 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,
// `|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))
})
// `|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 {
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;
}
}
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 { ~[] }
}
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,
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) {
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))
}
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,
@{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}})
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 {
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(),
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_};
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,
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) {
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: ~[]};
"]
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
/* temp */
"sep", "many", "at_least_one", "parse"
];
- for keys.each {|word|
+ for keys.each |word| {
words.insert(word, ());
}
words
"unchecked", "unsafe",
"while"
];
- for keys.each {|word|
+ for keys.each |word| {
words.insert(word, ());
}
words
}
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,
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);
}
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;
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) {
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);
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);
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
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);
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);
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);
}
}
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 */ }
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);
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 {
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) {
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, "|"); }
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");
}
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);
}
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") }
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)
}));
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"); }
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, "}");
}
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); }
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);
}
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);
}
}
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);
}
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);
}
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>) {
alt cd.node {
cdir_src_mod(_, _) { }
cdir_dir_mod(_, cdirs, _) {
- for cdirs.each {|cdir|
+ for cdirs.each |cdir| {
visit_crate_directive(cdir, e, v);
}
}
}
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>) { }
}
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);
}
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);
}
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);
}
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);
}
}
}
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); }
}
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 { }
}
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);
}
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);
}
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); }
}
}
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); }
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);
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,
}
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); }
}
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);
}
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: (),
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)
- }
});
}
output_type_bitcode {
if opts.optimize != 0u {
let filename = mk_intermediate_name(output, "no-opt.bc");
- str::as_c_str(filename,
- {|buf|
- llvm::LLVMWriteBitcodeToFile(llmod, buf)
- });
+ str::as_c_str(filename, |buf| {
+ llvm::LLVMWriteBitcodeToFile(llmod, buf)
+ });
}
}
_ {
let filename = mk_intermediate_name(output, "bc");
- str::as_c_str(filename,
- {|buf|
- llvm::LLVMWriteBitcodeToFile(llmod, buf)
- });
+ str::as_c_str(filename, |buf| {
+ llvm::LLVMWriteBitcodeToFile(llmod, buf)
+ });
}
}
}
let filename = mk_intermediate_name(output, "opt.bc");
llvm::LLVMRunPassManager(pm.llpm, llmod);
- str::as_c_str(filename,
- {|buf|
- llvm::LLVMWriteBitcodeToFile(llmod, buf)
- });
+ str::as_c_str(filename, |buf| {
+ llvm::LLVMWriteBitcodeToFile(llmod, buf)
+ });
pm = mk_pass_manager();
// Save the assembly file if -S is used
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,
buf_o,
lib::llvm::AssemblyFile as c_uint,
CodeGenOptLevel,
- true)})});
+ true)
+ })
+ });
}
// 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(
- sess.targ_cfg.target_strs.target_triple,
- {|buf_t|
- str::as_c_str(output, {|buf_o|
- llvm::LLVMRustWriteOutputFile(
- pm.llpm,
- llmod,
- buf_t,
- buf_o,
- lib::llvm::ObjectFile as c_uint,
- CodeGenOptLevel,
- 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,
buf_t,
buf_o,
- FileType as c_uint,
+ 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(
+ sess.targ_cfg.target_strs.target_triple,
+ |buf_t| {
+ str::as_c_str(output, |buf_o| {
+ llvm::LLVMRustWriteOutputFile(
+ pm.llpm,
+ llmod,
+ buf_t,
+ buf_o,
+ FileType as c_uint,
+ CodeGenOptLevel,
+ true)
+ })
+ });
}
// Clean up and return
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);
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); }
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) {
}
}
- for dep_hashes.each {|dh|
+ for dep_hashes.each |dh| {
sha.input_str(len_and_str(*dh));
}
// 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_"; }
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];
// # 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;
}
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
// 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);
}
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,
#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);
fn log_rpaths(desc: str, rpaths: ~[str]) {
#debug("%s rpaths:", desc);
- for rpaths.each {|rpath|
+ for rpaths.each |rpath| {
#debug(" %s", rpath);
}
}
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)
})
}
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));
}
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 {
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, ());
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);
// 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;
}
-> {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|
- front::intrinsic_inject::inject_intrinsic(sess, crate)
- });
+ crate = time(time_passes, "intrinsic injection", |copy crate| {
+ front::intrinsic_inject::inject_intrinsic(sess, crate)
+ });
- crate =
- time(time_passes, "core injection", {|copy crate|
- front::core_inject::maybe_inject_libcore_ref(sess, 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|
- resolve::resolve_crate(sess, ast_map, 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|
- middle::region::resolve_crate(sess, def_map, 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| {
+ freevars::annotate_freevars(def_map, 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|
- typeck::check_crate(ty_cx, impl_map, crate)
- });
- time(time_passes, "const checking", {|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| {
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|
- 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, "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| {
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);
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 ||
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)};
}
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}
};
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);
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))
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; }
}
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
}
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),
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));
}
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 */ }
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.
"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)
}
}
}
fn main(args: ~[str]) {
- do monitor {|demitter|
+ do monitor |demitter| {
run_compiler(args, demitter);
}
}
// 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)
}
}
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);
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)};
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};
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),
// 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; }
}
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);
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")
}
}
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 {
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));
}
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);
}
}
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;
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)};
}
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;
}
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);
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));
}
}
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)
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))
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);
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);
// 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", ~[]);
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));
}
#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 {
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)
}
}
#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};
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);
}
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) {
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);
}
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; }
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
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);
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>;
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
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),
- ast::class_immutable,
- {|d|
- alt ebml::doc_as_u8(d) as char {
- 'm' { ast::class_mutable }
- _ { ast::class_immutable }
- }
- })
+ option::map_default(
+ ebml::maybe_get_doc(d, tag_class_mut),
+ ast::class_immutable,
+ |d| {
+ alt ebml::doc_as_u8(d) as char {
+ 'm' { ast::class_mutable }
+ _ { ast::class_immutable }
+ }
+ })
}
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)
})
}
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
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);
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});
};
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)));
}
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));
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));
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);
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));
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);
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. */ }
}
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),
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
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);
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);
/* '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 {
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));
// 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);
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
}
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)]);
}
}
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)]);
}
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),
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]);
}
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");
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);
// 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
// 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)
}
}
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]);
}
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));
}
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));
}
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 {
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) {
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),
}
}
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,
}
}
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);
}
}
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);
}
}
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);
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);
@{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);
}
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));
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);
}
}
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);
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 {
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(_, _) {
}
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));
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 {
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));
}
};
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 {
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));
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,
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);
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) {
}
}
},
- 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) {
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;
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);
}
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();
}
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();
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();
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" {
// 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)};
// 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;
}
// 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();
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);
fn search<T: copy>(filesearch: filesearch, pick: pick<T>) -> option<T> {
let mut rslt = none;
- for filesearch.lib_search_paths().each {|lib_search_path|
+ for filesearch.lib_search_paths().each |lib_search_path| {
#debug("searching %s", lib_search_path);
- for os::list_dir_path(lib_search_path).each {|path|
+ for os::list_dir_path(lib_search_path).each |path| {
#debug("testing %s", path);
let maybe_picked = pick(path);
if option::is_some(maybe_picked) {
}
fn get_cargo_root_nearest() -> result<path, str> {
- do result::chain(get_cargo_root()) { |p|
+ do result::chain(get_cargo_root()) |p| {
let cwd = os::getcwd();
let mut dirname = path::dirname(cwd);
let mut dirpath = path::split(dirname);
}
fn get_cargo_lib_path() -> result<path, str> {
- do result::chain(get_cargo_root()) { |p|
+ do result::chain(get_cargo_root()) |p| {
result::ok(path::connect(p, libdir()))
}
}
fn get_cargo_lib_path_nearest() -> result<path, str> {
- do result::chain(get_cargo_root_nearest()) { |p|
+ do result::chain(get_cargo_root_nearest()) |p| {
result::ok(path::connect(p, libdir()))
}
}
let suffix: str = nn.suffix;
let mut matches = ~[];
- filesearch::search(filesearch, { |path|
+ filesearch::search(filesearch, |path| {
#debug("inspecting file %s", path);
let f: str = path::basename(path);
if !(str::starts_with(f, prefix) && str::ends_with(f, suffix)) {
cx.diag.span_err(
cx.span, #fmt("multiple matching crates for `%s`", *crate_name));
cx.diag.handler().note("candidates:");
- for matches.each {|match|
+ for matches.each |match| {
cx.diag.handler().note(#fmt("path: %s", match.ident));
let attrs = decoder::get_crate_attributes(match.data);
note_linkage_attrs(cx.diag, attrs);
}
fn note_linkage_attrs(diag: span_handler, attrs: ~[ast::attribute]) {
- for attr::find_linkage_attrs(attrs).each {|attr|
+ for attr::find_linkage_attrs(attrs).each |attr| {
diag.handler().note(#fmt("meta: %s", pprust::attr_to_str(attr)));
}
}
vec::len(local_metas), vec::len(extern_metas));
#debug("crate metadata:");
- for extern_metas.each {|have|
+ for extern_metas.each |have| {
#debug(" %s", pprust::meta_item_to_str(*have));
}
- for local_metas.each {|needed|
+ for local_metas.each |needed| {
#debug("looking for %s", pprust::meta_item_to_str(*needed));
if !attr::contains(extern_metas, needed) {
#debug("missing %s", pprust::meta_item_to_str(*needed));
fn get_metadata_section(os: os,
filename: str) -> option<@~[u8]> unsafe {
- let mb = str::as_c_str(filename, {|buf|
+ let mb = str::as_c_str(filename, |buf| {
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
});
if mb as int == 0 { ret option::none::<@~[u8]>; }
fn parse_ident(st: @pstate, last: char) -> ast::ident {
fn is_last(b: char, c: char) -> bool { ret c == b; }
- ret parse_ident_(st, {|a|is_last(last, a)});
+ ret parse_ident_(st, |a| is_last(last, a) );
}
fn parse_ident_(st: @pstate, is_last: fn@(char) -> bool) ->
}
fn parse_substs(st: @pstate, conv: conv_did) -> ty::substs {
- let self_r = parse_opt(st, {|| parse_region(st) });
+ let self_r = parse_opt(st, || parse_region(st) );
- let self_ty = parse_opt(st, {|| parse_ty(st, conv) });
+ let self_ty = parse_opt(st, || parse_ty(st, conv) );
assert next(st) == '[';
let mut params: [ty::t]/~ = []/~;
}
fn enc_substs(w: io::writer, cx: @ctxt, substs: ty::substs) {
- do enc_opt(w, substs.self_r) { |r| enc_region(w, cx, r) }
- do enc_opt(w, substs.self_ty) { |t| enc_ty(w, cx, t) }
+ do enc_opt(w, substs.self_r) |r| { enc_region(w, cx, r) }
+ do enc_opt(w, substs.self_ty) |t| { enc_ty(w, cx, t) }
w.write_char('[');
- for substs.tps.each { |t| enc_ty(w, cx, t); }
+ for substs.tps.each |t| { enc_ty(w, cx, t); }
w.write_char(']');
}
}
ty::ty_tup(ts) {
w.write_str("T["/&);
- for ts.each {|t| enc_ty(w, cx, t); }
+ for ts.each |t| { enc_ty(w, cx, t); }
w.write_char(']');
}
ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); }
ty::ty_unboxed_vec(mt) { w.write_char('U'); enc_mt(w, cx, mt); }
ty::ty_rec(fields) {
w.write_str("R["/&);
- for fields.each {|field|
+ for fields.each |field| {
w.write_str(*field.ident);
w.write_char('=');
enc_mt(w, cx, field.mt);
ty::ty_constr(ty, cs) {
w.write_str("A["/&);
enc_ty(w, cx, ty);
- for cs.each {|tc| enc_ty_constr(w, cx, tc); }
+ for cs.each |tc| { enc_ty_constr(w, cx, tc); }
w.write_char(']');
}
ty::ty_opaque_box { w.write_char('B'); }
enc_proto(w, ft.proto);
enc_purity(w, ft.purity);
w.write_char('[');
- for ft.inputs.each {|arg|
+ for ft.inputs.each |arg| {
enc_mode(w, cx, arg.mode);
enc_ty(w, cx, arg.ty);
}
w.write_char(']');
let mut colon = true;
- for ft.constraints.each {|c|
+ for ft.constraints.each |c| {
if colon {
w.write_char(':');
colon = false;
w.write_str(cx.ds(c.node.id));
w.write_char('|');
let mut semi = false;
- for c.node.args.each {|a|
+ for c.node.args.each |a| {
if semi { w.write_char(';'); } else { semi = true; }
write_arg(a);
}
}
fn enc_constr(w: io::writer, cx: @ctxt, c: @ty::constr) {
- enc_constr_gen(w, cx, c, {|a|
+ enc_constr_gen(w, cx, c, |a| {
alt a.node {
carg_base { w.write_char('*'); }
carg_ident(i) { w.write_uint(i); }
}
fn enc_ty_constr(w: io::writer, cx: @ctxt, c: @ty::type_constr) {
- enc_constr_gen(w, cx, c, {|a|
+ enc_constr_gen(w, cx, c, |a| {
alt a.node {
carg_base { w.write_char('*'); }
carg_ident(p) { w.write_str(path_to_str(p)); }
}
fn enc_bounds(w: io::writer, cx: @ctxt, bs: @~[ty::param_bound]) {
- for vec::each(*bs) {|bound|
+ for vec::each(*bs) |bound| {
alt bound {
ty::bound_send { w.write_char('S'); }
ty::bound_copy { w.write_char('C'); }
ebml_w.writer.tell()];
let id_range = ast_util::compute_id_range_for_inlined_item(ii);
- do ebml_w.wr_tag(c::tag_ast as uint) {||
+ do ebml_w.wr_tag(c::tag_ast as uint) || {
ast_util::serialize_id_range(ebml_w, id_range);
encode_ast(ebml_w, simplify_ast(ii));
encode_side_tables_for_ii(ecx, maps, ebml_w, ii);
// but eventually we should add entries to the local codemap as required.
fn encode_ast(ebml_w: ebml::writer, item: ast::inlined_item) {
- do ebml_w.wr_tag(c::tag_tree as uint) {||
+ do ebml_w.wr_tag(c::tag_tree as uint) || {
ast::serialize_inlined_item(ebml_w, item)
}
}
// inlined items.
fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
fn drop_nested_items(blk: ast::blk_, fld: fold::ast_fold) -> ast::blk_ {
- let stmts_sans_items = do vec::filter(blk.stmts) {|stmt|
+ let stmts_sans_items = do vec::filter(blk.stmts) |stmt| {
alt stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) { true }
fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item)
-> ast::inlined_item {
let fld = fold::make_fold(@{
- new_id: {|a|xcx.tr_id(a)},
- new_span: {|a|xcx.tr_span(a)}
+ new_id: |a| xcx.tr_id(a),
+ new_span: |a| xcx.tr_span(a)
with *fold::default_ast_fold()
});
// ty::t doesn't work, and there is no way (atm) to have
// hand-written serialization routines combine with auto-generated
// ones. perhaps we should fix this.
- do ebml_w.emit_from_vec(*dr) {|vtable_origin|
+ do ebml_w.emit_from_vec(*dr) |vtable_origin| {
encode_vtable_origin(ecx, ebml_w, vtable_origin)
}
}
fn encode_vtable_origin(ecx: @e::encode_ctxt,
ebml_w: ebml::writer,
vtable_origin: typeck::vtable_origin) {
- do ebml_w.emit_enum("vtable_origin") {||
+ do ebml_w.emit_enum("vtable_origin") || {
alt vtable_origin {
typeck::vtable_static(def_id, tys, vtable_res) {
- do ebml_w.emit_enum_variant("vtable_static", 0u, 3u) {||
- do ebml_w.emit_enum_variant_arg(0u) {||
+ do ebml_w.emit_enum_variant("vtable_static", 0u, 3u) || {
+ do ebml_w.emit_enum_variant_arg(0u) || {
ebml_w.emit_def_id(def_id)
}
- do ebml_w.emit_enum_variant_arg(1u) {||
+ do ebml_w.emit_enum_variant_arg(1u) || {
ebml_w.emit_tys(ecx, tys);
}
- do ebml_w.emit_enum_variant_arg(2u) {||
+ do ebml_w.emit_enum_variant_arg(2u) || {
encode_vtable_res(ecx, ebml_w, vtable_res);
}
}
}
typeck::vtable_param(pn, bn) {
- do ebml_w.emit_enum_variant("vtable_param", 1u, 2u) {||
- do ebml_w.emit_enum_variant_arg(0u) {||
+ do ebml_w.emit_enum_variant("vtable_param", 1u, 2u) || {
+ do ebml_w.emit_enum_variant_arg(0u) || {
ebml_w.emit_uint(pn);
}
- do ebml_w.emit_enum_variant_arg(1u) {||
+ do ebml_w.emit_enum_variant_arg(1u) || {
ebml_w.emit_uint(bn);
}
}
}
typeck::vtable_iface(def_id, tys) {
- do ebml_w.emit_enum_variant("vtable_iface", 1u, 3u) {||
- do ebml_w.emit_enum_variant_arg(0u) {||
+ do ebml_w.emit_enum_variant("vtable_iface", 1u, 3u) || {
+ do ebml_w.emit_enum_variant_arg(0u) || {
ebml_w.emit_def_id(def_id)
}
- do ebml_w.emit_enum_variant_arg(1u) {||
+ do ebml_w.emit_enum_variant_arg(1u) || {
ebml_w.emit_tys(ecx, tys);
}
}
impl helpers for ebml::ebml_deserializer {
fn read_vtable_res(xcx: extended_decode_ctxt) -> typeck::vtable_res {
- @self.read_to_vec({|| self.read_vtable_origin(xcx) })
+ @self.read_to_vec(|| self.read_vtable_origin(xcx) )
}
fn read_vtable_origin(xcx: extended_decode_ctxt)
-> typeck::vtable_origin {
- do self.read_enum("vtable_origin") {||
- do self.read_enum_variant {|i|
+ do self.read_enum("vtable_origin") || {
+ do self.read_enum_variant |i| {
alt check i {
0u {
typeck::vtable_static(
- do self.read_enum_variant_arg(0u) {||
+ do self.read_enum_variant_arg(0u) || {
self.read_def_id(xcx)
},
- do self.read_enum_variant_arg(1u) {||
+ do self.read_enum_variant_arg(1u) || {
self.read_tys(xcx)
},
- do self.read_enum_variant_arg(2u) {||
+ do self.read_enum_variant_arg(2u) || {
self.read_vtable_res(xcx)
}
)
}
1u {
typeck::vtable_param(
- do self.read_enum_variant_arg(0u) {||
+ do self.read_enum_variant_arg(0u) || {
self.read_uint()
},
- do self.read_enum_variant_arg(1u) {||
+ do self.read_enum_variant_arg(1u) || {
self.read_uint()
}
)
}
2u {
typeck::vtable_iface(
- do self.read_enum_variant_arg(0u) {||
+ do self.read_enum_variant_arg(0u) || {
self.read_def_id(xcx)
},
- do self.read_enum_variant_arg(1u) {||
+ do self.read_enum_variant_arg(1u) || {
self.read_tys(xcx)
}
)
@{diag: self.tcx.sess.diagnostic(),
ds: e::def_to_str,
tcx: self.tcx,
- reachable: {|a|encoder::reachable(self, a)},
+ reachable: |a| encoder::reachable(self, a),
abbrevs: tyencode::ac_use_abbrevs(self.type_abbrevs)}
}
}
}
fn emit_tys(ecx: @e::encode_ctxt, tys: ~[ty::t]) {
- do self.emit_from_vec(tys) {|ty|
+ do self.emit_from_vec(tys) |ty| {
e::write_type(ecx, self, ty)
}
}
}
fn emit_tpbt(ecx: @e::encode_ctxt, tpbt: ty::ty_param_bounds_and_ty) {
- do self.emit_rec {||
- do self.emit_rec_field("bounds", 0u) {||
- do self.emit_from_vec(*tpbt.bounds) {|bs|
+ do self.emit_rec || {
+ do self.emit_rec_field("bounds", 0u) || {
+ do self.emit_from_vec(*tpbt.bounds) |bs| {
self.emit_bounds(ecx, bs)
}
}
- do self.emit_rec_field("rp", 1u) {||
+ do self.emit_rec_field("rp", 1u) || {
ast::serialize_region_param(self, tpbt.rp)
}
- do self.emit_rec_field("ty", 2u) {||
+ do self.emit_rec_field("ty", 2u) || {
self.emit_ty(ecx, tpbt.ty);
}
}
impl writer for ebml::writer {
fn tag(tag_id: c::astencode_tag, f: fn()) {
- do self.wr_tag(tag_id as uint) {|| f() }
+ do self.wr_tag(tag_id as uint) || { f() }
}
fn id(id: ast::node_id) {
maps: maps,
ebml_w: ebml::writer,
ii: ast::inlined_item) {
- do ebml_w.wr_tag(c::tag_table as uint) {||
+ do ebml_w.wr_tag(c::tag_table as uint) || {
ast_util::visit_ids_for_inlined_item(
ii,
fn@(id: ast::node_id, copy ebml_w) {
#debug["Encoding side tables for id %d", id];
- do option::iter(tcx.def_map.find(id)) {|def|
- do ebml_w.tag(c::tag_table_def) {||
+ do option::iter(tcx.def_map.find(id)) |def| {
+ do ebml_w.tag(c::tag_table_def) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
+ do ebml_w.tag(c::tag_table_val) || {
ast::serialize_def(ebml_w, def)
}
}
}
- do option::iter((*tcx.node_types).find(id as uint)) {|ty|
- do ebml_w.tag(c::tag_table_node_type) {||
+ do option::iter((*tcx.node_types).find(id as uint)) |ty| {
+ do ebml_w.tag(c::tag_table_node_type) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
+ do ebml_w.tag(c::tag_table_val) || {
e::write_type(ecx, ebml_w, ty)
}
}
}
- do option::iter(tcx.node_type_substs.find(id)) {|tys|
- do ebml_w.tag(c::tag_table_node_type_subst) {||
+ do option::iter(tcx.node_type_substs.find(id)) |tys| {
+ do ebml_w.tag(c::tag_table_node_type_subst) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
+ do ebml_w.tag(c::tag_table_val) || {
ebml_w.emit_tys(ecx, tys)
}
}
}
- do option::iter(tcx.freevars.find(id)) {|fv|
- do ebml_w.tag(c::tag_table_freevars) {||
+ do option::iter(tcx.freevars.find(id)) |fv| {
+ do ebml_w.tag(c::tag_table_freevars) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
- do ebml_w.emit_from_vec(*fv) {|fv_entry|
+ do ebml_w.tag(c::tag_table_val) || {
+ do ebml_w.emit_from_vec(*fv) |fv_entry| {
encode_freevar_entry(ebml_w, *fv_entry)
}
}
}
let lid = {crate: ast::local_crate, node: id};
- do option::iter(tcx.tcache.find(lid)) {|tpbt|
- do ebml_w.tag(c::tag_table_tcache) {||
+ do option::iter(tcx.tcache.find(lid)) |tpbt| {
+ do ebml_w.tag(c::tag_table_tcache) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
+ do ebml_w.tag(c::tag_table_val) || {
ebml_w.emit_tpbt(ecx, tpbt);
}
}
}
- do option::iter(tcx.ty_param_bounds.find(id)) {|pbs|
- do ebml_w.tag(c::tag_table_param_bounds) {||
+ do option::iter(tcx.ty_param_bounds.find(id)) |pbs| {
+ do ebml_w.tag(c::tag_table_param_bounds) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
+ do ebml_w.tag(c::tag_table_val) || {
ebml_w.emit_bounds(ecx, pbs)
}
}
// }
//}
- do option::iter(maps.mutbl_map.find(id)) {|_m|
- do ebml_w.tag(c::tag_table_mutbl) {||
+ do option::iter(maps.mutbl_map.find(id)) |_m| {
+ do ebml_w.tag(c::tag_table_mutbl) || {
ebml_w.id(id);
}
}
- do option::iter(maps.last_use_map.find(id)) {|m|
- do ebml_w.tag(c::tag_table_last_use) {||
+ do option::iter(maps.last_use_map.find(id)) |m| {
+ do ebml_w.tag(c::tag_table_last_use) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
- do ebml_w.emit_from_vec((*m).get()) {|id|
+ do ebml_w.tag(c::tag_table_val) || {
+ do ebml_w.emit_from_vec((*m).get()) |id| {
ebml_w.emit_int(id);
}
}
// impl_map is not used except when emitting metadata,
// don't need to keep it.
- do option::iter(maps.method_map.find(id)) {|mme|
- do ebml_w.tag(c::tag_table_method_map) {||
+ do option::iter(maps.method_map.find(id)) |mme| {
+ do ebml_w.tag(c::tag_table_method_map) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
+ do ebml_w.tag(c::tag_table_val) || {
serialize_method_map_entry(ebml_w, mme)
}
}
}
- do option::iter(maps.vtable_map.find(id)) {|dr|
- do ebml_w.tag(c::tag_table_vtable_map) {||
+ do option::iter(maps.vtable_map.find(id)) |dr| {
+ do ebml_w.tag(c::tag_table_vtable_map) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
+ do ebml_w.tag(c::tag_table_val) || {
encode_vtable_res(ecx, ebml_w, dr);
}
}
}
- do option::iter(tcx.borrowings.find(id)) {|borrow|
- do ebml_w.tag(c::tag_table_borrowings) {||
+ do option::iter(tcx.borrowings.find(id)) |borrow| {
+ do ebml_w.tag(c::tag_table_borrowings) || {
ebml_w.id(id);
- do ebml_w.tag(c::tag_table_val) {||
+ do ebml_w.tag(c::tag_table_val) || {
ty::serialize_borrow(ebml_w, borrow)
}
}
tydecode::parse_ty_data(
self.parent.data, xcx.dcx.cdata.cnum, self.pos, xcx.dcx.tcx,
- {|a|xcx.tr_def_id(a)})
+ |a| xcx.tr_def_id(a) )
}
fn read_tys(xcx: extended_decode_ctxt) -> ~[ty::t] {
- self.read_to_vec({|| self.read_ty(xcx) })
+ self.read_to_vec(|| self.read_ty(xcx) )
}
fn read_bounds(xcx: extended_decode_ctxt) -> @~[ty::param_bound] {
tydecode::parse_bounds_data(
self.parent.data, self.pos, xcx.dcx.cdata.cnum, xcx.dcx.tcx,
- {|a|xcx.tr_def_id(a)})
+ |a| xcx.tr_def_id(a) )
}
fn read_ty_param_bounds_and_ty(xcx: extended_decode_ctxt)
-> ty::ty_param_bounds_and_ty {
- do self.read_rec {||
+ do self.read_rec || {
{
- bounds: self.read_rec_field("bounds", 0u, {||
- @self.read_to_vec({|| self.read_bounds(xcx) })
+ bounds: self.read_rec_field("bounds", 0u, || {
+ @self.read_to_vec(|| self.read_bounds(xcx) )
}),
- rp: self.read_rec_field("rp", 1u, {||
+ rp: self.read_rec_field("rp", 1u, || {
ast::deserialize_region_param(self)
}),
- ty: self.read_rec_field("ty", 2u, {||
+ ty: self.read_rec_field("ty", 2u, || {
self.read_ty(xcx)
})
}
ast_doc: ebml::doc) {
let dcx = xcx.dcx;
let tbl_doc = ast_doc[c::tag_table];
- do ebml::docs(tbl_doc) {|tag, entry_doc|
+ do ebml::docs(tbl_doc) |tag, entry_doc| {
let id0 = entry_doc[c::tag_table_id].as_int();
let id = xcx.tr_id(id0);
let tys = val_dsr.read_tys(xcx);
dcx.tcx.node_type_substs.insert(id, tys);
} else if tag == (c::tag_table_freevars as uint) {
- let fv_info = @val_dsr.read_to_vec({||
+ let fv_info = @val_dsr.read_to_vec(|| {
@val_dsr.read_freevar_entry(xcx)
});
dcx.tcx.freevars.insert(id, fv_info);
let bounds = val_dsr.read_bounds(xcx);
dcx.tcx.ty_param_bounds.insert(id, bounds);
} else if tag == (c::tag_table_last_use as uint) {
- let ids = val_dsr.read_to_vec({||
+ let ids = val_dsr.read_to_vec(|| {
xcx.tr_id(val_dsr.read_int())
});
let dvec = @dvec::from_vec(vec::to_mut(ids));
#[cfg(test)]
fn encode_item_ast(ebml_w: ebml::writer, item: @ast::item) {
- do ebml_w.wr_tag(c::tag_tree as uint) {||
+ do ebml_w.wr_tag(c::tag_tree as uint) || {
ast::serialize_item(ebml_w, *item);
}
}
#debug["out_item = %s", pprust::item_to_str(out_item)];
let exp_str =
- io::with_str_writer({|w| ast::serialize_item(w, *in_item) });
+ io::with_str_writer(|w| ast::serialize_item(w, *in_item) );
let out_str =
- io::with_str_writer({|w| ast::serialize_item(w, *out_item) });
+ io::with_str_writer(|w| ast::serialize_item(w, *out_item) );
#debug["expected string: %s", exp_str];
#debug["actual string : %s", out_str];
cx.allow_block = true;
v.visit_expr(f, cx, v);
let mut i = 0u;
- for ty::ty_fn_args(ty::expr_ty(cx.tcx, f)).each {|arg_t|
+ for ty::ty_fn_args(ty::expr_ty(cx.tcx, f)).each |arg_t| {
cx.allow_block = (ty::arg_mode(cx.tcx, arg_t) == by_ref);
v.visit_expr(args[i], cx, v);
i += 1u;
self.cat_to_repr(cmt.cat),
cmt.id,
self.mut_to_str(cmt.mutbl),
- cmt.lp.map_default("none", { |p| self.lp_to_str(p) }),
+ cmt.lp.map_default("none", |p| self.lp_to_str(p) ),
ty_to_str(self.tcx, cmt.ty)]
}
cmt: cmt) -> cmt {
@{id: arg.id(), span: arg.span(),
cat: cat_comp(cmt, comp_variant(enum_did)),
- lp: cmt.lp.map({ |l| @lp_comp(l, comp_variant(enum_did)) }),
+ lp: cmt.lp.map(|l| @lp_comp(l, comp_variant(enum_did)) ),
mutbl: cmt.mutbl, // imm iff in an immutable context
ty: self.tcx.ty(arg)}
}
m_mutbl | m_const { f_mutbl }
};
let f_comp = comp_field(f_name, f_mutbl);
- let lp = base_cmt.lp.map({ |lp|
- @lp_comp(lp, f_comp)
- });
+ let lp = base_cmt.lp.map(|lp| @lp_comp(lp, f_comp) );
@{id: node.id(), span: node.span(),
cat: cat_comp(base_cmt, f_comp), lp:lp,
mutbl: m, ty: self.tcx.ty(node)}
fn cat_deref<N:ast_node>(node: N, base_cmt: cmt, derefs: uint,
expl: bool) -> option<cmt> {
- do ty::deref(self.tcx, base_cmt.ty, expl).map { |mt|
+ do ty::deref(self.tcx, base_cmt.ty, expl).map |mt| {
alt deref_kind(self.tcx, base_cmt.ty) {
deref_ptr(ptr) {
- let lp = do base_cmt.lp.chain { |l|
+ let lp = do base_cmt.lp.chain |l| {
// Given that the ptr itself is loanable, we can
// loan out deref'd uniq ptrs as the data they are
// the only way to reach the data they point at.
}
deref_comp(comp) {
- let lp = base_cmt.lp.map({ |l| @lp_comp(l, comp) });
+ let lp = base_cmt.lp.map(|l| @lp_comp(l, comp) );
@{id:node.id(), span:node.span(),
cat:cat_comp(base_cmt, comp), lp:lp,
mutbl:mt.mutbl, ty:mt.ty}
deref_ptr(ptr) {
// make deref of vectors explicit, as explained in the comment at
// the head of this section
- let deref_lp = base_cmt.lp.map({ |lp| @lp_deref(lp, ptr) });
+ let deref_lp = base_cmt.lp.map(|lp| @lp_deref(lp, ptr) );
let deref_cmt = @{id:expr.id, span:expr.span,
cat:cat_deref(base_cmt, 0u, ptr), lp:deref_lp,
mutbl:m_imm, ty:mt.ty};
fn comp(expr: @ast::expr, of_cmt: cmt,
vect: ty::t, mt: ty::mt) -> cmt {
let comp = comp_index(vect, mt.mutbl);
- let index_lp = of_cmt.lp.map({ |lp| @lp_comp(lp, comp) });
+ let index_lp = of_cmt.lp.map(|lp| @lp_comp(lp, comp) );
@{id:expr.id, span:expr.span,
cat:cat_comp(of_cmt, comp), lp:index_lp,
mutbl:mt.mutbl, ty:mt.ty}
fn cat_tuple_elt<N: ast_node>(elt: N, cmt: cmt) -> cmt {
@{id: elt.id(), span: elt.span(),
cat: cat_comp(cmt, comp_tuple),
- lp: cmt.lp.map({ |l| @lp_comp(l, comp_tuple) }),
+ lp: cmt.lp.map(|l| @lp_comp(l, comp_tuple) ),
mutbl: cmt.mutbl, // imm iff in an immutable context
ty: self.tcx.ty(elt)}
}
// Need to refactor so that records/class fields can be treated uniformly.
alt ty::get(base_ty).struct {
ty::ty_rec(fields) {
- for fields.each { |f|
+ for fields.each |f| {
if f.ident == f_name {
ret some(f.mt.mutbl);
}
}
}
ty::ty_class(did, substs) {
- for ty::lookup_class_fields(tcx, did).each { |fld|
+ for ty::lookup_class_fields(tcx, did).each |fld| {
if fld.ident == f_name {
let m = alt fld.mutability {
ast::class_mutable { ast::m_mutbl }
let req_loan_map = self.req_maps.req_loan_map;
loop {
- for req_loan_map.find(scope_id).each { |loanss|
- for (*loanss).each { |loans|
- for (*loans).each { |loan|
+ for req_loan_map.find(scope_id).each |loanss| {
+ for (*loanss).each |loans| {
+ for (*loans).each |loan| {
if !f(loan) { ret; }
}
}
fn walk_loans_of(scope_id: ast::node_id,
lp: @loan_path,
f: fn(loan) -> bool) {
- for self.walk_loans(scope_id) { |loan|
+ for self.walk_loans(scope_id) |loan| {
if loan.lp == lp {
if !f(loan) { ret; }
}
#debug["check_pure_callee_or_arg(pc=%?, expr=%?, \
callee_id=%d, ty=%s)",
pc,
- opt_expr.map({|e| pprust::expr_to_str(e)}),
+ opt_expr.map(|e| pprust::expr_to_str(e) ),
callee_id,
ty_to_str(self.tcx(), ty::node_id_to_type(tcx, callee_id))];
};
let par_scope_id = self.tcx().region_map.get(scope_id);
- for self.walk_loans(par_scope_id) { |old_loan|
- for (*new_loanss).each { |new_loans|
- for (*new_loans).each { |new_loan|
+ for self.walk_loans(par_scope_id) |old_loan| {
+ for (*new_loanss).each |new_loans| {
+ for (*new_loans).each |new_loan| {
if old_loan.lp != new_loan.lp { cont; }
alt (old_loan.mutbl, new_loan.mutbl) {
(m_const, _) | (_, m_const) |
// which will be checked for compat separately in
// check_for_conflicting_loans()
if at != at_mutbl_ref {
- for cmt.lp.each { |lp|
+ for cmt.lp.each |lp| {
self.check_for_loan_conflicting_with_assignment(
at, ex, cmt, lp);
}
cmt: cmt,
lp: @loan_path) {
- for self.walk_loans_of(ex.id, lp) { |loan|
+ for self.walk_loans_of(ex.id, lp) |loan| {
alt loan.mutbl {
m_mutbl | m_const { /*ok*/ }
m_imm {
none { ret; }
some(lp) { lp }
};
- for self.walk_loans_of(cmt.id, lp) { |loan|
+ for self.walk_loans_of(cmt.id, lp) |loan| {
self.bccx.span_err(
cmt.span,
#fmt["moving out of %s prohibited due to outstanding loan",
none { ret; }
some(lp) { lp }
};
- for self.walk_loans_of(cmt.id, lp) { |_loan|
+ for self.walk_loans_of(cmt.id, lp) |_loan| {
#debug["Removing last use entry %? due to outstanding loan",
expr.id];
self.bccx.last_use_map.remove(expr.id);
some(pc) {
self.check_pure_callee_or_arg(
pc, callee, callee_id, callee_span);
- for args.each { |arg|
+ for args.each |arg| {
self.check_pure_callee_or_arg(
pc, some(arg), arg.id, arg.span);
}
let arg_tys =
ty::ty_fn_args(
ty::node_id_to_type(self.tcx(), callee_id));
- do vec::iter2(args, arg_tys) { |arg, arg_ty|
+ do vec::iter2(args, arg_tys) |arg, arg_ty| {
alt ty::resolved_mode(self.tcx(), arg_ty.mode) {
ast::by_move {
self.check_move_out(arg);
visitor: visit::vt<check_loan_ctxt>) {
#debug["purity on entry=%?", copy self.declared_purity];
- do save_and_restore(self.in_ctor) {||
- do save_and_restore(self.declared_purity) {||
- do save_and_restore(self.fn_args) {||
+ do save_and_restore(self.in_ctor) || {
+ do save_and_restore(self.declared_purity) || {
+ do save_and_restore(self.fn_args) || {
let is_stack_closure = self.is_stack_closure(id);
// In principle, we could consider fk_anon(*) or
visit::fk_ctor(*) {
self.in_ctor = true;
self.declared_purity = decl.purity;
- self.fn_args = @decl.inputs.map({|i| i.id});
+ self.fn_args = @decl.inputs.map(|i| i.id );
}
visit::fk_anon(*) |
visit::fk_fn_block(*) if is_stack_closure {
visit::fk_dtor(*) {
self.in_ctor = false;
self.declared_purity = decl.purity;
- self.fn_args = @decl.inputs.map({|i| i.id});
+ self.fn_args = @decl.inputs.map(|i| i.id );
}
}
}
ast::expr_fn(_, _, _, cap_clause) |
ast::expr_fn_block(_, _, cap_clause) {
- for (*cap_clause).each { |cap_item|
+ for (*cap_clause).each |cap_item| {
if cap_item.is_move {
let def = self.tcx().def_map.get(cap_item.id);
fn check_loans_in_block(blk: ast::blk,
&&self: check_loan_ctxt,
vt: visit::vt<check_loan_ctxt>) {
- do save_and_restore(self.declared_purity) {||
+ do save_and_restore(self.declared_purity) || {
self.check_for_conflicting_loans(blk.node.id);
alt blk.node.rules {
#debug["req_loans_in_expr(ex=%s)", pprust::expr_to_str(ex)];
// If this expression is borrowed, have to ensure it remains valid:
- for tcx.borrowings.find(ex.id).each { |borrow|
+ for tcx.borrowings.find(ex.id).each |borrow| {
let cmt = self.bccx.cat_borrow_of_expr(ex);
let scope_r = ty::re_scope(borrow.scope_id);
self.guarantee_valid(cmt, borrow.mutbl, scope_r);
ast::expr_call(f, args, _) {
let arg_tys = ty::ty_fn_args(ty::expr_ty(self.tcx(), f));
let scope_r = ty::re_scope(ex.id);
- do vec::iter2(args, arg_tys) { |arg, arg_ty|
+ do vec::iter2(args, arg_tys) |arg, arg_ty| {
alt ty::resolved_mode(self.tcx(), arg_ty.mode) {
ast::by_mutbl_ref {
let arg_cmt = self.bccx.cat_expr(arg);
ast::expr_alt(ex_v, arms, _) {
let cmt = self.bccx.cat_expr(ex_v);
- for arms.each { |arm|
- for arm.pats.each { |pat|
+ for arms.each |arm| {
+ for arm.pats.each |pat| {
self.gather_pat(cmt, pat, arm.body.node.id, ex.id);
}
}
};
let result = {
- do self.check_mutbl(req_mutbl, cmt).chain { |_ok|
+ do self.check_mutbl(req_mutbl, cmt).chain |_ok| {
self.bccx.preserve(cmt, opt_scope_id)
}
};
not variant", e])}
};
- for subpats.each { |subpat|
+ for subpats.each |subpat| {
let subcmt = self.bccx.cat_variant(subpat, enum_did, cmt);
self.gather_pat(subcmt, subpat, arm_id, alt_id);
}
self.guarantee_valid(cmt1, m_const, arm_scope);
- for o_pat.each { |p|
+ for o_pat.each |p| {
self.gather_pat(cmt, p, arm_id, alt_id);
}
}
ast::pat_rec(field_pats, _) {
// {f1: p1, ..., fN: pN}
- for field_pats.each { |fp|
+ for field_pats.each |fp| {
let cmt_field = self.bccx.cat_field(fp.pat, cmt, fp.ident);
self.gather_pat(cmt_field, fp.pat, arm_id, alt_id);
}
ast::pat_tup(subpats) {
// (p1, ..., pN)
- for subpats.each { |subpat|
+ for subpats.each |subpat| {
let subcmt = self.bccx.cat_tuple_elt(subpat, cmt);
self.gather_pat(subcmt, subpat, arm_id, alt_id);
}
let freevars = freevars::get_freevars(tcx, fn_expr_id);
let seen_defs = map::int_hash();
- for (*cap_clause).each { |cap_item|
+ for (*cap_clause).each |cap_item| {
let cap_def = tcx.def_map.get(cap_item.id);
- if !vec::any(*freevars, {|fv| fv.def == cap_def}) {
+ if !vec::any(*freevars, |fv| fv.def == cap_def ) {
tcx.sess.span_warn(
cap_item.span,
#fmt("captured variable '%s' not used in closure",
// first add entries for anything explicitly named in the cap clause
- for (*cap_clause).each { |cap_item|
+ for (*cap_clause).each |cap_item| {
#debug("Doing capture var: %s (%?)",
*cap_item.name, cap_item.id);
if cap_item.is_move {
// if we are moving the value in, but it's not actually used,
// must drop it.
- if vec::any(*freevars, {|fv| fv.def == cap_def}) {
+ if vec::any(*freevars, |fv| fv.def == cap_def ) {
cap_map.insert(cap_def_id, {def:cap_def,
span: cap_item.span,
cap_item: some(cap_item),
} else {
// if we are copying the value in, but it's not actually used,
// just ignore it.
- if vec::any(*freevars, {|fv| fv.def == cap_def}) {
+ if vec::any(*freevars, |fv| fv.def == cap_def ) {
cap_map.insert(cap_def_id, {def:cap_def,
span: cap_item.span,
cap_item: some(cap_item),
ast::proto_bare | ast::proto_box | ast::proto_uniq { cap_copy }
};
- do vec::iter(*freevars) { |fvar|
+ do vec::iter(*freevars) |fvar| {
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
alt cap_map.find(fvar_def_id) {
option::some(_) { /* was explicitly named, do nothing */ }
}
let mut result = ~[];
- for cap_map.each_value { |cap_var| vec::push(result, cap_var); }
+ for cap_map.each_value |cap_var| { vec::push(result, cap_var); }
ret result;
}
fn check_crate(tcx: ty::ctxt, crate: @crate) {
visit::visit_crate(*crate, (), visit::mk_vt(@{
- visit_expr: {|a,b,c|check_expr(tcx, a, b, c)},
- visit_local: {|a,b,c|check_local(tcx, a, b, c)}
+ visit_expr: |a,b,c| check_expr(tcx, a, b, c),
+ visit_local: |a,b,c| check_local(tcx, a, b, c)
with *visit::default_visitor::<()>()
}));
tcx.sess.abort_if_errors();
// Check for unreachable patterns
fn check_arms(tcx: ty::ctxt, arms: ~[arm]) {
let mut seen = ~[];
- for arms.each {|arm|
- for arm.pats.each {|pat|
+ for arms.each |arm| {
+ for arm.pats.each |pat| {
let v = ~[pat];
alt is_useful(tcx, seen, v) {
not_useful {
}
fn check_exhaustive(tcx: ty::ctxt, sp: span, pats: ~[@pat]) {
- let ext = alt is_useful(tcx, vec::map(pats, {|p| ~[p]}), ~[wild()]) {
+ let ext = alt is_useful(tcx, vec::map(pats, |p| ~[p]), ~[wild()]) {
not_useful { ret; } // This is good, wildcard pattern isn't reachable
useful_ { none }
useful(ty, ctor) {
ty::ty_enum(id, _) {
let vid = alt check ctor { variant(id) { id } };
alt check vec::find(*ty::enum_variants(tcx, id),
- {|v| v.id == vid}) {
+ |v| v.id == vid) {
some(v) { some(v.name) }
}
}
fn is_useful(tcx: ty::ctxt, m: matrix, v: ~[@pat]) -> useful {
if m.len() == 0u { ret useful_; }
if m[0].len() == 0u { ret not_useful; }
- let real_pat = alt vec::find(m, {|r| r[0].id != 0}) {
+ let real_pat = alt vec::find(m, |r| r[0].id != 0) {
some(r) { r[0] } none { v[0] }
};
let left_ty = if real_pat.id == 0 { ty::mk_nil(tcx) }
}
}
ty::ty_enum(eid, _) {
- for (*ty::enum_variants(tcx, eid)).each {|va|
+ for (*ty::enum_variants(tcx, eid)).each |va| {
alt is_useful_specialized(tcx, m, v, variant(va.id),
va.args.len(), left_ty) {
not_useful {}
}
}
some(ctor) {
- alt is_useful(tcx, vec::filter_map(m, {|r| default(tcx, r)}),
+ alt is_useful(tcx, vec::filter_map(m, |r| default(tcx, r) ),
vec::tail(v)) {
useful_ { useful(left_ty, ctor) }
u { u }
fn is_useful_specialized(tcx: ty::ctxt, m: matrix, v: ~[@pat], ctor: ctor,
arity: uint, lty: ty::t) -> useful {
- let ms = vec::filter_map(m, {|r| specialize(tcx, r, ctor, arity, lty)});
+ let ms = vec::filter_map(m, |r| specialize(tcx, r, ctor, arity, lty) );
alt is_useful(tcx, ms, option::get(specialize(tcx, v, ctor, arity, lty))){
useful_ { useful(lty, ctor) }
u { u }
fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> option<ctor> {
alt ty::get(left_ty).struct {
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_tup(_) | ty::ty_rec(_) {
- for m.each {|r|
+ for m.each |r| {
if !is_wild(tcx, r[0]) { ret none; }
}
ret some(single);
}
ty::ty_enum(eid, _) {
let mut found = ~[];
- for m.each {|r|
- do option::iter(pat_ctor_id(tcx, r[0])) {|id|
+ for m.each |r| {
+ do option::iter(pat_ctor_id(tcx, r[0])) |id| {
if !vec::contains(found, id) { vec::push(found, id); }
}
}
let variants = ty::enum_variants(tcx, eid);
if found.len() != (*variants).len() {
- for vec::each(*variants) {|v|
+ for vec::each(*variants) |v| {
if !found.contains(variant(v.id)) {
ret some(variant(v.id));
}
ty::ty_nil { none }
ty::ty_bool {
let mut true_found = false, false_found = false;
- for m.each {|r|
+ for m.each |r| {
alt check pat_ctor_id(tcx, r[0]) {
none {}
some(val(const_int(1i64))) { true_found = true; }
ty::ty_box(_) | ty::ty_uniq(_) { 1u }
ty::ty_enum(eid, _) {
let id = alt check ctor { variant(id) { id } };
- alt check vec::find(*ty::enum_variants(tcx, eid), {|v| v.id == id}) {
+ alt check vec::find(*ty::enum_variants(tcx, eid), |v| v.id == id ) {
some(v) { v.args.len() }
}
}
let ty_flds = alt check ty::get(left_ty).struct {
ty::ty_rec(flds) { flds }
};
- let args = vec::map(ty_flds, {|ty_f|
- alt vec::find(flds, {|f| f.ident == ty_f.ident}) {
+ let args = vec::map(ty_flds, |ty_f| {
+ alt vec::find(flds, |f| f.ident == ty_f.ident ) {
some(f) { f.pat } _ { wild() }
}
});
pat_wild | pat_ident(_, none) { false }
pat_lit(_) | pat_range(_, _) { true }
pat_rec(fields, _) {
- for fields.each {|it|
+ for fields.each |it| {
if is_refutable(tcx, it.pat) { ret true; }
}
false
}
pat_tup(elts) {
- for elts.each {|elt| if is_refutable(tcx, elt) { ret true; } }
+ for elts.each |elt| { if is_refutable(tcx, elt) { ret true; } }
false
}
pat_enum(_, some(args)) {
- for args.each {|p| if is_refutable(tcx, p) { ret true; } };
+ for args.each |p| { if is_refutable(tcx, p) { ret true; } };
false
}
pat_enum(_,_) { false }
def_map: resolve::def_map,
method_map: typeck::method_map, tcx: ty::ctxt) {
visit::visit_crate(*crate, false, visit::mk_vt(@{
- visit_item: {|a,b,c|check_item(sess, ast_map, def_map, a, b, c)},
+ visit_item: |a,b,c| check_item(sess, ast_map, def_map, a, b, c),
visit_pat: check_pat,
- visit_expr: {|a,b,c|
+ visit_expr: |a,b,c|
check_expr(sess, def_map, method_map, tcx, a, b, c)
- }
with *visit::default_visitor()
}));
sess.abort_if_errors();
check_item_recursion(sess, ast_map, def_map, it);
}
item_enum(vs, _, _) {
- for vs.each {|var|
- do option::iter(var.node.disr_expr) {|ex|
+ for vs.each |var| {
+ do option::iter(var.node.disr_expr) |ex| {
v.visit_expr(ex, true, v);
}
}
fn check_crate(tcx: ty::ctxt, crate: @crate) {
visit::visit_crate(*crate, {in_loop: false,can_ret: true}, visit::mk_vt(@{
- visit_item: {|i, _cx, v|
+ visit_item: |i, _cx, v| {
visit::visit_item(i, {in_loop: false, can_ret: true}, v);
},
- visit_expr: {|e: @expr, cx: ctx, v: visit::vt<ctx>|
+ visit_expr: |e: @expr, cx: ctx, v: visit::vt<ctx>| {
alt e.node {
expr_while(e, b) {
v.visit_expr(e, cx, v);
if !is_move { check_copy(cx, id, var_t, sp, is_implicit); }
// check that only immutable variables are implicitly copied in
- for fv.each { |fv|
+ for fv.each |fv| {
check_imm_free_var(cx, fv.def, fv.span);
}
}
if !is_move { check_copy(cx, id, var_t, sp, is_implicit); }
// check that only immutable variables are implicitly copied in
- for fv.each { |fv|
+ for fv.each |fv| {
check_imm_free_var(cx, fv.def, fv.span);
}
}
// Find the check function that enforces the appropriate bounds for this
// kind of function:
- do with_appropriate_checker(cx, fn_id) { |chk|
+ do with_appropriate_checker(cx, fn_id) |chk| {
// Begin by checking the variables in the capture clause, if any.
// Here we slightly abuse the map function to both check and report
visit::fk_item_fn(*) | visit::fk_method(*) |
visit::fk_ctor(*) | visit::fk_dtor(*) { @~[] }
};
- let captured_vars = do (*cap_clause).map { |cap_item|
+ let captured_vars = do (*cap_clause).map |cap_item| {
let cap_def = cx.tcx.def_map.get(cap_item.id);
let cap_def_id = ast_util::def_id_of_def(cap_def).node;
let ty = ty::node_id_to_type(cx.tcx, cap_def_id);
// Iterate over any free variables that may not have appeared in the
// capture list. Ensure that they too are of the appropriate kind.
- for vec::each(*freevars::get_freevars(cx.tcx, fn_id)) {|fv|
+ for vec::each(*freevars::get_freevars(cx.tcx, fn_id)) |fv| {
let id = ast_util::def_id_of_def(fv.def).node;
// skip over free variables that appear in the cap clause
check_copy_ex(cx, rs, false);
}
expr_rec(fields, def) {
- for fields.each {|field| maybe_copy(cx, field.node.expr); }
+ for fields.each |field| { maybe_copy(cx, field.node.expr); }
alt def {
some(ex) {
// All noncopyable fields must be overridden
ty::ty_rec(f) { f }
_ { cx.tcx.sess.span_bug(ex.span, "bad expr type in record"); }
};
- for ty_fields.each {|tf|
- if !vec::any(fields, {|f| f.node.ident == tf.ident}) &&
+ for ty_fields.each |tf| {
+ if !vec::any(fields, |f| f.node.ident == tf.ident ) &&
!ty::kind_can_be_copied(ty::type_kind(cx.tcx, tf.mt.ty)) {
cx.tcx.sess.span_err(ex.span,
"copying a noncopyable value");
}
}
expr_tup(exprs) | expr_vec(exprs, _) {
- for exprs.each {|expr| maybe_copy(cx, expr); }
+ for exprs.each |expr| { maybe_copy(cx, expr); }
}
expr_call(f, args, _) {
let mut i = 0u;
- for ty::ty_fn_args(ty::expr_ty(cx.tcx, f)).each {|arg_t|
+ for ty::ty_fn_args(ty::expr_ty(cx.tcx, f)).each |arg_t| {
alt ty::arg_mode(cx.tcx, arg_t) {
by_copy { maybe_copy(cx, args[i]); }
by_ref | by_val | by_mutbl_ref | by_move { }
}
}
expr_path(_) | expr_field(_, _, _) {
- do option::iter(cx.tcx.node_type_substs.find(e.id)) {|ts|
+ do option::iter(cx.tcx.node_type_substs.find(e.id)) |ts| {
let bounds = alt check e.node {
expr_path(_) {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id));
%s (%u tys), declared = %? (%u tys)",
tys_to_str(cx.tcx, ts), ts.len(), *bounds, (*bounds).len());
}
- do vec::iter2(ts, *bounds) {|ty, bound|
+ do vec::iter2(ts, *bounds) |ty, bound| {
check_bounds(cx, e.id, e.span, ty, bound)
}
}
fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
alt stmt.node {
stmt_decl(@{node: decl_local(locals), _}, _) {
- for locals.each {|local|
+ for locals.each |local| {
alt local.node.init {
some({op: init_assign, expr}) { maybe_copy(cx, expr); }
_ {}
fn check_ty(aty: @ty, cx: ctx, v: visit::vt<ctx>) {
alt aty.node {
ty_path(_, id) {
- do option::iter(cx.tcx.node_type_substs.find(id)) {|ts|
+ do option::iter(cx.tcx.node_type_substs.find(id)) |ts| {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id));
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
- do vec::iter2(ts, *bounds) {|ty, bound|
+ do vec::iter2(ts, *bounds) |ty, bound| {
check_bounds(cx, aty.id, aty.span, ty, bound)
}
}
let mut new_ctxt = self;
let metas = attr::attr_metas(attr::find_attrs_by_name(attrs, "warn"));
- for metas.each {|meta|
+ for metas.each |meta| {
alt meta.node {
ast::meta_list(_, metas) {
- for metas.each {|meta|
+ for metas.each |meta| {
alt meta.node {
ast::meta_word(lintname) {
alt lookup_lint(self.dict, *lintname) {
}
fn build_settings_item(i: @ast::item, &&cx: ctxt, v: visit::vt<ctxt>) {
- do cx.with_warn_attrs(i.attrs) {|cx|
+ do cx.with_warn_attrs(i.attrs) |cx| {
if !cx.is_default {
cx.sess.warning_settings.settings_map.insert(i.id, cx.curr);
}
sess: sess};
// Install defaults.
- for cx.dict.each {|_k, spec| cx.set_level(spec.lint, spec.default); }
+ for cx.dict.each |_k, spec| { cx.set_level(spec.lint, spec.default); }
// Install command-line options, overriding defaults.
- for sess.opts.lint_opts.each {|pair|
+ for sess.opts.lint_opts.each |pair| {
let (lint,level) = pair;
cx.set_level(lint, level);
}
- do cx.with_warn_attrs(crate.node.attrs) {|cx|
+ do cx.with_warn_attrs(crate.node.attrs) |cx| {
// Copy out the default settings
- for cx.curr.each {|k, v|
+ for cx.curr.each |k, v| {
sess.warning_settings.default_settings.insert(k, v);
}
// not traverse into subitems, since that is handled by the outer
// lint visitor.
fn item_stopping_visitor<E>(v: visit::vt<E>) -> visit::vt<E> {
- visit::mk_vt(@{visit_item: {|_i, _e, _v| } with **v})
+ visit::mk_vt(@{visit_item: |_i, _e, _v| { } with **v})
}
fn check_item_while_true(cx: ty::ctxt, it: @ast::item) {
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
decl: ast::fn_decl) {
- let tys = vec::map(decl.inputs, {|a| a.ty });
- for vec::each(vec::append_one(tys, decl.output)) {|ty|
+ let tys = vec::map(decl.inputs, |a| a.ty );
+ for vec::each(vec::append_one(tys, decl.output)) |ty| {
alt ty.node {
ast::ty_path(_, id) {
alt cx.def_map.get(id) {
alt it.node {
ast::item_foreign_mod(nmod) if attr::foreign_abi(it.attrs) !=
either::right(ast::foreign_abi_rust_intrinsic) {
- for nmod.items.each {|ni|
+ for nmod.items.each |ni| {
alt ni.node {
ast::foreign_item_fn(decl, tps) {
check_foreign_fn(cx, it.id, decl);
#debug["creating fn_maps: %x", ptr::addr_of(*fn_maps) as uint];
- for decl.inputs.each { |arg|
+ for decl.inputs.each |arg| {
#debug["adding argument %d", arg.id];
let mode = ty::resolved_mode(self.tcx, arg.mode);
(*fn_maps).add_variable(vk_arg(arg.id, arg.ident, mode));
}
fn add_class_fields(self: @ir_maps, did: def_id) {
- for ty::lookup_class_fields(self.tcx, did).each { |field_ty|
+ for ty::lookup_class_fields(self.tcx, did).each |field_ty| {
assert field_ty.id.crate == local_crate;
let var = (*self).add_variable(vk_field(field_ty.ident));
self.field_map.insert(field_ty.ident, var);
fn visit_local(local: @local, &&self: @ir_maps, vt: vt<@ir_maps>) {
let def_map = self.tcx.def_map;
- do pat_util::pat_bindings(def_map, local.node.pat) { |p_id, sp, path|
+ do pat_util::pat_bindings(def_map, local.node.pat) |p_id, sp, path| {
#debug["adding local variable %d", p_id];
let name = ast_util::path_to_ident(path);
(*self).add_live_node_for_node(p_id, lnk_vdef(sp));
let cvs = capture::compute_capture_vars(self.tcx, expr.id,
proto, cap_clause);
let mut call_caps = ~[];
- for cvs.each { |cv|
+ for cvs.each |cv| {
alt relevant_def(cv.def) {
some(rv) {
let cv_ln = (*self).add_live_node(lnk_freevar(cv.span));
alt expr.node {
expr_path(_) {
let def = self.tcx.def_map.get(expr.id);
- relevant_def(def).map({ |rdef|
- self.variable_from_rdef(rdef, expr.span)
- })
+ relevant_def(def).map(
+ |rdef| self.variable_from_rdef(rdef, expr.span)
+ )
}
_ {none}
}
span: span) -> option<variable> {
alt self.tcx.def_map.find(node_id) {
some(def) {
- relevant_def(def).map({ |rdef|
- self.variable_from_rdef(rdef, span)
- })
+ relevant_def(def).map(
+ |rdef| self.variable_from_rdef(rdef, span)
+ )
}
none {
self.tcx.sess.span_bug(
fn pat_bindings(pat: @pat, f: fn(live_node, variable, span)) {
let def_map = self.tcx.def_map;
- do pat_util::pat_bindings(def_map, pat) {|p_id, sp, _n|
+ do pat_util::pat_bindings(def_map, pat) |p_id, sp, _n| {
let ln = self.live_node(p_id, sp);
let var = self.variable(p_id, sp);
f(ln, var, sp);
fn indices(ln: live_node, op: fn(uint)) {
let node_base_idx = self.idx(ln, variable(0u));
- for uint::range(0u, self.ir.num_vars) { |var_idx|
+ for uint::range(0u, self.ir.num_vars) |var_idx| {
op(node_base_idx + var_idx)
}
}
op: fn(uint, uint)) {
let node_base_idx = self.idx(ln, variable(0u));
let succ_base_idx = self.idx(succ_ln, variable(0u));
- for uint::range(0u, self.ir.num_vars) { |var_idx|
+ for uint::range(0u, self.ir.num_vars) |var_idx| {
op(node_base_idx + var_idx, succ_base_idx + var_idx);
}
}
ln: live_node,
test: fn(uint) -> live_node) {
let node_base_idx = self.idx(ln, variable(0u));
- for uint::range(0u, self.ir.num_vars) { |var_idx|
+ for uint::range(0u, self.ir.num_vars) |var_idx| {
let idx = node_base_idx + var_idx;
if test(idx).is_valid() {
wr.write_str(" ");
}
fn ln_str(ln: live_node) -> str {
- do io::with_str_writer { |wr|
+ do io::with_str_writer |wr| {
wr.write_str("[ln(");
wr.write_uint(*ln);
wr.write_str(") of kind ");
wr.write_str(#fmt["%?", copy self.ir.lnks[*ln]]);
wr.write_str(" reads");
- self.write_vars(wr, ln, {|idx| self.users[idx].reader});
+ self.write_vars(wr, ln, |idx| self.users[idx].reader );
wr.write_str(" writes");
- self.write_vars(wr, ln, {|idx| self.users[idx].writer});
+ self.write_vars(wr, ln, |idx| self.users[idx].writer );
wr.write_str(" ");
wr.write_str(" precedes ");
wr.write_str((copy self.successors[*ln]).to_str());
fn init_from_succ(ln: live_node, succ_ln: live_node) {
// more efficient version of init_empty() / merge_from_succ()
self.successors[*ln] = succ_ln;
- self.indices2(ln, succ_ln, { |idx, succ_idx|
- self.users[idx] = self.users[succ_idx];
+ self.indices2(ln, succ_ln, |idx, succ_idx| {
+ self.users[idx] = self.users[succ_idx]
});
#debug["init_from_succ(ln=%s, succ=%s)",
self.ln_str(ln), self.ln_str(succ_ln)];
if ln == succ_ln { ret false; }
let mut changed = false;
- do self.indices2(ln, succ_ln) { |idx, succ_idx|
+ do self.indices2(ln, succ_ln) |idx, succ_idx| {
changed |= copy_if_invalid(copy self.users[succ_idx].reader,
self.users[idx].reader);
changed |= copy_if_invalid(copy self.users[succ_idx].writer,
// effectively a return---this only occurs in `for` loops,
// where the body is really a closure.
let entry_ln: live_node =
- self.with_loop_nodes(self.s.exit_ln, self.s.exit_ln, {||
+ self.with_loop_nodes(self.s.exit_ln, self.s.exit_ln, || {
self.propagate_through_fn_block(decl, body)
});
// hack to skip the loop unless #debug is enabled:
#debug["^^ liveness computation results for body %d (entry=%s)",
{
- for uint::range(0u, self.ir.num_live_nodes) { |ln_idx|
+ for uint::range(0u, self.ir.num_live_nodes) |ln_idx| {
#debug["%s", self.ln_str(live_node(ln_idx))];
}
body.node.id
fn propagate_through_fn_block(decl: fn_decl, blk: blk) -> live_node {
// inputs passed by & mode should be considered live on exit:
- for decl.inputs.each { |arg|
+ for decl.inputs.each |arg| {
alt ty::resolved_mode(self.tcx, arg.mode) {
by_mutbl_ref | by_ref | by_val {
// These are "non-owned" modes, so register a read at
self.acc(self.s.exit_ln, self.s.self_var, ACC_READ);
// in a ctor, there is an implicit use of self.f for all fields f:
- for self.ir.field_map.each_value { |var|
+ for self.ir.field_map.each_value |var| {
self.acc(self.s.exit_ln, var, ACC_READ|ACC_USE);
}
fn propagate_through_block(blk: blk, succ: live_node) -> live_node {
let succ = self.propagate_through_opt_expr(blk.node.expr, succ);
- do blk.node.stmts.foldr(succ) { |stmt, succ|
+ do blk.node.stmts.foldr(succ) |stmt, succ| {
self.propagate_through_stmt(stmt, succ)
}
}
fn propagate_through_decl(decl: @decl, succ: live_node) -> live_node {
alt decl.node {
decl_local(locals) {
- do locals.foldr(succ) { |local, succ|
+ do locals.foldr(succ) |local, succ| {
self.propagate_through_local(local, succ)
}
}
// initialization, which is mildly more complex than checking
// once at the func header but otherwise equivalent.
- let opt_init = local.node.init.map({ |i| i.expr });
+ let opt_init = local.node.init.map(|i| i.expr );
let mut succ = self.propagate_through_opt_expr(opt_init, succ);
- do self.pat_bindings(local.node.pat) { |ln, var, _sp|
+ do self.pat_bindings(local.node.pat) |ln, var, _sp| {
self.init_from_succ(ln, succ);
self.define(ln, var);
succ = ln;
fn propagate_through_exprs(exprs: ~[@expr],
succ: live_node) -> live_node {
- do exprs.foldr(succ) { |expr, succ|
+ do exprs.foldr(succ) |expr, succ| {
self.propagate_through_expr(expr, succ)
}
}
fn propagate_through_opt_expr(opt_expr: option<@expr>,
succ: live_node) -> live_node {
- do opt_expr.foldl(succ) { |succ, expr|
+ do opt_expr.foldl(succ) |succ, expr| {
self.propagate_through_expr(expr, succ)
}
}
// the construction of a closure itself is not important,
// but we have to consider the closed over variables.
let caps = (*self.ir).captures(expr);
- do (*caps).foldr(succ) { |cap, succ|
+ do (*caps).foldr(succ) |cap, succ| {
self.init_from_succ(cap.ln, succ);
let var = self.variable_from_rdef(cap.rv, expr.span);
self.acc(cap.ln, var, ACC_READ | ACC_USE);
let ln = self.live_node(expr.id, expr.span);
self.init_empty(ln, succ);
let mut first_merge = true;
- for arms.each { |arm|
+ for arms.each |arm| {
let arm_succ =
self.propagate_through_opt_expr(
arm.guard,
expr_rec(fields, with_expr) {
let succ = self.propagate_through_opt_expr(with_expr, succ);
- do fields.foldr(succ) { |field, succ|
+ do fields.foldr(succ) |field, succ| {
self.propagate_through_expr(field.node.expr, succ)
}
}
let ln = self.live_node(expr.id, expr.span);
if acc != 0u {
self.init_from_succ(ln, succ);
- for self.ir.field_map.each_value { |var|
+ for self.ir.field_map.each_value |var| {
self.acc(ln, var, acc);
}
}
alt def {
def_self(_) {
// Note: the field_map is empty unless we are in a ctor
- ret self.ir.field_map.find(fld).map({ |var|
+ ret self.ir.field_map.find(fld).map(|var| {
let ln = self.live_node(expr.id, expr.span);
(ln, var)
});
first_merge = false;
}
let cond_ln = self.propagate_through_opt_expr(cond, ln);
- let body_ln = self.with_loop_nodes(succ, ln, {||
+ let body_ln = self.with_loop_nodes(succ, ln, || {
self.propagate_through_block(body, cond_ln)
});
while self.merge_from_succ(ln, body_ln, first_merge) {
first_merge = false;
assert cond_ln == self.propagate_through_opt_expr(cond, ln);
- assert body_ln == self.with_loop_nodes(succ, ln, {||
+ assert body_ln == self.with_loop_nodes(succ, ln, || {
self.propagate_through_block(body, cond_ln)
});
}
// should not be live at this point.
#debug["check_local() with no initializer"];
- do (*self).pat_bindings(local.node.pat) { |ln, var, sp|
+ do (*self).pat_bindings(local.node.pat) |ln, var, sp| {
if !self.warn_about_unused(sp, ln, var) {
alt (*self).live_on_exit(ln, var) {
none { /* not live: good */ }
fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
alt expr.node {
expr_path(_) {
- for (*self).variable_from_def_map(expr.id, expr.span).each { |var|
+ for (*self).variable_from_def_map(expr.id, expr.span).each |var| {
let ln = (*self).live_node(expr.id, expr.span);
self.consider_last_use(expr, ln, var);
}
expr_fn(_, _, _, cap_clause) | expr_fn_block(_, _, cap_clause) {
let caps = (*self.ir).captures(expr);
- for (*caps).each { |cap|
+ for (*caps).each |cap| {
let var = (*self).variable_from_rdef(cap.rv, expr.span);
self.consider_last_use(expr, cap.ln, var);
if cap.is_move {
expr_call(f, args, _) {
let targs = ty::ty_fn_args(ty::expr_ty(self.tcx, f));
vt.visit_expr(f, self, vt);
- do vec::iter2(args, targs) { |arg_expr, arg_ty|
+ do vec::iter2(args, targs) |arg_expr, arg_ty| {
alt ty::resolved_mode(self.tcx, arg_ty.mode) {
by_val | by_copy | by_ref | by_mutbl_ref{
vt.visit_expr(arg_expr, self, vt);
impl check_methods for @liveness {
fn check_fields(sp: span, entry_ln: live_node) {
- for self.ir.field_map.each { |nm, var|
+ for self.ir.field_map.each |nm, var| {
alt (*self).live_on_entry(entry_ln, var) {
none { /* ok */ }
some(lnk_exit) {
}
fn check_for_reassignments_in_pat(pat: @pat) {
- do (*self).pat_bindings(pat) { |ln, var, sp|
+ do (*self).pat_bindings(pat) |ln, var, sp| {
self.check_for_reassignment(ln, var, sp);
}
}
}
fn warn_about_unused_args(sp: span, decl: fn_decl, entry_ln: live_node) {
- for decl.inputs.each { |arg|
+ for decl.inputs.each |arg| {
let var = (*self).variable(arg.id, arg.ty.span);
alt ty::resolved_mode(self.tcx, arg.mode) {
by_mutbl_ref {
}
fn warn_about_unused_or_dead_vars_in_pat(pat: @pat) {
- do (*self).pat_bindings(pat) { |ln, var, sp|
+ do (*self).pat_bindings(pat) |ln, var, sp| {
if !self.warn_about_unused(sp, ln, var) {
self.warn_about_dead_assign(sp, ln, var);
}
fn warn_about_unused(sp: span, ln: live_node, var: variable) -> bool {
if !(*self).used_on_entry(ln, var) {
- for self.should_warn(var).each { |name|
+ for self.should_warn(var).each |name| {
// annoying: for parameters in funcs like `fn(x: int)
// {ret}`, there is only one node, so asking about
fn warn_about_dead_assign(sp: span, ln: live_node, var: variable) {
if (*self).live_on_exit(ln, var).is_none() {
- for self.should_warn(var).each { |name|
+ for self.should_warn(var).each |name| {
self.tcx.sess.span_warn(
sp,
#fmt["value assigned to `%s` is never read", *name]);
// use the node_id of their namesake in the first pattern.
fn pat_id_map(dm: resolve::def_map, pat: @pat) -> pat_id_map {
let map = std::map::box_str_hash();
- do pat_bindings(dm, pat) {|p_id, _s, n|
+ do pat_bindings(dm, pat) |p_id, _s, n| {
map.insert(path_to_ident(n), p_id);
};
ret map;
// Could return a constrained type in order to express that (future work)
fn pat_bindings(dm: resolve::def_map, pat: @pat,
it: fn(node_id, span, @path)) {
- do walk_pat(pat) {|p|
+ do walk_pat(pat) |p| {
alt p.node {
pat_ident(pth, _) if !pat_is_variant(dm, p) {
it(p.id, p.span, pth);
fn pat_binding_ids(dm: resolve::def_map, pat: @pat) -> ~[node_id] {
let mut found = ~[];
- pat_bindings(dm, pat, {|b_id, _sp, _pt| vec::push(found, b_id); });
+ pat_bindings(dm, pat, |b_id, _sp, _pt| vec::push(found, b_id) );
ret found;
}
// although the capture items are not expressions per se, they
// do get "evaluated" in some sense as copies or moves of the
// relevant variables so we parent them like an expression
- for (*cap_clause).each { |cap_item|
+ for (*cap_clause).each |cap_item| {
record_parent(cx, cap_item.id);
}
visit::visit_expr(expr, cx, visitor);
fn_cx.parent: %?",
body.node.id, cx.parent, fn_cx.parent];
- for decl.inputs.each { |input|
+ for decl.inputs.each |input| {
cx.region_map.insert(input.id, body.node.id);
}
ret ast_util::def_eq(v1.did, v2.did) &&
str::eq(*v1.ident, *v2.ident) && v1.ns == v2.ns;
}
- std::map::hashmap(hash, {|a, b| a == b})
+ std::map::hashmap(hash, |a, b| a == b)
}
enum mod_index_entry {
check_for_collisions(e, *crate);
// FIXME: move this to the lint pass when rewriting resolve. (#1634)
- for sess.opts.lint_opts.each {|pair|
+ for sess.opts.lint_opts.each |pair| {
let (lint,level) = pair;
if lint == lint::unused_imports && level != lint::ignore {
check_unused_imports(e, level);
fn iter_export_paths(vi: ast::view_item, f: fn(vp: @ast::view_path)) {
alt vi.node {
ast::view_item_export(vps) {
- for vps.each {|vp|
+ for vps.each |vp| {
f(vp);
}
}
fn iter_import_paths(vi: ast::view_item, f: fn(vp: @ast::view_path)) {
alt vi.node {
ast::view_item_import(vps) {
- for vps.each {|vp| f(vp);}
+ for vps.each |vp| { f(vp);}
}
_ {}
}
fn iter_effective_import_paths(vi: ast::view_item,
f: fn(vp: @ast::view_path)) {
iter_import_paths(vi, f);
- do iter_export_paths(vi) {|vp|
+ do iter_export_paths(vi) |vp| {
alt vp.node {
ast::view_path_simple(_, _, _) { }
// FIXME (but also see #1893): support uniform ident-list exports
fn map_crate(e: @env, c: @ast::crate) {
fn index_vi(e: @env, i: @ast::view_item, &&sc: scopes, _v: vt<scopes>) {
- do iter_effective_import_paths(*i) { |vp|
+ do iter_effective_import_paths(*i) |vp| {
alt vp.node {
ast::view_path_simple(name, path, id) {
e.imports.insert(id, todo(name, @path.idents, vp.span,
e.imports.insert(id, is_glob(@path.idents, sc, vp.span));
}
ast::view_path_list(mod_path, idents, _) {
- for idents.each {|ident|
+ for idents.each |ident| {
let t = todo(ident.node.name,
@(vec::append_one(mod_path.idents,
ident.node.name)),
fn path_from_scope(sc: scopes, n: str) -> str {
let mut path = n + "::";
- do list::iter(sc) {|s|
+ do list::iter(sc) |s| {
alt s {
scope_item(i) { path = *i.ident + "::" + path; }
_ {}
// So we wind up reusing the glob-import machinery when looking at
// glob exports. They just do re-exporting in a later step.
fn link_glob(e: @env, vi: @ast::view_item, &&sc: scopes, _v: vt<scopes>) {
- do iter_effective_import_paths(*vi) { |vp|
+ do iter_effective_import_paths(*vi) |vp| {
alt vp.node {
ast::view_path_glob(path, _) {
alt follow_import(*e, sc, path.idents, vp.span) {
// First, find all the modules, and index the names that they contain
let v_map_mod =
- @{visit_view_item: {|a,b,c|index_vi(e, a, b, c)},
- visit_item: {|a,b,c|index_i(e, a, b, c)},
+ @{visit_view_item: |a,b,c| index_vi(e, a, b, c),
+ visit_item: |a,b,c| index_i(e, a, b, c),
visit_block: visit_block_with_scope
with *visit::default_visitor::<scopes>()};
visit::visit_crate(*c, top_scope(), visit::mk_vt(v_map_mod));
// Next, assemble the links for globbed imports and exports.
let v_link_glob =
- @{visit_view_item: {|a,b,c|link_glob(e, a, b, c)},
+ @{visit_view_item: |a,b,c| link_glob(e, a, b, c),
visit_block: visit_block_with_scope,
- visit_item: {|a,b,c|visit_item_with_scope(e, a, b, c)}
+ visit_item: |a,b,c| visit_item_with_scope(e, a, b, c)
with *visit::default_visitor::<scopes>()};
visit::visit_crate(*c, top_scope(), visit::mk_vt(v_link_glob));
fn resolve_imports(e: env) {
e.used_imports.track = true;
- for e.imports.each {|id, v|
+ for e.imports.each |id, v| {
alt check v {
todo(name, path, span, scopes) {
resolve_import(e, id, name, *path, span, scopes);
// using lint-specific control flags presently but resolve-specific data
// structures. Should use the general lint framework (with scopes, attrs).
fn check_unused_imports(e: @env, level: lint::level) {
- for e.imports.each {|k, v|
+ for e.imports.each |k, v| {
alt v {
resolved(_, _, _, _, name, sp) {
if !vec::contains(e.used_imports.data, k) {
e.used_imports.track = true;
let v =
@{visit_foreign_item: visit_foreign_item_with_scope,
- visit_item: {|a,b,c|walk_item(e, a, b, c)},
+ visit_item: |a,b,c| walk_item(e, a, b, c),
visit_block: visit_block_with_scope,
visit_decl: visit_decl_with_scope,
visit_arm: visit_arm_with_scope,
- visit_local: {|a,b,c|visit_local_with_scope(e, a, b, c)},
- visit_pat: {|a,b,c|walk_pat(e, a, b, c)},
- visit_expr: {|a,b,c|walk_expr(e, a, b ,c)},
- visit_ty: {|a,b,c|walk_ty(e, a, b, c)},
- visit_ty_params: {|a,b,c|walk_tps(e, a, b, c)},
- visit_constr: {|a,b,c,d,f|walk_constr(e, a, b, c, d, f)},
- visit_fn: {|a,b,c,d,f,g,h|
+ visit_local: |a,b,c| visit_local_with_scope(e, a, b, c),
+ visit_pat: |a,b,c| walk_pat(e, a, b, c),
+ visit_expr: |a,b,c| walk_expr(e, a, b ,c),
+ visit_ty: |a,b,c| walk_ty(e, a, b, c),
+ visit_ty_params: |a,b,c| walk_tps(e, a, b, c),
+ visit_constr: |a,b,c,d,f| walk_constr(e, a, b, c, d, f),
+ visit_fn: |a,b,c,d,f,g,h| {
visit_fn_with_scope(e, a, b, c, d, f, g, h)
}
with *visit::default_visitor()};
refer to, so it's possible to resolve them.
*/
ast::item_impl(_, _, ifce, _, _) {
- ifce.iter({|p| resolve_iface_ref(p, sc, e);})
+ ifce.iter(|p| resolve_iface_ref(p, sc, e))
}
ast::item_class(_, ifaces, _, _, _, _) {
- for ifaces.each {|p|
+ for ifaces.each |p| {
resolve_iface_ref(p, sc, e);
}
}
}
ast::expr_fn(_, _, _, cap_clause) |
ast::expr_fn_block(_, _, cap_clause) {
- for (*cap_clause).each { |ci|
+ for (*cap_clause).each |ci| {
resolve_capture_item(e, sc, ci);
}
}
&&sc: scopes, v: vt<scopes>) {
let outer_current_tp = e.current_tp;
let mut current = 0u;
- for tps.each {|tp|
+ for tps.each |tp| {
e.current_tp = some(current);
- for vec::each(*tp.bounds) {|bound|
+ for vec::each(*tp.bounds) |bound| {
alt bound {
bound_iface(t) { v.visit_ty(t, sc, v); }
_ {}
alt i.node {
ast::item_impl(tps, _, ifce, sty, methods) {
v.visit_ty_params(tps, sc, v);
- option::iter(ifce, {|p| visit::visit_path(p.path, sc, v)});
+ option::iter(ifce, |p| visit::visit_path(p.path, sc, v));
v.visit_ty(sty, sc, v);
- for methods.each {|m|
+ for methods.each |m| {
v.visit_ty_params(m.tps, sc, v);
let msc = @cons(scope_method(m.self_id, vec::append(tps, m.tps)),
sc);
ast::item_iface(tps, _, methods) {
v.visit_ty_params(tps, sc, v);
let isc = @cons(scope_method(i.id, tps), sc);
- for methods.each {|m|
+ for methods.each |m| {
v.visit_ty_params(m.tps, isc, v);
let msc = @cons(scope_method(i.id, vec::append(tps, m.tps)), sc);
- for m.decl.inputs.each {|a| v.visit_ty(a.ty, msc, v); }
+ for m.decl.inputs.each |a| { v.visit_ty(a.ty, msc, v); }
v.visit_ty(m.decl.output, msc, v);
}
}
let ctor_scope = @cons(scope_method(ctor.node.self_id, tps),
class_scope);
/* visit the iface refs in the class scope */
- for ifaces.each {|p|
+ for ifaces.each |p| {
visit::visit_path(p.path, class_scope, v);
}
visit_fn_with_scope(e, visit::fk_ctor(i.ident, tps, ctor.node.self_id,
local_def(i.id)), ctor.node.dec,
ctor.node.body, ctor.span, ctor.node.id,
ctor_scope, v);
- do option::iter(m_dtor) {|dtor|
+ do option::iter(m_dtor) |dtor| {
let dtor_scope = @cons(scope_method(dtor.node.self_id, tps),
class_scope);
dtor_scope, v);
};
/* visit the items */
- for members.each {|cm|
+ for members.each |cm| {
alt cm.node {
class_method(m) {
let msc = @cons(scope_method(m.self_id,
// here's where we need to set up the mapping
// for f's constrs in the table.
- for decl.constraints.each {|c| resolve_constr(e, c, sc, v); }
+ for decl.constraints.each |c| { resolve_constr(e, c, sc, v); }
let scope = alt fk {
visit::fk_item_fn(_, tps) | visit::fk_method(_, tps, _)
| visit::fk_ctor(_, tps, _, _) | visit::fk_dtor(tps, _, _) {
fn visit_block_with_scope(b: ast::blk, &&sc: scopes, v: vt<scopes>) {
let pos = @mut 0u, loc = @mut 0u;
let block_sc = @cons(scope_block(b, pos, loc), sc);
- for b.node.view_items.each {|vi| v.visit_view_item(vi, block_sc, v); }
- for b.node.stmts.each {|stmt|
+ for b.node.view_items.each |vi| { v.visit_view_item(vi, block_sc, v); }
+ for b.node.stmts.each |stmt| {
v.visit_stmt(stmt, block_sc, v);;
*pos += 1u;;
*loc = 0u;
};
alt d.node {
decl_local(locs) {
- for locs.each {|loc| v.visit_local(loc, sc, v);; *loc_pos += 1u; }
+ for locs.each |loc| { v.visit_local(loc, sc, v);; *loc_pos += 1u; }
}
decl_item(it) { v.visit_item(it, sc, v); }
}
}
fn visit_arm_with_scope(a: ast::arm, &&sc: scopes, v: vt<scopes>) {
- for a.pats.each {|p| v.visit_pat(p, sc, v); }
+ for a.pats.each |p| { v.visit_pat(p, sc, v); }
let sc_inner = @cons(scope_arm(a), sc);
visit::visit_expr_opt(a.guard, sc_inner, v);
v.visit_block(a.body, sc_inner, v);
// scope. We disallow this, in order to make alt patterns consisting of a
// single identifier unambiguous (does the pattern "foo" refer to enum
// foo, or is it binding a new name foo?)
- do ast_util::walk_pat(loc.node.pat) { |p|
+ do ast_util::walk_pat(loc.node.pat) |p| {
alt p.node {
pat_ident(path, _) {
alt lookup_in_scope(*e, sc, loc.span, path_to_ident(path),
alt dcur {
some(ast::def_mod(_)) | some(ast::def_foreign_mod(_)) { ret dcur; }
_ {
- e.sess.span_err(sp, str::connect(path.map({|x|*x}), "::") +
+ e.sess.span_err(sp, str::connect(path.map(|x|*x), "::") +
" does not name a module.");
ret none;
}
fn find_imports_after(e: env, id: node_id, &&sc: scopes) -> ~[node_id] {
fn lst(my_id: node_id, vis: ~[@view_item]) -> ~[node_id] {
let mut imports = ~[], found = false;
- for vis.each {|vi|
- do iter_effective_import_paths(*vi) {|vp|
+ for vis.each |vi| {
+ do iter_effective_import_paths(*vi) |vp| {
alt vp.node {
view_path_simple(_, _, id)
| view_path_glob(_, id) {
if found { vec::push(imports, id); }
}
view_path_list(_, ids, _) {
- for ids.each {|id|
+ for ids.each |id| {
if id.node.id == my_id { found = true; }
if found { vec::push(imports, id.node.id); }
}
let end_id = ids[n_idents - 1u];
if n_idents == 1u {
register(e, n_id, in_scope(sc), sp, name,
- {|ns| lookup_in_scope(e, sc, sp, end_id, ns, true) }, ~[]);
+ |ns| lookup_in_scope(e, sc, sp, end_id, ns, true), ~[]);
} else {
alt lookup_in_scope(e, sc, sp, ids[0], ns_module, true) {
none {
if i == n_idents - 1u {
let mut impls = ~[];
find_impls_in_mod(e, dcur, impls, some(end_id));
- register(e, n_id, in_mod(dcur), sp, name, {|ns|
+ register(e, n_id, in_mod(dcur), sp, name, |ns| {
lookup_in_mod(e, dcur, sp, end_id, ns, outside)
}, impls);
break;
fn unresolved_err(e: env, cx: ctxt, sp: span, name: ident, kind: str) {
fn find_fn_or_mod_scope(sc: scopes) -> option<scope> {
- for list::each(sc) {|cur|
+ for list::each(sc) |cur| {
alt cur {
scope_crate | scope_bare_fn(_, _, _) | scope_fn_expr(_, _, _) |
scope_item(@{node: ast::item_mod(_), _}) {
in_scope(sc) {
alt find_fn_or_mod_scope(sc) {
some(err_scope) {
- for e.reported.each {|rs|
+ for e.reported.each |rs| {
if str::eq(*rs.ident, *name) && err_scope == rs.sc { ret; }
}
e.reported.push({ident: name, sc: err_scope});
path = @(e.mod_map.get(did.node).path + *path);
} else if did.node != ast::crate_node_id {
let paths = e.ext_map.get(did);
- path = @str::connect(vec::append_one(paths, path).map({|x|*x}),
+ path = @str::connect(vec::append_one(paths, path).map(|x|*x),
"::");
}
}
fn lookup_in_ty_params(e: env, name: ident, ty_params: ~[ast::ty_param])
-> option<def> {
let mut n = 0u;
- for ty_params.each {|tp|
+ for ty_params.each |tp| {
if str::eq(*tp.ident, *name) && alt e.current_tp {
some(cur) { n < cur } none { true }
} { ret some(ast::def_ty_param(local_def(tp.id), n)); }
fn lookup_in_pat(e: env, name: ident, pat: @ast::pat) -> option<node_id> {
let mut found = none;
- do pat_util::pat_bindings(e.def_map, pat) {|p_id, _sp, n|
+ do pat_util::pat_bindings(e.def_map, pat) |p_id, _sp, n| {
if str::eq(*path_to_ident(n), *name)
{ found = some(p_id); }
};
ns: namespace) -> option<def> {
alt ns {
ns_val {
- for decl.inputs.each {|a|
+ for decl.inputs.each |a| {
if str::eq(*a.ident, *name) {
ret some(ast::def_arg(a.id, a.mode));
}
} else {
alt ns {
ns_val {
- for variants.each {|v|
+ for variants.each |v| {
if str::eq(*v.node.name, *name) {
let i = v.node.id;
ret some(ast::def_variant
_ { }
}
}
- for b.view_items.each {|vi|
+ for b.view_items.each |vi| {
let mut is_import = false;
alt vi.node {
ast::view_item_import(_) { is_import = true; }
alt vi.node {
ast::view_item_import(vps) | ast::view_item_export(vps) {
- for vps.each {|vp|
+ for vps.each |vp| {
alt vp.node {
ast::view_path_simple(ident, _, id) {
if is_import && name == ident {
}
ast::view_path_list(path, idents, _) {
- for idents.each {|ident|
+ for idents.each |ident| {
if name == ident.node.name {
ret lookup_import(e, ident.node.id, ns);
}
alt inf.index.find(id) {
none { }
some(lst) {
- let found = list_search(lst, {|x| lookup_in_mie(e, x, ns)});
+ let found = list_search(lst, |x| lookup_in_mie(e, x, ns));
if !is_none(found) {
ret found;
}
}
let g = copy globs; // FIXME #2405
let matches = vec::filter_map(g,
- {|x| lookup_in_mod_(e, x, sp, id, ns, dr)});
+ |x| lookup_in_mod_(e, x, sp, id, ns, dr));
if vec::len(matches) == 0u {
ret none;
}
else if vec::len(matches) == 1u {
ret some(matches[0].def);
} else {
- for matches.each {|match|
+ for matches.each |match| {
let sp = match.path.span;
e.sess.span_note(sp, #fmt["'%s' is imported here", *id]);
}
fn index_view_items(view_items: ~[@ast::view_item],
index: hashmap<ident, @list<mod_index_entry>>) {
- for view_items.each {|vi|
+ for view_items.each |vi| {
alt vi.node {
ast::view_item_use(ident, _, id) {
add_to_index(index, ident, mie_view_item(ident, id, vi.span));
_ {}
}
- do iter_effective_import_paths(*vi) {|vp|
+ do iter_effective_import_paths(*vi) |vp| {
alt vp.node {
ast::view_path_simple(ident, _, id) {
add_to_index(index, ident, mie_import_ident(id, vp.span));
}
ast::view_path_list(_, idents, _) {
- for idents.each {|ident|
+ for idents.each |ident| {
add_to_index(index, ident.node.name,
mie_import_ident(ident.node.id,
ident.span));
index_view_items(md.view_items, index);
- for md.items.each {|it|
+ for md.items.each |it| {
alt it.node {
ast::item_const(_, _) | ast::item_fn(_, _, _) | ast::item_mod(_) |
ast::item_foreign_mod(_) | ast::item_ty(_, _, _) |
ast::item_enum(variants, _, _) {
add_to_index(index, it.ident, mie_item(it));
let mut variant_idx: uint = 0u;
- for variants.each {|v|
+ for variants.each |v| {
add_to_index(index, v.node.name,
mie_enum_variant(variant_idx, variants,
it.id, it.span));
index_view_items(md.view_items, index);
- for md.items.each {|it|
+ for md.items.each |it| {
add_to_index(index, it.ident, mie_foreign_item(it));
}
ret index;
fn lookup_external(e: env, cnum: int, ids: ~[ident], ns: namespace) ->
option<def> {
let mut result = none;
- for csearch::lookup_defs(e.sess.cstore, cnum, ids).each {|d|
+ for csearch::lookup_defs(e.sess.cstore, cnum, ids).each |d| {
e.ext_map.insert(def_id_of_def(d), ids);
if ns == ns_for_def(d) { result = some(d); }
}
fn check_for_collisions(e: @env, c: ast::crate) {
// Module indices make checking those relatively simple -- just check each
// name for multiple entities in the same namespace.
- for e.mod_map.each_value {|val|
- for val.index.each {|k, v| check_mod_name(*e, k, v); };
+ for e.mod_map.each_value |val| {
+ for val.index.each |k, v| { check_mod_name(*e, k, v); };
};
// Other scopes have to be checked the hard way.
let v =
- @{visit_item: {|a,b,c|check_item(e, a, b, c)},
- visit_block: {|a,b,c|check_block(e, a, b, c)},
- visit_arm: {|a,b,c|check_arm(e, a, b, c)},
- visit_expr: {|a,b,c|check_expr(e, a, b, c)},
- visit_ty: {|a,b,c|check_ty(e, a, b, c)}
+ @{visit_item: |a,b,c| check_item(e, a, b, c),
+ visit_block: |a,b,c| check_block(e, a, b, c),
+ visit_arm: |a,b,c| check_arm(e, a, b, c),
+ visit_expr: |a,b,c| check_expr(e, a, b, c),
+ visit_ty: |a,b,c| check_ty(e, a, b, c)
with *visit::default_visitor()};
visit::visit_crate(c, (), visit::mk_vt(v));
}
fn check_item(e: @env, i: @ast::item, &&x: (), v: vt<()>) {
fn typaram_names(tps: ~[ast::ty_param]) -> ~[ident] {
let mut x: ~[ast::ident] = ~[];
- for tps.each {|tp| vec::push(x, tp.ident); }
+ for tps.each |tp| { vec::push(x, tp.ident); }
ret x;
}
visit::visit_item(i, x, v);
alt i.node {
ast::item_fn(decl, ty_params, _) {
check_fn(*e, i.span, decl);
- ensure_unique(*e, i.span, ty_params, {|tp| tp.ident},
+ ensure_unique(*e, i.span, ty_params, |tp| tp.ident,
"type parameter");
}
ast::item_enum(_, ty_params, _) {
- ensure_unique(*e, i.span, ty_params, {|tp| tp.ident},
+ ensure_unique(*e, i.span, ty_params, |tp| tp.ident,
"type parameter");
}
ast::item_iface(_, _, methods) {
- ensure_unique(*e, i.span, methods, {|m| m.ident},
+ ensure_unique(*e, i.span, methods, |m| m.ident,
"method");
}
ast::item_impl(_, _, _, _, methods) {
- ensure_unique(*e, i.span, methods, {|m| m.ident},
+ ensure_unique(*e, i.span, methods, |m| m.ident,
"method");
}
_ { }
}
fn check_pat(e: @env, ch: checker, p: @ast::pat) {
- do pat_util::pat_bindings(e.def_map, p) {|_i, p_sp, n|
+ do pat_util::pat_bindings(e.def_map, p) |_i, p_sp, n| {
add_name(ch, p_sp, path_to_ident(n));
};
}
e.sess.span_err(a.pats[i].span,
"inconsistent number of bindings");
} else {
- for ch.seen.each {|name|
- if is_none(vec::find(seen0, {|x|str::eq(*name, *x)})) {
+ for ch.seen.each |name| {
+ if is_none(vec::find(seen0, |x| str::eq(*name, *x))) {
// Fight the alias checker
let name_ = name;
e.sess.span_err(a.pats[i].span,
let values = checker(*e, "value");
let types = checker(*e, "type");
let mods = checker(*e, "module");
- for b.node.stmts.each {|st|
+ for b.node.stmts.each |st| {
alt st.node {
ast::stmt_decl(d, _) {
alt d.node {
ast::decl_local(locs) {
let local_values = checker(*e, "value");
- for locs.each {|loc|
+ for locs.each |loc| {
do pat_util::pat_bindings(e.def_map, loc.node.pat)
- {|_i, p_sp, n|
+ |_i, p_sp, n| {
let ident = path_to_ident(n);
add_name(local_values, p_sp, ident);
check_name(values, p_sp, ident);
alt it.node {
ast::item_enum(variants, _, _) {
add_name(types, it.span, it.ident);
- for variants.each {|v|
+ for variants.each |v| {
add_name(values, v.span, v.node.name);
}
}
}
fn check_name(ch: checker, sp: span, name: ident) {
- for ch.seen.each {|s|
+ for ch.seen.each |s| {
if str::eq(*s, *name) {
ch.sess.span_fatal(
sp, "duplicate " + ch.kind + " name: " + *name);
fn ensure_unique<T>(e: env, sp: span, elts: ~[T], id: fn(T) -> ident,
kind: str) {
let ch = checker(e, kind);
- for elts.each {|elt| add_name(ch, sp, id(elt)); }
+ for elts.each |elt| { add_name(ch, sp, id(elt)); }
}
fn check_exports(e: @env) {
assert mid.crate == ast::local_crate;
let ixm = e.mod_map.get(mid.node);
- for ixm.index.each {|ident, mies|
- do list::iter(mies) {|mie|
+ for ixm.index.each |ident, mies| {
+ do list::iter(mies) |mie| {
alt mie {
mie_item(item) {
let defs =
~[ found_def_item(item, ns_val),
found_def_item(item, ns_type),
found_def_item(item, ns_module) ];
- for defs.each {|d|
+ for defs.each |d| {
alt d {
some(def) {
f(ident, def);
fn maybe_add_reexport(e: @env, export_id: node_id, def: option<def>) {
- do option::iter(def) {|def|
+ do option::iter(def) |def| {
add_export(e, export_id, def_id_of_def(def), true);
}
}
if _mod.index.contains_key(ident) {
found_something = true;
let xs = _mod.index.get(ident);
- do list::iter(xs) {|x|
+ do list::iter(xs) |x| {
alt x {
mie_import_ident(id, _) {
alt check e.imports.get(id) {
e.sess.span_fatal(sp, #fmt("undefined id %s in an export", *id));
}
some(ms) {
- let maybe_id = do list_search(ms) {|m|
+ let maybe_id = do list_search(ms) |m| {
alt m {
mie_item(@{node: item_enum(_, _, _), id, _}) { some(id) }
_ { none }
ids: ~[ast::path_list_ident]) {
let parent_id = check_enum_ok(e, span, id, _mod);
add_export(e, export_id, local_def(parent_id), false);
- for ids.each {|variant_id|
+ for ids.each |variant_id| {
let mut found = false;
alt _mod.index.find(variant_id.node.name) {
some(ms) {
- do list::iter(ms) {|m|
+ do list::iter(ms) |m| {
alt m {
mie_enum_variant(_, _, actual_parent_id, _) {
found = true;
}
}
- for e.mod_map.each_value {|_mod|
+ for e.mod_map.each_value |_mod| {
alt _mod.m {
some(m) {
let glob_is_re_exported = int_hash();
- for m.view_items.each {|vi|
- do iter_export_paths(*vi) { |vp|
+ for m.view_items.each |vi| {
+ do iter_export_paths(*vi) |vp| {
alt vp.node {
ast::view_path_simple(ident, _, id) {
check_export(e, ident, _mod, id, vi);
}
// Now follow the export-glob links and fill in the
// globbed_exports and exp_map lists.
- for _mod.glob_imports.each {|glob|
+ for _mod.glob_imports.each |glob| {
let id = alt check glob.path.node {
ast::view_path_glob(_, node_id) { node_id }
};
if ! glob_is_re_exported.contains_key(id) { cont; }
do iter_mod(*e, glob.def,
- glob.path.span, outside) {|ident, def|
+ glob.path.span, outside) |ident, def| {
vec::push(_mod.globbed_exports, ident);
maybe_add_reexport(e, id, some(def));
}
fn resolve_impls(e: @env, c: @ast::crate) {
visit::visit_crate(*c, @nil, visit::mk_vt(@{
- visit_block: {|a,b,c|visit_block_with_impl_scope(e, a, b, c)},
- visit_mod: {|a,b,c,d,f|visit_mod_with_impl_scope(e, a, b, c, d, f)},
- visit_expr: {|a,b,c|resolve_impl_in_expr(e, a, b, c)}
+ visit_block: |a,b,c| visit_block_with_impl_scope(e, a, b, c),
+ visit_mod: |a,b,c,d,f| visit_mod_with_impl_scope(e, a, b, c, d, f),
+ visit_expr: |a,b,c| resolve_impl_in_expr(e, a, b, c)
with *visit::default_visitor()
}));
}
}
}
- do iter_effective_import_paths(*vi) { |vp|
+ do iter_effective_import_paths(*vi) |vp| {
alt vp.node {
ast::view_path_simple(name, pt, id) {
let mut found = ~[];
if vec::len(pt.idents) == 1u {
- do option::iter(sc) {|sc|
- do list::iter(sc) {|level|
+ do option::iter(sc) |sc| {
+ do list::iter(sc) |level| {
if vec::len(found) == 0u {
- for vec::each(*level) {|imp|
+ for vec::each(*level) |imp| {
if imp.ident == pt.idents[0] {
vec::push(found,
@{ident: name with *imp});
}
}
} else {
- do lookup_imported_impls(e, id) {|is|
- for vec::each(*is) {|i|
+ do lookup_imported_impls(e, id) |is| {
+ for vec::each(*is) |i| {
vec::push(impls, @{ident: name with *i});
}
}
}
ast::view_path_list(base, names, _) {
- for names.each {|nm|
- lookup_imported_impls(e, nm.node.id, {|is|
+ for names.each |nm| {
+ lookup_imported_impls(e, nm.node.id, |is| {
vec::push_all(impls, *is);
})
}
} {
vec::push(impls, @{did: local_def(i.id),
ident: i.ident,
- methods: vec::map(mthds, {|m|
+ methods: vec::map(mthds, |m| {
@{did: local_def(m.id),
n_tps: vec::len(m.tps),
ident: m.ident}
ast::item_class(tps, ifces, items, _, _, _) {
let (_, mthds) = ast_util::split_class_items(items);
let n_tps = tps.len();
- do vec::iter(ifces) {|p|
- // The def_id, in this case, identifies the combination of
- // class and iface
- vec::push(impls, @{did: local_def(p.id),
- ident: i.ident,
- methods: vec::map(mthds, {|m|
- @{did: local_def(m.id),
- n_tps: n_tps + m.tps.len(),
- ident: m.ident}})});
+ do vec::iter(ifces) |p| {
+ // The def_id, in this case, identifies the combination of
+ // class and iface
+ vec::push(impls, @{did: local_def(p.id),
+ ident: i.ident,
+ methods: vec::map(mthds, |m| {
+ @{did: local_def(m.id),
+ n_tps: n_tps + m.tps.len(),
+ ident: m.ident}})});
}
}
_ {}
let mut tmp = ~[];
let mi = e.mod_map.get(defid.node);
let md = option::get(mi.m);
- for md.view_items.each {|vi|
+ for md.view_items.each |vi| {
find_impls_in_view_item(e, vi, tmp, none);
}
- for md.items.each {|i|
+ for md.items.each |i| {
find_impls_in_item(e, i, tmp, none, none);
}
- @vec::filter(tmp, {|i| is_exported(e, i.ident, mi)})
+ @vec::filter(tmp, |i| is_exported(e, i.ident, mi))
} else {
csearch::get_impls_for_mod(e.sess.cstore, defid, none)
};
}
alt name {
some(n) {
- for vec::each(*cached) {|im|
+ for vec::each(*cached) |im| {
if n == im.ident { vec::push(impls, im); }
}
}
fn visit_block_with_impl_scope(e: @env, b: ast::blk, &&sc: iscopes,
v: vt<iscopes>) {
let mut impls = ~[];
- for b.node.view_items.each {|vi|
+ for b.node.view_items.each |vi| {
find_impls_in_view_item(*e, vi, impls, some(sc));
}
- for b.node.stmts.each {|st|
+ for b.node.stmts.each |st| {
alt st.node {
ast::stmt_decl(@{node: ast::decl_item(i), _}, _) {
find_impls_in_item(*e, i, impls, none, none);
fn visit_mod_with_impl_scope(e: @env, m: ast::_mod, s: span, id: node_id,
&&sc: iscopes, v: vt<iscopes>) {
let mut impls = ~[];
- for m.view_items.each {|vi|
+ for m.view_items.each |vi| {
find_impls_in_view_item(*e, vi, impls, some(sc));
}
- for m.items.each {|i| find_impls_in_item(*e, i, impls, none, none); }
+ for m.items.each |i| { find_impls_in_item(*e, i, impls, none, none); }
let impls = @impls;
visit::visit_mod(m, s, id, if vec::len(*impls) > 0u {
@cons(impls, sc)
fn variant_opt(tcx: ty::ctxt, pat_id: ast::node_id) -> opt {
let vdef = ast_util::variant_def_ids(tcx.def_map.get(pat_id));
let variants = ty::enum_variants(tcx, vdef.enm);
- for vec::each(*variants) {|v|
+ for vec::each(*variants) |v| {
if vdef.var == v.id { ret var(v.disr_val, vdef); }
}
core::unreachable();
type bind_map = ~[{ident: ast::ident, val: ValueRef}];
fn assoc(key: ast::ident, list: bind_map) -> option<ValueRef> {
- for vec::each(list) {|elt|
+ for vec::each(list) |elt| {
if str::eq(*elt.ident, *key) { ret some(elt.val); }
}
ret none;
type match = ~[match_branch];
fn has_nested_bindings(m: match, col: uint) -> bool {
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
alt br.pats[col].node {
ast::pat_ident(_, some(_)) { ret true; }
_ {}
fn expand_nested_bindings(m: match, col: uint, val: ValueRef) -> match {
let mut result = ~[];
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
alt br.pats[col].node {
ast::pat_ident(name, some(inner)) {
let pats = vec::append(
fn enter_match(dm: def_map, m: match, col: uint, val: ValueRef,
e: enter_pat) -> match {
let mut result = ~[];
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
alt e(br.pats[col]) {
some(sub) {
let pats = vec::append(
}
fn enter_default(dm: def_map, m: match, col: uint, val: ValueRef) -> match {
- do enter_match(dm, m, col, val) {|p|
+ do enter_match(dm, m, col, val) |p| {
alt p.node {
ast::pat_wild | ast::pat_rec(_, _) | ast::pat_tup(_) { some(~[]) }
ast::pat_ident(_, none) if !pat_is_variant(dm, p) {
fn enter_opt(tcx: ty::ctxt, m: match, opt: opt, col: uint,
variant_size: uint, val: ValueRef) -> match {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
- do enter_match(tcx.def_map, m, col, val) {|p|
+ do enter_match(tcx.def_map, m, col, val) |p| {
alt p.node {
ast::pat_enum(_, subpats) {
if opt_eq(tcx, variant_opt(tcx, p.id), opt) {
fn enter_rec(dm: def_map, m: match, col: uint, fields: ~[ast::ident],
val: ValueRef) -> match {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
- do enter_match(dm, m, col, val) {|p|
+ do enter_match(dm, m, col, val) |p| {
alt p.node {
ast::pat_rec(fpats, _) {
let mut pats = ~[];
- for vec::each(fields) {|fname|
+ for vec::each(fields) |fname| {
let mut pat = dummy;
- for vec::each(fpats) {|fpat|
+ for vec::each(fpats) |fpat| {
if str::eq(*fpat.ident, *fname) { pat = fpat.pat; break; }
}
vec::push(pats, pat);
fn enter_tup(dm: def_map, m: match, col: uint, val: ValueRef,
n_elts: uint) -> match {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
- do enter_match(dm, m, col, val) {|p|
+ do enter_match(dm, m, col, val) |p| {
alt p.node {
ast::pat_tup(elts) { some(elts) }
_ { some(vec::from_elem(n_elts, dummy)) }
fn enter_box(dm: def_map, m: match, col: uint, val: ValueRef) -> match {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
- do enter_match(dm, m, col, val) {|p|
+ do enter_match(dm, m, col, val) |p| {
alt p.node {
ast::pat_box(sub) { some(~[sub]) }
_ { some(~[dummy]) }
fn enter_uniq(dm: def_map, m: match, col: uint, val: ValueRef) -> match {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
- do enter_match(dm, m, col, val) {|p|
+ do enter_match(dm, m, col, val) |p| {
alt p.node {
ast::pat_uniq(sub) { some(~[sub]) }
_ { some(~[dummy]) }
fn get_options(ccx: @crate_ctxt, m: match, col: uint) -> ~[opt] {
fn add_to_set(tcx: ty::ctxt, &&set: dvec<opt>, val: opt) {
- if set.any({|l| opt_eq(tcx, l, val)}) {ret;}
+ if set.any(|l| opt_eq(tcx, l, val)) {ret;}
set.push(val);
}
let found = dvec();
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
let cur = br.pats[col];
if pat_is_variant(ccx.tcx.def_map, cur) {
add_to_set(ccx.tcx, found, variant_opt(ccx.tcx, br.pats[col].id));
}
let vdefs_tg = vdefs.enm;
let vdefs_var = vdefs.var;
- let args = do vec::from_fn(size) { |i|
+ let args = do vec::from_fn(size) |i| {
GEP_enum(bcx, blobptr, vdefs_tg, vdefs_var,
enum_ty_substs, i)
};
fn collect_record_fields(m: match, col: uint) -> ~[ast::ident] {
let mut fields: ~[ast::ident] = ~[];
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
alt br.pats[col].node {
ast::pat_rec(fs, _) {
- for vec::each(fs) {|f|
- if !vec::any(fields, {|x| str::eq(*f.ident, *x)}) {
+ for vec::each(fs) |f| {
+ if !vec::any(fields, |x| str::eq(*f.ident, *x)) {
vec::push(fields, f.ident);
}
}
}
fn root_pats_as_necessary(bcx: block, m: match, col: uint, val: ValueRef) {
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
let pat_id = br.pats[col].id;
alt bcx.ccx().maps.root_map.find({id:pat_id, derefs:0u}) {
}
fn any_box_pat(m: match, col: uint) -> bool {
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
alt br.pats[col].node { ast::pat_box(_) { ret true; } _ { } }
}
ret false;
}
fn any_uniq_pat(m: match, col: uint) -> bool {
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
alt br.pats[col].node { ast::pat_uniq(_) { ret true; } _ { } }
}
ret false;
}
fn any_tup_pat(m: match, col: uint) -> bool {
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
alt br.pats[col].node { ast::pat_tup(_) { ret true; } _ { } }
}
ret false;
}
}
let scores = vec::to_mut(vec::from_elem(m[0].pats.len(), 0u));
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
let mut i = 0u;
- for vec::each(br.pats) {|p| scores[i] += score(p); i += 1u; }
+ for vec::each(br.pats) |p| { scores[i] += score(p); i += 1u; }
}
let mut max_score = 0u;
let mut best_col = 0u;
let mut i = 0u;
- for vec::each(scores) {|score|
+ for vec::each(scores) |score| {
// Irrefutable columns always go first, they'd only be duplicated in
// the branches.
if score == 0u { ret i; }
some(e) {
// Temporarily set bindings. They'll be rewritten to PHI nodes
// for the actual arm block.
- for data.id_map.each {|key, val|
+ for data.id_map.each |key, val| {
let loc = local_mem(option::get(assoc(key, m[0].bound)));
bcx.fcx.lllocals.insert(val, loc);
};
let {bcx: guard_cx, val} = {
- do with_scope_result(bcx, e.info(), "guard") {|bcx|
+ do with_scope_result(bcx, e.info(), "guard") |bcx| {
trans_temp_expr(bcx, e)
}
};
- bcx = do with_cond(guard_cx, Not(guard_cx, val)) {|bcx|
+ bcx = do with_cond(guard_cx, Not(guard_cx, val)) |bcx| {
compile_submatch(bcx, vec::tail(m), vals, chk, exits);
bcx
};
vec::view(vals, col + 1u, vals.len()));
let ccx = bcx.fcx.ccx;
let mut pat_id = 0;
- for vec::each(m) {|br|
+ for vec::each(m) |br| {
// Find a real id (we're adding placeholder wildcard patterns, but
// each column is guaranteed to have at least one real pattern)
if pat_id == 0 { pat_id = br.pats[col].id; }
if rec_fields.len() > 0u {
let fields = ty::get_fields(node_id_type(bcx, pat_id));
let mut rec_vals = ~[];
- for vec::each(rec_fields) {|field_name|
+ for vec::each(rec_fields) |field_name| {
let ix = option::get(ty::field_idx(field_name, fields));
vec::push(rec_vals, GEPi(bcx, val, ~[0u, ix]));
}
}
}
}
- for vec::each(opts) {|o|
+ for vec::each(opts) |o| {
alt o {
range(_, _) { kind = compare; break; }
_ { }
let len = opts.len();
let mut i = 0u;
// Compile subtrees for each option
- for vec::each(opts) {|opt|
+ for vec::each(opts) |opt| {
i += 1u;
let mut opt_cx = else_cx;
if !exhaustive || i < len {
compare {
let t = node_id_type(bcx, pat_id);
let {bcx: after_cx, val: matches} = {
- do with_scope_result(bcx, none, "compare_scope") {|bcx|
+ do with_scope_result(bcx, none, "compare_scope") |bcx| {
alt trans_opt(bcx, opt) {
single_result({bcx, val}) {
trans_compare(bcx, ast::eq, test_val, t, val, t)
let _icx = bcx.insn_ctxt("alt::make_phi_bindings");
let our_block = bcx.llbb as uint;
let mut success = true, bcx = bcx;
- for ids.each {|name, node_id|
+ for ids.each |name, node_id| {
let mut llbbs = ~[];
let mut vals = ~[];
- for vec::each(map) {|ex|
+ for vec::each(map) |ex| {
if ex.to as uint == our_block {
alt assoc(name, ex.bound) {
some(val) {
mode: ast::alt_mode,
dest: dest) -> block {
let _icx = bcx.insn_ctxt("alt::trans_alt");
- do with_scope(bcx, alt_expr.info(), "alt") {|bcx|
+ do with_scope(bcx, alt_expr.info(), "alt") |bcx| {
trans_alt_inner(bcx, expr, arms, mode, dest)
}
}
let {bcx, val, _} = trans_temp_expr(bcx, expr);
if bcx.unreachable { ret bcx; }
- for vec::each(arms) {|a|
+ for vec::each(arms) |a| {
let body = scope_block(bcx, a.body.info(), "case_body");
let id_map = pat_util::pat_id_map(tcx.def_map, a.pats[0]);
vec::push(bodies, body);
- for vec::each(a.pats) {|p|
+ for vec::each(a.pats) |p| {
vec::push(match, @{pats: ~[p],
bound: ~[],
data: @{bodycx: body, guard: a.guard,
*done = some(fail_cx.llbb);
ret fail_cx.llbb;
}
- some({||mk_fail(scope_cx, expr.span, fail_cx)})
+ some(|| mk_fail(scope_cx, expr.span, fail_cx))
}
ast::alt_exhaustive { none }
};
compile_submatch(bcx, match, ~[spilled], mk_fail, exit_map);
let mut arm_cxs = ~[], arm_dests = ~[], i = 0u;
- for vec::each(arms) {|a|
+ for vec::each(arms) |a| {
let body_cx = bodies[i];
let id_map = pat_util::pat_id_map(tcx.def_map, a.pats[0]);
if make_phi_bindings(body_cx, exit_map, id_map) {
let vdefs = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat.id));
let args = extract_variant_args(bcx, pat.id, vdefs, val);
let mut i = 0;
- do option::iter(sub) {|sub| for vec::each(args.vals) {|argval|
+ do option::iter(sub) |sub| { for vec::each(args.vals) |argval| {
bcx = bind_irrefutable_pat(bcx, sub[i], argval, make_copy);
i += 1;
}}
}
ast::pat_rec(fields, _) {
let rec_fields = ty::get_fields(node_id_type(bcx, pat.id));
- for vec::each(fields) {|f|
+ for vec::each(fields) |f| {
let ix = option::get(ty::field_idx(f.ident, rec_fields));
let fldptr = GEPi(bcx, val, ~[0u, ix]);
bcx = bind_irrefutable_pat(bcx, f.pat, fldptr, make_copy);
}
ast::pat_tup(elems) {
let mut i = 0u;
- for vec::each(elems) {|elem|
+ for vec::each(elems) |elem| {
let fldptr = GEPi(bcx, val, ~[0u, i]);
bcx = bind_irrefutable_pat(bcx, elem, fldptr, make_copy);
i += 1u;
in_ds: ~[dest], out_dest: dest) -> block {
let out = sub_block(parent_cx, "join");
let mut reachable = false, i = 0u, phi = none;
- for vec::each(in_cxs) {|cx|
+ for vec::each(in_cxs) |cx| {
if !cx.unreachable {
Br(cx, out.llbb);
reachable = true;
fn decl_fn(llmod: ModuleRef, name: str, cc: lib::llvm::CallConv,
llty: TypeRef) -> ValueRef {
- let llfn: ValueRef = str::as_c_str(name, {|buf|
+ let llfn: ValueRef = str::as_c_str(name, |buf| {
llvm::LLVMGetOrInsertFunction(llmod, buf, llty)
});
lib::llvm::SetFunctionCallConv(llfn, cc);
fn get_extern_const(externs: hashmap<str, ValueRef>, llmod: ModuleRef,
name: str, ty: TypeRef) -> ValueRef {
if externs.contains_key(name) { ret externs.get(name); }
- let c = str::as_c_str(name, {|buf| llvm::LLVMAddGlobal(llmod, ty, buf) });
+ let c = str::as_c_str(name, |buf| llvm::LLVMAddGlobal(llmod, ty, buf));
externs.insert(name, c);
ret c;
}
let llforeign: ValueRef =
get_simple_extern_fn(cx, externs, llmod, name, n);
let mut call_args: ~[ValueRef] = ~[];
- for vec::each(args) {|a|
+ for vec::each(args) |a| {
vec::push(call_args, a);
}
ret Call(cx, llforeign, call_args);
let variant = ty::enum_variant_with_id(ccx.tcx, enum_id, variant_id);
assert ix < variant.args.len();
- let arg_lltys = vec::map(variant.args, {|aty|
+ let arg_lltys = vec::map(variant.args, |aty| {
type_of(ccx, ty::subst_tps(ccx.tcx, ty_substs, aty))
});
let typed_blobptr = PointerCast(bcx, llblobptr,
} else { mangle_internal_name_by_seq(ccx, @"tydesc") };
note_unique_llvm_symbol(ccx, name);
log(debug, #fmt("+++ declare_tydesc %s %s", ty_to_str(ccx.tcx, t), name));
- let gvar = str::as_c_str(name, {|buf|
+ let gvar = str::as_c_str(name, |buf| {
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type, buf)
});
let inf =
fn emit_tydescs(ccx: @crate_ctxt) {
let _icx = ccx.insn_ctxt("emit_tydescs");
- for ccx.tydescs.each {|key, val|
+ for ccx.tydescs.each |key, val| {
let glue_fn_ty = T_ptr(T_glue_fn(ccx));
let ti = val;
let take_glue =
}
ty::ty_class(did,substs) {
// Call the dtor if there is one
- do option::map_default(ty::ty_dtor(bcx.tcx(), did), bcx) {|dt_id|
+ do option::map_default(ty::ty_dtor(bcx.tcx(), did), bcx) |dt_id| {
trans_class_drop(bcx, v, dt_id, did, substs)
}
}
class_did: ast::def_id,
substs: ty::substs) -> block {
let drop_flag = GEPi(bcx, v0, ~[0u, 0u]);
- do with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag))) {|cx|
+ do with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag))) |cx| {
let mut bcx = cx;
// We have to cast v0
let classptr = GEPi(bcx, v0, ~[0u, 1u]);
// Drop the fields
for vec::eachi(ty::class_items_as_mutable_fields(bcx.tcx(), class_did,
substs))
- {|i, fld|
+ |i, fld| {
let llfld_a = GEPi(bcx, classptr, ~[0u, i]);
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
}
let llbox_ty = T_opaque_box_ptr(ccx);
let box_ptr = PointerCast(bcx, box_ptr, llbox_ty);
- do with_cond(bcx, IsNotNull(bcx, box_ptr)) {|bcx|
+ do with_cond(bcx, IsNotNull(bcx, box_ptr)) |bcx| {
let rc_ptr = GEPi(bcx, box_ptr, ~[0u, abi::box_field_refcnt]);
let rc = Sub(bcx, Load(bcx, rc_ptr), C_int(ccx, 1));
Store(bcx, rc, rc_ptr);
let zero_test = ICmp(bcx, lib::llvm::IntEQ, C_int(ccx, 0), rc);
- with_cond(bcx, zero_test, {|bcx| free_ty(bcx, box_ptr, t)})
+ with_cond(bcx, zero_test, |bcx| free_ty(bcx, box_ptr, t))
}
}
// Structural comparison: a rather involved form of glue.
fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: str) {
if cx.sess.opts.save_temps {
- let _: () = str::as_c_str(s, {|buf| llvm::LLVMSetValueName(v, buf) });
+ let _: () = str::as_c_str(s, |buf| llvm::LLVMSetValueName(v, buf));
}
}
fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
t: ty::t, op: ast::binop) -> result {
- let f = {|a|compare_scalar_values(cx, lhs, rhs, a, op)};
+ let f = |a| compare_scalar_values(cx, lhs, rhs, a, op);
alt ty::get(t).struct {
ty::ty_nil { ret rslt(cx, f(nil_type)); }
ty::ty_fn({inputs: args, _}) {
let mut j = 0u;
let v_id = variant.id;
- for vec::each(args) {|a|
+ for vec::each(args) |a| {
let llfldp_a = GEP_enum(cx, a_tup, tid, v_id, tps, j);
let ty_subst = ty::subst_tps(ccx.tcx, tps, a.ty);
cx = f(cx, llfldp_a, ty_subst);
let mut cx = cx;
alt ty::get(t).struct {
ty::ty_rec(fields) {
- for vec::eachi(fields) {|i, fld|
+ for vec::eachi(fields) |i, fld| {
let llfld_a = GEPi(cx, av, ~[0u, i]);
cx = f(cx, llfld_a, fld.mt.ty);
}
cx = tvec::iter_vec_raw(cx, base, t, len, f);
}
ty::ty_tup(args) {
- for vec::eachi(args) {|i, arg|
+ for vec::eachi(args) |i, arg| {
let llfld_a = GEPi(cx, av, ~[0u, i]);
cx = f(cx, llfld_a, arg);
}
Unreachable(unr_cx);
let llswitch = Switch(cx, lldiscrim_a, unr_cx.llbb, n_variants);
let next_cx = sub_block(cx, "enum-iter-next");
- for vec::each(*variants) {|variant|
+ for vec::each(*variants) |variant| {
let variant_cx =
sub_block(cx,
"enum-iter-variant-" +
else { av };
for vec::eachi(ty::class_items_as_mutable_fields(cx.tcx(), did,
substs))
- {|i, fld|
+ |i, fld| {
let llfld_a = GEPi(cx, classptr, ~[0u, i]);
cx = f(cx, llfld_a, fld.mt.ty);
}
let dstcmp = load_if_immediate(cx, dst, t);
let cast = PointerCast(cx, dstcmp, val_ty(src));
// Self-copy check
- do with_cond(cx, ICmp(cx, lib::llvm::IntNE, cast, src)) {|bcx|
+ do with_cond(cx, ICmp(cx, lib::llvm::IntNE, cast, src)) |bcx| {
copy_val_no_check(bcx, action, dst, src, t)
}
} else {
ret trans_call_inner(
bcx, un_expr.info(), fty,
expr_ty(bcx, un_expr),
- {|bcx| impl::trans_method_callee(bcx, callee_id, e, mentry) },
+ |bcx| impl::trans_method_callee(bcx, callee_id, e, mentry),
arg_exprs(~[]), dest);
}
_ {}
fn cast_shift_expr_rhs(cx: block, op: ast::binop,
lhs: ValueRef, rhs: ValueRef) -> ValueRef {
cast_shift_rhs(op, lhs, rhs,
- {|a,b|Trunc(cx, a, b)},
- {|a,b|ZExt(cx, a, b)})
+ |a,b| Trunc(cx, a, b),
+ |a,b| ZExt(cx, a, b))
}
fn cast_shift_const_rhs(op: ast::binop,
ty_to_str(cx.ccx().tcx, rhs_t));
}
};
- do with_cond(cx, is_zero) {|bcx|
+ do with_cond(cx, is_zero) |bcx| {
trans_fail(bcx, some(span), text)
}
}
let bcx = trans_call_inner(
bcx, ex.info(), fty,
expr_ty(bcx, ex),
- {|bcx|
+ |bcx| {
// FIXME (#2528): provide the already-computed address, not
// the expr.
impl::trans_method_callee(bcx, callee_id, dst, origin)
b: @ast::expr, dest: dest) -> block {
let _icx = bcx.insn_ctxt("trans_lazy_binop");
let {bcx: past_lhs, val: lhs} = {
- do with_scope_result(bcx, a.info(), "lhs") { |bcx|
+ do with_scope_result(bcx, a.info(), "lhs") |bcx| {
trans_temp_expr(bcx, a)
}
};
lazy_or { CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb); }
}
let {bcx: past_rhs, val: rhs} = {
- do with_scope_result(before_rhs, b.info(), "rhs") { |bcx|
+ do with_scope_result(before_rhs, b.info(), "rhs") |bcx| {
trans_temp_expr(bcx, b)
}
};
ret trans_call_inner(
bcx, ex.info(), fty,
expr_ty(bcx, ex),
- {|bcx|
+ |bcx| {
impl::trans_method_callee(bcx, callee_id, lhs, origin)
},
arg_exprs(~[rhs]), dest);
some(vts) {
let bounds = ty::lookup_item_type(ccx.tcx, item).bounds;
let mut i = 0u;
- vec::map2(*bounds, substs, {|bounds, subst|
+ vec::map2(*bounds, substs, |bounds, subst| {
let mut v = ~[];
- for vec::each(*bounds) {|bound|
+ for vec::each(*bounds) |bound| {
alt bound {
ty::bound_iface(_) {
vec::push(v, impl::vtable_id(ccx, vts[i]));
})
}
none {
- vec::map(substs, {|subst| mono_precise(subst, none)})
+ vec::map(substs, |subst| mono_precise(subst, none))
}
};
let param_ids = alt param_uses {
some(uses) {
- vec::map2(precise_param_ids, uses, {|id, uses|
+ vec::map2(precise_param_ids, uses, |id, uses| {
alt check id {
mono_precise(_, some(_)) { id }
mono_precise(subst, none) {
-> {val: ValueRef, must_cast: bool} {
let _icx = ccx.insn_ctxt("monomorphic_fn");
let mut must_cast = false;
- let substs = vec::map(real_substs, {|t|
+ let substs = vec::map(real_substs, |t| {
alt normalize_for_monomorphization(ccx.tcx, t) {
some(t) { must_cast = true; t }
none { t }
}
});
- for real_substs.each() {|s| assert !ty::type_has_params(s); };
- for substs.each() {|s| assert !ty::type_has_params(s); };
+ for real_substs.each() |s| { assert !ty::type_has_params(s); }
+ for substs.each() |s| { assert !ty::type_has_params(s); }
let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len());
let hash_id = make_mono_id(ccx, fn_id, substs, vtables, some(param_uses));
if vec::any(hash_id.params,
- {|p| alt p { mono_precise(_, _) { false } _ { true } } }) {
+ |p| alt p { mono_precise(_, _) { false } _ { true } }) {
must_cast = true;
}
#debug["monomorphic_fn(fn_id=%? (%s), real_substs=%?, substs=%?, \
hash_id = %?",
fn_id, ty::item_path_str(ccx.tcx, fn_id),
- real_substs.map({|s| ty_to_str(ccx.tcx, s)}),
- substs.map({|s| ty_to_str(ccx.tcx, s)}), hash_id];
+ real_substs.map(|s| ty_to_str(ccx.tcx, s)),
+ substs.map(|s| ty_to_str(ccx.tcx, s)), hash_id];
alt ccx.monomorphized.find(hash_id) {
some(val) {
let mut llitem_ty = tpt.ty;
let map_node = session::expect(ccx.sess, ccx.tcx.items.find(fn_id.node),
- {|| #fmt("While monomorphizing %?, couldn't find it in the item map \
+ || #fmt("While monomorphizing %?, couldn't find it in the item map \
(may have attempted to monomorphize an item defined in a different \
- crate?)", fn_id)});
+ crate?)", fn_id));
// Get the path so that we can create a symbol
let (pt, name, span) = alt map_node {
ast_map::node_item(i, pt) { (pt, i.ident, i.span) }
let pt = vec::append(*pt, ~[path_name(@ccx.names(*name))]);
let s = mangle_exported_name(ccx, pt, mono_ty);
- let mk_lldecl = {||
+ let mk_lldecl = || {
let lldecl = decl_internal_cdecl_fn(ccx.llmod, s, llfty);
ccx.monomorphized.insert(hash_id, lldecl);
lldecl
}
ast_map::node_variant(v, enum_item, _) {
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
- let this_tv = option::get(vec::find(*tvs, {|tv|
+ let this_tv = option::get(vec::find(*tvs, |tv| {
tv.id.node == fn_id.node}));
let d = mk_lldecl();
set_inline_hint(d);
none { // Not seen yet
alt csearch::maybe_get_item_ast(
ccx.tcx, fn_id,
- {|a,b,c,d|
+ |a,b,c,d| {
astencode::decode_inlined_item(a, b, ccx.maps, c, d)
}) {
ast::item_enum(_, _, _) {
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
- do vec::iter2(*vs_here, *vs_there) {|here, there|
+ do vec::iter2(*vs_here, *vs_there) |here, there| {
if there.id == fn_id { my_id = here.id.node; }
ccx.external.insert(there.id, some(here.id.node));
}
fn lval_static_fn(bcx: block, fn_id: ast::def_id, id: ast::node_id)
-> lval_maybe_callee {
let _icx = bcx.insn_ctxt("lval_static_fn");
- let vts = option::map(bcx.ccx().maps.vtable_map.find(id), {|vts|
+ let vts = option::map(bcx.ccx().maps.vtable_map.find(id), |vts| {
impl::resolve_vtables_in_fn_ctxt(bcx.fcx, vts)
});
lval_static_fn_inner(bcx, fn_id, id, node_id_type_params(bcx, id), vts)
// It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate);
let sym = csearch::get_symbol(ccx.sess.cstore, vid);
- let gvar = str::as_c_str(sym, {|buf|
+ let gvar = str::as_c_str(sym, |buf| {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
});
lib::llvm::SetLinkage(gvar, lib::llvm::ExternalLinkage);
#debug("trans_index: len %s", val_str(bcx.ccx().tn, len));
let bounds_check = ICmp(bcx, lib::llvm::IntUGE, scaled_ix, len);
- let bcx = do with_cond(bcx, bounds_check) {|bcx|
+ let bcx = do with_cond(bcx, bounds_check) |bcx| {
// fail: bad bounds check.
trans_fail(bcx, some(ex.span), "bounds check")
};
arg_exprs(es) {
let llarg_tys = type_of_explicit_args(ccx, arg_tys);
let last = es.len() - 1u;
- do vec::iteri(es) {|i, e|
+ do vec::iteri(es) |i, e| {
let r = trans_arg_expr(bcx, arg_tys[i], llarg_tys[i],
e, temp_cleanups, if i == last { ret_flag }
else { none }, 0u);
// now that all arguments have been successfully built, we can revoke any
// temporary cleanups, as they are only needed if argument construction
// should fail (for example, cleanup of copy mode args).
- do vec::iter(temp_cleanups) {|c|
+ do vec::iter(temp_cleanups) |c| {
revoke_clean(bcx, c)
}
let _icx = in_cx.insn_ctxt("trans_call");
trans_call_inner(
in_cx, call_ex.info(), expr_ty(in_cx, f), node_id_type(in_cx, id),
- {|cx| trans_callee(cx, f)}, args, dest)
+ |cx| trans_callee(cx, f), args, dest)
}
fn body_contains_ret(body: ast::blk) -> bool {
let cx = {mut found: false};
visit::visit_block(body, cx, visit::mk_vt(@{
- visit_item: {|_i, _cx, _v|},
- visit_expr: {|e: @ast::expr, cx: {mut found: bool}, v|
+ visit_item: |_i, _cx, _v| { },
+ visit_expr: |e: @ast::expr, cx: {mut found: bool}, v| {
if !cx.found {
alt e.node {
ast::expr_ret(_) { cx.found = true; }
args: call_args,
dest: dest) -> block {
- do with_scope(in_cx, call_info, "call") {|cx|
+ do with_scope(in_cx, call_info, "call") |cx| {
let ret_in_loop = alt args {
arg_exprs(args) { args.len() > 0u && alt vec::last(args).node {
ast::expr_loop_body(@{node: ast::expr_fn_block(_, body, _), _}) {
if ty::type_is_bot(ret_ty) {
Unreachable(bcx);
} else if ret_in_loop {
- bcx = do with_cond(bcx, Load(bcx, option::get(ret_flag))) {|bcx|
- do option::iter(copy bcx.fcx.loop_ret) {|lret|
+ bcx = do with_cond(bcx, Load(bcx, option::get(ret_flag))) |bcx| {
+ do option::iter(copy bcx.fcx.loop_ret) |lret| {
Store(bcx, C_bool(true), lret.flagptr);
Store(bcx, C_bool(false), bcx.fcx.llretptr);
}
loop {
alt cur.kind {
block_scope(inf) {
- for vec::each(inf.cleanups) {|cleanup|
+ for vec::each(inf.cleanups) |cleanup| {
alt cleanup {
clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) {
if cleanup_type == normal_exit_and_unwind {
fn have_cached_lpad(bcx: block) -> bool {
let mut res = false;
- do in_lpad_scope_cx(bcx) {|inf|
+ do in_lpad_scope_cx(bcx) |inf| {
alt inf.landing_pad {
some(_) { res = true; }
none { res = false; }
let _icx = bcx.insn_ctxt("get_landing_pad");
let mut cached = none, pad_bcx = bcx; // Guaranteed to be set below
- do in_lpad_scope_cx(bcx) {|inf|
+ do in_lpad_scope_cx(bcx) |inf| {
// If there is a valid landing pad still around, use it
alt copy inf.landing_pad {
some(target) { cached = some(target); }
let mut bcx = bcx;
let addr = alt dest {
ignore {
- for vec::each(elts) {|ex| bcx = trans_expr(bcx, ex, ignore); }
+ for vec::each(elts) |ex| { bcx = trans_expr(bcx, ex, ignore); }
ret bcx;
}
save_in(pos) { pos }
_ { bcx.tcx().sess.bug("trans_tup: weird dest"); }
};
let mut temp_cleanups = ~[];
- for vec::eachi(elts) {|i, e|
+ for vec::eachi(elts) |i, e| {
let dst = GEPi(bcx, addr, ~[0u, i]);
let e_ty = expr_ty(bcx, e);
bcx = trans_expr_save_in(bcx, e, dst);
add_clean_temp_mem(bcx, dst, e_ty);
vec::push(temp_cleanups, dst);
}
- for vec::each(temp_cleanups) {|cleanup| revoke_clean(bcx, cleanup); }
+ for vec::each(temp_cleanups) |cleanup| { revoke_clean(bcx, cleanup); }
ret bcx;
}
let mut bcx = bcx;
let addr = alt check dest {
ignore {
- for vec::each(fields) {|fld|
+ for vec::each(fields) |fld| {
bcx = trans_expr(bcx, fld.node.expr, ignore);
}
ret bcx;
let ty_fields = alt check ty::get(t).struct { ty::ty_rec(f) { f } };
let mut temp_cleanups = ~[];
- for fields.each {|fld|
- let ix = option::get(vec::position(ty_fields, {|ft|
+ for fields.each |fld| {
+ let ix = option::get(vec::position(ty_fields, |ft| {
str::eq(*fld.node.ident, *ft.ident)
}));
let dst = GEPi(bcx, addr, ~[0u, ix]);
let {bcx: cx, val: base_val} = trans_temp_expr(bcx, bexp);
bcx = cx;
// Copy over inherited fields
- for ty_fields.eachi {|i, tf|
- if !vec::any(fields, {|f| str::eq(*f.node.ident, *tf.ident)}) {
+ for ty_fields.eachi |i, tf| {
+ if !vec::any(fields, |f| str::eq(*f.node.ident, *tf.ident)) {
let dst = GEPi(bcx, addr, ~[0u, i]);
let base = GEPi(bcx, base_val, ~[0u, i]);
let val = load_if_immediate(bcx, base, tf.mt.ty);
// Now revoke the cleanups as we pass responsibility for the data
// structure on to the caller
- for temp_cleanups.each {|cleanup| revoke_clean(bcx, cleanup); }
+ for temp_cleanups.each |cleanup| { revoke_clean(bcx, cleanup); }
ret bcx;
}
ret alt::trans_alt(bcx, e, expr, arms, mode, dest);
}
ast::expr_block(blk) {
- ret do with_scope(bcx, blk.info(), "block-expr body") {|bcx|
+ ret do with_scope(bcx, blk.info(), "block-expr body") |bcx| {
trans_block(bcx, blk, dest)
};
}
ret trans_call_inner(
bcx, e.info(), fty,
expr_ty(bcx, e),
- { |bcx|
- impl::trans_method_callee(bcx, callee_id, base, origin)
- },
+ |bcx| impl::trans_method_callee(bcx, callee_id, base, origin),
arg_exprs(~[idx]), dest);
}
otherwise. */
let c = get_extern_const(bcx.ccx().externs, bcx.ccx().llmod,
"check_claims", T_bool());
- ret do with_cond(bcx, Load(bcx, c)) {|bcx|
+ ret do with_cond(bcx, Load(bcx, c)) |bcx| {
trans_check_expr(bcx, e, a, "Claim")
};
}
let origin = bcx.ccx().maps.method_map.get(alloc_id);
let bcx = trans_call_inner(
bcx, e.info(), node_id_type(bcx, alloc_id), void_ty,
- {|bcx| impl::trans_method_callee(bcx, alloc_id,
- pool, origin) },
+ |bcx| impl::trans_method_callee(bcx, alloc_id,
+ pool, origin),
arg_vals(args),
save_in(voidval));
let modpath = vec::append(
~[path_mod(ccx.link_meta.name)],
- vec::filter(bcx.fcx.path, {|e|
+ vec::filter(bcx.fcx.path, |e|
alt e { path_mod(_) { true } _ { false } }
- }));
+ ));
let modname = path_str(modpath);
let global = if ccx.module_data.contains_key(modname) {
} else {
let s = link::mangle_internal_name_by_path_and_seq(
ccx, modpath, @"loglevel");
- let global = str::as_c_str(s, {|buf|
+ let global = str::as_c_str(s, |buf| {
llvm::LLVMAddGlobal(ccx.llmod, T_i32(), buf)
});
llvm::LLVMSetGlobalConstant(global, False);
};
let current_level = Load(bcx, global);
let {bcx, val: level} = {
- do with_scope_result(bcx, lvl.info(), "level") {|bcx|
+ do with_scope_result(bcx, lvl.info(), "level") |bcx| {
trans_temp_expr(bcx, lvl)
}
};
- do with_cond(bcx, ICmp(bcx, lib::llvm::IntUGE, current_level, level)) {
- |bcx|
- do with_scope(bcx, log_ex.info(), "log") {|bcx|
+ do with_cond(bcx, ICmp(bcx, lib::llvm::IntUGE, current_level, level))
+ |bcx| {
+ do with_scope(bcx, log_ex.info(), "log") |bcx| {
let {bcx, val, _} = trans_temp_expr(bcx, e);
let e_ty = expr_ty(bcx, e);
let tydesc = get_tydesc_simple(ccx, e_ty);
let _icx = bcx.insn_ctxt("trans_check_expr");
let expr_str = s + " " + expr_to_str(pred_expr) + " failed";
let {bcx, val} = {
- do with_scope_result(bcx, chk_expr.info(), "check") {|bcx|
+ do with_scope_result(bcx, chk_expr.info(), "check") |bcx| {
trans_temp_expr(bcx, pred_expr)
}
};
- do with_cond(bcx, Not(bcx, val)) {|bcx|
+ do with_cond(bcx, Not(bcx, val)) |bcx| {
trans_fail(bcx, some(pred_expr.span), expr_str)
}
}
ast::stmt_decl(d, _) {
alt d.node {
ast::decl_local(locals) {
- for vec::each(locals) {|local|
+ for vec::each(locals) |local| {
bcx = init_local(bcx, local);
if cx.sess().opts.extra_debuginfo {
debuginfo::create_local_var(bcx, local);
let s = if cx.ccx.sess.opts.save_temps || cx.ccx.sess.opts.debuginfo {
cx.ccx.names(name)
} else { "" };
- let llbb: BasicBlockRef = str::as_c_str(s, {|buf|
+ let llbb: BasicBlockRef = str::as_c_str(s, |buf| {
llvm::LLVMAppendBasicBlock(cx.llfn, buf)
});
let bcx = mk_block(llbb, parent, kind, opt_node_info, cx);
- do option::iter(parent) {|cx|
+ do option::iter(parent) |cx| {
if cx.unreachable { Unreachable(bcx); }
};
ret bcx;
alt check cleanup_cx.kind {
block_scope({cleanups, _}) {
let cleanups = copy cleanups;
- do vec::riter(cleanups) {|cu|
+ do vec::riter(cleanups) |cu| {
alt cu {
clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) {
// Some types don't need to be cleaned up during
alt cur.kind {
block_scope(inf) if inf.cleanups.len() > 0u {
for vec::find(inf.cleanup_paths,
- {|cp| cp.target == leave}).each {|cp|
+ |cp| cp.target == leave).each |cp| {
Br(bcx, cp.dest);
ret;
}
}
fn block_locals(b: ast::blk, it: fn(@ast::local)) {
- for vec::each(b.node.stmts) {|s|
+ for vec::each(b.node.stmts) |s| {
alt s.node {
ast::stmt_decl(d, _) {
alt d.node {
ast::decl_local(locals) {
- for vec::each(locals) {|local| it(local); }
+ for vec::each(locals) |local| { it(local); }
}
_ {/* fall through */ }
}
};
let val = alloc_ty(cx, t);
if cx.sess().opts.debuginfo {
- do option::iter(simple_name) {|name|
- str::as_c_str(*name, {|buf|
+ do option::iter(simple_name) |name| {
+ str::as_c_str(*name, |buf| {
llvm::LLVMSetValueName(val, buf)
});
}
-> block {
let _icx = bcx.insn_ctxt("trans_block");
let mut bcx = bcx;
- do block_locals(b) {|local| bcx = alloc_local(bcx, local); };
- for vec::each(b.node.stmts) {|s|
+ do block_locals(b) |local| { bcx = alloc_local(bcx, local); };
+ for vec::each(b.node.stmts) |s| {
debuginfo::update_source_pos(bcx, b.span);
bcx = trans_stmt(bcx, *s);
}
// Creates the standard set of basic blocks for a function
fn mk_standard_basic_blocks(llfn: ValueRef) ->
{sa: BasicBlockRef, ca: BasicBlockRef, rt: BasicBlockRef} {
- {sa: str::as_c_str("static_allocas", {|buf|
- llvm::LLVMAppendBasicBlock(llfn, buf) }),
- ca: str::as_c_str("load_env", {|buf|
- llvm::LLVMAppendBasicBlock(llfn, buf) }),
- rt: str::as_c_str("return", {|buf|
- llvm::LLVMAppendBasicBlock(llfn, buf) })}
+ {sa: str::as_c_str("static_allocas",
+ |buf| llvm::LLVMAppendBasicBlock(llfn, buf)),
+ ca: str::as_c_str("load_env",
+ |buf| llvm::LLVMAppendBasicBlock(llfn, buf)),
+ rt: str::as_c_str("return",
+ |buf| llvm::LLVMAppendBasicBlock(llfn, buf))}
}
// Populate the llargs field of the function context with the ValueRefs
// that we get from llvm::LLVMGetParam for each argument.
- for vec::each(args) {|arg|
+ for vec::each(args) |arg| {
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
assert (llarg as int != 0);
// Note that this uses local_mem even for things passed by value.
tcx.sess.bug("someone forgot\
to document an invariant in copy_args_to_allocas!");
};
- for vec::each(arg_tys) {|arg|
+ for vec::each(arg_tys) |arg| {
let id = args[arg_n].id;
let argval = alt fcx.llargs.get(id) { local_mem(v) { v }
_ { epic_fail() } };
else { {sec: 0i64, nsec: 0i32} };
let _icx = ccx.insn_ctxt("trans_fn");
trans_closure(ccx, path, decl, body, llfndecl, ty_self,
- param_substs, id, {|fcx|
- if ccx.sess.opts.extra_debuginfo {
- debuginfo::create_function(fcx);
- }
- }, {|_bcx|});
+ param_substs, id,
+ |fcx| {
+ if ccx.sess.opts.extra_debuginfo {
+ debuginfo::create_function(fcx);
+ }
+ },
+ |_bcx| { });
if do_time {
let end = time::get_time();
log_fn_time(ccx, path_str(path), start, end);
llfndecl: ValueRef) {
let _icx = ccx.insn_ctxt("trans_enum_variant");
// Translate variant arguments to function arguments.
- let fn_args = vec::map(variant.node.args, {|varg|
+ let fn_args = vec::map(variant.node.args, |varg|
{mode: ast::expl(ast::by_copy),
ty: varg.ty,
ident: @"arg",
- id: varg.id}
- });
+ id: varg.id});
let fcx = new_fn_ctxt_w_id(ccx, ~[], llfndecl, variant.node.id,
param_substs, none);
create_llargs_for_fn_args(fcx, no_self, fn_args);
};
let t_id = local_def(enum_id);
let v_id = local_def(variant.node.id);
- for vec::eachi(variant.node.args) {|i, va|
+ for vec::eachi(variant.node.args) |i, va| {
let lldestptr = GEP_enum(bcx, llblobptr, t_id, v_id,
ty_param_substs, i);
// If this argument to this function is a enum, it'll have come in to
let mut bcx = bcx_top;
// Initialize fields to zero so init assignments can validly
// drop their LHS
- for fields.each {|field|
+ for fields.each |field| {
let ix = field_idx_strict(bcx.tcx(), sp, field.ident, fields);
bcx = zero_mem(bcx, GEPi(bcx, valptr, ~[0u, ix]), field.mt.ty);
}
/* Look up the parent class's def_id */
let mut class_ty = ty::lookup_item_type(tcx, parent_id).ty;
/* Substitute in the class type if necessary */
- do option::iter(psubsts) {|ss|
+ do option::iter(psubsts) |ss| {
class_ty = ty::subst_tps(tcx, ss.tys, class_ty);
}
/* If we're monomorphizing, register the monomorphized decl
for the dtor */
- do option::iter(hash_id) {|h_id|
+ do option::iter(hash_id) |h_id| {
ccx.monomorphized.insert(h_id, lldecl);
}
/* Translate the dtor body */
vec::append(*path, ~[path_name(item.ident)]),
decl, body, llfndecl, no_self, none, item.id);
} else {
- for vec::each(body.node.stmts) {|stmt|
+ for vec::each(body.node.stmts) |stmt| {
alt stmt.node {
ast::stmt_decl(@{node: ast::decl_item(i), _}, _) {
trans_item(ccx, *i);
let degen = variants.len() == 1u;
let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
let mut i = 0;
- for vec::each(variants) {|variant|
+ for vec::each(variants) |variant| {
if variant.node.args.len() > 0u {
let llfn = get_item_val(ccx, variant.node.id);
trans_enum_variant(ccx, item.id, variant,
trans_class_ctor(ccx, *path, ctor.node.dec, ctor.node.body,
get_item_val(ccx, ctor.node.id), psubsts,
ctor.node.id, local_def(item.id), ctor.span);
- do option::iter(m_dtor) {|dtor|
+ do option::iter(m_dtor) |dtor| {
trans_class_dtor(ccx, *path, dtor.node.body,
dtor.node.id, none, none, local_def(item.id));
};
// and control visibility.
fn trans_mod(ccx: @crate_ctxt, m: ast::_mod) {
let _icx = ccx.insn_ctxt("trans_mod");
- for vec::each(m.items) {|item| trans_item(ccx, *item); }
+ for vec::each(m.items) |item| { trans_item(ccx, *item); }
}
fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
fn main_name() -> str { ret "main"; }
let llfty = T_fn(~[ccx.int_type, ccx.int_type], ccx.int_type);
let llfn = decl_cdecl_fn(ccx.llmod, main_name(), llfty);
- let llbb = str::as_c_str("top", {|buf|
+ let llbb = str::as_c_str("top", |buf| {
llvm::LLVMAppendBasicBlock(llfn, buf)
});
let bld = ccx.builder.B;
ast::item_const(_, _) {
let typ = ty::node_id_to_type(ccx.tcx, i.id);
let s = mangle_exported_name(ccx, my_path, typ);
- let g = str::as_c_str(s, {|buf|
+ let g = str::as_c_str(s, |buf| {
llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, typ), buf)
});
ccx.item_symbols.insert(i.id, s);
node: it.id});
let mut i = 0;
let path = item_path(ccx, it);
- for vec::each(variants) {|variant|
+ for vec::each(variants) |variant| {
let p = vec::append(path, ~[path_name(variant.node.name),
path_name(@"discrim")]);
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
let disr_val = vi[i].disr_val;
note_unique_llvm_symbol(ccx, s);
- let discrim_gvar = str::as_c_str(s, {|buf|
+ let discrim_gvar = str::as_c_str(s, |buf| {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
});
llvm::LLVMSetInitializer(discrim_gvar, C_int(ccx, disr_val));
fn trans_constants(ccx: @crate_ctxt, crate: @ast::crate) {
visit::visit_crate(*crate, (), visit::mk_simple_visitor(@{
- visit_item: {|a|trans_constant(ccx, a)}
+ visit_item: |a| trans_constant(ccx, a)
with *visit::default_simple_visitor()
}));
}
fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
let elttype = T_struct(~[ccx.int_type, ccx.int_type]);
let maptype = T_array(elttype, ccx.module_data.size() + 1u);
- let map = str::as_c_str("_rust_mod_map", {|buf|
+ let map = str::as_c_str("_rust_mod_map", |buf| {
llvm::LLVMAddGlobal(ccx.llmod, maptype, buf)
});
lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
let mut elts: ~[ValueRef] = ~[];
- for ccx.module_data.each {|key, val|
+ for ccx.module_data.each |key, val| {
let elt = C_struct(~[p2i(ccx, C_cstr(ccx, key)),
p2i(ccx, val)]);
vec::push(elts, elt);
- };
+ }
let term = C_struct(~[C_int(ccx, 0), C_int(ccx, 0)]);
vec::push(elts, term);
llvm::LLVMSetInitializer(map, C_array(elttype, elts));
let sym_name = "_rust_crate_map_" + mapname;
let arrtype = T_array(int_type, n_subcrates as uint);
let maptype = T_struct(~[int_type, arrtype]);
- let map = str::as_c_str(sym_name, {|buf|
+ let map = str::as_c_str(sym_name, |buf| {
llvm::LLVMAddGlobal(llmod, maptype, buf)
});
lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage);
let nm = "_rust_crate_map_" + cdata.name +
"_" + *cstore::get_crate_vers(cstore, i) +
"_" + *cstore::get_crate_hash(cstore, i);
- let cr = str::as_c_str(nm, {|buf|
+ let cr = str::as_c_str(nm, |buf| {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
});
vec::push(subcrates, p2i(ccx, cr));
-> encoder::encode_parms {
let encode_inlined_item =
- {|a,b,c,d|astencode::encode_inlined_item(a, b, c, d, cx.maps)};
+ |a,b,c,d| astencode::encode_inlined_item(a, b, c, d, cx.maps);
ret {
diag: cx.sess.diagnostic(),
tcx: cx.tcx,
reachable: cx.reachable,
reexports: reexports(cx),
- impl_map: {|a|impl_map(cx, a)},
+ impl_map: |a| impl_map(cx, a),
item_symbols: cx.item_symbols,
discrim_symbols: cx.discrim_symbols,
link_meta: cx.link_meta,
fn reexports(cx: @crate_ctxt) -> ~[(str, ast::def_id)] {
let mut reexports = ~[];
- for cx.exp_map.each {|exp_id, defs|
- for defs.each {|def|
+ for cx.exp_map.each |exp_id, defs| {
+ for defs.each |def| {
if !def.reexp { cont; }
let path = alt check cx.tcx.items.get(exp_id) {
ast_map::node_export(_, path) {
fn impl_map(cx: @crate_ctxt,
id: ast::node_id) -> ~[(ast::ident, ast::def_id)] {
let mut result = ~[];
- for list::each(cx.maps.impl_map.get(id)) {
- |impls|
- vec::push_all(result, (*impls).map({|i| (i.ident, i.did) }));
+ for list::each(cx.maps.impl_map.get(id)) |impls| {
+ vec::push_all(result, (*impls).map(|i| (i.ident, i.did)));
}
ret result;
}
let encode_parms = crate_ctxt_to_encode_parms(cx);
let llmeta = C_bytes(encoder::encode_metadata(encode_parms, crate));
let llconst = C_struct(~[llmeta]);
- let mut llglobal = str::as_c_str("rust_metadata", {|buf|
+ let mut llglobal = str::as_c_str("rust_metadata", |buf| {
llvm::LLVMAddGlobal(cx.llmod, val_ty(llconst), buf)
});
llvm::LLVMSetInitializer(llglobal, llconst);
- str::as_c_str(cx.sess.targ_cfg.target_strs.meta_sect_name, {|buf|
+ str::as_c_str(cx.sess.targ_cfg.target_strs.meta_sect_name, |buf| {
llvm::LLVMSetSection(llglobal, buf)
});
lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage);
let t_ptr_i8 = T_ptr(T_i8());
llglobal = llvm::LLVMConstBitCast(llglobal, t_ptr_i8);
- let llvm_used = str::as_c_str("llvm.used", {|buf|
+ let llvm_used = str::as_c_str("llvm.used", |buf| {
llvm::LLVMAddGlobal(cx.llmod, T_array(t_ptr_i8, 1u), buf)
});
lib::llvm::SetLinkage(llvm_used, lib::llvm::AppendingLinkage);
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
let llmod_id = *link_meta.name + ".rc";
- let llmod = str::as_c_str(llmod_id, {|buf|
+ let llmod = str::as_c_str(llmod_id, |buf| {
llvm::LLVMModuleCreateWithNameInContext
(buf, llvm::LLVMGetGlobalContext())
});
let targ_triple = sess.targ_cfg.target_strs.target_triple;
let _: () =
str::as_c_str(data_layout,
- {|buf| llvm::LLVMSetDataLayout(llmod, buf) });
+ |buf| llvm::LLVMSetDataLayout(llmod, buf));
let _: () =
str::as_c_str(targ_triple,
- {|buf| llvm::LLVMSetTarget(llmod, buf) });
+ |buf| llvm::LLVMSetTarget(llmod, buf));
let targ_cfg = sess.targ_cfg;
let td = mk_target_data(sess.targ_cfg.target_strs.data_layout);
let tn = mk_type_names();
discrim_symbols: int_hash::<str>(),
tydescs: ty::new_ty_hash(),
external: ast_util::new_def_hash(),
- monomorphized: map::hashmap(hash_mono_id, {|a, b| a == b}),
+ monomorphized: map::hashmap(hash_mono_id, |a, b| a == b),
monomorphizing: ast_util::new_def_hash(),
type_use_cache: ast_util::new_def_hash(),
- vtables: map::hashmap(hash_mono_id, {|a, b| a == b}),
+ vtables: map::hashmap(hash_mono_id, |a, b| a == b),
const_cstr_cache: map::str_hash(),
module_data: str_hash::<ValueRef>(),
lltypes: ty::new_ty_hash(),
// FIXME (#2280): this temporary shouldn't be
// necessary, but seems to be, for borrowing.
let times = copy *ccx.stats.fn_times;
- for vec::each(times) {|timing|
+ for vec::each(times) |timing| {
io::println(#fmt("time: %s took %d ms", timing.ident,
timing.time));
}
}
if ccx.sess.count_llvm_insns() {
- for ccx.stats.llvm_insns.each { |k, v|
+ for ccx.stats.llvm_insns.each |k, v| {
io::println(#fmt("%-7u %s", v, k));
}
}
cx.terminated = true;
#debug["Invoke(%s with arguments (%s))",
val_str(cx.ccx().tn, Fn),
- str::connect(vec::map(Args, {|a|val_str(cx.ccx().tn, a)}),
+ str::connect(vec::map(Args, |a| val_str(cx.ccx().tn, a)),
", ")];
unsafe {
count_insn(cx, "invoke");
// in C_i32()
fn GEPi(cx: block, base: ValueRef, ixs: ~[uint]) -> ValueRef {
let mut v: ~[ValueRef] = ~[];
- for vec::each(ixs) {|i| vec::push(v, C_i32(i as i32)); }
+ for vec::each(ixs) |i| { vec::push(v, C_i32(i as i32)); }
count_insn(cx, "gepi");
ret InBoundsGEP(cx, base, v);
}
if !ccx.sess.no_asm_comments() {
let sanitized = str::replace(text, "$", "");
let comment_text = "# " + sanitized;
- let asm = str::as_c_str(comment_text, {|c|
- str::as_c_str("", {|e|
+ let asm = str::as_c_str(comment_text, |c| {
+ str::as_c_str("", |e| {
count_insn(bcx, "inlineasm");
llvm::LLVMConstInlineAsm(T_fn(~[], T_void()), c, e,
False, False)
#debug["Call(Fn=%s, Args=%?)",
val_str(cx.ccx().tn, Fn),
- Args.map({ |arg| val_str(cx.ccx().tn, arg) })];
+ Args.map(|arg| val_str(cx.ccx().tn, arg))];
ret llvm::LLVMBuildCall(B(cx), Fn, vec::unsafe::to_ptr(Args),
Args.len() as c_uint, noname());
let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(b);
let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB);
let M: ModuleRef = llvm::LLVMGetGlobalParent(FN);
- let T: ValueRef = str::as_c_str("llvm.trap", {|buf|
+ let T: ValueRef = str::as_c_str("llvm.trap", |buf| {
llvm::LLVMGetNamedFunction(M, buf)
});
assert (T as int != 0);
let mut bound_tys = ~[];
// Compute the closed over data
- for vec::each(bound_values) {|bv|
+ for vec::each(bound_values) |bv| {
vec::push(bound_tys, alt bv {
env_copy(_, t, _) { t }
env_move(_, t, _) { t }
// Copy expr values into boxed bindings.
let mut bcx = bcx;
- do vec::iteri(bound_values) { |i, bv|
+ do vec::iteri(bound_values) |i, bv| {
#debug["Copy %s into closure", ev_to_str(ccx, bv)];
if !ccx.sess.no_asm_comments() {
}
}
}
- for vec::each(temp_cleanups) {|cleanup| revoke_clean(bcx, cleanup); }
+ for vec::each(temp_cleanups) |cleanup| { revoke_clean(bcx, cleanup); }
ret {llbox: llbox, cdata_ty: cdata_ty, bcx: bcx};
}
let ccx = bcx.ccx(), tcx = ccx.tcx;
// Package up the captured upvars
- do vec::iter(cap_vars) { |cap_var|
+ do vec::iter(cap_vars) |cap_var| {
#debug["Building closure: captured variable %?", cap_var];
let lv = trans_local_var(bcx, cap_var.def);
let nid = ast_util::def_id_of_def(cap_var.def).node;
}
}
}
- do option::iter(include_ret_handle) {|flagptr|
+ do option::iter(include_ret_handle) |flagptr| {
let our_ret = alt bcx.fcx.loop_ret {
some({retptr, _}) { retptr }
none { bcx.fcx.llretptr }
// Populate the upvars from the environment.
let mut i = 0u;
- do vec::iter(cap_vars) { |cap_var|
+ do vec::iter(cap_vars) |cap_var| {
alt cap_var.mode {
capture::cap_drop { /* ignore */ }
_ {
let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, ck, id,
ret_handle);
trans_closure(ccx, sub_path, decl, body, llfn, no_self,
- bcx.fcx.param_substs, id, {|fcx|
+ bcx.fcx.param_substs, id, |fcx| {
load_environment(fcx, cdata_ty, cap_vars,
option::is_some(ret_handle), ck);
- }, {|bcx|
+ }, |bcx| {
if option::is_some(is_loop_body) {
Store(bcx, C_bool(true), bcx.fcx.llretptr);
}
ast::proto_uniq { trans_closure_env(ty::ck_uniq) }
ast::proto_bare {
trans_closure(ccx, sub_path, decl, body, llfn, no_self, none,
- id, {|_fcx|}, {|_bcx|});
+ id, |_fcx| { }, |_bcx| { });
C_null(T_opaque_box_ptr(ccx))
}
};
let _icx = cx.insn_ctxt("closure::trans_bind1");
let ccx = cx.ccx();
let mut bound: ~[@ast::expr] = ~[];
- for vec::each(args) {|argopt|
+ for vec::each(args) |argopt| {
alt argopt { none { } some(e) { vec::push(bound, e); } }
}
let mut bcx = f_res.bcx;
if dest == ignore {
- for vec::each(bound) {|ex| bcx = trans_expr(bcx, ex, ignore); }
+ for vec::each(bound) |ex| { bcx = trans_expr(bcx, ex, ignore); }
ret bcx;
}
// Actually construct the closure
let {llbox, cdata_ty, bcx} = store_environment(
bcx, vec::append(env_vals,
- vec::map(bound, {|x| env_expr(x, expr_ty(bcx, x))})),
+ vec::map(bound, |x| {
+ env_expr(x, expr_ty(bcx, x))
+ })),
ty::ck_box);
// Make thunk
let fn_env = fn@(ck: ty::closure_kind) -> block {
let box_cell_v = GEPi(cx, v, ~[0u, abi::fn_field_box]);
let box_ptr_v = Load(cx, box_cell_v);
- do with_cond(cx, IsNotNull(cx, box_ptr_v)) {|bcx|
+ do with_cond(cx, IsNotNull(cx, box_ptr_v)) |bcx| {
let closure_ty = ty::mk_opaque_closure_ptr(tcx, ck);
glue_fn(bcx, box_cell_v, closure_ty)
}
let ccx = bcx.ccx(), tcx = ccx.tcx;
let llopaquecboxty = T_opaque_box_ptr(ccx);
let cbox_in = Load(bcx, cboxptr);
- do with_cond(bcx, IsNotNull(bcx, cbox_in)) {|bcx|
+ do with_cond(bcx, IsNotNull(bcx, cbox_in)) |bcx| {
// Load the size from the type descr found in the cbox
let cbox_in = PointerCast(bcx, cbox_in, llopaquecboxty);
let tydescptr = GEPi(bcx, cbox_in, ~[0u, abi::box_field_tydesc]);
}
let ccx = bcx.ccx();
- do with_cond(bcx, IsNotNull(bcx, cbox)) {|bcx|
+ do with_cond(bcx, IsNotNull(bcx, cbox)) |bcx| {
// Load the type descr found in the cbox
let lltydescty = T_ptr(ccx.tydesc_type);
let cbox = PointerCast(bcx, cbox, T_opaque_cbox_ptr(ccx));
let mut a: uint = first_real_arg; // retptr, env come first
let mut b: uint = starting_idx;
let mut outgoing_arg_index: uint = 0u;
- for vec::each(args) {|arg|
+ for vec::each(args) |arg| {
let out_arg = outgoing_args[outgoing_arg_index];
alt arg {
// Arg provided at binding time; thunk copies it from
cx.to_str(), val_str(cx.ccx().tn, val),
ty_to_str(cx.ccx().tcx, ty)];
let cleanup_type = cleanup_type(cx.tcx(), ty);
- do in_scope_cx(cx) {|info|
- vec::push(info.cleanups, clean({|a|base::drop_ty(a, val, ty)},
+ do in_scope_cx(cx) |info| {
+ vec::push(info.cleanups, clean(|a| base::drop_ty(a, val, ty),
cleanup_type));
scope_clean_changed(info);
}
ret base::drop_ty(bcx, val, ty);
}
}
- do in_scope_cx(cx) {|info|
- vec::push(info.cleanups, clean_temp(val, {|a|do_drop(a, val, ty)},
+ do in_scope_cx(cx) |info| {
+ vec::push(info.cleanups, clean_temp(val, |a| do_drop(a, val, ty),
cleanup_type));
scope_clean_changed(info);
}
cx.to_str(), val_str(cx.ccx().tn, val),
ty_to_str(cx.ccx().tcx, ty)];
let cleanup_type = cleanup_type(cx.tcx(), ty);
- do in_scope_cx(cx) {|info|
+ do in_scope_cx(cx) |info| {
vec::push(info.cleanups,
- clean_temp(val, {|a|base::drop_ty(a, val, ty)},
+ clean_temp(val, |a| base::drop_ty(a, val, ty),
cleanup_type));
scope_clean_changed(info);
}
}
fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
let free_fn = alt heap {
- heap_shared { {|a|base::trans_free(a, ptr)} }
- heap_exchange { {|a|base::trans_unique_free(a, ptr)} }
+ heap_shared { |a| base::trans_free(a, ptr) }
+ heap_exchange { |a| base::trans_unique_free(a, ptr) }
};
- do in_scope_cx(cx) {|info|
+ do in_scope_cx(cx) |info| {
vec::push(info.cleanups, clean_temp(ptr, free_fn,
normal_exit_and_unwind));
scope_clean_changed(info);
// this will be more involved. For now, we simply zero out the local, and the
// drop glue checks whether it is zero.
fn revoke_clean(cx: block, val: ValueRef) {
- do in_scope_cx(cx) {|info|
- do option::iter(vec::position(info.cleanups, {|cu|
+ do in_scope_cx(cx) |info| {
+ do option::iter(vec::position(info.cleanups, |cu| {
alt cu { clean_temp(v, _, _) if v == val { true } _ { false } }
- })) {|i|
+ })) |i| {
info.cleanups =
vec::append(vec::slice(info.cleanups, 0u, i),
vec::view(info.cleanups,
impl node_info for option<@ast::expr> {
fn info() -> option<node_info> {
- self.chain({ |s| s.info() })
+ self.chain(|s| s.info())
}
}
fn T_named_struct(name: str) -> TypeRef {
let c = llvm::LLVMGetGlobalContext();
- ret str::as_c_str(name, {|buf| llvm::LLVMStructCreateNamed(c, buf) });
+ ret str::as_c_str(name, |buf| llvm::LLVMStructCreateNamed(c, buf));
}
fn set_struct_body(t: TypeRef, elts: ~[TypeRef]) unsafe {
}
fn C_floating(s: str, t: TypeRef) -> ValueRef {
- ret str::as_c_str(s, {|buf| llvm::LLVMConstRealOfString(t, buf) });
+ ret str::as_c_str(s, |buf| llvm::LLVMConstRealOfString(t, buf));
}
fn C_nil() -> ValueRef {
none { }
}
- let sc = do str::as_c_str(s) {|buf|
+ let sc = do str::as_c_str(s) |buf| {
llvm::LLVMConstString(buf, str::len(s) as c_uint, False)
};
let g =
str::as_c_str(cx.names("str"),
- {|buf| llvm::LLVMAddGlobal(cx.llmod, val_ty(sc), buf) });
+ |buf| llvm::LLVMAddGlobal(cx.llmod, val_ty(sc), buf));
llvm::LLVMSetInitializer(g, sc);
llvm::LLVMSetGlobalConstant(g, True);
lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
// Returns a Plain Old LLVM String:
fn C_postr(s: str) -> ValueRef {
- ret do str::as_c_str(s) {|buf|
+ ret do str::as_c_str(s) |buf| {
llvm::LLVMConstString(buf, str::len(s) as c_uint, False)
};
}
fn C_shape(ccx: @crate_ctxt, bytes: ~[u8]) -> ValueRef {
let llshape = C_bytes(bytes);
- let llglobal = str::as_c_str(ccx.names("shape"), {|buf|
+ let llglobal = str::as_c_str(ccx.names("shape"), |buf| {
llvm::LLVMAddGlobal(ccx.llmod, val_ty(llshape), buf)
});
llvm::LLVMSetInitializer(llglobal, llshape);
type mono_id = @{def: ast::def_id, params: ~[mono_param_id]};
fn hash_mono_id(&&mi: mono_id) -> uint {
let mut h = syntax::ast_util::hash_def(mi.def);
- for vec::each(mi.params) {|param|
+ for vec::each(mi.params) |param| {
h = h * alt param {
mono_precise(ty, vts) {
let mut h = ty::type_id(ty);
- do option::iter(vts) {|vts|
- for vec::each(vts) {|vt| h += hash_mono_id(vt); }
+ do option::iter(vts) |vts| {
+ for vec::each(vts) |vt| { h += hash_mono_id(vt); }
}
h
}
fn path_str(p: path) -> str {
let mut r = "", first = true;
- for vec::each(p) {|e|
+ for vec::each(p) |e| {
alt e { ast_map::path_name(s) | ast_map::path_mod(s) {
if first { first = false; }
else { r += "::"; }
let params = ty::node_id_to_type_params(tcx, id);
alt bcx.fcx.param_substs {
some(substs) {
- vec::map(params, {|t| ty::subst_tps(tcx, substs.tys, t) })
+ vec::map(params, |t| ty::subst_tps(tcx, substs.tys, t))
}
_ { params }
}
const DW_ATE_unsigned_char: int = 0x08;
fn llstr(s: str) -> ValueRef {
- str::as_c_str(s, {|sbuf|
+ str::as_c_str(s, |sbuf| {
llvm::LLVMMDString(sbuf, str::len(s) as libc::c_uint)
})
}
}
fn add_named_metadata(cx: @crate_ctxt, name: str, val: ValueRef) {
- str::as_c_str(name, {|sbuf|
+ str::as_c_str(name, |sbuf| {
llvm::LLVMAddNamedMetadataOperand(cx.llmod, sbuf, val)
})
}
eq: fn(md: T) -> bool) -> option<T> unsafe {
if cache.contains_key(mdtag) {
let items = cache.get(mdtag);
- for items.each {|item|
+ for items.each |item| {
let md: T = md_from_metadata::<T>(item);
if eq(md) {
ret option::some(md);
let crate_name = option::get(cx.dbg_cx).crate_file;
let tg = CompileUnitTag;
alt cached_metadata::<@metadata<compile_unit_md>>(cache, tg,
- {|md| md.data.name == crate_name}) {
+ |md| md.data.name == crate_name) {
option::some(md) { ret md; }
option::none {}
}
let cache = get_cache(cx);;
let tg = FileDescriptorTag;
alt cached_metadata::<@metadata<file_md>>(
- cache, tg, {|md| md.data.path == full_path}) {
+ cache, tg, |md| md.data.path == full_path) {
option::some(md) { ret md; }
option::none {}
}
let cache = get_cache(cx);
let tg = BasicTypeDescriptorTag;
alt cached_metadata::<@metadata<tydesc_md>>(
- cache, tg, {|md| ty::type_id(t) == md.data.hash}) {
+ cache, tg, |md| ty::type_id(t) == md.data.hash) {
option::some(md) { ret md; }
option::none {}
}
option::get(cx.dbg_cx).names("rec"),
line_from_span(cx.sess.codemap,
span) as int);
- for fields.each {|field|
+ for fields.each |field| {
let field_t = ty::get_field(t, field.node.ident).mt.ty;
let ty_md = create_ty(cx, field_t, field.node.mt.ty);
let (size, align) = size_and_align_of(cx, field_t);
let cache = get_cache(cx);
let tg = AutoVariableTag;
alt cached_metadata::<@metadata<local_var_md>>(
- cache, tg, {|md| md.data.id == local.node.id}) {
+ cache, tg, |md| md.data.id == local.node.id) {
option::some(md) { ret md; }
option::none {}
}
let cache = get_cache(cx);
let tg = ArgVariableTag;
alt cached_metadata::<@metadata<argument_md>>(
- cache, ArgVariableTag, {|md| md.data.id == arg.id}) {
+ cache, ArgVariableTag, |md| md.data.id == arg.id) {
option::some(md) { ret md; }
option::none {}
}
let cache = get_cache(cx);
alt cached_metadata::<@metadata<subprogram_md>>(
- cache, SubprogramTag, {|md| md.data.id == id}) {
+ cache, SubprogramTag, |md| md.data.id == id) {
option::some(md) { ret md; }
option::none {}
}
fn struct_tys(ty: TypeRef) -> ~[TypeRef] {
let n = llvm::LLVMCountStructElementTypes(ty);
let elts = vec::from_elem(n as uint, ptr::null());
- do vec::as_buf(elts) {|buf|
+ do vec::as_buf(elts) |buf| {
llvm::LLVMGetStructElementTypes(ty, buf);
}
ret elts;
2 /* float */ { 4u }
3 /* double */ { 8u }
10 /* struct */ {
- do vec::foldl(0u, struct_tys(ty)) {|a, t|
+ do vec::foldl(0u, struct_tys(ty)) |a, t| {
uint::max(a, ty_align(t))
}
}
2 /* float */ { 4u }
3 /* double */ { 8u }
10 /* struct */ {
- do vec::foldl(0u, struct_tys(ty)) {|s, t|
+ do vec::foldl(0u, struct_tys(ty)) |s, t| {
s + ty_size(t)
}
}
}
fn all_mem(cls: ~[mut x86_64_reg_class]) {
- for uint::range(0u, cls.len()) { |i|
+ for uint::range(0u, cls.len()) |i| {
cls[i] = memory_class;
}
}
classify(T_i64(), cls, i, off);
} else {
let mut field_off = off;
- for vec::each(tys) {|ty|
+ for vec::each(tys) |ty| {
field_off = align(field_off, ty);
classify(ty, cls, i, field_off);
field_off += ty_size(ty);
fn llreg_ty(cls: ~[x86_64_reg_class]) -> TypeRef {
fn llvec_len(cls: ~[x86_64_reg_class]) -> uint {
let mut len = 1u;
- for vec::each(cls) {|c|
+ for vec::each(cls) |c| {
if c != sseup_class {
break;
}
let mut arg_tys = ~[];
let mut attrs = ~[];
- for vec::each(atys) {|t|
+ for vec::each(atys) |t| {
let (ty, attr) = x86_64_ty(t, is_pass_byval, ByValAttribute);
vec::push(arg_tys, ty);
vec::push(attrs, attr);
fn decl_x86_64_fn(tys: x86_64_tys,
decl: fn(fnty: TypeRef) -> ValueRef) -> ValueRef {
- let atys = vec::map(tys.arg_tys, {|t| t.ty });
+ let atys = vec::map(tys.arg_tys, |t| t.ty);
let rty = tys.ret_ty.ty;
let fnty = T_fn(atys, rty);
let llfn = decl(fnty);
- do vec::iteri(tys.attrs) {|i, a|
+ do vec::iteri(tys.attrs) |i, a| {
alt a {
option::some(attr) {
let llarg = get_param(llfn, i);
let _icx = bcx.insn_ctxt("foreign::shim::build_ret");
alt tys.x86_64_tys {
some(x86_64) {
- do vec::iteri(x86_64.attrs) {|i, a|
+ do vec::iteri(x86_64.attrs) |i, a| {
alt a {
some(attr) {
llvm::LLVMAddInstrAttribute(
// Declare the "prototype" for the base function F:
alt tys.x86_64_tys {
some(x86_64) {
- do decl_x86_64_fn(x86_64) {|fnty|
+ do decl_x86_64_fn(x86_64) |fnty| {
decl_fn(ccx.llmod, lname, cc, fnty)
}
}
let llbasefn = base_fn(ccx, link_name(item), tys, cc);
let ty = ty::lookup_item_type(ccx.tcx,
ast_util::local_def(item.id)).ty;
- let args = vec::from_fn(ty::ty_fn_args(ty).len(), {|i|
+ let args = vec::from_fn(ty::ty_fn_args(ty).len(), |i| {
get_param(decl, i + first_real_arg)
});
let retval = Call(bcx, llbasefn, args);
ast::foreign_abi_stdcall { lib::llvm::X86StdcallCallConv }
};
- for vec::each(foreign_mod.items) {|foreign_item|
+ for vec::each(foreign_mod.items) |foreign_item| {
alt foreign_item.node {
ast::foreign_item_fn(fn_decl, typarams) {
let id = foreign_item.id;
constraints: ~[]
});
bcx = trans_call_inner(bcx, none, fty, ty::mk_nil(bcx.tcx()),
- { |bcx|
- lval_no_env(
- bcx,
- get_param(decl, first_real_arg),
- temporary)
- },
+ |bcx| lval_no_env(
+ bcx,
+ get_param(decl, first_real_arg),
+ temporary),
arg_vals(~[frameaddress_val]), ignore);
}
}
_ {
let llretptr = alloca(bcx, tys.ret_ty);
let n = vec::len(tys.arg_tys);
- for uint::range(0u, n) {|i|
+ for uint::range(0u, n) |i| {
let llargval = get_param(llwrapfn, i);
store_inbounds(bcx, llargval, llargbundle,
~[0u, i]);
ret if ccx.sess.targ_cfg.arch == arch_x86_64 {
let ret_def = !ty::type_is_bot(ret_ty) && !ty::type_is_nil(ret_ty);
let x86_64 = x86_64_tys(llargtys, llretty, ret_def);
- do decl_x86_64_fn(x86_64) {|fnty|
+ do decl_x86_64_fn(x86_64) |fnty| {
register_fn_fuller(ccx, sp, path, node_id,
t, lib::llvm::CCallConv, fnty)
}
let _icx = ccx.insn_ctxt("impl::trans_impl");
if tps.len() > 0u { ret; }
let sub_path = vec::append_one(path, path_name(name));
- for vec::each(methods) {|m|
+ for vec::each(methods) |m| {
if m.tps.len() == 0u {
let llfn = get_item_val(ccx, m.id);
trans_fn(ccx,
fn method_from_methods(ms: ~[@ast::method], name: ast::ident)
-> ast::def_id {
- local_def(option::get(vec::find(ms, {|m| m.ident == name})).id)
+ local_def(option::get(vec::find(ms, |m| m.ident == name)).id)
}
fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id,
let mut vtable_off = n_bound, i = 0u;
// Vtables are stored in a flat array, finding the right one is
// somewhat awkward
- for vec::each(*ps.bounds) {|bounds|
+ for vec::each(*ps.bounds) |bounds| {
if i >= n_param { break; }
- for vec::each(*bounds) {|bound|
+ for vec::each(*bounds) |bound| {
alt bound { ty::bound_iface(_) { vtable_off += 1u; } _ {} }
}
i += 1u;
fn resolve_vtables_in_fn_ctxt(fcx: fn_ctxt, vts: typeck::vtable_res)
-> typeck::vtable_res {
- @vec::map(*vts, {|d| resolve_vtable_in_fn_ctxt(fcx, d)})
+ @vec::map(*vts, |d| resolve_vtable_in_fn_ctxt(fcx, d))
}
fn resolve_vtable_in_fn_ctxt(fcx: fn_ctxt, vt: typeck::vtable_origin)
typeck::vtable_static(iid, tys, sub) {
let tys = alt fcx.param_substs {
some(substs) {
- vec::map(tys, {|t|
- ty::subst_tps(fcx.ccx.tcx, substs.tys, t)
- })
+ vec::map(tys, |t| ty::subst_tps(fcx.ccx.tcx, substs.tys, t))
}
_ { tys }
};
}
typeck::vtable_iface(iface_id, substs) {
@{def: iface_id,
- params: vec::map(substs, {|t| mono_precise(t, none)})}
+ params: vec::map(substs, |t| mono_precise(t, none))}
}
}
}
fn make_vtable(ccx: @crate_ctxt, ptrs: ~[ValueRef]) -> ValueRef {
let _icx = ccx.insn_ctxt("impl::make_vtable");
let tbl = C_struct(ptrs);
- let vt_gvar = str::as_c_str(ccx.names("vtable"), {|buf|
+ let vt_gvar = str::as_c_str(ccx.names("vtable"), |buf| {
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl), buf)
});
llvm::LLVMSetInitializer(vt_gvar, tbl);
let ifce_id = expect(ccx.sess,
ty::ty_to_def_id(option::get(ty::impl_iface(tcx,
impl_id))),
- {|| "make_impl_vtable: non-iface-type implemented"});
+ || "make_impl_vtable: non-iface-type implemented");
let has_tps = (*ty::lookup_item_type(ccx.tcx, impl_id).bounds).len() > 0u;
- make_vtable(ccx, vec::map(*ty::iface_methods(tcx, ifce_id), {|im|
+ make_vtable(ccx, vec::map(*ty::iface_methods(tcx, ifce_id), |im| {
let fty = ty::subst_tps(tcx, substs, ty::mk_fn(tcx, im.fty));
if (*im.tps).len() > 0u || ty::type_has_self(fty) {
C_null(T_ptr(T_nil()))
fn traverse_exports(cx: ctx, vis: ~[@view_item]) -> bool {
let mut found_export = false;
- for vec::each(vis) {|vi|
+ for vec::each(vis) |vi| {
alt vi.node {
view_item_export(vps) {
found_export = true;
- for vec::each(vps) {|vp|
+ for vec::each(vps) |vp| {
alt vp.node {
view_path_simple(_, _, id) | view_path_glob(_, id) |
view_path_list(_, _, id) {
}
fn traverse_export(cx: ctx, exp_id: node_id) {
- do option::iter(cx.exp_map.find(exp_id)) {|defs|
- for vec::each(defs) {|def| traverse_def_id(cx, def.id); }
+ do option::iter(cx.exp_map.find(exp_id)) |defs| {
+ for vec::each(defs) |def| { traverse_def_id(cx, def.id); }
}
}
fn traverse_public_mod(cx: ctx, m: _mod) {
if !traverse_exports(cx, m.view_items) {
// No exports, so every local item is exported
- for vec::each(m.items) {|item| traverse_public_item(cx, item); }
+ for vec::each(m.items) |item| { traverse_public_item(cx, item); }
}
}
item_mod(m) { traverse_public_mod(cx, m); }
item_foreign_mod(nm) {
if !traverse_exports(cx, nm.view_items) {
- for vec::each(nm.items) {|item| cx.rmap.insert(item.id, ()); }
+ for vec::each(nm.items) |item| { cx.rmap.insert(item.id, ()); }
}
}
item_fn(_, tps, blk) {
}
}
item_impl(tps, _, _, _, ms) {
- for vec::each(ms) {|m|
+ for vec::each(ms) |m| {
if tps.len() > 0u || m.tps.len() > 0u ||
attr::find_inline_attr(m.attrs) != attr::ia_none {
cx.rmap.insert(m.id, ());
}
item_class(tps, _ifaces, items, ctor, m_dtor, _) {
cx.rmap.insert(ctor.node.id, ());
- do option::iter(m_dtor) {|dtor|
+ do option::iter(m_dtor) |dtor| {
cx.rmap.insert(dtor.node.id, ());
// dtors don't have attrs
if tps.len() > 0u {
traverse_inline_body(cx, dtor.node.body);
}
}
- for vec::each(items) {|item|
+ for vec::each(items) |item| {
alt item.node {
class_method(m) {
cx.rmap.insert(m.id, ());
some(d) { traverse_def_id(cx, def_id_of_def(d)); }
none { /* do nothing -- but should we fail here? */ }
}
- for p.types.each {|t| v.visit_ty(t, cx, v); };
+ for p.types.each |t| { v.visit_ty(t, cx, v); };
}
_ { visit::visit_ty(ty, cx, v); }
}
fn traverse_all_resources(cx: ctx, crate_mod: _mod) {
visit::visit_mod(crate_mod, ast_util::dummy_sp(), 0, cx, visit::mk_vt(@{
- visit_expr: {|_e, _cx, _v|},
- visit_item: {|i, cx, v|
+ visit_expr: |_e, _cx, _v| { },
+ visit_item: |i, cx, v| {
visit::visit_item(i, cx, v);
alt i.node {
item_class(_, _, _, _, some(_), _) {
*self.visitor_methods));
let mth_ty = ty::mk_fn(tcx, self.visitor_methods[mth_idx].fty);
let v = self.visitor_val;
- let get_lval = {|bcx|
+ let get_lval = |bcx| {
let callee =
impl::trans_iface_callee(bcx, v, mth_ty, mth_idx);
#debug("calling mth ty %s, lltype %s",
};
#debug("passing %u args:", vec::len(args));
let bcx = self.bcx;
- for args.eachi {|i, a|
+ for args.eachi |i, a| {
#debug("arg %u: %s", i, val_str(bcx.ccx().tn, a));
}
self.bcx =
ty::ty_vec(mt) { self.bracketed_mt("vec", mt, ~[]) }
ty::ty_estr(vst) {
- do self.vstore_name_and_extra(t, vst) {|name, extra|
+ do self.vstore_name_and_extra(t, vst) |name, extra| {
self.visit("estr_" + name, extra)
}
}
ty::ty_evec(mt, vst) {
- do self.vstore_name_and_extra(t, vst) {|name, extra|
+ do self.vstore_name_and_extra(t, vst) |name, extra| {
self.bracketed_mt("evec_" + name, mt, extra)
}
}
let extra = (vec::append(~[self.c_uint(vec::len(fields))],
self.c_size_and_align(t)));
self.visit("enter_rec", extra);
- for fields.eachi {|i, field|
+ for fields.eachi |i, field| {
self.bracketed_mt("rec_field", field.mt,
~[self.c_uint(i),
self.c_slice(*field.ident)]);
let extra = (vec::append(~[self.c_uint(vec::len(tys))],
self.c_size_and_align(t)));
self.visit("enter_tup", extra);
- for tys.eachi {|i, t|
+ for tys.eachi |i, t| {
self.bracketed_t("tup_field", t, ~[self.c_uint(i)]);
}
self.visit("leave_tup", extra);
self.c_uint(vec::len(fty.inputs)),
self.c_uint(retval)];
self.visit("enter_fn", extra);
- for fty.inputs.eachi {|i, arg|
+ for fty.inputs.eachi |i, arg| {
let modeval = alt arg.mode {
ast::infer(_) { 0u }
ast::expl(e) {
self.c_size_and_align(t));
self.visit("enter_class", extra);
- for fields.eachi {|i, field|
+ for fields.eachi |i, field| {
self.bracketed_mt("class_field", field.mt,
~[self.c_uint(i),
self.c_slice(*field.ident)]);
self.c_size_and_align(t));
self.visit("enter_enum", extra);
- for variants.eachi {|i, v|
+ for variants.eachi |i, v| {
let extra = ~[self.c_uint(i),
self.c_int(v.disr_val),
self.c_uint(vec::len(v.args)),
self.c_slice(*v.name)];
self.visit("enter_enum_variant", extra);
- for v.args.eachi {|j, a|
+ for v.args.eachi |j, a| {
self.bracketed_t("enum_variant_field", a,
~[self.c_uint(j)]);
}
fn mk_nominal_id(tcx: ty::ctxt, did: ast::def_id,
parent_id: option<ast::def_id>,
tps: ~[ty::t]) -> nominal_id {
- let tps_norm = tps.map({ |t| ty::normalize_ty(tcx, t) });
+ let tps_norm = tps.map(|t| ty::normalize_ty(tcx, t));
@{did: did, parent_id: parent_id, tps: tps_norm}
}
h += ri.did.crate as uint;
h *= 33u;
h += ri.did.node as uint;
- for vec::each(ri.tps) {|t|
+ for vec::each(ri.tps) |t| {
h *= 33u;
h += ty::type_id(t);
}
if mi.did != ni.did {
false
} else {
- do vec::all2(mi.tps, ni.tps) { |m_tp, n_tp|
+ do vec::all2(mi.tps, ni.tps) |m_tp, n_tp| {
ty::type_id(m_tp) == ty::type_id(n_tp)
}
}
ValueRef {
let llglobal =
str::as_c_str(name,
- {|buf|
+ |buf| {
lib::llvm::llvm::LLVMAddGlobal(ccx.llmod,
val_ty(llval), buf)
});
fn enum_kind(ccx: @crate_ctxt, did: ast::def_id) -> enum_kind {
let variants = ty::enum_variants(ccx.tcx, did);
- if vec::any(*variants, {|v| vec::len(v.args) > 0u}) {
+ if vec::any(*variants, |v| vec::len(v.args) > 0u) {
if vec::len(*variants) == 1u { tk_newtype }
else { tk_complex }
} else {
fn mk_ctxt(llmod: ModuleRef) -> ctxt {
let llshapetablesty = trans::common::T_named_struct("shapes");
- let llshapetables = str::as_c_str("shapes", {|buf|
+ let llshapetables = str::as_c_str("shapes", |buf| {
lib::llvm::llvm::LLVMAddGlobal(llmod, llshapetablesty, buf)
});
ty::ty_rec(fields) {
let mut s = ~[shape_struct], sub = ~[];
- for vec::each(fields) {|f|
+ for vec::each(fields) |f| {
sub += shape_of(ccx, f.mt.ty);
}
add_substr(s, sub);
}
ty::ty_tup(elts) {
let mut s = ~[shape_struct], sub = ~[];
- for vec::each(elts) {|elt|
+ for vec::each(elts) |elt| {
sub += shape_of(ccx, elt);
}
add_substr(s, sub);
~[shape_res]
}
else { ~[shape_struct] }, sub = ~[];
- do option::iter(m_dtor_did) {|dtor_did|
+ do option::iter(m_dtor_did) |dtor_did| {
let ri = @{did: dtor_did, parent_id: some(did), tps: tps};
let id = interner::intern(ccx.shape_cx.resources, ri);
add_u16(s, id as u16);
// hasn't changed since we started monomorphizing.
add_u16(s, 0_u16);
};
- for ty::class_items_as_mutable_fields(ccx.tcx, did, substs).each {|f|
+ for ty::class_items_as_mutable_fields(ccx.tcx, did, substs).each |f| {
sub += shape_of(ccx, f.mt.ty);
}
add_substr(s, sub);
fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info) -> ~[u8] {
let mut s = ~[];
- for vec::each(v.args) {|t| s += shape_of(ccx, t); }
+ for vec::each(v.args) |t| { s += shape_of(ccx, t); }
ret s;
}
while i < ccx.shape_cx.tag_order.len() {
let {did, substs} = ccx.shape_cx.tag_order[i];
let variants = @ty::substd_enum_variants(ccx.tcx, did, substs);
- do vec::iter(*variants) {|v|
+ do vec::iter(*variants) |v| {
offsets += ~[vec::len(data) as u16];
let variant_shape = shape_of_variant(ccx, v);
let data_sz = vec::len(data) as u16;
let mut inf_sz = 0u16;
- for enum_variants.each { |variants|
+ for enum_variants.each |variants| {
let num_variants = vec::len(*variants) as u16;
add_u16(header, header_sz + inf_sz);
inf_sz += 2u16 * (num_variants + 2u16) + 3u16;
let mut lv_table = ~[];
let mut i = 0u;
- for enum_variants.each { |variants|
+ for enum_variants.each |variants| {
add_u16(inf, vec::len(*variants) as u16);
// Construct the largest-variants table.
let lv = largest_variants(ccx, variants);
add_u16(lv_table, vec::len(lv) as u16);
- for vec::each(lv) {|v| add_u16(lv_table, v as u16); }
+ for vec::each(lv) |v| { add_u16(lv_table, v as u16); }
// Determine whether the enum has dynamic size.
- assert !vec::any(*variants, {|v|
- vec::any(v.args, {|t| ty::type_has_params(t)})
+ assert !vec::any(*variants, |v| {
+ vec::any(v.args, |t| ty::type_has_params(t))
});
// If we can, write in the static size and alignment of the enum.
inf += ~[size_align.align];
// Now write in the offset of each variant.
- for vec::each(*variants) {|_v|
+ for vec::each(*variants) |_v| {
add_u16(inf, header_sz + inf_sz + offsets[i]);
i += 1u;
}
// variant that contains (T,T) must be as least as large as
// any variant that contains just T.
let mut ranges = ~[];
- for vec::each(*variants) {|variant|
+ for vec::each(*variants) |variant| {
let mut bounded = true;
let mut min_size = 0u, min_align = 0u;
- for vec::each(variant.args) {|elem_t|
+ for vec::each(variant.args) |elem_t| {
if ty::type_has_params(elem_t) {
// NB: We could do better here; this causes us to
// conservatively assume that (int, T) has minimum size 0,
// Initialize the candidate set to contain all variants.
let mut candidates = ~[mut];
- for vec::each(*variants) {|_v| candidates += ~[mut true]; }
+ for vec::each(*variants) |_v| { candidates += ~[mut true]; }
// Do a pairwise comparison among all variants still in the
// candidate set. Throw out any variant that we know has size
-> size_align {
let mut max_size = 0u16;
let mut max_align = 1u8;
- for vec::each(largest_variants) {|vid|
+ for vec::each(largest_variants) |vid| {
// We increment a "virtual data pointer" to compute the size.
let mut lltys = ~[];
- for vec::each(variants[vid].args) {|typ|
+ for vec::each(variants[vid].args) |typ| {
lltys += ~[type_of::type_of(ccx, typ)];
}
fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
let mut dtors = ~[];
let len = interner::len(ccx.shape_cx.resources);
- for uint::range(0u, len) {|i|
+ for uint::range(0u, len) |i| {
let ri = interner::get(ccx.shape_cx.resources, i);
- for ri.tps.each() {|s| assert !ty::type_has_params(s); }
- do option::iter(ri.parent_id) {|id|
+ for ri.tps.each() |s| { assert !ty::type_has_params(s); }
+ do option::iter(ri.parent_id) |id| {
dtors += ~[trans::base::get_res_dtor(ccx, ri.did, id, ri.tps)];
}
}
// Compute max(variant sizes).
let mut max_size = 0u;
let variants = ty::enum_variants(cx.tcx, tid);
- for vec::each(*variants) {|variant|
+ for vec::each(*variants) |variant| {
let tup_ty = simplify_type(cx.tcx,
ty::mk_tup(cx.tcx, variant.args));
// Perform any type parameter substitutions.
ty::mk_u8(tcx),
mutbl: ast::m_mutbl}}] }
else { ~[] }) +
- do ty::lookup_class_fields(tcx, did).map {|f|
+ do ty::lookup_class_fields(tcx, did).map |f| {
let t = ty::lookup_field_type(tcx, did, f.id, substs);
{ident: f.ident,
mt: {ty: simplify_type(tcx, t), mutbl: ast::m_const}}
_ { typ }
}
}
- ty::fold_ty(tcx, typ, {|t| simplifier(tcx, t) })
+ ty::fold_ty(tcx, typ, |t| simplifier(tcx, t))
}
let ccx = bcx.ccx();
let mut bcx = bcx;
if dest == base::ignore {
- for vec::each(args) {|arg|
+ for vec::each(args) |arg| {
bcx = base::trans_expr(bcx, arg, base::ignore);
}
ret bcx;
#debug("trans_evec: v: %s, dataptr: %s",
val_str(ccx.tn, val),
val_str(ccx.tn, dataptr));
- for vec::each(args) {|e|
+ for vec::each(args) |e| {
let lleltptr = InBoundsGEP(bcx, dataptr, ~[C_uint(ccx, i)]);
bcx = base::trans_expr_save_in(bcx, e, lleltptr);
add_clean_temp_mem(bcx, lleltptr, unit_ty);
i += 1u;
}
- for vec::each(temp_cleanups) {|cln| revoke_clean(bcx, cln); }
+ for vec::each(temp_cleanups) |cln| { revoke_clean(bcx, cln); }
alt vst {
ast::vstore_fixed(_) {
if strings { lhs_off = Sub(bcx, lhs_off, C_int(ccx, 1)); }
let write_ptr = pointer_add(bcx, lhs_data, lhs_off);
let write_ptr_ptr = do_spill_noroot(bcx, write_ptr);
- iter_vec_uniq(bcx, rhs, vec_ty, rfill, {|bcx, addr, _ty|
+ iter_vec_uniq(bcx, rhs, vec_ty, rfill, |bcx, addr, _ty| {
let write_ptr = Load(bcx, write_ptr_ptr);
let bcx = copy_val(bcx, INIT, write_ptr,
load_if_immediate(bcx, addr, unit_ty), unit_ty);
let elt_llty = type_of::type_of(ccx, elt_ty);
let elt_sz = shape::llsize_of(ccx, elt_llty);
let scratch = base::alloca(bcx, elt_llty);
- for vec::each(vals) {|val|
+ for vec::each(vals) |val| {
bcx = base::trans_expr_save_in(bcx, val, scratch);
let vptr = get_bodyptr(bcx, Load(bcx, vptrptr));
let old_fill = get_fill(bcx, vptr);
let new_fill = Add(bcx, old_fill, elt_sz);
let do_grow = ICmp(bcx, lib::llvm::IntUGT, new_fill,
get_alloc(bcx, vptr));
- bcx = do base::with_cond(bcx, do_grow) {|bcx|
+ bcx = do base::with_cond(bcx, do_grow) |bcx| {
let pt = PointerCast(bcx, vptrptr,
T_ptr(T_ptr(T_i8())));
Call(bcx, ccx.upcalls.vec_grow, ~[pt, new_fill]);
fn type_of_explicit_args(cx: @crate_ctxt,
inputs: ~[ty::arg]) -> ~[TypeRef] {
- do vec::map(inputs) {|arg|
+ do vec::map(inputs) |arg| {
let arg_ty = arg.ty;
let llty = type_of(cx, arg_ty);
alt ty::resolved_mode(cx.tcx, arg.mode) {
ty::ty_rec(fields) {
let mut tys: ~[TypeRef] = ~[];
- for vec::each(fields) {|f|
+ for vec::each(fields) |f| {
let mt_ty = f.mt.ty;
vec::push(tys, type_of(cx, mt_ty));
}
ty::ty_type { T_ptr(cx.tydesc_type) }
ty::ty_tup(elts) {
let mut tys = ~[];
- for vec::each(elts) {|elt|
+ for vec::each(elts) |elt| {
vec::push(tys, type_of(cx, elt));
}
T_struct(tys)
ty::ty_class(did, ts) {
// Only instance vars are record fields at runtime.
let fields = lookup_class_fields(cx.tcx, did);
- let mut tys = do vec::map(fields) {|f|
+ let mut tys = do vec::map(fields) |f| {
let t = ty::lookup_field_type(cx.tcx, did, f.id, ts);
type_of(cx, t)
};
let cx = {ccx: ccx, uses: vec::to_mut(vec::from_elem(n_tps, 0u))};
alt ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).struct {
ty::ty_fn({inputs, _}) {
- for vec::each(inputs) {|arg|
+ for vec::each(inputs) |arg| {
if arg.mode == expl(by_val) { type_needs(cx, use_repr, arg.ty); }
}
}
handle_body(cx, body);
}
ast_map::node_variant(_, _, _) {
- for uint::range(0u, n_tps) {|n| cx.uses[n] |= use_repr;}
+ for uint::range(0u, n_tps) |n| { cx.uses[n] |= use_repr;}
}
ast_map::node_foreign_item(i@@{node: foreign_item_fn(_, _), _},
abi, _) {
}
"forget" | "addr_of" { 0u }
};
- for uint::range(0u, n_tps) {|n| cx.uses[n] |= flags;}
+ for uint::range(0u, n_tps) |n| { cx.uses[n] |= flags;}
}
}
ast_map::node_ctor(_, _, ctor, _, _){
fn type_needs(cx: ctx, use: uint, ty: ty::t) {
let mut done = true;
// Optimization -- don't descend type if all params already have this use
- for vec::each(cx.uses) {|u| if u & use != use { done = false } }
+ for vec::each(cx.uses) |u| { if u & use != use { done = false } }
if !done { type_needs_inner(cx, use, ty, @nil); }
}
fn type_needs_inner(cx: ctx, use: uint, ty: ty::t,
enums_seen: @list<def_id>) {
- do ty::maybe_walk_ty(ty) {|ty|
+ do ty::maybe_walk_ty(ty) |ty| {
if ty::type_has_params(ty) {
alt ty::get(ty).struct {
/*
ty::ty_fn(_) | ty::ty_ptr(_) | ty::ty_rptr(_, _)
| ty::ty_iface(_, _) { false }
ty::ty_enum(did, substs) {
- if option::is_none(list::find(enums_seen, {|id| id == did})) {
+ if option::is_none(list::find(enums_seen, |id| id == did)) {
let seen = @cons(did, enums_seen);
- for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) {|v|
- for vec::each(v.args) {|aty|
+ for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
+ for vec::each(v.args) |aty| {
let t = ty::subst(cx.ccx.tcx, substs, aty);
type_needs_inner(cx, use, t, seen);
}
}
}
expr_path(_) {
- do cx.ccx.tcx.node_type_substs.find(e.id).iter {|ts|
+ do cx.ccx.tcx.node_type_substs.find(e.id).iter |ts| {
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get(e.id));
- vec::iter2(type_uses_for(cx.ccx, id, ts.len()), ts, {|uses, subst|
- type_needs(cx, uses, subst)
- })
+ vec::iter2(type_uses_for(cx.ccx, id, ts.len()), ts,
+ |uses, subst| {
+ type_needs(cx, uses, subst)
+ })
}
}
expr_fn(*) | expr_fn_block(*) {
alt ty::ty_fn_proto(ty::expr_ty(cx.ccx.tcx, e)) {
proto_bare | proto_any | proto_uniq {}
proto_box | proto_block {
- for vec::each(*freevars::get_freevars(cx.ccx.tcx, e.id)) {|fv|
+ for vec::each(*freevars::get_freevars(cx.ccx.tcx, e.id)) |fv| {
let node_id = ast_util::def_id_of_def(fv.def).node;
node_type_needs(cx, use_repr, node_id);
}
let base_ty = ty::node_id_to_type(cx.ccx.tcx, base.id);
type_needs(cx, use_repr, ty::type_autoderef(cx.ccx.tcx, base_ty));
- do option::iter(cx.ccx.maps.method_map.find(e.id)) {|mth|
+ do option::iter(cx.ccx.maps.method_map.find(e.id)) |mth| {
alt mth.origin {
typeck::method_static(did) {
- do option::iter(cx.ccx.tcx.node_type_substs.find(e.id)) {|ts|
+ do option::iter(cx.ccx.tcx.node_type_substs.find(e.id)) |ts| {
do vec::iter2(type_uses_for(cx.ccx, did, ts.len()), ts)
- {|uses, subst| type_needs(cx, uses, subst)}
+ |uses, subst| { type_needs(cx, uses, subst)}
}
}
typeck::method_param({param_num: param, _}) {
node_type_needs(cx, use_repr, v.id);
}
expr_call(f, _, _) {
- vec::iter(ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)), {|a|
+ vec::iter(ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)), |a| {
alt a.mode {
expl(by_move) | expl(by_copy) | expl(by_val) {
type_needs(cx, use_repr, a.ty);
fn handle_body(cx: ctx, body: blk) {
let v = visit::mk_vt(@{
- visit_expr: {|e, cx, v|
+ visit_expr: |e, cx, v| {
visit::visit_expr(e, cx, v);
mark_for_expr(cx, e);
},
- visit_local: {|l, cx, v|
+ visit_local: |l, cx, v| {
visit::visit_local(l, cx, v);
node_type_needs(cx, use_repr, l.node.id);
},
- visit_pat: {|p, cx, v|
+ visit_pat: |p, cx, v| {
visit::visit_pat(p, cx, v);
node_type_needs(cx, use_repr, p.id);
},
- visit_block: {|b, cx, v|
+ visit_block: |b, cx, v| {
visit::visit_block(b, cx, v);
- do option::iter(b.node.expr) {|e|
+ do option::iter(b.node.expr) |e| {
node_type_needs(cx, use_repr, e.id);
}
},
- visit_item: {|_i, _cx, _v|}
+ visit_item: |_i, _cx, _v| { }
with *visit::default_visitor()
});
v.visit_block(body, cx, v);
fn make_free_glue(bcx: block, vptr: ValueRef, t: ty::t)
-> block {
let _icx = bcx.insn_ctxt("uniq::make_free_glue");
- do with_cond(bcx, IsNotNull(bcx, vptr)) {|bcx|
+ do with_cond(bcx, IsNotNull(bcx, vptr)) |bcx| {
let content_ty = content_ty(t);
let body_ptr = opaque_box_body(bcx, content_ty, vptr);
let bcx = drop_ty(bcx, body_ptr, content_ty);
fn node_ids_in_fn(tcx: ty::ctxt, body: blk, rs: @mut ~[node_id]) {
let collect_ids =
- visit::mk_simple_visitor(@{visit_expr: {|a|collect_ids_expr(a, rs)},
- visit_block: {|a|collect_ids_block(a, rs)},
- visit_stmt: {|a|collect_ids_stmt(a, rs)},
- visit_local: {|a|
- collect_ids_local(tcx, a, rs)}
+ visit::mk_simple_visitor(@{visit_expr: |a| collect_ids_expr(a, rs),
+ visit_block: |a| collect_ids_block(a, rs),
+ visit_stmt: |a| collect_ids_stmt(a, rs),
+ visit_local: |a|
+ collect_ids_local(tcx, a, rs)
with *visit::default_simple_visitor()});
collect_ids.visit_block(body, (), collect_ids);
}
fn init_vecs(ccx: crate_ctxt, node_ids: ~[node_id], len: uint) {
- for node_ids.each {|i|
+ for node_ids.each |i| {
log(debug, int::str(i) + " |-> " + uint::str(len));
add_node(ccx, i, empty_ann(len));
}
fn annotate_crate(ccx: crate_ctxt, crate: crate) {
let do_ann =
visit::mk_simple_visitor(
- @{visit_fn: {|a,b,c,d,e|annotate_in_fn(ccx, a, b, c, d, e)}
+ @{visit_fn: |a,b,c,d,e| annotate_in_fn(ccx, a, b, c, d, e)
with *visit::default_simple_visitor()});
visit::visit_crate(crate, (), do_ann);
}
fn comma_str(args: ~[@constr_arg_use]) -> str {
let mut rslt = "";
let mut comma = false;
- for args.each {|a|
+ for args.each |a| {
if comma { rslt += ", "; } else { comma = true; }
alt a.node {
carg_base { rslt += "*"; }
fn tritv_to_str(fcx: fn_ctxt, v: tritv::t) -> str {
let mut s = "";
let mut comma = false;
- for constraints(fcx).each {|p|
+ for constraints(fcx).each |p| {
alt tritv_get(v, p.bit_num) {
dont_care { }
tt {
fn first_difference_string(fcx: fn_ctxt, expected: tritv::t, actual: tritv::t)
-> str {
let mut s = "";
- for constraints(fcx).each {|c|
+ for constraints(fcx).each |c| {
if tritv_get(expected, c.bit_num) == ttrue &&
tritv_get(actual, c.bit_num) != ttrue {
s = constraint_to_str(fcx.ccx.tcx, c.c);
fn tos(v: ~[uint]) -> str {
let mut rslt = "";
- for v.each {|i|
+ for v.each |i| {
if i == 0u {
rslt += "0";
} else if i == 1u { rslt += "1"; } else { rslt += "?"; }
fn norm_a_constraint(id: def_id, c: constraint) -> ~[norm_constraint] {
let mut rslt: ~[norm_constraint] = ~[];
- for (*c.descs).each {|pd|
+ for (*c.descs).each |pd| {
vec::push(rslt,
{bit_num: pd.node.bit_num,
c: respan(pd.span, {path: c.path,
// non-exhaustive match in trans.
fn constraints(fcx: fn_ctxt) -> ~[norm_constraint] {
let mut rslt: ~[norm_constraint] = ~[];
- for fcx.enclosing.constrs.each {|key, val|
+ for fcx.enclosing.constrs.each |key, val| {
vec::push_all(rslt, norm_a_constraint(key, val));
};
ret rslt;
occ: ~[@constr_arg_use]) -> uint {
#debug("match_args: looking at %s",
constr_args_to_str(fn@(i: inst) -> str { ret *i.ident; }, occ));
- for (*occs).each {|pd|
+ for (*occs).each |pd| {
log(debug,
"match_args: candidate " + pred_args_to_str(pd));
fn eq(p: inst, q: inst) -> bool { ret p.node == q.node; }
fn exprs_to_constr_args(tcx: ty::ctxt,
args: ~[@expr]) -> ~[@constr_arg_use] {
- let f = {|a|expr_to_constr_arg(tcx, a)};
+ let f = |a| expr_to_constr_arg(tcx, a);
let mut rslt: ~[@constr_arg_use] = ~[];
- for args.each {|e| vec::push(rslt, f(e)); }
+ for args.each |e| { vec::push(rslt, f(e)); }
rslt
}
fn substitute_constr_args(cx: ty::ctxt, actuals: ~[@expr], c: @ty::constr) ->
tsconstr {
let mut rslt: ~[@constr_arg_use] = ~[];
- for c.node.args.each {|a|
+ for c.node.args.each |a| {
vec::push(rslt, substitute_arg(cx, actuals, a));
}
ret {path: c.node.path,
desc: pred_args) ->
bool {
let mut i = 0u;
- for desc.node.args.each {|c|
+ for desc.node.args.each |c| {
let n = pattern[i];
alt c.node {
carg_ident(p) {
fn find_instance_(pattern: ~[constr_arg_general_<inst>],
descs: ~[pred_args]) ->
option<uint> {
- for descs.each {|d|
+ for descs.each |d| {
if pred_args_matches(pattern, d) { ret some(d.node.bit_num); }
}
ret none;
if vec::len(subst) == 0u { ret ~[]; }
let mut res = ~[];
- do (*c.descs).swap { |v|
+ do (*c.descs).swap |v| {
let v <- vec::from_mut(v);
- for v.each { |d|
+ for v.each |d| {
if args_mention(d.node.args, find_in_subst_bool, subst) {
let old_bit_num = d.node.bit_num;
let newv = replace(subst, d);
}
fn find_in_subst(id: node_id, s: subst) -> option<inst> {
- for s.each {|p|
+ for s.each |p| {
if id == p.from.node { ret some(p.to); }
}
ret none;
fn insts_to_str(stuff: ~[constr_arg_general_<inst>]) -> str {
let mut rslt = "<";
- for stuff.each {|i|
+ for stuff.each |i| {
rslt +=
" " +
alt i {
fn replace(subst: subst, d: pred_args) -> ~[constr_arg_general_<inst>] {
let mut rslt: ~[constr_arg_general_<inst>] = ~[];
- for d.node.args.each {|c|
+ for d.node.args.each |c| {
alt c.node {
carg_ident(p) {
alt find_in_subst(p.node, subst) {
fn for_constraints_mentioning(fcx: fn_ctxt, id: node_id,
f: fn(norm_constraint)) {
- for constraints(fcx).each {|c|
+ for constraints(fcx).each |c| {
if constraint_mentions(fcx, c, id) { f(c); }
};
}
}
- for fcx.enclosing.constrs.each_value {|val|
+ for fcx.enclosing.constrs.each_value |val| {
// replace any occurrences of the src def_id with the
// dest def_id
let insts = find_instances(fcx, subst, val);
- for insts.each {|p|
+ for insts.each |p| {
if bitvectors::promises_(p.from, src_post) {
set_in_poststate_(p.to, target_post);
}
// In the postcondition given by parent_exp, clear the bits
// for any constraints mentioning dead_v
let d = local_node_id_to_local_def_id(fcx, dead_v);
- do option::iter(d) {|d_id|
- do for_constraints_mentioning(fcx, d_id) {|c|
+ do option::iter(d) |d_id| {
+ do for_constraints_mentioning(fcx, d_id) |c| {
#debug("clearing constraint %u %s",
c.bit_num,
constraint_to_str(fcx.ccx.tcx, c.c));
// for any constraints mentioning dead_v
let d = local_node_id_to_local_def_id(fcx, dead_v);
let mut changed = false;
- do option::iter(d) {|d_id|
- do for_constraints_mentioning(fcx, d_id) {|c|
+ do option::iter(d) |d_id| {
+ do for_constraints_mentioning(fcx, d_id) |c| {
changed |= clear_in_poststate_(c.bit_num, p);
}
}
}
fn any_eq(v: ~[node_id], d: node_id) -> bool {
- for v.each {|i| if i == d { ret true; } }
+ for v.each |i| { if i == d { ret true; } }
false
}
q: fn(~[T], node_id) -> bool,
s: ~[T]) -> bool {
- for args.each {|a|
+ for args.each |a| {
alt a.node { carg_ident(p1) { if q(s, p1.node) { ret true; } } _ { } }
}
ret false;
-> ~[@constr_arg_use] {
let mut actuals: ~[@constr_arg_use] = ~[];
let num_args = vec::len(args);
- for indices.each {|a|
+ for indices.each |a| {
vec::push(
actuals,
@respan(a.span,
fn local_to_bindings(tcx: ty::ctxt, loc: @local) -> binding {
let mut lhs = ~[];
- do pat_bindings(tcx.def_map, loc.node.pat) {|p_id, _s, name|
+ do pat_bindings(tcx.def_map, loc.node.pat) |p_id, _s, name| {
vec::push(lhs, local_dest({ident: path_to_ident(name), node: p_id}));
};
{lhs: lhs, rhs: loc.node.init}
fn locals_to_bindings(tcx: ty::ctxt, locals: ~[@local]) -> ~[binding] {
let mut rslt = ~[];
- for locals.each {|loc| vec::push(rslt, local_to_bindings(tcx, loc)); }
+ for locals.each |loc| { vec::push(rslt, local_to_bindings(tcx, loc)); }
ret rslt;
}
alt ty::get(ty).struct {
ty::ty_fn({inputs: args, _}) {
let mut modes = ~[];
- for args.each {|arg| vec::push(modes, arg.mode); }
+ for args.each |arg| { vec::push(modes, arg.mode); }
ret modes;
}
_ {
}
fn callee_arg_init_ops(fcx: fn_ctxt, callee: node_id) -> ~[init_op] {
- do vec::map(callee_modes(fcx, callee)) {|m|
+ do vec::map(callee_modes(fcx, callee)) |m| {
alt ty::resolved_mode(fcx.ccx.tcx, m) {
by_move { init_move }
by_copy | by_ref | by_val | by_mutbl_ref { init_assign }
fn arg_bindings(ops: ~[init_op], es: ~[@expr]) -> ~[binding] {
let mut bindings: ~[binding] = ~[];
let mut i = 0u;
- for ops.each {|op|
+ for ops.each |op| {
vec::push(bindings,
{lhs: ~[call], rhs: some({op: op, expr: es[i]})});
i += 1u;
let sz = vec::len(ps);
if sz >= 1u {
let prev = tritv_clone(ps[0]);
- vec::iter_between(ps, 1u, sz, {|p| seq_tritv(prev, p); });
+ vec::iter_between(ps, 1u, sz, |p| seq_tritv(prev, p) );
ret prev;
} else { ret ann::empty_poststate(num_constraints(fcx.enclosing)); }
}
let visitor = visit::mk_vt(
@{visit_stmt: check_states_stmt,
visit_expr: check_states_expr,
- visit_fn: {|a,b,c,d,e,f,g|
+ visit_fn: |a,b,c,d,e,f,g| {
do_nothing::<fn_ctxt>(a, b, c, d, e, f, g)
}
with *visit::default_visitor::<fn_ctxt>()});
// If it's a call, generate appropriate instances of the
// call's constraints.
expr_call(operator, operands, _) {
- for constraints_expr(cx.tcx, operator).each {|c|
+ for constraints_expr(cx.tcx, operator).each |c| {
let ct: sp_constr =
respan(c.span,
aux::substitute_constr_args(cx.tcx, operands, c));
}
/* if this function has any constraints, instantiate them to the
argument names and add them */
- for f_decl.constraints.each {|c|
+ for f_decl.constraints.each |c| {
let sc = ast_constr_to_sp_constr(cx.tcx, f_decl.inputs, c);
next = add_constraint(cx.tcx, sc, next, res_map);
}
fn mk_f_to_fn_info(ccx: crate_ctxt, c: @crate) {
let visitor =
visit::mk_simple_visitor(@{
- visit_fn: {|a,b,c,d,e|
- mk_fn_info(ccx, a, b, c, d, e)
- }
+ visit_fn: |a,b,c,d,e| mk_fn_info(ccx, a, b, c, d, e)
with *visit::default_simple_visitor()});
visit::visit_crate(*c, (), visitor);
}
fail "find_pre_post_item: shouldn't be called on item_class";
}
item_impl(_, _, _, _, ms) {
- for ms.each {|m| find_pre_post_method(ccx, m); }
+ for ms.each |m| { find_pre_post_method(ccx, m); }
}
}
}
#debug["find_pre_post_exprs: oper = %s", expr_to_str(args[0])];
}
fn do_one(fcx: fn_ctxt, e: @expr) { find_pre_post_expr(fcx, e); }
- for args.each {|e| do_one(fcx, e); }
+ for args.each |e| { do_one(fcx, e); }
fn get_pp(ccx: crate_ctxt, &&e: @expr) -> pre_and_post {
ret expr_pp(ccx, e);
}
- let pps = vec::map(args, {|a|get_pp(fcx.ccx, a)});
+ let pps = vec::map(args, |a| get_pp(fcx.ccx, a) );
set_pre_and_post(fcx.ccx, id, seq_preconds(fcx, pps),
seq_postconds(fcx, vec::map(pps, get_post)));
fn forget_args_moved_in(fcx: fn_ctxt, parent: @expr, modes: ~[mode],
operands: ~[@expr]) {
- do vec::iteri(modes) {|i,mode|
+ do vec::iteri(modes) |i,mode| {
alt ty::resolved_mode(fcx.ccx.tcx, mode) {
by_move { forget_in_postcond(fcx, parent.id, operands[i].id); }
by_ref | by_val | by_mutbl_ref | by_copy { }
find_pre_post_exprs(fcx, args, e.id);
/* see if the call has any constraints on its type */
- for constraints_expr(fcx.ccx.tcx, operator).each {|c|
+ for constraints_expr(fcx.ccx.tcx, operator).each |c| {
let i =
bit_num(fcx, substitute_constr_args(fcx.ccx.tcx, args, c));
require(i, expr_pp(fcx.ccx, e));
expr_fn(_, _, _, cap_clause) | expr_fn_block(_, _, cap_clause) {
find_pre_post_expr_fn_upvars(fcx, e);
- for (*cap_clause).each { |cap_item|
+ for (*cap_clause).each |cap_item| {
let d = local_node_id_to_local_def_id(fcx, cap_item.id);
- option::iter(d, { |id| use_var(fcx, id) });
+ option::iter(d, |id| use_var(fcx, id) );
}
- for (*cap_clause).each { |cap_item|
+ for (*cap_clause).each |cap_item| {
if cap_item.is_move {
log(debug, ("forget_in_postcond: ", cap_item));
forget_in_postcond(fcx, e.id, cap_item.id);
ret block_pp(fcx.ccx, an_alt.body);
}
let mut alt_pps = ~[];
- for alts.each {|a| vec::push(alt_pps, do_an_alt(fcx, a)); }
+ for alts.each |a| { vec::push(alt_pps, do_an_alt(fcx, a)); }
fn combine_pp(antec: pre_and_post, fcx: fn_ctxt, &&pp: pre_and_post,
&&next: pre_and_post) -> pre_and_post {
union(pp.precondition, seq_preconds(fcx, ~[antec, next]));
let e_pp =
{precondition: empty_prestate(num_local_vars),
postcondition: false_postcond(num_local_vars)};
- let g = {|a,b|combine_pp(antec_pp, fcx, a, b)};
+ let g = |a,b| combine_pp(antec_pp, fcx, a, b);
let alts_overall_pp =
vec::foldl(e_pp, alt_pps, g);
set_pre_and_post(fcx.ccx, e.id, alts_overall_pp.precondition,
alt adecl.node {
decl_local(alocals) {
let prev_pp = empty_pre_post(num_constraints(fcx.enclosing));
- for alocals.each {|alocal|
+ for alocals.each |alocal| {
alt alocal.node.init {
some(an_init) {
/* LHS always becomes initialized,
whether or not this is a move */
find_pre_post_expr(fcx, an_init.expr);
do pat_bindings(fcx.ccx.tcx.def_map, alocal.node.pat)
- {|p_id, _s, _n|
+ |p_id, _s, _n| {
copy_pre_post(fcx.ccx, p_id, an_init.expr);
};
/* Inherit ann from initializer, and add var being
}
do pat_bindings(fcx.ccx.tcx.def_map, alocal.node.pat)
- {|p_id, _s, n|
+ |p_id, _s, n| {
let ident = path_to_ident(n);
alt p {
some(p) {
}
none {
do pat_bindings(fcx.ccx.tcx.def_map, alocal.node.pat)
- {|p_id, _s, _n|
+ |p_id, _s, _n| {
clear_pp(node_id_to_ts_ann(fcx.ccx, p_id).conditions);
};
clear_pp(node_id_to_ts_ann(fcx.ccx, id).conditions);
fn do_one_(fcx: fn_ctxt, s: @stmt) {
find_pre_post_stmt(fcx, *s);
}
- for b.node.stmts.each {|s| do_one_(fcx, s); }
+ for b.node.stmts.each |s| { do_one_(fcx, s); }
fn do_inner_(fcx: fn_ctxt, &&e: @expr) { find_pre_post_expr(fcx, e); }
- let do_inner = {|a|do_inner_(fcx, a)};
+ let do_inner = |a| do_inner_(fcx, a);
option::map::<@expr, ()>(b.node.expr, do_inner);
let mut pps: ~[pre_and_post] = ~[];
- for b.node.stmts.each {|s| vec::push(pps, stmt_pp(fcx.ccx, *s)); }
+ for b.node.stmts.each |s| { vec::push(pps, stmt_pp(fcx.ccx, *s)); }
alt b.node.expr {
none {/* no-op */ }
some(e) { vec::push(pps, expr_pp(fcx.ccx, e)); }
let block_precond = seq_preconds(fcx, pps);
let mut postconds = ~[];
- for pps.each {|pp| vec::push(postconds, get_post(pp)); }
+ for pps.each |pp| { vec::push(postconds, get_post(pp)); }
/* A block may be empty, so this next line ensures that the postconds
vector is non-empty. */
{changed: bool, post: poststate} {
let mut changed = false;
let mut post = tritv_clone(pres);
- for bindings.each {|b|
+ for bindings.each |b| {
alt b.rhs {
some(an_init) {
// an expression, with or without a destination
changed |=
find_pre_post_state_expr(fcx, post, an_init.expr) || changed;
post = tritv_clone(expr_poststate(fcx.ccx, an_init.expr));
- for b.lhs.each {|d|
+ for b.lhs.each |d| {
alt an_init.expr.node {
expr_path(p) {
handle_move_or_copy(fcx, post, p, an_init.expr.id, d,
let ccx = fcx.ccx;
let pres_changed = set_prestate_ann(ccx, e_id, pres);
let post = tritv_clone(pres);
- for (*cap_clause).each { |cap_item|
+ for (*cap_clause).each |cap_item| {
if cap_item.is_move {
forget_in_poststate(fcx, post, cap_item.id);
}
let base_pres = alt vec::last_opt(exs) { none { pres }
some(f) { expr_poststate(fcx.ccx, f) }};
- option::iter(maybe_base, {|base|
+ option::iter(maybe_base, |base| {
changed |= find_pre_post_state_expr(fcx, base_pres, base) |
- set_poststate_ann(fcx.ccx, e.id,
- expr_poststate(fcx.ccx, base))});
+ set_poststate_ann(fcx.ccx, e.id,
+ expr_poststate(fcx.ccx, base))
+ });
ret changed;
}
expr_tup(elts) {
let mut a_post;
if vec::len(alts) > 0u {
a_post = false_postcond(num_constrs);
- for alts.each {|an_alt|
+ for alts.each |an_alt| {
alt an_alt.guard {
some(e) {
changed |= find_pre_post_state_expr(fcx, e_post, e);
let post = false_postcond(num_constrs);
ret set_prestate_ann(fcx.ccx, e.id, pres) |
set_poststate_ann(fcx.ccx, e.id, post) |
- option::map_default(maybe_fail_val, false, {|fail_val|
- find_pre_post_state_expr(fcx, pres, fail_val)});
+ option::map_default(
+ maybe_fail_val, false,
+ |fail_val|
+ find_pre_post_state_expr(fcx, pres, fail_val) );
}
expr_check(_, p) {
/* predicate p holds after this expression executes */
initializes. Then <pres> becomes the new poststate. */
let mut changed = false;
- for b.node.stmts.each {|s|
+ for b.node.stmts.each |s| {
changed |= find_pre_post_state_stmt(fcx, pres, s);
pres = stmt_poststate(fcx.ccx, *s);
}
// Instantiate any constraints on the arguments so we can use them
let block_pre = block_prestate(fcx.ccx, f_body);
- for f_decl.constraints.each {|c|
+ for f_decl.constraints.each |c| {
let tsc = ast_constr_to_ts_constr(fcx.ccx.tcx, f_decl.inputs, c);
set_in_prestate_constr(fcx, tsc, block_pre);
}
fn param_bounds_to_kind(bounds: param_bounds) -> kind {
let mut kind = kind_noncopyable();
- for vec::each(*bounds) {|bound|
+ for vec::each(*bounds) |bound| {
alt bound {
bound_copy {
kind = raise_kind(kind, kind_implicitly_copyable());
}
fn new_ty_hash<V: copy>() -> map::hashmap<t, V> {
- map::hashmap({|&&t: t| type_id(t)},
- {|&&a: t, &&b: t| type_id(a) == type_id(b)})
+ map::hashmap(|&&t: t| type_id(t),
+ |&&a: t, &&b: t| type_id(a) == type_id(b))
}
fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
freevars: freevars::freevar_map,
region_map: middle::region::region_map) -> ctxt {
- let interner = map::hashmap({|&&k: intern_key|
+ let interner = map::hashmap(|&&k: intern_key| {
hash_type_structure(k.struct) +
option::map_default(k.o_def_id, 0u, ast_util::hash_def)
- }, {|&&a, &&b| a == b});
+ }, |&&a, &&b| a == b);
let vecs_implicitly_copyable =
get_warning_level(s.warning_settings.default_settings,
vecs_not_implicitly_copyable) == ignore;
}
fn sflags(substs: substs) -> uint {
let mut f = 0u;
- for substs.tps.each {|tt| f |= get(tt).flags; }
- substs.self_r.iter({ |r| f |= rflags(r) });
+ for substs.tps.each |tt| { f |= get(tt).flags; }
+ substs.self_r.iter(|r| f |= rflags(r));
ret f;
}
alt st {
flags |= get(m.ty).flags;
}
ty_rec(flds) {
- for flds.each {|f| flags |= get(f.mt.ty).flags; }
+ for flds.each |f| { flags |= get(f.mt.ty).flags; }
}
ty_tup(ts) {
- for ts.each {|tt| flags |= get(tt).flags; }
+ for ts.each |tt| { flags |= get(tt).flags; }
}
ty_fn(f) {
- for f.inputs.each {|a| flags |= get(a.ty).flags; }
+ for f.inputs.each |a| { flags |= get(a.ty).flags; }
flags |= get(f.output).flags;
}
ty_constr(tt, _) {
}
fn walk_ty(ty: t, f: fn(t)) {
- maybe_walk_ty(ty, {|t| f(t); true});
+ maybe_walk_ty(ty, |t| { f(t); true });
}
fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
}
ty_enum(_, substs) | ty_class(_, substs) |
ty_iface(_, substs) {
- for substs.tps.each {|subty| maybe_walk_ty(subty, f); }
+ for substs.tps.each |subty| { maybe_walk_ty(subty, f); }
}
ty_rec(fields) {
- for fields.each {|fl| maybe_walk_ty(fl.mt.ty, f); }
+ for fields.each |fl| { maybe_walk_ty(fl.mt.ty, f); }
}
- ty_tup(ts) { for ts.each {|tt| maybe_walk_ty(tt, f); } }
+ ty_tup(ts) { for ts.each |tt| { maybe_walk_ty(tt, f); } }
ty_fn(ft) {
- for ft.inputs.each {|a| maybe_walk_ty(a.ty, f); }
+ for ft.inputs.each |a| { maybe_walk_ty(a.ty, f); }
maybe_walk_ty(ft.output, f);
}
ty_constr(sub, _) { maybe_walk_ty(sub, f); }
fn fold_sty(sty: sty, fldop: fn(t) -> t) -> sty {
fn fold_substs(substs: substs, fldop: fn(t) -> t) -> substs {
{self_r: substs.self_r,
- self_ty: substs.self_ty.map({ |t| fldop(t) }),
- tps: substs.tps.map({ |t| fldop(t) })}
+ self_ty: substs.self_ty.map(|t| fldop(t)),
+ tps: substs.tps.map(|t| fldop(t))}
}
alt sty {
ty_iface(did, fold_substs(substs, fldop))
}
ty_rec(fields) {
- let new_fields = do vec::map(fields) {|fl|
+ let new_fields = do vec::map(fields) |fl| {
let new_ty = fldop(fl.mt.ty);
let new_mt = {ty: new_ty, mutbl: fl.mt.mutbl};
{ident: fl.ident, mt: new_mt}
ty_rec(new_fields)
}
ty_tup(ts) {
- let new_ts = vec::map(ts, {|tt| fldop(tt) });
+ let new_ts = vec::map(ts, |tt| fldop(tt));
ty_tup(new_ts)
}
ty_fn(f) {
- let new_args = vec::map(f.inputs, {|a|
+ let new_args = vec::map(f.inputs, |a| {
let new_ty = fldop(a.ty);
{mode: a.mode, ty: new_ty}
});
// Folds types from the bottom up.
fn fold_ty(cx: ctxt, t0: t, fldop: fn(t) -> t) -> t {
- let sty = fold_sty(get(t0).struct, {|t| fold_ty(cx, fldop(t), fldop) });
+ let sty = fold_sty(get(t0).struct, |t| fold_ty(cx, fldop(t), fldop));
fldop(mk_t(cx, sty))
}
if (walkt(ty)) {
fold_regions_and_ty(
cx, ty,
- { |r| walkr(r); r },
- { |t| walkt(t); walk_regions_and_ty(cx, t, walkr, walkt); t },
- { |t| walkt(t); walk_regions_and_ty(cx, t, walkr, walkt); t });
+ |r| { walkr(r); r },
+ |t| { walkt(t); walk_regions_and_ty(cx, t, walkr, walkt); t },
+ |t| { walkt(t); walk_regions_and_ty(cx, t, walkr, walkt); t });
}
}
fldr: fn(r: region) -> region,
fldt: fn(t: t) -> t) -> substs {
- {self_r: substs.self_r.map({ |r| fldr(r) }),
- self_ty: substs.self_ty.map({ |t| fldt(t) }),
- tps: substs.tps.map({ |t| fldt(t) })}
+ {self_r: substs.self_r.map(|r| fldr(r)),
+ self_ty: substs.self_ty.map(|t| fldt(t)),
+ tps: substs.tps.map(|t| fldt(t))}
}
let tb = ty::get(ty);
ty::mk_iface(cx, def_id, fold_substs(substs, fldr, fldt))
}
sty @ ty_fn(_) {
- fold_sty_to_ty(cx, sty, {|t| fldfnt(t) })
+ fold_sty_to_ty(cx, sty, |t| fldfnt(t))
}
sty {
- fold_sty_to_ty(cx, sty, {|t| fldt(t) })
+ fold_sty_to_ty(cx, sty, |t| fldt(t))
}
}
}
if !type_has_regions(ty) { ret ty; }
fold_regions_and_ty(
cx, ty,
- { |r| fldr(r, in_fn) },
- { |t| do_fold(cx, t, true, fldr) },
- { |t| do_fold(cx, t, in_fn, fldr) })
+ |r| fldr(r, in_fn),
+ |t| do_fold(cx, t, true, fldr),
+ |t| do_fold(cx, t, in_fn, fldr))
}
do_fold(cx, ty, false, fldr)
}
t0
}
sty {
- do fold_sty_to_ty(cx, sty) {|t|
+ do fold_sty_to_ty(cx, sty) |t| {
do_fold(cx, t, under_r, fldop)
}
}
if !tbox_has_flag(tb, has_params) { ret typ; }
alt tb.struct {
ty_param(idx, _) { tps[idx] }
- sty { fold_sty_to_ty(cx, sty, {|t| subst_tps(cx, tps, t) }) }
+ sty { fold_sty_to_ty(cx, sty, |t| subst_tps(cx, tps, t)) }
}
}
fn substs_to_str(cx: ctxt, substs: substs) -> str {
#fmt["substs(self_r=%s, self_ty=%s, tps=%?)",
- substs.self_r.map_default("none", { |r| region_to_str(cx, r) }),
- substs.self_ty.map_default("none", { |t| ty_to_str(cx, t) }),
- substs.tps.map({ |t| ty_to_str(cx, t) })]
+ substs.self_r.map_default("none", |r| region_to_str(cx, r)),
+ substs.self_ty.map_default("none", |t| ty_to_str(cx, t)),
+ substs.tps.map(|t| ty_to_str(cx, t))]
}
fn subst(cx: ctxt,
_ {
fold_regions_and_ty(
cx, typ,
- { |r|
- alt r {
- re_bound(br_self) {substs.self_r.get()}
- _ {r}
- }
+ |r| alt r {
+ re_bound(br_self) {substs.self_r.get()}
+ _ {r}
},
- { |t| do_subst(cx, substs, t) },
- { |t| do_subst(cx, substs, t) })
+ |t| do_subst(cx, substs, t),
+ |t| do_subst(cx, substs, t))
}
}
}
ty_evec(mt, vstore_fixed(_)) { type_needs_drop(cx, mt.ty) }
ty_unboxed_vec(mt) { type_needs_drop(cx, mt.ty) }
ty_rec(flds) {
- for flds.each {|f| if type_needs_drop(cx, f.mt.ty) { accum = true; } }
+ for flds.each |f| {
+ if type_needs_drop(cx, f.mt.ty) { accum = true; }
+ }
accum
}
ty_class(did, substs) {
// Any class with a dtor needs a drop
option::is_some(ty_dtor(cx, did)) || {
- for vec::each(ty::class_items_as_fields(cx, did, substs)) {|f|
+ for vec::each(ty::class_items_as_fields(cx, did, substs)) |f| {
if type_needs_drop(cx, f.mt.ty) { accum = true; }
}
accum
}
}
ty_tup(elts) {
- for elts.each {|m| if type_needs_drop(cx, m) { accum = true; } }
+ for elts.each |m| { if type_needs_drop(cx, m) { accum = true; } }
accum
}
ty_enum(did, substs) {
let variants = enum_variants(cx, did);
- for vec::each(*variants) {|variant|
- for variant.args.each {|aty|
+ for vec::each(*variants) |variant| {
+ for variant.args.each |aty| {
// Perform any type parameter substitutions.
let arg_ty = subst(cx, substs, aty);
if type_needs_drop(cx, arg_ty) { accum = true; }
let mut encountered_box = encountered_box;
let mut needs_unwind_cleanup = false;
- do maybe_walk_ty(ty) {|ty|
+ do maybe_walk_ty(ty) |ty| {
let old_encountered_box = encountered_box;
let result = alt get(ty).struct {
ty_box(_) | ty_opaque_box {
true
}
ty_enum(did, substs) {
- for vec::each(*enum_variants(cx, did)) {|v|
- for v.args.each {|aty|
+ for vec::each(*enum_variants(cx, did)) |v| {
+ for v.args.each |aty| {
let t = subst(cx, substs, aty);
needs_unwind_cleanup |=
type_needs_unwind_cleanup_(cx, t, tycache,
// Records lower to the lowest of their members.
ty_rec(flds) {
let mut lowest = kind_top();
- for flds.each {|f|
+ for flds.each |f| {
lowest = lower_kind(lowest, mutable_type_kind(cx, f.mt));
}
lowest
// also factor out this code, copied from the records case
let mut lowest = kind_top();
let flds = class_items_as_fields(cx, did, substs);
- for flds.each {|f|
+ for flds.each |f| {
lowest = lower_kind(lowest, mutable_type_kind(cx, f.mt));
}
// ...but classes with dtors are never copyable (they can be
// Tuples lower to the lowest of their members.
ty_tup(tys) {
let mut lowest = kind_top();
- for tys.each {|ty| lowest = lower_kind(lowest, type_kind(cx, ty)); }
+ for tys.each |ty| { lowest = lower_kind(lowest, type_kind(cx, ty)); }
lowest
}
// Enums lower to the lowest of their variants.
if vec::len(*variants) == 0u {
lowest = kind_send_only();
} else {
- for vec::each(*variants) {|variant|
- for variant.args.each {|aty|
+ for vec::each(*variants) |variant| {
+ for variant.args.each |aty| {
// Perform any type parameter substitutions.
let arg_ty = subst(cx, substs, aty);
lowest = lower_kind(lowest, type_kind(cx, arg_ty));
}
ty_rec(fields) {
- do vec::any(fields) {|field|
+ do vec::any(fields) |field| {
type_requires(cx, seen, r_ty, field.mt.ty)
}
}
ty_class(did, substs) {
vec::push(*seen, did);
- let r = vec::any(class_items_as_fields(cx, did, substs),{|f|
- type_requires(cx, seen, r_ty, f.mt.ty)});
+ let r = vec::any(class_items_as_fields(cx, did, substs),
+ |f| type_requires(cx, seen, r_ty, f.mt.ty));
vec::pop(*seen);
r
}
ty_tup(ts) {
- vec::any(ts, {|t|
- type_requires(cx, seen, r_ty, t)
- })
+ vec::any(ts, |t| type_requires(cx, seen, r_ty, t))
}
ty_enum(did, _) if vec::contains(*seen, did) {
ty_enum(did, substs) {
vec::push(*seen, did);
let vs = enum_variants(cx, did);
- let r = vec::len(*vs) > 0u && vec::all(*vs, {|variant|
- vec::any(variant.args, {|aty|
+ let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| {
+ vec::any(variant.args, |aty| {
let sty = subst(cx, substs, aty);
type_requires(cx, seen, r_ty, sty)
})
if test(sty) { ret true; }
alt sty {
ty_enum(did, substs) {
- for vec::each(*enum_variants(cx, did)) {|variant|
- for variant.args.each {|aty|
+ for vec::each(*enum_variants(cx, did)) |variant| {
+ for variant.args.each |aty| {
let sty = subst(cx, substs, aty);
if type_structurally_contains(cx, sty, test) { ret true; }
}
ret false;
}
ty_rec(fields) {
- for fields.each {|field|
+ for fields.each |field| {
if type_structurally_contains(cx, field.mt.ty, test) { ret true; }
}
ret false;
}
ty_class(did, substs) {
- for lookup_class_fields(cx, did).each {|field|
+ for lookup_class_fields(cx, did).each |field| {
let ft = lookup_field_type(cx, did, field.id, substs);
if type_structurally_contains(cx, ft, test) { ret true; }
}
}
ty_tup(ts) {
- for ts.each {|tt|
+ for ts.each |tt| {
if type_structurally_contains(cx, tt, test) { ret true; }
}
ret false;
// distinguished from the value itself. I.e. types with mut content that's
// not shared through a pointer.
fn type_allows_implicit_copy(cx: ctxt, ty: t) -> bool {
- ret !type_structurally_contains(cx, ty, {|sty|
+ ret !type_structurally_contains(cx, ty, |sty| {
alt sty {
ty_param(_, _) { true }
mt.mutbl != ast::m_imm
}
ty_rec(fields) {
- vec::any(fields, {|f| f.mt.mutbl != ast::m_imm})
+ vec::any(fields, |f| f.mt.mutbl != ast::m_imm)
}
_ { false }
}
}
fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
- ret type_structurally_contains(cx, ty, {|sty|
+ ret type_structurally_contains(cx, ty, |sty| {
alt sty {
ty_uniq(_) |
ty_vec(_) |
// Structural types
ty_enum(did, substs) {
let variants = enum_variants(cx, did);
- for vec::each(*variants) {|variant|
+ for vec::each(*variants) |variant| {
let tup_ty = mk_tup(cx, variant.args);
// Perform any type parameter substitutions.
}
}
ty_rec(flds) {
- for flds.each {|f|
+ for flds.each |f| {
if !type_is_pod(cx, f.mt.ty) { result = false; }
}
}
ty_tup(elts) {
- for elts.each {|elt| if !type_is_pod(cx, elt) { result = false; } }
+ for elts.each |elt| { if !type_is_pod(cx, elt) { result = false; } }
}
ty_estr(vstore_fixed(_)) { result = true; }
ty_evec(mt, vstore_fixed(_)) | ty_unboxed_vec(mt) {
ty_param(_, _) { result = false; }
ty_opaque_closure_ptr(_) { result = true; }
ty_class(did, substs) {
- result = vec::any(lookup_class_fields(cx, did), { |f|
+ result = vec::any(lookup_class_fields(cx, did), |f| {
let fty = ty::lookup_item_type(cx, f.id);
let sty = subst(cx, substs, fty.ty);
type_is_pod(cx, sty)
alt get(ty).struct {
ty_enum(did, substs) {
let variants = enum_variants(cx, did);
- let some_n_ary = vec::any(*variants, {|v| vec::len(v.args) > 0u});
+ let some_n_ary = vec::any(*variants, |v| vec::len(v.args) > 0u);
ret !some_n_ary;
}
_ { ret false;}
fn br_hashmap<V:copy>() -> hashmap<bound_region, V> {
map::hashmap(hash_bound_region,
- {|&&a: bound_region, &&b: bound_region| a == b })
+ |&&a: bound_region, &&b: bound_region| a == b)
}
// Type hashing.
fn hash_subty(id: uint, subty: t) -> uint { (id << 2u) + type_id(subty) }
fn hash_subtys(id: uint, subtys: ~[t]) -> uint {
let mut h = id;
- for subtys.each {|s| h = (h << 2u) + type_id(s) }
+ for subtys.each |s| { h = (h << 2u) + type_id(s) }
h
}
fn hash_type_constr(id: uint, c: @type_constr) -> uint {
let mut h = id;
h = (h << 2u) + hash_def(h, c.node.id);
- for c.node.args.each {|a|
+ for c.node.args.each |a| {
alt a.node {
carg_base { h += h << 2u; }
carg_lit(_) { fail "lit args not implemented yet"; }
ty_tup(ts) { hash_subtys(25u, ts) }
ty_rec(fields) {
let mut h = 26u;
- for fields.each {|f| h = hash_subty(h, f.mt.ty); }
+ for fields.each |f| { h = hash_subty(h, f.mt.ty); }
h
}
ty_fn(f) {
let mut h = 27u;
- for f.inputs.each {|a| h = hash_subty(h, a.ty); }
+ for f.inputs.each |a| { h = hash_subty(h, a.ty); }
hash_subty(h, f.output)
}
ty_self { 28u }
ty_ptr(mt) { hash_subty(35u, mt.ty) }
ty_constr(t, cs) {
let mut h = hash_subty(36u, t);
- for cs.each {|c| h = (h << 2u) + hash_type_constr(h, c); }
+ for cs.each |c| { h = (h << 2u) + hash_type_constr(h, c); }
h
}
ty_uniq(mt) { hash_subty(37u, mt.ty) }
a: ~[@sp_constr_arg<T>],
b: ~[@sp_constr_arg<T>]) -> bool {
let mut i: uint = 0u;
- for a.each {|arg|
+ for a.each |arg| {
if !arg_eq(eq, arg, b[i]) { ret false; }
i += 1u;
}
fn constrs_eq(cs: ~[@constr], ds: ~[@constr]) -> bool {
if vec::len(cs) != vec::len(ds) { ret false; }
let mut i = 0u;
- for cs.each {|c| if !constr_eq(c, ds[i]) { ret false; } i += 1u; }
+ for cs.each |c| { if !constr_eq(c, ds[i]) { ret false; } i += 1u; }
ret true;
}
// Returns a vec of all the input and output types of fty.
fn tys_in_fn_ty(fty: fn_ty) -> ~[t] {
- vec::append_one(fty.inputs.map({|a| a.ty}), fty.output)
+ vec::append_one(fty.inputs.map(|a| a.ty), fty.output)
}
// Just checks whether it's a fn that returns bool,
fn field_idx(id: ast::ident, fields: ~[field]) -> option<uint> {
let mut i = 0u;
- for fields.each {|f| if f.ident == id { ret some(i); } i += 1u; }
+ for fields.each |f| { if f.ident == id { ret some(i); } i += 1u; }
ret none;
}
fn get_field(rec_ty: t, id: ast::ident) -> field {
- alt check vec::find(get_fields(rec_ty), {|f| str::eq(*f.ident, *id) }) {
+ alt check vec::find(get_fields(rec_ty), |f| str::eq(*f.ident, *id)) {
some(f) { f }
}
}
fn method_idx(id: ast::ident, meths: ~[method]) -> option<uint> {
let mut i = 0u;
- for meths.each {|m| if m.ident == id { ret some(i); } i += 1u; }
+ for meths.each |m| { if m.ident == id { ret some(i); } i += 1u; }
ret none;
}
// contain duplicates. (Integral type vars aren't counted.)
fn vars_in_type(ty: t) -> ~[tv_vid] {
let mut rslt = ~[];
- do walk_ty(ty) {|ty|
+ do walk_ty(ty) |ty| {
alt get(ty).struct { ty_var(v) { vec::push(rslt, v); } _ { } }
}
rslt
fn substd_enum_variants(cx: ctxt,
id: ast::def_id,
substs: substs) -> ~[variant_info] {
- do vec::map(*enum_variants(cx, id)) { |variant_info|
- let substd_args = vec::map(variant_info.args, {|aty|
- subst(cx, substs, aty)
- });
+ do vec::map(*enum_variants(cx, id)) |variant_info| {
+ let substd_args = vec::map(variant_info.args,
+ |aty| subst(cx, substs, aty));
let substd_ctor_ty = subst(cx, substs, variant_info.ctor_ty);
alt cx.items.get(id.node) {
ast_map::node_item(@{node: ast::item_enum(variants, _, _), _}, _) {
let mut disr_val = -1;
- @vec::map(variants, {|variant|
+ @vec::map(variants, |variant| {
let ctor_ty = node_id_to_type(cx, variant.node.id);
let arg_tys = {
if vec::len(variant.node.args) > 0u {
- ty_fn_args(ctor_ty).map({ |a| a.ty })
+ ty_fn_args(ctor_ty).map(|a| a.ty)
} else { ~[] }
};
alt variant.node.disr_expr {
fn lookup_class_field(cx: ctxt, parent: ast::def_id, field_id: ast::def_id)
-> field_ty {
alt vec::find(lookup_class_fields(cx, parent),
- {|f| f.id.node == field_id.node}) {
+ |f| f.id.node == field_id.node) {
some(t) { t }
none { cx.sess.bug("class ID not found in parent's fields"); }
}
alt cx.items.find(did.node) {
some(ast_map::node_item(@{node: item_class(_,_,items,_,_,_), _}, _)) {
let (_,ms) = split_class_items(items);
- vec::map(ms, {|m| {name: m.ident, id: m.id,
- vis: m.vis}})
+ vec::map(ms, |m| {name: m.ident, id: m.id,
+ vis: m.vis})
}
_ {
cx.sess.bug("lookup_class_method_ids: id not bound to a class");
sp: span) -> def_id {
if check is_local(did) {
let ms = lookup_class_method_ids(cx, did);
- for ms.each {|m|
+ for ms.each |m| {
if m.name == name {
ret ast_util::local_def(m.id);
}
fn class_field_tys(items: ~[@class_member]) -> ~[field_ty] {
let mut rslt = ~[];
- for items.each {|it|
+ for items.each |it| {
alt it.node {
instance_var(nm, _, cm, id, vis) {
vec::push(rslt, {ident: nm, id: ast_util::local_def(id),
// be used in trans.
fn class_items_as_mutable_fields(cx:ctxt, did: ast::def_id,
substs: substs) -> ~[field] {
- class_item_fields(cx, did, substs, {|_mt| m_mutbl})
+ class_item_fields(cx, did, substs, |_mt| m_mutbl)
}
// Same as class_items_as_mutable_fields, but doesn't change
// mutability.
fn class_items_as_fields(cx:ctxt, did: ast::def_id,
substs: substs) -> ~[field] {
- class_item_fields(cx, did, substs, {|mt| alt mt {
+ class_item_fields(cx, did, substs, |mt| alt mt {
class_mutable { m_mutbl }
- class_immutable { m_imm }}})
+ class_immutable { m_imm }})
}
substs: substs, frob_mutability: fn(class_mutability) -> mutability)
-> ~[field] {
let mut rslt = ~[];
- for lookup_class_fields(cx, did).each {|f|
+ for lookup_class_fields(cx, did).each |f| {
// consider all instance vars mut, because the
// constructor may mutate all vars
vec::push(rslt, {ident: f.ident, mt:
}
fn ty_params_to_tys(tcx: ty::ctxt, tps: ~[ast::ty_param]) -> ~[t] {
- vec::from_fn(tps.len(), {|i|
+ vec::from_fn(tps.len(), |i| {
ty::mk_param(tcx, i, ast_util::local_def(tps[i].id))
})
}
// types, which isn't necessary after #2187
let t = mk_t(cx, mach_sty(cx.sess.targ_cfg, t));
- let sty = fold_sty(get(t).struct, {|t| normalize_ty(cx, t) });
+ let sty = fold_sty(get(t).struct, |t| { normalize_ty(cx, t) });
let t_norm = mk_t(cx, sty);
cx.normalized_cache.insert(t, t_norm);
ret t_norm;
#fmt["wrong number of type arguments, expected %u but found %u",
(*decl_bounds).len(), path.types.len()]);
}
- let tps = path.types.map({ |a_t| ast_ty_to_ty(self, rscope, a_t) });
+ let tps = path.types.map(|a_t| ast_ty_to_ty(self, rscope, a_t));
let substs = {self_r:self_r, self_ty:none, tps:tps};
{substs: substs, ty: ty::subst(tcx, substs, decl_ty)}
ty::mk_rptr(tcx, r, mt)
}
ast::ty_tup(fields) {
- let flds = vec::map(fields, { |t| ast_ty_to_ty(self, rscope, t) });
+ let flds = vec::map(fields, |t| ast_ty_to_ty(self, rscope, t));
ty::mk_tup(tcx, flds)
}
ast::ty_rec(fields) {
- let flds = do fields.map {|f|
+ let flds = do fields.map |f| {
let tm = ast_mt_to_mt(self, rscope, f.node.mt);
{ident: f.node.ident, mt: tm}
};
}
ast::ty_constr(t, cs) {
let mut out_cs = ~[];
- for cs.each {|constr|
+ for cs.each |constr| {
vec::push(out_cs, ty::ast_constr_to_constr(tcx, constr));
}
ty::mk_constr(tcx, ast_ty_to_ty(self, rscope, t), out_cs)
expected_tys: expected_tys) -> ty::fn_ty {
#debug["ty_of_fn_decl"];
- do indent {||
+ do indent || {
// new region names that appear inside of the fn decl are bound to
// that function type
let rb = in_binding_rscope(rscope);
- let input_tys = do decl.inputs.mapi { |i, a|
- let expected_arg_ty = do expected_tys.chain { |e|
+ let input_tys = do decl.inputs.mapi |i, a| {
+ let expected_arg_ty = do expected_tys.chain |e| {
// no guarantee that the correct number of expected args
// were supplied
if i < e.inputs.len() {some(e.inputs[i])} else {none}
ty_of_arg(self, rb, a, expected_arg_ty)
};
- let expected_ret_ty = expected_tys.map({ |e| e.output });
+ let expected_ret_ty = expected_tys.map(|e| e.output);
let output_ty = alt decl.output.node {
ast::ty_infer if expected_ret_ty.is_some() {expected_ret_ty.get()}
ast::ty_infer {self.ty_infer(decl.output.span)}
_ {ast_ty_to_ty(self, rb, decl.output)}
};
- let out_constrs = vec::map(decl.constraints, {|constr|
+ let out_constrs = vec::map(decl.constraints, |constr| {
ty::ast_constr_to_constr(self.tcx(), constr)
});
}
fn find(br: ty::bound_region) -> option<ty::region> {
- for list::each(self) { |isr|
+ for list::each(self) |isr| {
let (isr_br, isr_r) = isr;
if isr_br == br { ret some(isr_r); }
}
fn check_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
let visit = visit::mk_simple_visitor(@{
- visit_item: {|a|check_item(ccx, a)}
+ visit_item: |a| check_item(ccx, a)
with *visit::default_simple_visitor()
});
visit::visit_crate(*crate, (), visit);
let {isr, self_ty, fn_ty} = {
let old_isr = option::map_default(old_fcx, @nil,
- { |fcx| fcx.in_scope_regions });
+ |fcx| fcx.in_scope_regions);
replace_bound_regions_in_fn_ty(tcx, old_isr, self_ty, fn_ty,
- { |br| ty::re_free(body.node.id, br) })
+ |br| ty::re_free(body.node.id, br))
};
- let arg_tys = fn_ty.inputs.map({ |a| a.ty });
+ let arg_tys = fn_ty.inputs.map(|a| a.ty);
let ret_ty = fn_ty.output;
#debug["check_fn(arg_tys=%?, ret_ty=%?, self_ty=%?)",
- arg_tys.map({|a| ty_to_str(tcx, a) }),
+ arg_tys.map(|a| ty_to_str(tcx, a)),
ty_to_str(tcx, ret_ty),
- option::map(self_ty, {|st| ty_to_str(tcx, st) })];
+ option::map(self_ty, |st| ty_to_str(tcx, st))];
// ______________________________________________________________________
// Create the function context. This is either derived from scratch or,
}
let mut i = 0u;
- do vec::iter(arg_tys) {|arg|
+ do vec::iter(arg_tys) |arg| {
fcx.write_ty(decl.inputs[i].id, arg);
i += 1u;
}
};
// Add formal parameters.
- do vec::iter2(arg_tys, decl.inputs) {|arg_ty, input|
+ do vec::iter2(arg_tys, decl.inputs) |arg_ty, input| {
assign(input.id, some(arg_ty));
#debug["Argument %s is assigned to %s",
*input.ident, fcx.locals.get(input.id).to_str()];
}
ast::item_impl(tps, rp, _, ty, ms) {
let self_ty = ccx.to_ty(rscope::type_rscope(rp), ty);
- for ms.each {|m| check_method(ccx, m, self_ty);}
+ for ms.each |m| { check_method(ccx, m, self_ty);}
}
ast::item_class(tps, ifaces, members, ctor, m_dtor, rp) {
let tcx = ccx.tcx;
// Write the ctor's self's type
write_ty_to_tcx(tcx, ctor.node.self_id, class_t);
- do option::iter(m_dtor) {|dtor|
+ do option::iter(m_dtor) |dtor| {
// typecheck the dtor
check_bare_fn(ccx, ast_util::dtor_dec(),
dtor.node.body, dtor.node.id,
write_ty_to_tcx(tcx, dtor.node.self_id, class_t);
};
// typecheck the members
- for members.each {|m| check_class_member(ccx, class_t, m); }
+ for members.each |m| { check_class_member(ccx, class_t, m); }
// Check that there's at least one field
let (fields,_) = split_class_items(members);
if fields.len() < 1u {
ast::item_foreign_mod(m) {
if syntax::attr::foreign_abi(it.attrs) ==
either::right(ast::foreign_abi_rust_intrinsic) {
- for m.items.each { |item|
+ for m.items.each |item| {
check_intrinsic_type(ccx, item);
}
} else {
- for m.items.each { |item|
+ for m.items.each |item| {
let tpt = ty::lookup_item_type(ccx.tcx, local_def(item.id));
if (*tpt.bounds).is_not_empty() {
ccx.tcx.sess.span_err(
result::ok(self.infcx.next_region_var())
}
fn named_region(id: ast::ident) -> result<ty::region, str> {
- do empty_rscope.named_region(id).chain_err { |_e|
+ do empty_rscope.named_region(id).chain_err |_e| {
alt self.in_scope_regions.find(ty::br_named(id)) {
some(r) { result::ok(r) }
none if *id == "blk" { self.block_region() }
fn check_expr(fcx: @fn_ctxt, expr: @ast::expr,
expected: option<ty::t>) -> bool {
- ret do check_expr_with_unifier(fcx, expr, expected) {||
- for expected.each {|t|
+ ret do check_expr_with_unifier(fcx, expr, expected) || {
+ for expected.each |t| {
demand::suptype(fcx, expr.span, t, fcx.expr_ty(expr));
}
};
items:~[ty::field_ty], fieldname: ast::ident,
substs: ty::substs) -> option<ty::t> {
- let o_field = vec::find(items, {|f| f.ident == fieldname});
- do option::map(o_field) {|f|
+ let o_field = vec::find(items, |f| f.ident == fieldname);
+ do option::map(o_field) |f| {
ty::lookup_field_type(tcx, class_id, f.id, substs)
}
}
sty @ ty::ty_fn(fn_ty) {
replace_bound_regions_in_fn_ty(
fcx.ccx.tcx, @nil, none, fn_ty,
- { |_br| fcx.infcx.next_region_var() }).fn_ty
+ |_br| fcx.infcx.next_region_var()).fn_ty
}
sty {
// I would like to make this span_err, but it's
// if the wrong number of arguments were supplied
let expected_arg_count = vec::len(fn_ty.inputs);
let arg_tys = if expected_arg_count == supplied_arg_count {
- fn_ty.inputs.map({ |a| a.ty })
+ fn_ty.inputs.map(|a| a.ty)
} else {
fcx.ccx.tcx.sess.span_err(
sp, #fmt["this function takes %u parameter%s but %u \
// functions. This is so that we have more information about the types
// of arguments when we typecheck the functions. This isn't really the
// right way to do this.
- for [false, true]/_.each { |check_blocks|
- for args.eachi {|i, a_opt|
+ for [false, true]/_.each |check_blocks| {
+ for args.eachi |i, a_opt| {
alt a_opt {
some(a) {
let is_block = alt a.node {
if is_block == check_blocks {
let arg_ty = arg_tys[i];
bot |= check_expr_with_unifier(
- fcx, a, some(arg_ty), {||
- demand::assign(fcx, a.span, call_expr_id,
- arg_ty, a);
- });
+ fcx, a, some(arg_ty),
+ || demand::assign(fcx, a.span, call_expr_id,
+ arg_ty, a)
+ );
}
}
none { }
// Call the generic checker.
let fty = {
- let args_opt = args.map({ |arg| some(arg) });
+ let args_opt = args.map(|arg| some(arg));
let r = check_call_or_bind(fcx, sp, call_expr_id,
fn_ty, args_opt);
bot |= r.bot;
expected: option<ty::t>) {
let tcx = fcx.ccx.tcx;
- let expected_tys = do unpack_expected(fcx, expected) { |sty|
+ let expected_tys = do unpack_expected(fcx, expected) |sty| {
alt sty {
ty::ty_fn(fn_ty) {some({inputs:fn_ty.inputs,
output:fn_ty.output})}
ast::expr_vec(args, mutbl) {
let tt = ast_expr_vstore_to_vstore(fcx, ev, vec::len(args), vst);
let t: ty::t = fcx.infcx.next_ty_var();
- for args.each {|e| bot |= check_expr_with(fcx, e, t); }
+ for args.each |e| { bot |= check_expr_with(fcx, e, t); }
ty::mk_evec(tcx, {ty: t, mutbl: mutbl}, tt)
}
_ {
fcx.write_nil(expr.id);
}
ast::expr_unary(unop, oprnd) {
- let exp_inner = do unpack_expected(fcx, expected) {|sty|
+ let exp_inner = do unpack_expected(fcx, expected) |sty| {
alt unop {
ast::box(_) | ast::uniq(_) {
alt sty {
fcx.write_ty(id, oprnd_t);
}
ast::expr_addr_of(mutbl, oprnd) {
- bot = check_expr(fcx, oprnd, unpack_expected(fcx, expected, {|ty|
+ bot = check_expr(fcx, oprnd, unpack_expected(fcx, expected, |ty|
alt ty { ty::ty_rptr(_, mt) { some(mt.ty) } _ { none } }
- }));
+ ));
let region = region_of(fcx, oprnd);
let tm = { ty: fcx.expr_ty(oprnd), mutbl: mutbl };
let oprnd_t = ty::mk_rptr(tcx, region, tm);
}
ast::expr_fn_block(decl, body, cap_clause) {
// Take the prototype from the expected type, but default to block:
- let proto = unpack_expected(fcx, expected, {|sty|
+ let proto = unpack_expected(fcx, expected, |sty|
alt sty { ty::ty_fn({proto, _}) { some(proto) } _ { none } }
- }).get_default(ast::proto_box);
+ ).get_default(ast::proto_box);
check_expr_fn(fcx, expr, proto, decl, body, false, expected);
capture::check_capture_clause(tcx, expr.id, cap_clause);
}
// parameter. The catch here is that we need to validate two things:
// 1. a closure that returns a bool is expected
// 2. the cloure that was given returns unit
- let expected_sty = unpack_expected(fcx, expected, {|x|some(x)}).get();
+ let expected_sty = unpack_expected(fcx, expected, |x| some(x)).get();
let (inner_ty, proto) = alt expected_sty {
ty::ty_fn(fty) {
alt infer::mk_subty(fcx.infcx, fty.output, ty::mk_bool(tcx)) {
}
}
ast::expr_do_body(b) {
- let expected_sty = unpack_expected(fcx, expected, {|x|some(x)}).get();
+ let expected_sty = unpack_expected(fcx, expected, |x| some(x)).get();
let (inner_ty, proto) = alt expected_sty {
ty::ty_fn(fty) {
(ty::mk_fn(tcx, fty), fty.proto)
}
ast::expr_vec(args, mutbl) {
let t: ty::t = fcx.infcx.next_ty_var();
- for args.each {|e| bot |= check_expr_with(fcx, e, t); }
+ for args.each |e| { bot |= check_expr_with(fcx, e, t); }
let typ = ty::mk_vec(tcx, {ty: t, mutbl: mutbl});
fcx.write_ty(id, typ);
}
ast::expr_tup(elts) {
let mut elt_ts = ~[];
vec::reserve(elt_ts, vec::len(elts));
- let flds = unpack_expected(fcx, expected, {|sty|
+ let flds = unpack_expected(fcx, expected, |sty| {
alt sty { ty::ty_tup(flds) { some(flds) } _ { none } }
});
- for elts.eachi {|i, e|
- check_expr(fcx, e, flds.map({|fs| fs[i]}));
+ for elts.eachi |i, e| {
+ check_expr(fcx, e, flds.map(|fs| fs[i]));
let ety = fcx.expr_ty(e);
vec::push(elt_ts, ety);
}
fcx.write_ty(id, typ);
}
ast::expr_rec(fields, base) {
- option::iter(base, {|b| check_expr(fcx, b, expected); });
+ option::iter(base, |b| { check_expr(fcx, b, expected); });
let expected = if expected == none && base != none {
some(fcx.expr_ty(base.get()))
} else { expected };
- let flds = unpack_expected(fcx, expected, {|sty|
+ let flds = unpack_expected(fcx, expected, |sty|
alt sty { ty::ty_rec(flds) { some(flds) } _ { none } }
- });
- let fields_t = vec::map(fields, {|f|
- bot |= check_expr(fcx, f.node.expr, flds.chain({|flds|
- vec::find(flds, {|tf| tf.ident == f.node.ident})
- }).map({|tf| tf.mt.ty}));
+ );
+ let fields_t = vec::map(fields, |f| {
+ bot |= check_expr(fcx, f.node.expr, flds.chain(|flds|
+ vec::find(flds, |tf| tf.ident == f.node.ident)
+ ).map(|tf| tf.mt.ty));
let expr_t = fcx.expr_ty(f.node.expr);
let expr_mt = {ty: expr_t, mutbl: f.node.mutbl};
// for the most precise error message,
}
};
fcx.write_ty(id, bexpr_t);
- for fields_t.each {|f|
+ for fields_t.each |f| {
let mut found = false;
- for base_fields.each {|bf|
+ for base_fields.each |bf| {
if str::eq(*f.node.ident, *bf.ident) {
demand::suptype(fcx, f.span, bf.mt.ty, f.node.mt.ty);
found = true;
_ {}
}
if !handled {
- let tps = vec::map(tys, { |ty| fcx.to_ty(ty) });
+ let tps = vec::map(tys, |ty| fcx.to_ty(ty));
let is_self_ref = self_ref(fcx, base.id);
// this will be the call or block that immediately
node_id = id;
alt decl.node {
ast::decl_local(ls) {
- for ls.each {|l| bot |= check_decl_local(fcx, l); }
+ for ls.each |l| { bot |= check_decl_local(fcx, l); }
}
ast::decl_item(_) {/* ignore for now */ }
}
vec::push(fcx.blocks, blk.node.id);
let mut bot = false;
let mut warned = false;
- for blk.node.stmts.each {|s|
+ for blk.node.stmts.each |s| {
if bot && !warned &&
alt s.node {
ast::stmt_decl(@{node: ast::decl_local(_), _}, _) |
let mut disr_vals: ~[int] = ~[];
let mut disr_val = 0;
let mut variants = ~[];
- for vs.each {|v|
+ for vs.each |v| {
alt v.node.disr_expr {
some(e) {
check_expr(fcx, e, none);
vec::push(disr_vals, disr_val);
let ctor_ty = ty::node_id_to_type(ccx.tcx, v.node.id);
let arg_tys = if v.node.args.len() > 0u {
- ty::ty_fn_args(ctor_ty).map({|a| a.ty })
+ ty::ty_fn_args(ctor_ty).map(|a| a.ty)
} else { ~[] };
vec::push(variants, @{args: arg_tys, ctor_ty: ctor_ty,
name: v.node.name, id: local_def(v.node.id),
// Check that it is possible to represent this enum:
let mut outer = true, did = local_def(id);
- if ty::type_structurally_contains(ccx.tcx, rty, {|sty|
+ if ty::type_structurally_contains(ccx.tcx, rty, |sty| {
alt sty {
ty::ty_enum(id, _) if id == did {
if outer { outer = false; false }
in constraint");
}
}
- for operands.each {|operand|
+ for operands.each |operand| {
if !ast_util::is_constraint_arg(operand) {
let s =
"constraint args must be slot variables or literals";
fn check_constraints(fcx: @fn_ctxt, cs: ~[@ast::constr],
args: ~[ast::arg]) {
let num_args = vec::len(args);
- for cs.each {|c|
+ for cs.each |c| {
let mut c_args = ~[];
- for c.node.args.each {|a|
+ for c.node.args.each |a| {
vec::push(c_args,
// "base" should not occur in a fn type thing, as of
// yet, b/c we don't allow constraints on the return type
(sp, "not enough type parameters provided for this item");
fcx.infcx.next_ty_vars(ty_param_count)
} else {
- pth.types.map({ |aty| fcx.to_ty(aty) })
+ pth.types.map(|aty| fcx.to_ty(aty))
};
let substs = {self_r: self_r, self_ty: none, tps: tps};
ty::walk_regions_and_ty(
ccx.tcx, ty,
- { |r|
+ |r| {
alt r {
ty::re_bound(_) { r_used = true; }
_ { }
}
},
- { |t|
+ |t| {
alt ty::get(t).struct {
ty::ty_param(idx, _) { tps_used[idx] = true; }
_ { }
reference-parameterized type");
}
- for tps_used.eachi { |i, b|
+ for tps_used.eachi |i, b| {
if !b {
ccx.tcx.sess.span_err(
span, #fmt["type parameter `%s` is unused", *tps[i].ident]);
} else {
require_same_types(
tcx, none, it.span, i_ty.ty, fty,
- {|| #fmt["intrinsic has wrong type: \
+ || #fmt["intrinsic has wrong type: \
expected `%s`",
- ty_to_str(ccx.tcx, fty)]});
+ ty_to_str(ccx.tcx, fty)]);
}
}
// Typecheck the patterns first, so that we get types for all the
// bindings.
- for arms.each {|arm|
+ for arms.each |arm| {
let pcx = {
fcx: fcx,
map: pat_id_map(tcx.def_map, arm.pats[0]),
pat_region: ty::re_scope(expr.id)
};
- for arm.pats.each {|p| check_pat(pcx, p, pattern_ty);}
+ for arm.pats.each |p| { check_pat(pcx, p, pattern_ty);}
}
// Now typecheck the blocks.
let mut result_ty = fcx.infcx.next_ty_var();
let mut arm_non_bot = false;
- for arms.each {|arm|
+ for arms.each |arm| {
alt arm.guard {
some(e) { check_expr_with(fcx, e, ty::mk_bool(tcx)); }
none { }
let vinfo =
ty::enum_variant_with_id(
tcx, v_def_ids.enm, v_def_ids.var);
- vinfo.args.map({ |t| ty::subst(tcx, expected_substs, t) })
+ vinfo.args.map(|t| { ty::subst(tcx, expected_substs, t) })
};
let arg_len = arg_types.len(), subpats_len = alt subpats {
none { arg_len }
tcx.sess.span_fatal(pat.span, s);
}
- do option::iter(subpats) {|pats|
- do vec::iter2(pats, arg_types) {|subpat, arg_ty|
+ do option::iter(subpats) |pats| {
+ do vec::iter2(pats, arg_types) |subpat, arg_ty| {
check_pat(pcx, subpat, arg_ty);
}
};
#debug["pat_range ending type: %?", e_ty];
if !require_same_types(
tcx, some(fcx.infcx), pat.span, b_ty, e_ty,
- {|| "mismatched types in range" }) {
+ || "mismatched types in range") {
// no-op
} else if !ty::type_is_numeric(b_ty) {
tcx.sess.span_err(pat.span, "non-numeric type used in range");
fn matches(name: ast::ident, f: ty::field) -> bool {
ret str::eq(*name, *f.ident);
}
- for fields.each {|f|
- alt vec::find(ex_fields, {|a|matches(f.ident, a)}) {
+ for fields.each |f| {
+ alt vec::find(ex_fields, |a| matches(f.ident, a)) {
some(field) {
check_pat(pcx, f.pat, field.mt.ty);
}
fields", vec::len(ex_elts), e_count]);
}
let mut i = 0u;
- for elts.each {|elt|
+ for elts.each |elt| {
check_pat(pcx, elt, ex_elts[i]);
i += 1u;
}
self.expr.span,
"multiple applicable methods in scope");
- for self.candidates.eachi { |i, candidate|
+ for self.candidates.eachi |i, candidate| {
alt candidate.entry.origin {
method_static(did) {
self.report_static_candidate(i, did);
let tcx = self.tcx();
let mut iface_bnd_idx = 0u; // count only iface bounds
let bounds = tcx.ty_param_bounds.get(did.node);
- for vec::each(*bounds) {|bound|
+ for vec::each(*bounds) |bound| {
let (iid, bound_substs) = alt bound {
ty::bound_copy | ty::bound_send | ty::bound_const {
cont; /* ok */
};
let ifce_methods = ty::iface_methods(tcx, iid);
- alt vec::position(*ifce_methods, {|m| m.ident == self.m_name}) {
+ alt vec::position(*ifce_methods, |m| m.ident == self.m_name) {
none {
/* check next bound */
iface_bnd_idx += 1u;
#debug["method_from_iface"];
let ms = *ty::iface_methods(self.tcx(), did);
- for ms.eachi {|i, m|
+ for ms.eachi |i, m| {
if m.ident != self.m_name { cont; }
let m_fty = ty::mk_fn(self.tcx(), m.fty);
let ms = *ty::iface_methods(self.tcx(), did);
- for ms.each {|m|
+ for ms.each |m| {
if m.ident != self.m_name { cont; }
if m.vis == ast::private && !self.include_private {
#debug["method_from_scope"];
- for list::each(impls_vecs) {|impls|
- for vec::each(*impls) {|im|
+ for list::each(impls_vecs) |impls| {
+ for vec::each(*impls) |im| {
// Check whether this impl has a method with the right name.
- for im.methods.find({|m| m.ident == self.m_name}).each {|m|
+ for im.methods.find(|m| m.ident == self.m_name).each |m| {
// determine the `self` of the impl with fresh
// variables for each parameter:
}
v.visit_ty(l.node.ty, rcx, v);
- for l.node.init.each { |i|
+ for l.node.init.each |i| {
v.visit_expr(i.expr, rcx, v);
}
}
let e = rcx.errors_reported;
ty::walk_regions_and_ty(
tcx, ty,
- { |r| constrain_region(rcx, encl_region, span, r); },
- { |t| ty::type_has_regions(t) });
+ |r| constrain_region(rcx, encl_region, span, r),
+ |t| ty::type_has_regions(t));
ret (e == rcx.errors_reported);
fn constrain_region(rcx: rcx,
fn_ty: ty::fn_ty} {
let mut all_tys = ty::tys_in_fn_ty(fn_ty);
- for self_ty.each { |t| vec::push(all_tys, t) }
+ for self_ty.each |t| { vec::push(all_tys, t) }
#debug["replace_bound_regions_in_fn_ty(self_ty=%?, fn_ty=%s, all_tys=%?)",
- self_ty.map({ |t| ty_to_str(tcx, t) }),
+ self_ty.map(|t| ty_to_str(tcx, t)),
ty_to_str(tcx, ty::mk_fn(tcx, fn_ty)),
- all_tys.map({ |t| ty_to_str(tcx, t) })];
+ all_tys.map(|t| ty_to_str(tcx, t))];
let _i = indenter();
- let isr = do create_bound_region_mapping(tcx, isr, all_tys) { |br|
+ let isr = do create_bound_region_mapping(tcx, isr, all_tys) |br| {
#debug["br=%?", br];
mapf(br)
};
- let t_fn = ty::fold_sty_to_ty(tcx, ty::ty_fn(fn_ty), { |t|
+ let t_fn = ty::fold_sty_to_ty(tcx, ty::ty_fn(fn_ty), |t| {
replace_bound_regions(tcx, isr, t)
});
- let t_self = self_ty.map({ |t| replace_bound_regions(tcx, isr, t) });
+ let t_self = self_ty.map(|t| replace_bound_regions(tcx, isr, t));
#debug["result of replace_bound_regions_in_fn_ty: self_ty=%?, fn_ty=%s",
- t_self.map({ |t| ty_to_str(tcx, t) }),
+ t_self.map(|t| ty_to_str(tcx, t)),
ty_to_str(tcx, t_fn)];
ret {isr: isr,
}
// For each type `ty` in `tys`...
- do tys.foldl(isr) { |isr, ty|
+ do tys.foldl(isr) |isr, ty| {
let mut isr = isr;
// Using fold_regions is inefficient, because it
// terms of locating all the regions within the various
// kinds of types. This had already caused me several
// bugs so I decided to switch over.
- do ty::fold_regions(tcx, ty) { |r, in_fn|
+ do ty::fold_regions(tcx, ty) |r, in_fn| {
if !in_fn { isr = append_isr(isr, to_r, r); }
r
};
isr: isr_alist,
ty: ty::t) -> ty::t {
- do ty::fold_regions(tcx, ty) { |r, in_fn|
+ do ty::fold_regions(tcx, ty) |r, in_fn| {
alt r {
// As long as we are not within a fn() type, `&T` is
// mapped to the free region anon_r. But within a fn
import check::{fn_ctxt, impl_self_ty, methods};
fn has_iface_bounds(tps: ~[ty::param_bounds]) -> bool {
- vec::any(tps, {|bs|
- vec::any(*bs, {|b|
+ vec::any(tps, |bs| {
+ vec::any(*bs, |b| {
alt b { ty::bound_iface(_) { true } _ { false } }
})
})
allow_unsafe: bool) -> vtable_res {
let tcx = fcx.ccx.tcx;
let mut result = ~[], i = 0u;
- for substs.tps.each {|ty|
- for vec::each(*bounds[i]) {|bound|
+ for substs.tps.each |ty| {
+ for vec::each(*bounds[i]) |bound| {
alt bound {
ty::bound_iface(i_ty) {
let i_ty = ty::subst(tcx, substs, i_ty);
alt ty::get(ty).struct {
ty::ty_param(n, did) {
let mut n_bound = 0u;
- for vec::each(*tcx.ty_param_bounds.get(did.node)) { |bound|
+ for vec::each(*tcx.ty_param_bounds.get(did.node)) |bound| {
alt bound {
ty::bound_send | ty::bound_copy | ty::bound_const {
/* ignore */
ty::ty_iface(did, substs) if iface_id == did {
relate_iface_tys(fcx, sp, iface_ty, ty);
if !allow_unsafe {
- for vec::each(*ty::iface_methods(tcx, did)) {|m|
+ for vec::each(*ty::iface_methods(tcx, did)) |m| {
if ty::type_has_self(ty::mk_fn(tcx, m.fty)) {
tcx.sess.span_err(
sp, "a boxed iface with self types may not be \
_ {
let mut found = ~[];
- for list::each(isc) {|impls|
+ for list::each(isc) |impls| {
/* For each impl in scope... */
- for vec::each(*impls) {|im|
+ for vec::each(*impls) |im| {
// im = one specific impl
// find the iface that im implements (if any)
let of_ty = alt ty::impl_iface(tcx, im.did) {
alt check ty::get(iface_ty).struct {
ty::ty_iface(_, substs) {
vec::iter2(substs.tps, iface_tys,
- {|a, b| demand::suptype(fcx, sp, a, b);});
+ |a, b| demand::suptype(fcx, sp, a, b));
}
}
}
alt fcx.opt_node_ty_substs(id) {
some(substs) {
let mut new_tps = ~[];
- for substs.tps.each {|subst|
+ for substs.tps.each |subst| {
alt resolve_type_vars_in_type(fcx, sp, subst) {
some(t) { vec::push(new_tps, t); }
none { wbcx.success = false; ret none; }
alt e.node {
ast::expr_fn(_, decl, _, _) |
ast::expr_fn_block(decl, _, _) {
- do vec::iter(decl.inputs) {|input|
+ do vec::iter(decl.inputs) |input| {
let r_ty = resolve_type_vars_for_node(wbcx, e.span, input.id);
// Just in case we never constrained the mode to anything,
let wbcx = {fcx: fcx, mut success: true};
let visit = mk_visitor();
visit.visit_block(blk, wbcx, visit);
- for decl.inputs.each {|arg|
+ for decl.inputs.each |arg| {
resolve_type_vars_for_node(wbcx, arg.ty.span, arg.id);
}
ret wbcx.success;
// FIXME (#2592): hooking into the "intrinsic" root module is crude.
// There ought to be a better approach. Attributes?
- for crate.node.module.items.each {|crate_item|
+ for crate.node.module.items.each |crate_item| {
if *crate_item.ident == "intrinsic" {
alt crate_item.node {
ast::item_mod(m) {
- for m.items.each {|intrinsic_item|
+ for m.items.each |intrinsic_item| {
alt intrinsic_item.node {
ast::item_iface(_, _, _) {
let def_id = { crate: ast::local_crate,
}
visit::visit_crate(*crate, (), visit::mk_simple_visitor(@{
- visit_item: {|a|convert(ccx, a)},
- visit_foreign_item: {|a|convert_foreign(ccx, a)}
+ visit_item: |a|convert(ccx, a),
+ visit_foreign_item: |a|convert_foreign(ccx, a)
with *visit::default_simple_visitor()
}));
}
let tcx = ccx.tcx;
// Create a set of parameter types shared among all the variants.
- for variants.each {|variant|
+ for variants.each |variant| {
// Nullary enum constructors get turned into constants; n-ary enum
// constructors get turned into functions.
let result_ty = if vec::len(variant.node.args) == 0u {
enum_ty
} else {
let rs = type_rscope(rp);
- let args = variant.node.args.map({ |va|
+ let args = variant.node.args.map(|va| {
let arg_ty = ccx.to_ty(rs, va.ty);
{mode: ast::expl(ast::by_copy), ty: arg_ty}
});
let tcx = ccx.tcx;
alt check tcx.items.get(id) {
ast_map::node_item(@{node: ast::item_iface(_, rp, ms), _}, _) {
- store_methods::<ast::ty_method>(ccx, id, ms, {|m|
+ store_methods::<ast::ty_method>(ccx, id, ms, |m| {
ty_of_ty_method(ccx, m, rp)
});
}
let (_,ms) = split_class_items(its);
// All methods need to be stored, since lookup_method
// relies on the same method cache for self-calls
- store_methods::<@ast::method>(ccx, id, ms, {|m|
+ store_methods::<@ast::method>(ccx, id, ms, |m| {
ty_of_method(ccx, m, rp)
});
}
replace_bound_self(tcx, impl_fty, dummy_self_r)
};
let if_fty = {
- let dummy_tps = do vec::from_fn((*if_m.tps).len()) { |i|
+ let dummy_tps = do vec::from_fn((*if_m.tps).len()) |i| {
// hack: we don't know the def id of the impl tp, but it
// is not important for unification
ty::mk_param(tcx, i + impl_tps, {crate: 0, node: 0})
};
require_same_types(
tcx, none, sp, impl_fty, if_fty,
- {|| "method `" + *if_m.ident + "` has an incompatible type"});
+ || "method `" + *if_m.ident + "` has an incompatible type");
ret;
// Replaces bound references to the self region with `with_r`.
fn replace_bound_self(tcx: ty::ctxt, ty: ty::t,
with_r: ty::region) -> ty::t {
- do ty::fold_regions(tcx, ty) { |r, _in_fn|
+ do ty::fold_regions(tcx, ty) |r, _in_fn| {
if r == ty::re_bound(ty::br_self) {with_r} else {r}
}
}
if did.crate == ast::local_crate {
ensure_iface_methods(ccx, did.node);
}
- for vec::each(*ty::iface_methods(tcx, did)) {|if_m|
- alt vec::find(ms, {|m| if_m.ident == m.mty.ident}) {
+ for vec::each(*ty::iface_methods(tcx, did)) |if_m| {
+ alt vec::find(ms, |m| if_m.ident == m.mty.ident) {
some({mty: m, id, span}) {
if m.purity != if_m.purity {
ccx.tcx.sess.span_err(
self_ty: ty::t) -> ~[converted_method] {
let tcx = ccx.tcx;
- do vec::map(ms) { |m|
+ do vec::map(ms) |m| {
write_ty_to_tcx(tcx, m.self_id, self_ty);
let bounds = ty_param_bounds(ccx, m.tps);
let mty = ty_of_method(ccx, m, rp);
ty: selfty});
let cms = convert_methods(ccx, ms, rp, i_bounds, selfty);
- for ifce.each { |t|
+ for ifce.each |t| {
check_methods_against_iface(ccx, tps, rp, selfty, t, cms);
}
}
write_ty_to_tcx(tcx, it.id, tpt.ty);
tcx.tcache.insert(local_def(it.id), tpt);
// Write the ctor type
- let t_args = ctor.node.dec.inputs.map({|a|
- ty_of_arg(ccx, type_rscope(rp), a, none)});
+ let t_args = ctor.node.dec.inputs.map(
+ |a| ty_of_arg(ccx, type_rscope(rp), a, none) );
let t_res = ty::mk_class(tcx, local_def(it.id),
{self_r: alt rp {
ast::rp_none { none }
{bounds: tpt.bounds,
rp: rp,
ty: t_ctor});
- do option::iter(m_dtor) {|dtor|
+ do option::iter(m_dtor) |dtor| {
// Write the dtor type
let t_dtor = ty::mk_fn(
tcx,
// Write the type of each of the members
let (fields, methods) = split_class_items(members);
- for fields.each {|f|
+ for fields.each |f| {
convert_class_item(ccx, rp, tpt.bounds, f);
}
let {bounds, substs} = mk_substs(ccx, tps, rp);
let selfty = ty::mk_class(tcx, local_def(it.id), substs);
let cms = convert_methods(ccx, methods, rp, bounds, selfty);
- for ifaces.each { |ifce|
+ for ifaces.each |ifce| {
check_methods_against_iface(ccx, tps, rp, selfty, ifce, cms);
// FIXME #2434---this is somewhat bogus, but it seems that
fn compute_bounds(ccx: @crate_ctxt,
param: ast::ty_param) -> ty::param_bounds {
- @do vec::flat_map(*param.bounds) { |b|
+ @do vec::flat_map(*param.bounds) |b| {
alt b {
ast::bound_send { ~[ty::bound_send] }
ast::bound_copy { ~[ty::bound_copy] }
}
}
- @do params.map { |param|
+ @do params.map |param| {
alt ccx.tcx.ty_param_bounds.find(param.id) {
some(bs) { bs }
none {
let bounds = ty_param_bounds(ccx, ty_params);
let rb = in_binding_rscope(empty_rscope);
- let input_tys = decl.inputs.map({ |a| ty_of_arg(ccx, rb, a, none) });
+ let input_tys = decl.inputs.map(|a| ty_of_arg(ccx, rb, a, none) );
let output_ty = ast_ty_to_ty(ccx, rb, decl.output);
let t_fn = ty::mk_fn(ccx.tcx, {purity: decl.purity,
let mut i = 0u;
let bounds = ty_param_bounds(ccx, atps);
{bounds: bounds,
- params: vec::map(atps, {|atp|
+ params: vec::map(atps, |atp| {
let t = ty::mk_param(ccx.tcx, i, local_def(atp.id));
i += 1u;
t
fn mk_subty(cx: infer_ctxt, a: ty::t, b: ty::t) -> ures {
#debug["mk_subty(%s <: %s)", a.to_str(cx), b.to_str(cx)];
- indent({|| cx.commit({|| sub(cx).tys(a, b) }) }).to_ures()
+ indent(|| cx.commit(|| sub(cx).tys(a, b) ) ).to_ures()
}
fn can_mk_subty(cx: infer_ctxt, a: ty::t, b: ty::t) -> ures {
#debug["can_mk_subty(%s <: %s)", a.to_str(cx), b.to_str(cx)];
- indent({|| cx.probe({|| sub(cx).tys(a, b) }) }).to_ures()
+ indent(|| cx.probe(|| sub(cx).tys(a, b) ) ).to_ures()
}
fn mk_subr(cx: infer_ctxt, a: ty::region, b: ty::region) -> ures {
#debug["mk_subr(%s <: %s)", a.to_str(cx), b.to_str(cx)];
- indent({|| cx.commit({|| sub(cx).regions(a, b) }) }).to_ures()
+ indent(|| cx.commit(|| sub(cx).regions(a, b) ) ).to_ures()
}
fn mk_eqty(cx: infer_ctxt, a: ty::t, b: ty::t) -> ures {
#debug["mk_eqty(%s <: %s)", a.to_str(cx), b.to_str(cx)];
- indent({|| cx.commit({|| cx.eq_tys(a, b) }) }).to_ures()
+ indent(|| cx.commit(|| cx.eq_tys(a, b) ) ).to_ures()
}
fn mk_assignty(cx: infer_ctxt, anmnt: assignment,
a: ty::t, b: ty::t) -> ures {
#debug["mk_assignty(%? / %s <: %s)",
anmnt, a.to_str(cx), b.to_str(cx)];
- indent({|| cx.commit({||
+ indent(|| cx.commit(||
cx.assign_tys(anmnt, a, b)
- }) }).to_ures()
+ ) ).to_ures()
}
fn can_mk_assignty(cx: infer_ctxt, anmnt: assignment,
// used in method lookup, and there must be exactly one match or an
// error is reported. Still, it should be fixed.
- indent({|| cx.probe({||
+ indent(|| cx.probe(||
cx.assign_tys(anmnt, a, b)
- }) }).to_ures()
+ ) ).to_ures()
}
// See comment on the type `resolve_state` below
impl methods for ures {
fn then<T:copy>(f: fn() -> result<T,ty::type_err>)
-> result<T,ty::type_err> {
- self.chain({|_i| f() })
+ self.chain(|_i| f())
}
}
}
fn compare(t: T, f: fn() -> ty::type_err) -> cres<T> {
- do self.chain {|s|
+ do self.chain |s| {
if s == t {
self
} else {
impl of st for ty::region {
fn sub(infcx: infer_ctxt, &&b: ty::region) -> ures {
- sub(infcx).regions(self, b).chain({|_r| ok(()) })
+ sub(infcx).regions(self, b).chain(|_r| ok(()))
}
fn lub(infcx: infer_ctxt, &&b: ty::region) -> cres<ty::region> {
}
fn next_ty_vars(n: uint) -> ~[ty::t] {
- vec::from_fn(n, {|_i| self.next_ty_var() })
+ vec::from_fn(n, |_i| self.next_ty_var())
}
fn next_ty_var_integral_id() -> tvi_vid {
ok(b)
}
(some(v_a), some(v_b)) {
- do merge_op(v_a, v_b).chain {|v|
+ do merge_op(v_a, v_b).chain |v| {
ok(some(v))
}
}
glb: fn(V,V) -> cres<V>) -> cres<bounds<V>> {
let _r = indenter();
- do self.merge_bnd(a.ub, b.ub, glb).chain {|ub|
+ do self.merge_bnd(a.ub, b.ub, glb).chain |ub| {
#debug["glb of ubs %s and %s is %s",
a.ub.to_str(self), b.ub.to_str(self),
ub.to_str(self)];
- do self.merge_bnd(a.lb, b.lb, lub).chain {|lb|
+ do self.merge_bnd(a.lb, b.lb, lub).chain |lb| {
#debug["lub of lbs %s and %s is %s",
a.lb.to_str(self), b.lb.to_str(self),
lb.to_str(self)];
// them explicitly gives the type inferencer more
// information and helps to produce tighter bounds
// when necessary.
- do indent {||
- do self.bnds(a.lb, b.ub).then {||
- do self.bnds(b.lb, a.ub).then {||
- do self.merge_bnd(a.ub, b.ub, {|x, y| x.glb(self, y)}).chain {|ub|
- do self.merge_bnd(a.lb, b.lb, {|x, y| x.lub(self, y)}).chain {|lb|
+ do indent || {
+ do self.bnds(a.lb, b.ub).then || {
+ do self.bnds(b.lb, a.ub).then || {
+ do self.merge_bnd(a.ub, b.ub, |x, y| x.glb(self, y) ).chain |ub| {
+ do self.merge_bnd(a.lb, b.lb, |x, y| x.lub(self, y) ).chain |lb| {
let bnds = {lb: lb, ub: ub};
#debug["merge(%s): bnds=%s",
v_id.to_str(),
// the new bounds must themselves
// be relatable:
- do self.bnds(bnds.lb, bnds.ub).then {||
+ do self.bnds(bnds.lb, bnds.ub).then || {
self.set(vb, v_id, root(bnds, rank));
uok()
- }
+ }
}}}}}
}
// see if we can make those types subtypes.
alt (a_bounds.ub, b_bounds.lb) {
(some(a_ub), some(b_lb)) {
- let r = self.try({|| a_ub.sub(self, b_lb) });
+ let r = self.try(|| a_ub.sub(self, b_lb));
alt r {
ok(()) { ret result::ok(()); }
err(_) { /*fallthrough */ }
// i.e., b should redirect to a.
self.set(vb, b_id, redirect(a_id));
self.set_var_to_merged_bounds(
- vb, a_id, a_bounds, b_bounds, nde_a.rank).then({||
- uok()
- })
+ vb, a_id, a_bounds, b_bounds, nde_a.rank).then(|| uok() )
} else if nde_a.rank < nde_b.rank {
#debug["vars(): b has smaller rank"];
// b has greater rank, so a should redirect to b.
self.set(vb, a_id, redirect(b_id));
self.set_var_to_merged_bounds(
- vb, b_id, a_bounds, b_bounds, nde_b.rank).then({||
- uok()
- })
+ vb, b_id, a_bounds, b_bounds, nde_b.rank).then(|| uok() )
} else {
#debug["vars(): a and b have equal rank"];
assert nde_a.rank == nde_b.rank;
// to a and increment a's rank.
self.set(vb, b_id, redirect(a_id));
self.set_var_to_merged_bounds(
- vb, a_id, a_bounds, b_bounds, nde_a.rank + 1u).then({||
- uok()
- })
+ vb, a_id, a_bounds, b_bounds, nde_a.rank + 1u
+ ).then(|| uok() )
}
}
let actual_arg_len = vec::len(actual_constr.node.args);
if expected_arg_len != actual_arg_len { ret err_res; }
let mut i = 0u;
- for expected.node.args.each {|a|
+ for expected.node.args.each |a| {
let actual = actual_constr.node.args[i];
alt a.node {
ast::carg_base {
a: bound<T>, b: bound<T>) -> ures {
#debug("bnds(%s <: %s)", a.to_str(self), b.to_str(self));
- do indent {||
+ do indent || {
alt (a, b) {
(none, none) |
(some(_), none) |
as: ~[@ty::type_constr], bs: ~[@ty::type_constr]) -> ures {
if check vec::same_length(as, bs) {
- do iter_vec2(as, bs) {|a,b|
+ do iter_vec2(as, bs) |a,b| {
self.constrs(a, b)
}
} else {
}
fn sub_tys(a: ty::t, b: ty::t) -> ures {
- sub(self).tys(a, b).chain({|_t| ok(()) })
+ sub(self).tys(a, b).chain(|_t| ok(()) )
}
fn sub_regions(a: ty::region, b: ty::region) -> ures {
- sub(self).regions(a, b).chain({|_t| ok(()) })
+ sub(self).regions(a, b).chain(|_t| ok(()) )
}
fn eq_tys(a: ty::t, b: ty::t) -> ures {
- self.sub_tys(a, b).then({||
+ self.sub_tys(a, b).then(|| {
self.sub_tys(b, a)
})
}
fn eq_regions(a: ty::region, b: ty::region) -> ures {
#debug["eq_regions(%s, %s)",
a.to_str(self), b.to_str(self)];
- do indent {||
- do self.sub_regions(a, b).then {||
+ do indent || {
+ do self.sub_regions(a, b).then || {
self.sub_regions(b, a)
}
}
// allow us to pass back errors in any useful way.
assert vec::is_empty(self.v_seen) && vec::is_empty(self.r_seen);
- let rty = indent({|| self.resolve1(typ) });
+ let rty = indent(|| self.resolve1(typ) );
assert vec::is_empty(self.v_seen) && vec::is_empty(self.r_seen);
alt self.err {
none {
_ {
ty::fold_regions_and_ty(
self.infcx.tcx, typ,
- { |r| self.resolve_region(r) },
- { |t| self.resolve_if_deep(t) },
- { |t| self.resolve_if_deep(t) })
+ |r| self.resolve_region(r),
+ |t| self.resolve_if_deep(t),
+ |t| self.resolve_if_deep(t))
}
}
})
anmnt, a.to_str(self), nr_b.to_str(self),
r_b.to_str(self)];
- do indent {||
- do self.sub_tys(a, nr_b).then {||
+ do indent || {
+ do self.sub_tys(a, nr_b).then || {
let r_a = ty::re_scope(anmnt.borrow_scope);
#debug["anmnt=%?", anmnt];
- do sub(self).contraregions(r_a, r_b).chain {|_r|
+ do sub(self).contraregions(r_a, r_b).chain |_r| {
// if successful, add an entry indicating that
// borrowing occurred
#debug["borrowing expression #%?", anmnt];
ok(none)
}
(some(a), some(b)) {
- do infcx.eq_regions(a, b).then {||
+ do infcx.eq_regions(a, b).then || {
ok(some(a))
}
}
}
}
- do self.tps(a.tps, b.tps).chain { |tps|
- do self.self_tys(a.self_ty, b.self_ty).chain { |self_ty|
- do eq_opt_regions(self.infcx(), a.self_r, b.self_r).chain {
- |self_r|
+ do self.tps(a.tps, b.tps).chain |tps| {
+ do self.self_tys(a.self_ty, b.self_ty).chain |self_ty| {
+ do eq_opt_regions(self.infcx(), a.self_r, b.self_r).chain
+ |self_r| {
ok({self_r: self_r, self_ty: self_ty, tps: tps})
}
}
// variance.
if check vec::same_length(as, bs) {
- iter_vec2(as, bs, {|a, b|
+ iter_vec2(as, bs, |a, b| {
self.infcx().eq_tys(a, b)
- }).then({||
- ok(as)
- })
+ }).then(|| ok(as) )
} else {
err(ty::terr_ty_param_size(bs.len(), as.len()))
}
ok(none)
}
(some(a), some(b)) {
- self.infcx().eq_tys(a, b).then({||
- ok(some(a))
- })
+ self.infcx().eq_tys(a, b).then(|| ok(some(a)) )
}
(none, some(_)) |
(some(_), none) {
self: C, a: ty::field, b: ty::field) -> cres<ty::field> {
if a.ident == b.ident {
- self.mts(a.mt, b.mt).chain({|mt|
- ok({ident: a.ident, mt: mt})
- }).chain_err({|e|
- err(ty::terr_in_field(@e, a.ident))
- })
+ self.mts(a.mt, b.mt)
+ .chain(|mt| ok({ident: a.ident, mt: mt}) )
+ .chain_err(|e| err(ty::terr_in_field(@e, a.ident)) )
} else {
err(ty::terr_record_fields(b.ident, a.ident))
}
self: C, a: ty::arg, b: ty::arg)
-> cres<ty::arg> {
- do self.modes(a.mode, b.mode).chain {|m|
- do self.contratys(a.ty, b.ty).chain {|t|
+ do self.modes(a.mode, b.mode).chain |m| {
+ do self.contratys(a.ty, b.ty).chain |t| {
ok({mode: m, ty: t})
}
}
alt (a, b) {
(ty::vstore_slice(a_r), ty::vstore_slice(b_r)) {
- do self.contraregions(a_r, b_r).chain {|r|
+ do self.contraregions(a_r, b_r).chain |r| {
ok(ty::vstore_slice(r))
}
}
b_args: ~[ty::arg]) -> cres<~[ty::arg]> {
if check vec::same_length(a_args, b_args) {
- map_vec2(a_args, b_args, {|a, b| self.args(a, b) })
+ map_vec2(a_args, b_args, |a, b| self.args(a, b) )
} else {
err(ty::terr_arg_count)
}
}
- do self.protos(a_f.proto, b_f.proto).chain {|p|
- do self.ret_styles(a_f.ret_style, b_f.ret_style).chain {|rs|
- do argvecs(self, a_f.inputs, b_f.inputs).chain {|inputs|
- do self.tys(a_f.output, b_f.output).chain {|output|
- do self.purities(a_f.purity, b_f.purity).chain {|purity|
+ do self.protos(a_f.proto, b_f.proto).chain |p| {
+ do self.ret_styles(a_f.ret_style, b_f.ret_style).chain |rs| {
+ do argvecs(self, a_f.inputs, b_f.inputs).chain |inputs| {
+ do self.tys(a_f.output, b_f.output).chain |output| {
+ do self.purities(a_f.purity, b_f.purity).chain |purity| {
// FIXME: uncomment if #2588 doesn't get accepted:
// self.infcx().constrvecs(a_f.constraints,
// b_f.constraints).then {||
// Have to handle these first
(ty::ty_var_integral(a_id), ty::ty_var_integral(b_id)) {
- self.infcx().vars_integral(self.infcx().tvib, a_id, b_id).then({||
- ok(a) })
+ self.infcx().vars_integral(self.infcx().tvib, a_id, b_id)
+ .then(|| ok(a) )
}
(ty::ty_var_integral(a_id), ty::ty_int(_)) |
(ty::ty_var_integral(a_id), ty::ty_uint(_)) {
- self.infcx().vart_integral(self.infcx().tvib, a_id, b).then({||
- ok(a) })
+ self.infcx().vart_integral(self.infcx().tvib, a_id, b)
+ .then(|| ok(a) )
}
(ty::ty_int(_), ty::ty_var_integral(b_id)) |
(ty::ty_uint(_), ty::ty_var_integral(b_id)) {
- self.infcx().tvar_integral(self.infcx().tvib, a, b_id).then({||
- ok(a) })
+ self.infcx().tvar_integral(self.infcx().tvib, a, b_id)
+ .then(|| ok(a) )
}
(ty::ty_int(_), _) |
(ty::ty_enum(a_id, a_substs), ty::ty_enum(b_id, b_substs))
if a_id == b_id {
- do self.substs(a_substs, b_substs).chain {|tps|
+ do self.substs(a_substs, b_substs).chain |tps| {
ok(ty::mk_enum(tcx, a_id, tps))
}
}
(ty::ty_iface(a_id, a_substs), ty::ty_iface(b_id, b_substs))
if a_id == b_id {
- do self.substs(a_substs, b_substs).chain {|substs|
+ do self.substs(a_substs, b_substs).chain |substs| {
ok(ty::mk_iface(tcx, a_id, substs))
}
}
(ty::ty_class(a_id, a_substs), ty::ty_class(b_id, b_substs))
if a_id == b_id {
- do self.substs(a_substs, b_substs).chain {|substs|
+ do self.substs(a_substs, b_substs).chain |substs| {
ok(ty::mk_class(tcx, a_id, substs))
}
}
(ty::ty_box(a_mt), ty::ty_box(b_mt)) {
- do self.mts(a_mt, b_mt).chain {|mt|
+ do self.mts(a_mt, b_mt).chain |mt| {
ok(ty::mk_box(tcx, mt))
}
}
(ty::ty_uniq(a_mt), ty::ty_uniq(b_mt)) {
- do self.mts(a_mt, b_mt).chain {|mt|
+ do self.mts(a_mt, b_mt).chain |mt| {
ok(ty::mk_uniq(tcx, mt))
}
}
(ty::ty_vec(a_mt), ty::ty_vec(b_mt)) {
- do self.mts(a_mt, b_mt).chain {|mt|
+ do self.mts(a_mt, b_mt).chain |mt| {
ok(ty::mk_vec(tcx, mt))
}
}
(ty::ty_ptr(a_mt), ty::ty_ptr(b_mt)) {
- do self.mts(a_mt, b_mt).chain {|mt|
+ do self.mts(a_mt, b_mt).chain |mt| {
ok(ty::mk_ptr(tcx, mt))
}
}
(ty::ty_rptr(a_r, a_mt), ty::ty_rptr(b_r, b_mt)) {
- do self.contraregions(a_r, b_r).chain {|r|
- do self.mts(a_mt, b_mt).chain {|mt|
+ do self.contraregions(a_r, b_r).chain |r| {
+ do self.mts(a_mt, b_mt).chain |mt| {
ok(ty::mk_rptr(tcx, r, mt))
}
}
}
(ty::ty_evec(a_mt, vs_a), ty::ty_evec(b_mt, vs_b)) {
- do self.mts(a_mt, b_mt).chain {|mt|
- do self.vstores(ty::terr_vec, vs_a, vs_b).chain {|vs|
+ do self.mts(a_mt, b_mt).chain |mt| {
+ do self.vstores(ty::terr_vec, vs_a, vs_b).chain |vs| {
ok(ty::mk_evec(tcx, mt, vs))
}
}
}
(ty::ty_estr(vs_a), ty::ty_estr(vs_b)) {
- do self.vstores(ty::terr_str, vs_a, vs_b).chain {|vs|
+ do self.vstores(ty::terr_str, vs_a, vs_b).chain |vs| {
ok(ty::mk_estr(tcx,vs))
}
}
(ty::ty_rec(as), ty::ty_rec(bs)) {
if check vec::same_length(as, bs) {
- map_vec2(as, bs, {|a,b|
+ map_vec2(as, bs, |a,b| {
self.flds(a, b)
- }).chain({|flds|
- ok(ty::mk_rec(tcx, flds))
- })
+ }).chain(|flds| ok(ty::mk_rec(tcx, flds)) )
} else {
err(ty::terr_record_size(bs.len(), as.len()))
}
(ty::ty_tup(as), ty::ty_tup(bs)) {
if check vec::same_length(as, bs) {
- map_vec2(as, bs, {|a, b| self.tys(a, b) }).chain({|ts|
- ok(ty::mk_tup(tcx, ts))
- })
+ map_vec2(as, bs, |a, b| self.tys(a, b) )
+ .chain(|ts| ok(ty::mk_tup(tcx, ts)) )
} else {
err(ty::terr_tuple_size(bs.len(), as.len()))
}
}
(ty::ty_fn(a_fty), ty::ty_fn(b_fty)) {
- do self.fns(a_fty, b_fty).chain {|fty|
+ do self.fns(a_fty, b_fty).chain |fty| {
ok(ty::mk_fn(tcx, fty))
}
}
(ty::ty_constr(a_t, a_constrs), ty::ty_constr(b_t, b_constrs)) {
- do self.tys(a_t, b_t).chain {|t|
- do self.infcx().constrvecs(a_constrs, b_constrs).then {||
+ do self.tys(a_t, b_t).chain |t| {
+ do self.infcx().constrvecs(a_constrs, b_constrs).then || {
ok(ty::mk_constr(tcx, t, a_constrs))
}
}
self.tag(),
a.to_str(self.infcx()),
b.to_str(self.infcx())];
- do indent {||
+ do indent || {
alt (a, b) {
(ty::re_var(a_id), ty::re_var(b_id)) {
- do self.infcx().vars(self.rb, a_id, b_id).then {||
+ do self.infcx().vars(self.rb, a_id, b_id).then || {
ok(a)
}
}
(ty::re_var(a_id), _) {
- do self.infcx().vart(self.rb, a_id, b).then {||
+ do self.infcx().vart(self.rb, a_id, b).then || {
ok(a)
}
}
(_, ty::re_var(b_id)) {
- do self.infcx().tvar(self.rb, a, b_id).then {||
+ do self.infcx().tvar(self.rb, a, b_id).then || {
ok(a)
}
}
_ {
- do self.lub().regions(a, b).compare(b) {||
+ do self.lub().regions(a, b).compare(b) || {
ty::terr_regions_differ(b, a)
}
}
m_mutbl {
// If supertype is mut, subtype must match exactly
// (i.e., invariant if mut):
- self.infcx().eq_tys(a.ty, b.ty).then({|| ok(a) })
+ self.infcx().eq_tys(a.ty, b.ty).then(|| ok(a) )
}
m_imm | m_const {
// Otherwise we can be covariant:
- self.tys(a.ty, b.ty).chain({|_t| ok(a) })
+ self.tys(a.ty, b.ty).chain(|_t| ok(a) )
}
}
}
fn protos(a: ast::proto, b: ast::proto) -> cres<ast::proto> {
- self.lub().protos(a, b).compare(b, {||
+ self.lub().protos(a, b).compare(b, || {
ty::terr_proto_mismatch(b, a)
})
}
fn purities(f1: purity, f2: purity) -> cres<purity> {
- self.lub().purities(f1, f2).compare(f2, {||
+ self.lub().purities(f1, f2).compare(f2, || {
ty::terr_purity_mismatch(f2, f1)
})
}
fn ret_styles(a: ret_style, b: ret_style) -> cres<ret_style> {
- self.lub().ret_styles(a, b).compare(b, {||
+ self.lub().ret_styles(a, b).compare(b, || {
ty::terr_ret_style_mismatch(b, a)
})
}
#debug("%s.tys(%s, %s)", self.tag(),
a.to_str(*self), b.to_str(*self));
if a == b { ret ok(a); }
- do indent {||
+ do indent || {
alt (ty::get(a).struct, ty::get(b).struct) {
(ty::ty_bot, _) {
ok(a)
}
(ty::ty_var(a_id), ty::ty_var(b_id)) {
- self.infcx().vars(self.tvb, a_id, b_id).then({|| ok(a) })
+ self.infcx().vars(self.tvb, a_id, b_id).then(|| ok(a) )
}
(ty::ty_var(a_id), _) {
- self.infcx().vart(self.tvb, a_id, b).then({|| ok(a) })
+ self.infcx().vart(self.tvb, a_id, b).then(|| ok(a) )
}
(_, ty::ty_var(b_id)) {
- self.infcx().tvar(self.tvb, a, b_id).then({|| ok(a) })
+ self.infcx().tvar(self.tvb, a, b_id).then(|| ok(a) )
}
(_, ty::ty_bot) {
err(ty::terr_sorts(b, a))
// First, we instantiate each bound region in the subtype with a fresh
// region variable.
let {fn_ty: a_fn_ty, _} = {
- do replace_bound_regions_in_fn_ty(self.tcx, @nil, none, a) { |br|
+ do replace_bound_regions_in_fn_ty(self.tcx, @nil, none, a) |br| {
// N.B.: The name of the bound region doesn't have
// anything to do with the region variable that's created
// for it. The only thing we're doing with `br` here is
// Second, we instantiate each bound region in the supertype with a
// fresh concrete region.
let {fn_ty: b_fn_ty, _} = {
- do replace_bound_regions_in_fn_ty(self.tcx, @nil, none, b) { |br|
+ do replace_bound_regions_in_fn_ty(self.tcx, @nil, none, b) |br| {
// FIXME: eventually re_skolemized (issue #2263)
ty::re_bound(br)
}
alt m {
m_imm | m_const {
- self.tys(a.ty, b.ty).chain({|t|
- ok({ty: t, mutbl: m})
- })
+ self.tys(a.ty, b.ty).chain(|t| ok({ty: t, mutbl: m}) )
}
m_mutbl {
- self.infcx().try({||
- self.infcx().eq_tys(a.ty, b.ty).then({||
+ self.infcx().try(|| {
+ self.infcx().eq_tys(a.ty, b.ty).then(|| {
ok({ty: a.ty, mutbl: m})
})
- }).chain_err({|_e|
- self.tys(a.ty, b.ty).chain({|t|
+ }).chain_err(|_e| {
+ self.tys(a.ty, b.ty).chain(|t| {
ok({ty: t, mutbl: m_const})
})
})
a.to_str(self.infcx()),
b.to_str(self.infcx())];
- do indent {||
+ do indent || {
alt (a, b) {
(ty::re_static, _) | (_, ty::re_static) {
ok(ty::re_static) // nothing lives longer than static
// If one side or both is mut, then the GLB must use
// the precise type from the mut side.
(m_mutbl, m_const) {
- sub(*self).tys(a.ty, b.ty).chain({|_t|
+ sub(*self).tys(a.ty, b.ty).chain(|_t| {
ok({ty: a.ty, mutbl: m_mutbl})
})
}
(m_const, m_mutbl) {
- sub(*self).tys(b.ty, a.ty).chain({|_t|
+ sub(*self).tys(b.ty, a.ty).chain(|_t| {
ok({ty: b.ty, mutbl: m_mutbl})
})
}
(m_mutbl, m_mutbl) {
- self.infcx().eq_tys(a.ty, b.ty).then({||
+ self.infcx().eq_tys(a.ty, b.ty).then(|| {
ok({ty: a.ty, mutbl: m_mutbl})
})
}
(m_imm, m_const) |
(m_const, m_imm) |
(m_imm, m_imm) {
- self.tys(a.ty, b.ty).chain({|t|
+ self.tys(a.ty, b.ty).chain(|t| {
ok({ty: t, mutbl: m_imm})
})
}
// If both sides are const, then we can use GLB of both
// sides and mutbl of only `m_const`.
(m_const, m_const) {
- self.tys(a.ty, b.ty).chain({|t|
+ self.tys(a.ty, b.ty).chain(|t| {
ok({ty: t, mutbl: m_const})
})
}
a.to_str(self.infcx()),
b.to_str(self.infcx())];
- do indent {||
+ do indent || {
alt (a, b) {
(ty::re_static, r) | (r, ty::re_static) {
// static lives longer than everything else
a.to_str(self.infcx()),
b.to_str(self.infcx()));
if a == b { ret ok(a); }
- do indent {||
+ do indent || {
alt (ty::get(a).struct, ty::get(b).struct) {
(ty::ty_bot, _) { self.ty_bot(b) }
(_, ty::ty_bot) { self.ty_bot(a) }
(ty::ty_var(a_id), ty::ty_var(b_id)) {
lattice_vars(self, self.infcx().tvb,
a, a_id, b_id,
- {|x, y| self.tys(x, y) })
+ |x, y| self.tys(x, y) )
}
(ty::ty_var(a_id), _) {
lattice_var_t(self, self.infcx().tvb, a_id, b,
- {|x, y| self.tys(x, y) })
+ |x, y| self.tys(x, y) )
}
(_, ty::ty_var(b_id)) {
lattice_var_t(self, self.infcx().tvb, b_id, a,
- {|x, y| self.tys(x, y) })
+ |x, y| self.tys(x, y) )
}
_ {
super_tys(self, a, b)
(ty::re_var(a_id), ty::re_var(b_id)) {
lattice_vars(self, self.infcx().rb,
a, a_id, b_id,
- {|x, y| self.regions(x, y) })
+ |x, y| self.regions(x, y) )
}
(ty::re_var(v_id), r) | (r, ty::re_var(v_id)) {
lattice_var_t(self, self.infcx().rb,
v_id, r,
- {|x, y| self.regions(x, y) })
+ |x, y| self.regions(x, y) )
}
_ {
let a_bnd = self.bnd(a_bounds), b_bnd = self.bnd(b_bounds);
alt (a_bnd, b_bnd) {
(some(a_ty), some(b_ty)) {
- alt self.infcx().try({|| c_ts(a_ty, b_ty) }) {
+ alt self.infcx().try(|| c_ts(a_ty, b_ty) ) {
ok(t) { ret ok(t); }
err(_) { /*fallthrough */ }
}
// Otherwise, we need to merge A and B into one variable. We can
// then use either variable as an upper bound:
- self.infcx().vars(vb, a_vid, b_vid).then({||
- ok(a_t)
- })
+ self.infcx().vars(vb, a_vid, b_vid).then(|| ok(a_t) )
}
fn lattice_var_t<V:copy vid, T:copy to_str st, L:lattice_ops combine>(
// and then return b.
#debug["bnd=none"];
let a_bounds = self.with_bnd(a_bounds, b);
- do self.infcx().bnds(a_bounds.lb, a_bounds.ub).then {||
+ do self.infcx().bnds(a_bounds.lb, a_bounds.ub).then || {
self.infcx().set(vb, a_id, root(a_bounds,
nde_a.rank));
ok(b)
}
}
fn named_region(id: ast::ident) -> result<ty::region, str> {
- do empty_rscope.named_region(id).chain_err { |_e|
+ do empty_rscope.named_region(id).chain_err |_e| {
if *id == "self" { self.anon_region() }
else {
result::err("named regions other than `self` are not \
result::ok(ty::re_bound(ty::br_anon))
}
fn named_region(id: ast::ident) -> result<ty::region, str> {
- do self.base.named_region(id).chain_err {|_e|
+ do self.base.named_region(id).chain_err |_e| {
result::ok(ty::re_bound(ty::br_named(id)))
}
}
fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] {
let mut es = ~[];
- for fields.each {|f| vec::push(es, f.node.expr); }
+ for fields.each |f| { vec::push(es, f.node.expr); }
ret es;
}
// of b -- skipping any inner loops (loop, while, loop_body)
fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool {
let rs = @mut false;
- let visit_expr = {|e: @ast::expr, &&flag: @mut bool,
- v: visit::vt<@mut bool>|
+ let visit_expr =
+ |e: @ast::expr, &&flag: @mut bool, v: visit::vt<@mut bool>| {
*flag |= p(e.node);
alt e.node {
// Skip inner loops, since a break in the inner loop isn't a
}
fn has_nonlocal_exits(b: ast::blk) -> bool {
- do loop_query(b) {|e| alt e {
+ do loop_query(b) |e| { alt e {
ast::expr_break | ast::expr_cont { true }
_ { false }}}
}
fn may_break(b: ast::blk) -> bool {
- do loop_query(b) {|e| alt e {
+ do loop_query(b) |e| { alt e {
ast::expr_break { true }
_ { false }}}
}
fn tys_to_str(cx: ctxt, ts: ~[t]) -> str {
let mut rs = "";
- for ts.each {|t| rs += ty_to_str(cx, t); }
+ for ts.each |t| { rs += ty_to_str(cx, t); }
rs
}
alt ident { some(i) { s += " "; s += *i; } _ { } }
s += "(";
let mut strs = ~[];
- for inputs.each {|a| vec::push(strs, fn_input_to_str(cx, a)); }
+ for inputs.each |a| { vec::push(strs, fn_input_to_str(cx, a)); }
s += str::connect(strs, ", ");
s += ")";
if ty::get(output).struct != ty_nil {
}
// if there is an id, print that instead of the structural type:
- for ty::type_def_id(typ).each { |def_id|
+ for ty::type_def_id(typ).each |def_id| {
// note that this typedef cannot have type parameters
ret ast_map::path_to_str(ty::item_path(cx, def_id));
}
ty_type { "type" }
ty_rec(elems) {
let mut strs: ~[str] = ~[];
- for elems.each {|fld| vec::push(strs, field_to_str(cx, fld)); }
+ for elems.each |fld| { vec::push(strs, field_to_str(cx, fld)); }
"{" + str::connect(strs, ",") + "}"
}
ty_tup(elems) {
let mut strs = ~[];
- for elems.each {|elem| vec::push(strs, ty_to_str(cx, elem)); }
+ for elems.each |elem| { vec::push(strs, ty_to_str(cx, elem)); }
"(" + str::connect(strs, ",") + ")"
}
ty_fn(f) {
};
if vec::len(tps) > 0u {
- let strs = vec::map(tps, {|t| ty_to_str(cx, t)});
+ let strs = vec::map(tps, |t| ty_to_str(cx, t) );
#fmt["%s%s<%s>", base, r_str, str::connect(strs, ",")]
} else {
#fmt["%s%s", base, r_str]
fn constrs_str(constrs: ~[@constr]) -> str {
let mut s = "";
let mut colon = true;
- for constrs.each {|c|
+ for constrs.each |c| {
if colon { s += " : "; colon = false; } else { s += ", "; }
s += constr_to_str(c);
}
fn run<T>(owner: srv_owner<T>, source: str, +parse: parser) -> T {
let srv_ = srv({
- ch: do task::spawn_listener {|po|
+ ch: do task::spawn_listener |po| {
act(po, source, parse);
}
});
#[test]
fn should_prune_unconfigured_items() {
let source = "#[cfg(shut_up_and_leave_me_alone)]fn a() { }";
- do from_str(source) {|srv|
- do exec(srv) {|ctxt|
+ do from_str(source) |srv| {
+ do exec(srv) |ctxt| {
assert vec::is_empty(ctxt.ast.node.module.items);
}
}
#[test]
fn srv_should_build_ast_map() {
let source = "fn a() { }";
- do from_str(source) {|srv|
- do exec(srv) {|ctxt|
+ do from_str(source) |srv| {
+ do exec(srv) |ctxt| {
assert ctxt.ast_map.size() != 0u
};
}
#[test]
fn srv_should_build_reexport_map() {
let source = "import a::b; export b; mod a { mod b { } }";
- do from_str(source) {|srv|
- do exec(srv) {|ctxt|
+ do from_str(source) |srv| {
+ do exec(srv) |ctxt| {
assert ctxt.exp_map.size() != 0u
};
}
fn f() -> std::sha1::sha1 {\
std::sha1::mk_sha1() }";
// Just testing that resolve doesn't crash
- from_str(source, {|_srv| })
+ from_str(source, |_srv| { } )
}
#[test]
fn srv_should_resolve_core_crate() {
let source = "fn a() -> option { fail }";
// Just testing that resolve doesn't crash
- from_str(source, {|_srv| })
+ from_str(source, |_srv| { } )
}
#[test]
// We want to ignore things we can't resolve. Shouldn't
// need to be able to find external crates to create docs.
let source = "import wooboo; fn a() { }";
- from_str(source, {|_srv| })
+ from_str(source, |_srv| { } )
}
#[test]
fn srv_should_resolve_non_existant_uses() {
let source = "use forble; fn a() { }";
- from_str(source, {|_srv| })
+ from_str(source, |_srv| { } )
}
#[test]
fn should_ignore_external_import_paths_that_dont_exist() {
let source = "use forble; import forble::bippy;";
- from_str(source, {|_srv| })
+ from_str(source, |_srv| { } )
}
#[test]
fn srv_should_return_request_result() {
let source = "fn a() { }";
- do from_str(source) {|srv|
- let result = exec(srv, {|_ctxt| 1000});
+ do from_str(source) |srv| {
+ let result = exec(srv, |_ctxt| 1000 );
assert result == 1000;
}
}
{
name: attr::last_meta_item_value_str_by_name(
- link_metas, "name").map({|x|*x})
+ link_metas, "name").map(|x| *x )
}
}
fn parse_desc(attrs: ~[ast::attribute]) -> option<str> {
alt doc_meta(attrs) {
some(meta) {
- attr::get_meta_item_value_str(meta).map({|x|*x})
+ attr::get_meta_item_value_str(meta).map(|x| *x )
}
none { none }
}
let srv = fold.ctxt;
let doc = fold::default_seq_fold_crate(fold, doc);
- let attrs = do astsrv::exec(srv) {|ctxt|
+ let attrs = do astsrv::exec(srv) |ctxt| {
let attrs = ctxt.ast.node.attrs;
attr_parser::parse_crate(attrs)
};
let desc = if doc.id == ast::crate_node_id {
// This is the top-level mod, use the crate attributes
- do astsrv::exec(srv) {|ctxt|
+ do astsrv::exec(srv) |ctxt| {
attr_parser::parse_desc(ctxt.ast.node.attrs)
}
} else {
srv: astsrv::srv,
id: doc::ast_id,
+parse_attrs: fn~(~[ast::attribute]) -> T) -> T {
- do astsrv::exec(srv) {|ctxt|
+ do astsrv::exec(srv) |ctxt| {
let attrs = alt ctxt.ast_map.get(id) {
ast_map::node_item(item, _) { item.attrs }
ast_map::node_foreign_item(item, _, _) { item.attrs }
let doc = fold::default_seq_fold_enum(fold, doc);
{
- variants: do par::anymap(doc.variants) {|variant|
- let desc = do astsrv::exec(srv) {|ctxt|
+ variants: do par::anymap(doc.variants) |variant| {
+ let desc = do astsrv::exec(srv) |ctxt| {
alt check ctxt.ast_map.get(doc_id) {
ast_map::node_item(@{
node: ast::item_enum(ast_variants, _, _), _
}, _) {
let ast_variant = option::get(
- vec::find(ast_variants, {|v|
+ vec::find(ast_variants, |v| {
*v.node.name == variant.name
}));
) -> ~[doc::methoddoc] {
// Create an assoc list from method name to attributes
- let attrs: ~[(str, option<str>)] = do astsrv::exec(srv) {|ctxt|
+ let attrs: ~[(str, option<str>)] = do astsrv::exec(srv) |ctxt| {
alt ctxt.ast_map.get(item_id) {
ast_map::node_item(@{
node: ast::item_iface(_, _, methods), _
}, _) {
- par::seqmap(methods, {|method|
+ par::seqmap(methods, |method| {
(*method.ident, attr_parser::parse_desc(method.attrs))
})
}
ast_map::node_item(@{
node: ast::item_impl(_, _, _, _, methods), _
}, _) {
- par::seqmap(methods, {|method|
+ par::seqmap(methods, |method| {
(*method.ident, attr_parser::parse_desc(method.attrs))
})
}
}
};
- do vec::map2(docs, attrs) {|doc, attrs|
+ do vec::map2(docs, attrs) |doc, attrs| {
assert doc.name == tuple::first(attrs);
let desc = tuple::second(attrs);
#[cfg(test)]
mod test {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
run(srv, doc)
}
println("Usage: rustdoc ~[options] <cratefile>\n");
println("Options:\n");
- for opts().each {|opt|
+ for opts().each |opt| {
println(#fmt(" %s", tuple::second(opt)));
}
println("");
let config = default_config(input_crate);
let result = result::ok(config);
- let result = do result::chain(result) {|config|
+ let result = do result::chain(result) |config| {
let output_dir = getopts::opt_maybe_str(match, opt_output_dir());
result::ok({
output_dir: option::get_default(output_dir, config.output_dir)
with config
})
};
- let result = do result::chain(result) {|config|
+ let result = do result::chain(result) |config| {
let output_format = getopts::opt_maybe_str(
match, opt_output_format());
do option::map_default(output_format, result::ok(config))
- {|output_format|
+ |output_format| {
do result::chain(parse_output_format(output_format))
- {|output_format|
+ |output_format| {
result::ok({
output_format: output_format
}
}
};
- let result = do result::chain(result) {|config|
+ let result = do result::chain(result) |config| {
let output_style = getopts::opt_maybe_str(match, opt_output_style());
do option::map_default(output_style, result::ok(config))
- {|output_style|
- do result::chain(parse_output_style(output_style)) {|output_style|
+ |output_style| {
+ do result::chain(parse_output_style(output_style))
+ |output_style| {
result::ok({
output_style: output_style
with config
}
}
};
- let result = do result::chain(result) {|config|
+ let result = do result::chain(result) |config| {
let pandoc_cmd = getopts::opt_maybe_str(match, opt_pandoc_cmd());
let pandoc_cmd = maybe_find_pandoc(
config, pandoc_cmd, program_output);
- do result::chain(pandoc_cmd) {|pandoc_cmd|
+ do result::chain(pandoc_cmd) |pandoc_cmd| {
result::ok({
pandoc_cmd: pandoc_cmd
with config
}
};
- let pandoc = do vec::find(possible_pandocs) {|pandoc|
+ let pandoc = do vec::find(possible_pandocs) |pandoc| {
let output = program_output(pandoc, ~["--version"]);
#debug("testing pandoc cmd %s: %?", pandoc, output);
output.status == 0
let doc =fold::default_seq_fold_iface(fold, doc);
{
- methods: par::anymap(doc.methods, {|doc|
- {
- brief: extract(doc.desc)
- with doc
- }
+ methods: par::anymap(doc.methods, |doc| {
+ brief: extract(doc.desc)
+ with doc
})
with doc
}
let doc =fold::default_seq_fold_impl(fold, doc);
{
- methods: par::anymap(doc.methods, {|doc|
- {
- brief: extract(doc.desc)
- with doc
- }
+ methods: par::anymap(doc.methods, |doc| {
+ brief: extract(doc.desc)
+ with doc
})
with doc
}
#[cfg(test)]
mod test {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass().f(srv, doc);
run(srv, doc)
let mut dotcount = 0;
// The index of the character following a single dot. This allows
// Things like [0..1) to appear in the brief description
- let idx = do str::find(s) {|ch|
+ let idx = do str::find(s) |ch| {
if ch == '.' {
dotcount += 1;
false
let lines = str::lines_any(s);
let mut whitespace_lines = 0;
let mut accum = "";
- let paras = do vec::foldl(~[], lines) {|paras, line|
+ let paras = do vec::foldl(~[], lines) |paras, line| {
let mut res = paras;
if str::is_whitespace(line) {
impl util for doc {
fn cratedoc() -> cratedoc {
- option::get(vec::foldl(none, self.pages, {|_m, page|
+ option::get(vec::foldl(none, self.pages, |_m, page| {
alt page {
doc::cratepage(doc) { some(doc) }
_ { none }
impl util for moddoc {
fn mods() -> ~[moddoc] {
- do vec::filter_map(self.items) {|itemtag|
+ do vec::filter_map(self.items) |itemtag| {
alt itemtag {
modtag(moddoc) { some(moddoc) }
_ { none }
}
fn nmods() -> ~[nmoddoc] {
- do vec::filter_map(self.items) {|itemtag|
+ do vec::filter_map(self.items) |itemtag| {
alt itemtag {
nmodtag(nmoddoc) { some(nmoddoc) }
_ { none }
}
fn fns() -> ~[fndoc] {
- do vec::filter_map(self.items) {|itemtag|
+ do vec::filter_map(self.items) |itemtag| {
alt itemtag {
fntag(fndoc) { some(fndoc) }
_ { none }
}
fn consts() -> ~[constdoc] {
- do vec::filter_map(self.items) {|itemtag|
+ do vec::filter_map(self.items) |itemtag| {
alt itemtag {
consttag(constdoc) { some(constdoc) }
_ { none }
}
fn enums() -> ~[enumdoc] {
- do vec::filter_map(self.items) {|itemtag|
+ do vec::filter_map(self.items) |itemtag| {
alt itemtag {
enumtag(enumdoc) { some(enumdoc) }
_ { none }
}
fn ifaces() -> ~[ifacedoc] {
- do vec::filter_map(self.items) {|itemtag|
+ do vec::filter_map(self.items) |itemtag| {
alt itemtag {
ifacetag(ifacedoc) { some(ifacedoc) }
_ { none }
}
fn impls() -> ~[impldoc] {
- do vec::filter_map(self.items) {|itemtag|
+ do vec::filter_map(self.items) |itemtag| {
alt itemtag {
impltag(impldoc) { some(impldoc) }
_ { none }
}
fn types() -> ~[tydoc] {
- do vec::filter_map(self.items) {|itemtag|
+ do vec::filter_map(self.items) |itemtag| {
alt itemtag {
tytag(tydoc) { some(tydoc) }
_ { none }
impl util for ~[page] {
fn mods() -> ~[moddoc] {
- do vec::filter_map(self) {|page|
+ do vec::filter_map(self) |page| {
alt page {
itempage(modtag(moddoc)) { some(moddoc) }
_ { none }
}
fn nmods() -> ~[nmoddoc] {
- do vec::filter_map(self) {|page|
+ do vec::filter_map(self) |page| {
alt page {
itempage(nmodtag(nmoddoc)) { some(nmoddoc) }
_ { none }
}
fn fns() -> ~[fndoc] {
- do vec::filter_map(self) {|page|
+ do vec::filter_map(self) |page| {
alt page {
itempage(fntag(fndoc)) { some(fndoc) }
_ { none }
}
fn consts() -> ~[constdoc] {
- do vec::filter_map(self) {|page|
+ do vec::filter_map(self) |page| {
alt page {
itempage(consttag(constdoc)) { some(constdoc) }
_ { none }
}
fn enums() -> ~[enumdoc] {
- do vec::filter_map(self) {|page|
+ do vec::filter_map(self) |page| {
alt page {
itempage(enumtag(enumdoc)) { some(enumdoc) }
_ { none }
}
fn ifaces() -> ~[ifacedoc] {
- do vec::filter_map(self) {|page|
+ do vec::filter_map(self) |page| {
alt page {
itempage(ifacetag(ifacedoc)) { some(ifacedoc) }
_ { none }
}
fn impls() -> ~[impldoc] {
- do vec::filter_map(self) {|page|
+ do vec::filter_map(self) |page| {
alt page {
itempage(impltag(impldoc)) { some(impldoc) }
_ { none }
}
fn types() -> ~[tydoc] {
- do vec::filter_map(self) {|page|
+ do vec::filter_map(self) |page| {
alt page {
itempage(tytag(tydoc)) { some(tydoc) }
_ { none }
#[doc = "Use the AST service to create a document tree"];
- do astsrv::exec(srv) {|ctxt|
+ do astsrv::exec(srv) |ctxt| {
extract(ctxt.ast, default_name)
}
}
) -> doc::moddoc {
{
item: itemdoc,
- items: do vec::filter_map(module.items) {|item|
+ items: do vec::filter_map(module.items) |item| {
let itemdoc = mk_itemdoc(item.id, item.ident);
alt item.node {
ast::item_mod(m) {
) -> doc::nmoddoc {
{
item: itemdoc,
- fns: do par::seqmap(module.items) {|item|
+ fns: do par::seqmap(module.items) |item| {
let itemdoc = mk_itemdoc(item.id, item.ident);
alt item.node {
ast::foreign_item_fn(_, _) {
) -> doc::ifacedoc {
{
item: itemdoc,
- methods: do par::seqmap(methods) {|method|
+ methods: do par::seqmap(methods) |method| {
{
name: *method.ident,
brief: none,
item: itemdoc,
iface_ty: none,
self_ty: none,
- methods: do par::seqmap(methods) {|method|
+ methods: do par::seqmap(methods) |method| {
{
name: *method.ident,
brief: none,
#[test]
fn extract_from_seq_srv() {
let source = "";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = from_srv(srv, "name");
assert doc.cratemod().name() == "name";
}
fn default_any_fold<T:send copy>(ctxt: T) -> fold<T> {
mk_fold(
ctxt,
- {|f, d| default_seq_fold_doc(f, d)},
- {|f, d| default_seq_fold_crate(f, d)},
- {|f, d| default_seq_fold_item(f, d)},
- {|f, d| default_any_fold_mod(f, d)},
- {|f, d| default_any_fold_nmod(f, d)},
- {|f, d| default_seq_fold_fn(f, d)},
- {|f, d| default_seq_fold_const(f, d)},
- {|f, d| default_seq_fold_enum(f, d)},
- {|f, d| default_seq_fold_iface(f, d)},
- {|f, d| default_seq_fold_impl(f, d)},
- {|f, d| default_seq_fold_type(f, d)}
+ |f, d| default_seq_fold_doc(f, d),
+ |f, d| default_seq_fold_crate(f, d),
+ |f, d| default_seq_fold_item(f, d),
+ |f, d| default_any_fold_mod(f, d),
+ |f, d| default_any_fold_nmod(f, d),
+ |f, d| default_seq_fold_fn(f, d),
+ |f, d| default_seq_fold_const(f, d),
+ |f, d| default_seq_fold_enum(f, d),
+ |f, d| default_seq_fold_iface(f, d),
+ |f, d| default_seq_fold_impl(f, d),
+ |f, d| default_seq_fold_type(f, d)
)
}
fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
mk_fold(
ctxt,
- {|f, d| default_seq_fold_doc(f, d)},
- {|f, d| default_seq_fold_crate(f, d)},
- {|f, d| default_seq_fold_item(f, d)},
- {|f, d| default_seq_fold_mod(f, d)},
- {|f, d| default_seq_fold_nmod(f, d)},
- {|f, d| default_seq_fold_fn(f, d)},
- {|f, d| default_seq_fold_const(f, d)},
- {|f, d| default_seq_fold_enum(f, d)},
- {|f, d| default_seq_fold_iface(f, d)},
- {|f, d| default_seq_fold_impl(f, d)},
- {|f, d| default_seq_fold_type(f, d)}
+ |f, d| default_seq_fold_doc(f, d),
+ |f, d| default_seq_fold_crate(f, d),
+ |f, d| default_seq_fold_item(f, d),
+ |f, d| default_seq_fold_mod(f, d),
+ |f, d| default_seq_fold_nmod(f, d),
+ |f, d| default_seq_fold_fn(f, d),
+ |f, d| default_seq_fold_const(f, d),
+ |f, d| default_seq_fold_enum(f, d),
+ |f, d| default_seq_fold_iface(f, d),
+ |f, d| default_seq_fold_impl(f, d),
+ |f, d| default_seq_fold_type(f, d)
)
}
fn default_par_fold<T:send copy>(ctxt: T) -> fold<T> {
mk_fold(
ctxt,
- {|f, d| default_seq_fold_doc(f, d)},
- {|f, d| default_seq_fold_crate(f, d)},
- {|f, d| default_seq_fold_item(f, d)},
- {|f, d| default_par_fold_mod(f, d)},
- {|f, d| default_par_fold_nmod(f, d)},
- {|f, d| default_seq_fold_fn(f, d)},
- {|f, d| default_seq_fold_const(f, d)},
- {|f, d| default_seq_fold_enum(f, d)},
- {|f, d| default_seq_fold_iface(f, d)},
- {|f, d| default_seq_fold_impl(f, d)},
- {|f, d| default_seq_fold_type(f, d)}
+ |f, d| default_seq_fold_doc(f, d),
+ |f, d| default_seq_fold_crate(f, d),
+ |f, d| default_seq_fold_item(f, d),
+ |f, d| default_par_fold_mod(f, d),
+ |f, d| default_par_fold_nmod(f, d),
+ |f, d| default_seq_fold_fn(f, d),
+ |f, d| default_seq_fold_const(f, d),
+ |f, d| default_seq_fold_enum(f, d),
+ |f, d| default_seq_fold_iface(f, d),
+ |f, d| default_seq_fold_impl(f, d),
+ |f, d| default_seq_fold_type(f, d)
)
}
fn default_seq_fold_doc<T>(fold: fold<T>, doc: doc::doc) -> doc::doc {
{
- pages: do par::seqmap(doc.pages) {|page|
+ pages: do par::seqmap(doc.pages) |page| {
alt page {
doc::cratepage(doc) {
doc::cratepage(fold.fold_crate(fold, doc))
) -> doc::moddoc {
{
item: fold.fold_item(fold, doc.item),
- items: par::anymap(doc.items, {|itemtag, copy fold|
+ items: par::anymap(doc.items, |itemtag, copy fold| {
fold_itemtag(fold, itemtag)
})
with doc
) -> doc::moddoc {
{
item: fold.fold_item(fold, doc.item),
- items: par::seqmap(doc.items, {|itemtag|
+ items: par::seqmap(doc.items, |itemtag| {
fold_itemtag(fold, itemtag)
})
with doc
) -> doc::moddoc {
{
item: fold.fold_item(fold, doc.item),
- items: par::parmap(doc.items, {|itemtag, copy fold|
+ items: par::parmap(doc.items, |itemtag, copy fold| {
fold_itemtag(fold, itemtag)
})
with doc
) -> doc::nmoddoc {
{
item: fold.fold_item(fold, doc.item),
- fns: par::anymap(doc.fns, {|fndoc, copy fold|
+ fns: par::anymap(doc.fns, |fndoc, copy fold| {
fold.fold_fn(fold, fndoc)
})
with doc
) -> doc::nmoddoc {
{
item: fold.fold_item(fold, doc.item),
- fns: par::seqmap(doc.fns, {|fndoc|
+ fns: par::seqmap(doc.fns, |fndoc| {
fold.fold_fn(fold, fndoc)
})
with doc
) -> doc::nmoddoc {
{
item: fold.fold_item(fold, doc.item),
- fns: par::parmap(doc.fns, {|fndoc, copy fold|
+ fns: par::parmap(doc.fns, |fndoc, copy fold| {
fold.fold_fn(fold, fndoc)
})
with doc
config: config::config
) -> doc::index {
{
- entries: par::anymap(doc.items, {|doc|
+ entries: par::anymap(doc.items, |doc| {
item_to_entry(doc, config)
})
}
config: config::config
) -> doc::index {
{
- entries: par::anymap(doc.fns, {|doc|
+ entries: par::anymap(doc.fns, |doc| {
item_to_entry(doc::fntag(doc), config)
})
}
#[cfg(test)]
mod test {
fn mk_doc(output_style: config::output_style, source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let config = {
output_style: output_style
with config::default_config("whatever")
doc: doc::doc,
+writer_factory: writer_factory
) {
- do par::anymap(doc.pages) {|page|
+ do par::anymap(doc.pages) |page| {
let ctxt = {
w: writer_factory(page)
};
let doc = page_pass::mk_pass(config::doc_per_mod).f(srv, doc);
write_markdown(doc, writer_factory);
// We expect two pages to have been written
- do iter::repeat(2u) {||
+ do iter::repeat(2u) || {
comm::recv(po);
}
}
"#[link(name = \"core\")]; mod a { }");
let doc = page_pass::mk_pass(config::doc_per_mod).f(srv, doc);
write_markdown(doc, writer_factory);
- do iter::repeat(2u) {||
+ do iter::repeat(2u) || {
let (page, markdown) = comm::recv(po);
alt page {
doc::cratepage(_) {
}
fn write_sections(ctxt: ctxt, sections: ~[doc::section]) {
- do vec::iter(sections) {|section|
+ do vec::iter(sections) |section| {
write_section(ctxt, section);
}
}
write_index(ctxt, option::get(doc.index));
}
- for doc.items.each {|itemtag|
+ for doc.items.each |itemtag| {
write_item(ctxt, itemtag);
}
}
ret;
}
- for index.entries.each {|entry|
+ for index.entries.each |entry| {
let header = header_text_(entry.kind, entry.name);
let id = entry.link;
if option::is_some(entry.brief) {
write_index(ctxt, option::get(doc.index));
}
- for doc.fns.each {|fndoc|
+ for doc.fns.each |fndoc| {
write_item_header(ctxt, doc::fntag(fndoc));
write_fn(ctxt, fndoc);
}
fn code_block_indent(s: str) -> str {
let lines = str::lines_any(s);
- let indented = par::seqmap(lines, { |line| #fmt(" %s", line) });
+ let indented = par::seqmap(lines, |line| #fmt(" %s", line) );
str::connect(indented, "\n")
}
write_header_(ctxt, h4, "Variants");
- vec::iter(docs, {|variant| write_variant(ctxt, variant) });
+ vec::iter(docs, |variant| write_variant(ctxt, variant) );
ctxt.w.write_line("");
}
}
fn write_methods(ctxt: ctxt, docs: ~[doc::methoddoc]) {
- do vec::iter(docs) {|doc| write_method(ctxt, doc) }
+ do vec::iter(docs) |doc| { write_method(ctxt, doc) }
}
fn write_method(ctxt: ctxt, doc: doc::methoddoc) {
}
fn create_doc_srv(source: str) -> (astsrv::srv, doc::doc) {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let config = {
output_style: config::doc_per_crate
page: doc::page
) -> writer {
let filename = make_local_filename(config, page);
- do generic_writer {|markdown|
+ do generic_writer |markdown| {
write_file(filename, markdown);
}
}
"--output=" + filename
];
- do generic_writer {|markdown|
+ do generic_writer |markdown| {
import io::writer_util;
#debug("pandoc cmd: %s", pandoc_cmd);
let stdout_po = comm::port();
let stdout_ch = comm::chan(stdout_po);
- do task::spawn_sched(task::single_threaded) {||
+ do task::spawn_sched(task::single_threaded) || {
comm::send(stdout_ch, readclose(pipe_out.in));
}
let stdout = comm::recv(stdout_po);
let stderr_po = comm::port();
let stderr_ch = comm::chan(stderr_po);
- do task::spawn_sched(task::single_threaded) {||
+ do task::spawn_sched(task::single_threaded) || {
comm::send(stderr_ch, readclose(pipe_err.in));
}
let stderr = comm::recv(stderr_po);
}
fn generic_writer(+process: fn~(markdown: str)) -> writer {
- let ch = do task::spawn_listener {|po: comm::port<writeinstr>|
+ let ch = do task::spawn_listener |po: comm::port<writeinstr>| {
let mut markdown = "";
let mut keep_going = true;
while keep_going {
#[cfg(test)]
mod test {
fn mk_doc(name: str, source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, name);
let doc = path_pass::mk_pass().f(srv, doc);
doc
let writer_factory = fn~(page: doc::page) -> writer {
let writer_po = comm::port();
let writer_ch = comm::chan(writer_po);
- do task::spawn {||
+ do task::spawn || {
let (writer, future) = future_writer();
comm::send(writer_ch, writer);
let s = future::get(future);
let writer = fn~(+instr: writeinstr) {
comm::send(chan, copy instr);
};
- let future = do future::from_fn {||
+ let future = do future::from_fn || {
let mut res = "";
loop {
alt comm::recv(port) {
let result_port = comm::port();
let result_chan = comm::chan(result_port);
- let page_chan = do task::spawn_listener {|page_port|
+ let page_chan = do task::spawn_listener |page_port| {
comm::send(result_chan, make_doc_from_pages(page_port));
};
fn strip_mod(doc: doc::moddoc) -> doc::moddoc {
{
- items: do vec::filter(doc.items) {|item|
+ items: do vec::filter(doc.items) |item| {
alt item {
doc::modtag(_) { false }
doc::nmodtag(_) { false }
output_style: config::output_style,
source: str
) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
run(srv, doc, output_style)
}
}
fn parmap<T:send, U:send>(v: ~[T], f: fn~(T) -> U) -> ~[U] unsafe {
- let futures = do vec::map(v) {|elt|
+ let futures = do vec::map(v) |elt| {
let po = comm::port();
let ch = comm::chan(po);
let addr = ptr::addr_of(elt);
- do task::spawn {|copy f|
+ do task::spawn |copy f| {
comm::send(ch, f(*addr));
}
po
};
- do vec::map(futures) {|future|
+ do vec::map(futures) |future| {
comm::recv(future)
}
}
#[test]
fn test_parallel_map() {
let i = ~[1, 2, 3, 4];
- let j = parmap(i, {|e| e + 1 });
+ let j = parmap(i, |e| e + 1 );
assert j == ~[2, 3, 4, 5];
}
#[test]
fn should_record_mod_paths() {
let source = "mod a { mod b { mod c { } } mod d { mod e { } } }";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
assert doc.cratemod().mods()[0].mods()[0].mods()[0].path()
#[test]
fn should_record_fn_paths() {
let source = "mod a { fn b() { } }";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
assert doc.cratemod().mods()[0].fns()[0].path() == ~["a"];
#[test]
fn should_record_foreign_mod_paths() {
let source = "mod a { native mod b { } }";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
assert doc.cratemod().mods()[0].nmods()[0].path() == ~["a"];
#[test]
fn should_record_foreign_fn_paths() {
let source = "native mod a { fn b(); }";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
assert doc.cratemod().nmods()[0].fns[0].path() == ~["a"];
let doc = fold::default_any_fold_mod(fold, doc);
{
- items: vec::filter(doc.items, {|itemtag|
+ items: vec::filter(doc.items, |itemtag| {
!is_hidden(fold.ctxt, itemtag.item())
})
with doc
import syntax::ast_map;
let id = doc.id;
- do astsrv::exec(srv) {|ctxt|
+ do astsrv::exec(srv) |ctxt| {
let attrs = alt ctxt.ast_map.get(id) {
ast_map::node_item(item, _) { item.attrs }
_ { ~[] }
#[cfg(test)]
mod test {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
run(srv, doc)
}
srv: astsrv::srv,
doc: doc::moddoc
) -> ~[doc::itemtag] {
- exported_items_from(srv, doc, {|a,b|
+ exported_items_from(srv, doc, |a,b| {
is_exported_from_mod(a, doc.id(), b)
})
}
doc: doc::moddoc,
is_exported: fn(astsrv::srv, str) -> bool
) -> ~[doc::itemtag] {
- do vec::filter_map(doc.items) { |itemtag|
+ do vec::filter_map(doc.items) |itemtag| {
let itemtag = alt itemtag {
doc::enumtag(enumdoc) {
// Also need to check variant exportedness
doc: doc::enumdoc,
is_exported: fn(astsrv::srv, str) -> bool
) -> ~[doc::variantdoc] {
- do vec::filter_map(doc.variants) { |doc|
+ do vec::filter_map(doc.variants) |doc| {
if is_exported(srv, doc.name) {
some(doc)
} else {
mod_id: doc::ast_id,
item_name: str
) -> bool {
- do astsrv::exec(srv) {|ctxt|
+ do astsrv::exec(srv) |ctxt| {
alt ctxt.ast_map.get(mod_id) {
ast_map::node_item(item, _) {
alt item.node {
srv: astsrv::srv,
item_name: str
) -> bool {
- do astsrv::exec(srv) {|ctxt|
+ do astsrv::exec(srv) |ctxt| {
ast_util::is_exported(@item_name, ctxt.ast.node.module)
}
}
#[test]
fn should_not_prune_reexports() {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = reexport_pass::mk_pass().f(srv, doc);
run(srv, doc)
#[cfg(test)]
mod test {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
run(srv, doc)
}
) -> ~[(K, V)] {
let mut vec = ~[];
- for map.each {|k, v|
+ for map.each |k, v| {
vec += ~[(k, v)];
}
ret vec;
) -> map::hashmap<K, V> {
let map = new_hash();
- do vec::iter(list) {|elt|
+ do vec::iter(list) |elt| {
let (k, v) = elt;
map.insert(k, v);
}
}
fn build_reexport_def_set(srv: astsrv::srv) -> def_set {
- let assoc_list = do astsrv::exec(srv) {|ctxt|
+ let assoc_list = do astsrv::exec(srv) |ctxt| {
let def_set = ast_util::new_def_hash();
- for ctxt.exp_map.each {|_id, defs|
- for defs.each {|def|
+ for ctxt.exp_map.each |_id, defs| {
+ for defs.each |def| {
if def.reexp {
def_set.insert(def.id, ());
}
}
}
- for find_reexport_impls(ctxt).each {|def|
+ for find_reexport_impls(ctxt).each |def| {
def_set.insert(def, ());
}
to_assoc_list(def_set)
fn find_reexport_impls(ctxt: astsrv::ctxt) -> ~[ast::def_id] {
let defs = @mut ~[];
- do for_each_reexported_impl(ctxt) {|_mod_id, i|
+ do for_each_reexported_impl(ctxt) |_mod_id, i| {
*defs += ~[i.did]
}
ret *defs;
fn fold_mod(fold: fold::fold<ctxt>, doc: doc::moddoc) -> doc::moddoc {
let doc = fold::default_seq_fold_mod(fold, doc);
- for doc.items.each {|item|
+ for doc.items.each |item| {
let def_id = ast_util::local_def(item.id());
if fold.ctxt.def_set.contains_key(def_id) {
fold.ctxt.def_map.insert(def_id, item);
fn fold_nmod(fold: fold::fold<ctxt>, doc: doc::nmoddoc) -> doc::nmoddoc {
let doc = fold::default_seq_fold_nmod(fold, doc);
- for doc.fns.each {|fndoc|
+ for doc.fns.each |fndoc| {
let def_id = ast_util::local_def(fndoc.id());
if fold.ctxt.def_set.contains_key(def_id) {
fold.ctxt.def_map.insert(def_id, doc::fntag(fndoc));
let def_assoc_list = to_assoc_list(def_map);
#debug("def_map: %?", def_assoc_list);
- let assoc_list = do astsrv::exec(srv) {|ctxt|
+ let assoc_list = do astsrv::exec(srv) |ctxt| {
let def_map = from_def_assoc_list(def_assoc_list);
let path_map = map::str_hash::<~[(str,doc::itemtag)]>();
- for ctxt.exp_map.each {|exp_id, defs|
+ for ctxt.exp_map.each |exp_id, defs| {
let path = alt check ctxt.ast_map.get(exp_id) {
ast_map::node_export(_, path) { path }
};
let modpath = ast_map::path_to_str(vec::init(*path));
let mut reexportdocs = ~[];
- for defs.each {|def|
+ for defs.each |def| {
if !def.reexp { cont; }
alt def_map.find(def.id) {
some(itemtag) {
}
if reexportdocs.len() > 0u {
- do option::iter(path_map.find(modpath)) {|docs|
- reexportdocs = docs + vec::filter(reexportdocs, {|x|
+ do option::iter(path_map.find(modpath)) |docs| {
+ reexportdocs = docs + vec::filter(reexportdocs, |x| {
!vec::contains(docs, x)
});
}
}
}
- for find_reexport_impl_docs(ctxt, def_map).each {|elt|
+ for find_reexport_impl_docs(ctxt, def_map).each |elt| {
let (path, doc) = elt;
let docs = alt path_map.find(path) {
some(docs) { docs + ~[(doc)] }
) -> ~[(str, (str, doc::itemtag))] {
let docs = @mut ~[];
- do for_each_reexported_impl(ctxt) {|mod_id, i|
+ do for_each_reexported_impl(ctxt) |mod_id, i| {
let path = alt ctxt.ast_map.find(mod_id) {
some(ast_map::node_item(item, path)) {
let path = ast_map::path_to_str(*path);
f: fn@(ast::node_id, resolve::_impl)
) {
let visitor = @{
- visit_mod: {|a,b,c|visit_mod(ctxt, f, a, b, c)}
+ visit_mod: |a,b,c| visit_mod(ctxt, f, a, b, c)
with *visit::default_simple_visitor()
};
let visitor = visit::mk_simple_visitor(visitor);
let all_impls = all_impls(m);
alt check *ctxt.impl_map.get(mod_id) {
list::cons(impls, @list::nil) {
- for vec::each(*impls) {|i|
+ for vec::each(*impls) |i| {
// This impl is not an item in the current mod
if !all_impls.contains_key(i.did) {
// Ignore external impls because I don't
fn all_impls(m: ast::_mod) -> map::set<ast::def_id> {
let all_impls = ast_util::new_def_hash();
- for m.items.each {|item|
+ for m.items.each |item| {
alt item.node {
ast::item_impl(_, _, _, _, _) {
all_impls.insert(ast_util::local_def(item.id), ());
#debug("looking for reexports in path %?", path);
alt path_map.find(str::connect(path, "::")) {
some(name_docs) {
- do vec::foldl(~[], name_docs) {|v, name_doc|
+ do vec::foldl(~[], name_docs) |v, name_doc| {
let (name, doc) = name_doc;
v + ~[reexport_doc(doc, name)]
}
import a::b; import a::c; \
export b; export c; \
}";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = path_pass::mk_pass().f(srv, doc);
let doc = run(srv, doc);
#[test]
fn should_reexport_in_topmod() {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "core");
let doc = path_pass::mk_pass().f(srv, doc);
run(srv, doc)
#[cfg(test)]
mod test {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = path_pass::mk_pass().f(srv, doc);
run(srv, doc)
)];
let mut passno = 0;
- do vec::foldl(doc, passes) {|doc, pass|
+ do vec::foldl(doc, passes) |doc, pass| {
log(debug, #fmt("pass #%d", passno));
passno += 1;
log(debug, doc);
- do time(pass.name) {||
+ do time(pass.name) || {
pass.f(srv, doc)
}
}
}
}
let source = "";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let passes = ~[
{
name: "",
fn run(config: config::config) {
let source_file = config.input_crate;
- do astsrv::from_file(source_file) {|srv|
- do time("wait_ast") {||
- do astsrv::exec(srv) {|_ctxt| () }
+ do astsrv::from_file(source_file) |srv| {
+ do time("wait_ast") || {
+ do astsrv::exec(srv) |_ctxt| { }
};
- let doc = time("extract", {||
+ let doc = time("extract", || {
let default_name = source_file;
extract::from_srv(srv, default_name)
});
let doc = fold::default_seq_fold_iface(fold, doc);
{
- methods: do par::anymap(doc.methods) {|method|
+ methods: do par::anymap(doc.methods) |method| {
let (desc, sections) = sectionalize(method.desc);
{
let doc = fold::default_seq_fold_impl(fold, doc);
{
- methods: do par::anymap(doc.methods) {|method|
+ methods: do par::anymap(doc.methods) |method| {
let (desc, sections) = sectionalize(method.desc);
{
let mut current_section = none;
let mut sections = ~[];
- for lines.each {|line|
+ for lines.each |line| {
alt parse_header(line) {
some(header) {
if option::is_some(current_section) {
#[cfg(test)]
mod test {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass().f(srv, doc);
run(srv, doc)
export mk_pass;
fn mk_pass() -> pass {
- sort_pass::mk_pass("sort_item_name", { |item1, item2|
+ sort_pass::mk_pass("sort_item_name", |item1, item2| {
str::le(item1.name(), item2.name())
})
}
#[test]
fn test() {
let source = "mod z { } fn y() { }";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = mk_pass().f(srv, doc);
assert doc.cratemod().items[0].name() == "y";
export mk_pass;
fn mk_pass() -> pass {
- do sort_pass::mk_pass("sort_item_type") { |item1, item2|
+ do sort_pass::mk_pass("sort_item_type") |item1, item2| {
fn score(item: doc::itemtag) -> int {
alt item {
doc::consttag(_) { 0 }
iface iiface { fn a(); } \
impl iimpl for int { fn a() { } } \
type itype = int;";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = mk_pass().f(srv, doc);
assert doc.cratemod().items[0].name() == "iconst";
}
let source = "mod z { mod y { } fn x() { } } mod w { }";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = mk_pass("", name_lteq).f(srv, doc);
assert doc.cratemod().mods()[0].name() == "w";
}
let source = "mod a { mod b { } } mod c { mod d { } }";
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = mk_pass("", always_eq).f(srv, doc);
assert doc.cratemod().mods()[0].items[0].name() == "b";
}
fn maybe_apply_op(op: op, s: option<str>) -> option<str> {
- option::map(s, {|s| op(s) })
+ option::map(s, |s| op(s) )
}
fn fold_item(fold: fold::fold<op>, doc: doc::itemdoc) -> doc::itemdoc {
}
fn apply_to_sections(op: op, sections: ~[doc::section]) -> ~[doc::section] {
- par::anymap(sections, {|section, copy op|
- {
- header: op(section.header),
- body: op(section.body)
- }
+ par::anymap(sections, |section, copy op| {
+ header: op(section.header),
+ body: op(section.body)
})
}
let doc = fold::default_seq_fold_enum(fold, doc);
{
- variants: do par::anymap(doc.variants) {|variant, copy fold|
+ variants: do par::anymap(doc.variants) |variant, copy fold| {
{
desc: maybe_apply_op(fold.ctxt, variant.desc)
with variant
}
fn apply_to_methods(op: op, docs: ~[doc::methoddoc]) -> ~[doc::methoddoc] {
- do par::anymap(docs) {|doc, copy op|
+ do par::anymap(docs) |doc, copy op| {
{
brief: maybe_apply_op(op, doc.brief),
desc: maybe_apply_op(op, doc.desc),
#[cfg(test)]
mod test {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass().f(srv, doc);
let doc = desc_to_brief_pass::mk_pass().f(srv, doc);
let doc = sectionalize_pass::mk_pass().f(srv, doc);
- mk_pass("", {|s| str::trim(s)}).f(srv, doc)
+ mk_pass("", |s| str::trim(s) ).f(srv, doc)
}
}
}
export mk_pass;
fn mk_pass() -> pass {
- text_pass::mk_pass("trim", {|s| str::trim(s)})
+ text_pass::mk_pass("trim", |s| str::trim(s) )
}
#[test]
#[cfg(test)]
mod test {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass().f(srv, doc);
mk_pass().f(srv, doc)
}
fn get_fn_sig(srv: astsrv::srv, fn_id: doc::ast_id) -> option<str> {
- do astsrv::exec(srv) {|ctxt|
+ do astsrv::exec(srv) |ctxt| {
alt check ctxt.ast_map.get(fn_id) {
ast_map::node_item(@{
ident: ident,
let srv = fold.ctxt;
{
- sig: some(do astsrv::exec(srv) {|ctxt|
+ sig: some(do astsrv::exec(srv) |ctxt| {
alt check ctxt.ast_map.get(doc.id()) {
ast_map::node_item(@{
node: ast::item_const(ty, _), _
let srv = fold.ctxt;
{
- variants: do par::anymap(doc.variants) {|variant|
- let sig = do astsrv::exec(srv) {|ctxt|
+ variants: do par::anymap(doc.variants) |variant| {
+ let sig = do astsrv::exec(srv) |ctxt| {
alt check ctxt.ast_map.get(doc_id) {
ast_map::node_item(@{
node: ast::item_enum(ast_variants, _, _), _
}, _) {
let ast_variant = option::get(
- do vec::find(ast_variants) {|v|
+ do vec::find(ast_variants) |v| {
*v.node.name == variant.name
});
item_id: doc::ast_id,
docs: ~[doc::methoddoc]
) -> ~[doc::methoddoc] {
- do par::anymap(docs) {|doc|
+ do par::anymap(docs) |doc| {
{
sig: get_method_sig(srv, item_id, doc.name)
with doc
item_id: doc::ast_id,
method_name: str
) -> option<str> {
- do astsrv::exec(srv) {|ctxt|
+ do astsrv::exec(srv) |ctxt| {
alt check ctxt.ast_map.get(item_id) {
ast_map::node_item(@{
node: ast::item_iface(_, _, methods), _
}, _) {
- alt check vec::find(methods, {|method|
+ alt check vec::find(methods, |method| {
*method.ident == method_name
}) {
some(method) {
ast_map::node_item(@{
node: ast::item_impl(_, _, _, _, methods), _
}, _) {
- alt check vec::find(methods, {|method|
+ alt check vec::find(methods, |method| {
*method.ident == method_name
}) {
some(method) {
let srv = fold.ctxt;
- let (iface_ty, self_ty) = do astsrv::exec(srv) {|ctxt|
+ let (iface_ty, self_ty) = do astsrv::exec(srv) |ctxt| {
alt ctxt.ast_map.get(doc.id()) {
ast_map::node_item(@{
node: ast::item_impl(_, _, iface_ty, self_ty, _), _
}, _) {
- let iface_ty = option::map(iface_ty, {|p|
+ let iface_ty = option::map(iface_ty, |p| {
pprust::path_to_str(p.path)
});
(iface_ty, some(pprust::ty_to_str(self_ty)))
let srv = fold.ctxt;
{
- sig: do astsrv::exec(srv) {|ctxt|
+ sig: do astsrv::exec(srv) |ctxt| {
alt ctxt.ast_map.get(doc.id()) {
ast_map::node_item(@{
ident: ident,
#[cfg(test)]
mod test {
fn mk_doc(source: str) -> doc::doc {
- do astsrv::from_str(source) {|srv|
+ do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv, "");
run(srv, doc)
}
let lines = str::lines_any(s);
let mut saw_first_line = false;
let mut saw_second_line = false;
- let min_indent = do vec::foldl(uint::max_value, lines) {|min_indent, line|
+ let min_indent = do vec::foldl(uint::max_value, lines)
+ |min_indent, line| {
// After we see the first non-whitespace line, look at
// the line we have. If it is not whitespace, and therefore
} else {
saw_first_line = true;
let mut spaces = 0u;
- do str::all(line) {|char|
+ do str::all(line) |char| {
// Only comparing against space because I wouldn't
// know what to do with mixed whitespace chars
if char == ' ' {
if check vec::is_not_empty(lines) {
let unindented = ~[str::trim(vec::head(lines))]
- + do par::anymap(vec::tail(lines)) {|line|
+ + do par::anymap(vec::tail(lines)) |line| {
if str::is_whitespace(line) {
line
} else {
fn foo<T: send copy>(x: T) -> port<T> {
let p = port();
let c = chan(p);
- do task::spawn() {|copy c, copy x|
+ do task::spawn() |copy c, copy x| {
c.send(x);
}
p
class cat {
priv {
let mut meows : uint;
- fn nap() { for uint::range(1u, 10000u) {|_i|}}
+ fn nap() { for uint::range(1u, 10000u) |_i|{}}
}
let how_hungry : int;
fn alist_get<A: copy, B: copy>(lst: alist<A,B>, k: A) -> B {
let eq_fn = lst.eq_fn;
- for lst.data.each {|entry|
+ for lst.data.each |entry| {
if eq_fn(entry.key, k) { ret entry.value; }
}
fail;
self.po = po; }
drop unsafe {
#debug("in the port_ptr destructor");
- do task::unkillable {||
+ do task::unkillable || {
let yield = 0u;
let yieldp = ptr::addr_of(yield);
rustrt::rust_port_begin_detach(self.po, yieldp);
"src/test/bench/shootout-k-nucleotide.data"
);
- for int::range(0, 3) {|_i|
+ for int::range(0, 3) |_i| {
let reader = result::get(io::file_reader(path));
while !reader.eof() {
reader.read_line();
let s = map::hashmap(str::hash, str::eq);
- for int::range(0, 1000) {|_i|
+ for int::range(0, 1000) |_i| {
map::set_add(s, r.gen_str(10));
}
let mut found = 0;
- for int::range(0, 1000) {|_i|
+ for int::range(0, 1000) |_i| {
alt s.find(r.gen_str(10)) {
some(_) { found += 1; }
none { }
let r = rand::rng();
let mut v = ~[];
- for uint::range(0, 1500) {|i|
+ for uint::range(0, 1500) |i| {
let mut rv = vec::from_elem(r.gen_uint_range(0, i + 1), i);
if r.gen_bool() {
vec::push_all(v, rv);
let n = uint::from_str(args[1]).get();
- for uint::range(0u, n) {|i|
+ for uint::range(0u, n) |i| {
let x = uint::to_str(i, 10u);
log(debug, x);
}
fn collect_raw(num: uint) -> ~[uint] {
let mut result = ~[];
- for uint::range(0u, num) { |i|
+ for uint::range(0u, num) |i| {
vec::push(result, i);
}
ret result;
fn collect_dvec(num: uint) -> ~[mut uint] {
let result = dvec();
- for uint::range(0u, num) { |i|
+ for uint::range(0u, num) |i| {
result.push(i);
}
ret dvec::unwrap(result);
// check each vector
assert raw_v.len() == max;
- for raw_v.eachi { |i, v| assert i == v; }
+ for raw_v.eachi |i, v| { assert i == v; }
assert dvec_v.len() == max;
- for dvec_v.eachi { |i, v| assert i == v; }
+ for dvec_v.eachi |i, v| { assert i == v; }
let raw = mid - start;
let dvec = end - mid;
}
}
- do vec::from_fn((1u << scale) * edgefactor) {|_i|
+ do vec::from_fn((1u << scale) * edgefactor) |_i| {
choose_edge(0i64, 0i64, scale, r)
}
}
fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
- let graph = do vec::from_fn(N) {|_i|
- map::hashmap::<node_id, ()>({|x| x as uint }, {|x, y| x == y })
+ let graph = do vec::from_fn(N) |_i| {
+ map::hashmap::<node_id, ()>(|x| x as uint , |x, y| x == y )
};
- do vec::each(edges) {|e|
+ do vec::each(edges) |e| {
let (i, j) = e;
map::set_add(graph[i], j);
map::set_add(graph[j], i);
true
}
- do graph.map() {|v|
+ do graph.map() |v| {
map::vec_from_set(v)
}
}
fn gen_search_keys(graph: graph, n: uint) -> ~[node_id] {
- let keys = map::hashmap::<node_id, ()>({|x| x as uint }, {|x, y| x == y });
+ let keys = map::hashmap::<node_id, ()>(|x| x as uint , |x, y| x == y );
let r = rand::rng();
while keys.size() < n {
let k = r.gen_uint_range(0u, graph.len());
- if graph[k].len() > 0u && vec::any(graph[k], {|i|
+ if graph[k].len() > 0u && vec::any(graph[k], |i| {
i != k as node_id
}) {
map::set_add(keys, k as node_id);
while Q.size() > 0u {
let t = Q.pop_front();
- do graph[t].each() {|k|
+ do graph[t].each() |k| {
if marks[k] == -1i64 {
marks[k] = t;
Q.add_back(k);
black(node_id)
};
- let mut colors = do vec::from_fn(graph.len()) {|i|
+ let mut colors = do vec::from_fn(graph.len()) |i| {
if i as node_id == key {
gray(key)
}
// Do the BFS.
log(info, #fmt("PBFS iteration %?", i));
i += 1u;
- colors = do colors.mapi() {|i, c|
+ colors = do colors.mapi() |i, c| {
let c : color = c;
alt c {
white {
let mut color = white;
- do neighbors.each() {|k|
+ do neighbors.each() |k| {
if is_gray(colors[k]) {
color = gray(k);
false
}
// Convert the results.
- do vec::map(colors) {|c|
+ do vec::map(colors) |c| {
alt c {
white { -1i64 }
black(parent) { parent }
black(node_id)
};
- let mut colors = do vec::from_fn((*arc::get(&graph)).len()) {|i|
+ let mut colors = do vec::from_fn((*arc::get(&graph)).len()) |i| {
if i as node_id == key {
gray(key)
}
let color = arc::arc(colors);
- colors = do par::mapi_factory(*arc::get(&color)) {||
+ colors = do par::mapi_factory(*arc::get(&color)) || {
let colors = arc::clone(&color);
let graph = arc::clone(&graph);
fn~(i: uint, c: color) -> color {
let mut color = white;
- do neighbors.each() {|k|
+ do neighbors.each() |k| {
if is_gray(colors[k]) {
color = gray(k);
false
}
// Convert the results.
- do par::map(colors) {|c|
+ do par::map(colors) |c| {
alt c {
white { -1i64 }
black(parent) { parent }
log(info, "Verifying tree structure...");
let mut status = true;
- let level = do tree.map() {|parent|
+ let level = do tree.map() |parent| {
let mut parent = parent;
let mut path = ~[];
log(info, "Verifying tree edges...");
- let status = do tree.alli() {|k, parent|
+ let status = do tree.alli() |k, parent| {
if parent != root && parent != -1i64 {
level[parent] == level[k] - 1
}
log(info, "Verifying graph edges...");
- let status = do edges.all() {|e|
+ let status = do edges.all() |e| {
let (u, v) = e;
abs(level[u] - level[v]) <= 1
log(info, "Verifying tree and graph edges...");
- let status = do par::alli(tree) {|u, v|
+ let status = do par::alli(tree) |u, v| {
let u = u as node_id;
if v == -1i64 || u == root {
true
let stop = time::precise_time_s();
let mut total_edges = 0u;
- vec::each(graph, {|edges| total_edges += edges.len(); true });
+ vec::each(graph, |edges| { total_edges += edges.len(); true });
io::stdout().write_line(#fmt("Generated graph with %? edges in %? seconds.",
total_edges / 2u,
let graph_arc = arc::arc(copy graph);
- do gen_search_keys(graph, num_keys).map() {|root|
+ do gen_search_keys(graph, num_keys).map() |root| {
io::stdout().write_line("");
io::stdout().write_line(#fmt("Search key: %?", root));
num_chan: chan<uint>,
num_port: port<uint>) {
// Send/Receive lots of messages.
- for uint::range(0u, count) {|j|
+ for uint::range(0u, count) |j| {
num_chan.send(i * j);
num_port.recv();
};
// create the ring
let mut futures = ~[];
- for uint::range(1u, num_tasks) {|i|
+ for uint::range(1u, num_tasks) |i| {
let get_chan = port();
let get_chan_chan = chan(get_chan);
{
let num_chan = num_chan.clone();
- futures += ~[do future::spawn {|move num_chan, move get_chan_chan|
+ futures += ~[do future::spawn |move num_chan, move get_chan_chan| {
let p = port();
get_chan_chan.send(chan(p));
thread_ring(i, msg_per_task, num_chan, p)
thread_ring(0u, msg_per_task, num_chan, num_port);
// synchronize
- for futures.each {|f| f.get() };
+ for futures.each |f| { f.get() };
let stop = time::precise_time_s();
num_chan: comm::chan<uint>,
num_port: comm::port<uint>) {
// Send/Receive lots of messages.
- for uint::range(0u, count) {|j|
+ for uint::range(0u, count) |j| {
num_chan.send(i * j);
num_port.recv();
};
// create the ring
let mut futures = ~[];
- for uint::range(1u, num_tasks) {|i|
+ for uint::range(1u, num_tasks) |i| {
let get_chan = port();
let get_chan_chan = chan(get_chan);
- futures += ~[do future::spawn {|copy num_chan, move get_chan_chan|
+ futures += ~[do future::spawn |copy num_chan, move get_chan_chan| {
let p = port();
get_chan_chan.send(chan(p));
thread_ring(i, msg_per_task, num_chan, p)
thread_ring(0u, msg_per_task, num_chan, num_port);
// synchronize
- for futures.each {|f| f.get() };
+ for futures.each |f| { f.get() };
let stop = time::precise_time_s();
fn run(args: ~[str]) {
let from_child = comm::port();
let to_parent = comm::chan(from_child);
- let to_child = do task::spawn_listener {|po|
+ let to_child = do task::spawn_listener |po| {
server(po, to_parent);
};
let size = option::get(uint::from_str(args[1]));
let start = std::time::precise_time_s();
let to_child = to_child;
let mut worker_results = ~[];
- for uint::range(0u, workers) {|_i|
+ for uint::range(0u, workers) |_i| {
let builder = task::builder();
vec::push(worker_results, task::future_result(builder));
- do task::run(builder) {||
- for uint::range(0u, size / workers) {|_i|
+ do task::run(builder) || {
+ for uint::range(0u, size / workers) |_i| {
comm::send(to_child, bytes(100u));
}
};
}
- vec::iter(worker_results, {|r| future::get(r); });
+ vec::iter(worker_results, |r| { future::get(r); } );
comm::send(to_child, stop);
let result = comm::recv(from_child);
let end = std::time::precise_time_s();
fn make_cumulative(aa: ~[aminoacids]) -> ~[aminoacids] {
let mut cp: u32 = 0u32;
let mut ans: ~[aminoacids] = ~[];
- for aa.each {|a| cp += a.prob; ans += ~[{ch: a.ch, prob: cp}]; }
+ for aa.each |a| { cp += a.prob; ans += ~[{ch: a.ch, prob: cp}]; }
ret ans;
}
wr.write_line(">" + id + " " + desc);
let rng = @{mut last: std::rand::rng().next()};
let mut op: str = "";
- for uint::range(0u, n as uint) {|_i|
+ for uint::range(0u, n as uint) |_i| {
str::push_char(op, select_random(myrandom_next(rng, 100u32),
genelist));
if str::len(op) >= LINE_LENGTH() {
wr.write_line(">" + id + " " + desc);
let mut op: str = "";
let sl: uint = str::len(s);
- for uint::range(0u, n as uint) {|i|
+ for uint::range(0u, n as uint) |i| {
str::unsafe::push_byte(op, s[i % sl]);
if str::len(op) >= LINE_LENGTH() {
wr.write_line(op);
line = comm::recv(from_parent);
if line == ~[] { break; }
- carry = windows_with_carry(carry + line, sz, { |window|
+ carry = windows_with_carry(carry + line, sz, |window| {
update_freq(freqs, window);
total += 1u;
});
// initialize each sequence sorter
let sizes = ~[1u,2u,3u,4u,6u,12u,18u];
- let from_child = vec::map (sizes, { |_sz| comm::port() });
- let to_parent = vec::mapi(sizes, { |ii, _sz| comm::chan(from_child[ii]) });
+ let from_child = vec::map (sizes, |_sz| comm::port() );
+ let to_parent = vec::mapi(sizes, |ii, _sz| comm::chan(from_child[ii]) );
let to_child = vec::mapi(sizes, fn@(ii: uint, sz: uint) -> comm::chan<~[u8]> {
- ret do task::spawn_listener { |from_parent|
+ ret do task::spawn_listener |from_parent| {
make_sequence_processor(sz, from_parent, to_parent[ii]);
};
});
(_, true) {
let line_bytes = str::bytes(line);
- for sizes.eachi { |ii, _sz|
+ for sizes.eachi |ii, _sz| {
let mut lb = line_bytes;
comm::send(to_child[ii], lb);
}
}
// finish...
- for sizes.eachi { |ii, _sz|
+ for sizes.eachi |ii, _sz| {
comm::send(to_child[ii], ~[]);
}
// now fetch and print result messages
- for sizes.eachi { |ii, _sz|
+ for sizes.eachi |ii, _sz| {
io::println(comm::recv(from_child[ii]));
}
}
let incr = 2f64/(size as f64);
let y = incr*(i as f64) - 1f64;
let xincr = 8f64*incr;
- for uint::range(0_u, size/8_u) {
- |j|
+ for uint::range(0_u, size/8_u) |j| {
let x = {re: xincr*(j as f64) - 1.5f64, im: y};
vec::push(crv, fillbyte(x, incr));
};
let writep = comm::port();
let writech = comm::chan(writep);
- do task::spawn {||
+ do task::spawn || {
writer(path, writech, size);
};
let ch = comm::recv(writep);
- for uint::range(0_u, size) {|j|
- do task::spawn {|| chanmb(j, size, ch);};
+ for uint::range(0_u, size) |j| {
+ task::spawn(|| chanmb(j, size, ch) );
if j % yieldevery == 0_u {
#debug("Y %u", j);
task::yield();
} else {
let p = port();
let ch = chan(p);
- task::spawn({|| pfib(ch, n - 1); });
- task::spawn({|| pfib(ch, n - 2); });
+ task::spawn(|| pfib(ch, n - 1) );
+ task::spawn(|| pfib(ch, n - 2) );
send(c, recv(p) + recv(p));
}
}
let p = port();
let ch = chan(p);
- let t = task::spawn({|| pfib(ch, n); });
+ let t = task::spawn(|| pfib(ch, n) );
ret recv(p);
}
fn stress(num_tasks: int) {
let mut results = ~[];
- for range(0, num_tasks) {|i|
+ for range(0, num_tasks) |i| {
let builder = task::builder();
results += ~[task::future_result(builder)];
- task::run(builder, {|| stress_task(i); });
+ task::run(builder, || stress_task(i) );
}
- for results.each {|r| future::get(r); }
+ for results.each |r| { future::get(r); }
}
fn main(args: ~[str]) {
let out = io::stdout();
- for range(1, max + 1) {|n|
- for range(0, num_trials) {|i|
+ for range(1, max + 1) |n| {
+ for range(0, num_trials) |i| {
let start = time::precise_time_ns();
let fibn = fib(n);
let stop = time::precise_time_ns();
let p = comm::port();
let mut ch = comm::chan(p);
- for int::range(2, n_threads + 1) { |i|
+ for int::range(2, n_threads + 1) |i| {
let id = n_threads + 2 - i;
- let to_child = do task::spawn_listener::<int> {|p, copy ch|
+ let to_child = do task::spawn_listener::<int> |p, copy ch| {
roundtrip(id, p, ch)
};
ch = to_child;
import io::writer_util;
fn append_sequential(min: uint, max: uint, map: smallintmap<uint>) {
- for uint::range(min, max) { |i|
+ for uint::range(min, max) |i| {
map.insert(i, i + 22u);
}
}
fn check_sequential(min: uint, max: uint, map: smallintmap<uint>) {
- for uint::range(min, max) { |i|
+ for uint::range(min, max) |i| {
assert map.get(i) == i + 22u;
}
}
let mut checkf = 0.0;
let mut appendf = 0.0;
- for uint::range(0u, rep) {|_r|
+ for uint::range(0u, rep) |_r| {
let map = smallintmap::mk();
let start = std::time::precise_time_s();
append_sequential(0u, max, map);
if start_color < 10u8 {
// colors not yet used
let avail = bitv::bitv(10u, false);
- for u8::range(start_color, 10u8) { |color|
+ for u8::range(start_color, 10u8) |color| {
bitv::set(avail, color as uint, true);
}
drop_colors(g, avail, row, col);
// find first remaining color that is available
- for uint::range(1u, 10u) {|i|
+ for uint::range(1u, 10u) |i| {
if bitv::get(avail, i) {
g[row][col] = i as u8;
ret true;
if color != 0u8 { bitv::set(colors, color as uint, false); }
}
- let it = {|a,b|drop_color(g, avail, a, b)};
+ let it = |a,b| drop_color(g, avail, a, b);
- for u8::range(0u8, 9u8) { |idx|
+ for u8::range(0u8, 9u8) |idx| {
it(idx, col); /* check same column fields */
it(row, idx); /* check same row fields */
}
// check same block fields
let row0 = (row / 3u8) * 3u8;
let col0 = (col / 3u8) * 3u8;
- for u8::range(row0, row0 + 3u8) { |alt_row|
- for u8::range(col0, col0 + 3u8) { |alt_col| it(alt_row, alt_col); }
+ for u8::range(row0, row0 + 3u8) |alt_row| {
+ for u8::range(col0, col0 + 3u8) |alt_col| { it(alt_row, alt_col); }
}
}
let mut work: ~[(u8, u8)] = ~[]; /* queue of uncolored fields */
- for u8::range(0u8, 9u8) { |row|
- for u8::range(0u8, 9u8) { |col|
+ for u8::range(0u8, 9u8) |row| {
+ for u8::range(0u8, 9u8) |col| {
let color = (*g)[row][col];
if color == 0u8 { work += ~[(row, col)]; }
}
}
fn write_grid(f: io::writer, g: grid_t) {
- for u8::range(0u8, 9u8) { |row|
+ for u8::range(0u8, 9u8) |row| {
f.write_str(#fmt("%u", (*g)[row][0] as uint));
- for u8::range(1u8, 9u8) { |col|
+ for u8::range(1u8, 9u8) |col| {
f.write_str(#fmt(" %u", (*g)[row][col] as uint));
}
f.write_char('\n');
let grid = if vec::len(args) == 1u {
// FIXME create sudoku inline since nested vec consts dont work yet
// (#571)
- let g = vec::from_fn(10u, {|_i|
+ let g = vec::from_fn(10u, |_i| {
vec::to_mut(vec::from_elem(10u, 0 as u8))
});
g[0][1] = 4u8;
}
fn run(repeat: int, depth: int) {
- do iter::repeat(repeat as uint) { ||
+ do iter::repeat(repeat as uint) || {
#debug("starting %.4f", precise_time_s());
- do task::try { ||
+ do task::try || {
recurse_or_fail(depth, none)
};
#debug("stopping %.4f", precise_time_s());
let mut child_chs = ~[];
let mut sum = 0;
- do iter::repeat (children) {||
- do task::spawn {||
+ do iter::repeat (children) || {
+ do task::spawn || {
calc(0u, chan);
};
}
- do iter::repeat (children) {||
+ do iter::repeat (children) || {
alt check comm::recv(port) {
ready(child_ch) {
vec::push(child_chs, child_ch);
alt check comm::recv(port) {
start {
- do vec::iter (child_chs) { |child_ch|
+ do vec::iter (child_chs) |child_ch| {
comm::send(child_ch, start);
}
}
}
- do iter::repeat (children) {||
+ do iter::repeat (children) || {
alt check comm::recv(port) {
done(child_sum) { sum += child_sum; }
}
let children = uint::from_str(args[1]).get();
let port = comm::port();
let chan = comm::chan(port);
- do task::spawn {||
+ do task::spawn || {
calc(children, chan);
};
alt check comm::recv(port) {
fn f(&&n: uint) {
let mut i = 0u;
while i < n {
- do task::try {|| g() };
+ task::try(|| g() );
i += 1u;
}
}
};
let n = uint::from_str(args[1]).get();
let mut i = 0u;
- while i < n { task::spawn({|| f(n); }); i += 1u; }
+ while i < n { task::spawn(|| f(n) ); i += 1u; }
}
// These used to be in task, but they disappeard.
type joinable_task = port<()>;
-fn spawn_joinable(f: fn~()) -> joinable_task {
+fn spawn_joinable(+f: fn~()) -> joinable_task {
let p = port();
let c = chan(p);
- do task::spawn() {||
+ do task::spawn() |move f| {
f();
c.send(());
}
-> ~[joinable_task]
{
let mut tasks = ~[];
- for inputs.each {|i|
- tasks += ~[spawn_joinable({|| map_task(map, ctrl, i)})];
+ for inputs.each |i| {
+ tasks += ~[spawn_joinable(|| map_task(map, ctrl, i) )];
}
ret tasks;
}
ret none;
}
- reduce(key, {||get(p, ref_count, is_done)});
+ reduce(key, || get(p, ref_count, is_done) );
}
fn map_reduce<K1: copy send, K2: copy send, V: copy send>(
let ch = chan(p);
let r = reduce, kk = k;
tasks += ~[
- spawn_joinable({|| reduce_task(r, kk, ch) })
+ spawn_joinable(|| reduce_task(r, kk, ch) )
];
c = recv(p);
treemap::insert(reducers, k, c);
}
treemap::traverse(reducers, finish);
- for tasks.each {|t| join(t); }
+ for tasks.each |t| { join(t); }
}
}
fn start_mappers(ctrl: chan<ctrl_proto>, -inputs: ~[str]) ->
~[future::future<task::task_result>] {
let mut results = ~[];
- for inputs.each {|i|
+ for inputs.each |i| {
let builder = task::builder();
results += ~[task::future_result(builder)];
- do task::run(builder) {|| map_task(ctrl, i)}
+ task::run(builder, || map_task(ctrl, i));
}
ret results;
}
send(c, emit_val(val));
}
- map(input, {|a,b|emit(intermediates, ctrl, a, b)});
+ map(input, |a,b| emit(intermediates, ctrl, a, b) );
- for intermediates.each_value {|v| send(v, release); }
+ for intermediates.each_value |v| { send(v, release); }
send(ctrl, mapper_done);
}
ret none;
}
- reduce(key, {||get(p, state)});
+ reduce(key, || get(p, state) );
}
fn map_reduce(-inputs: ~[str]) {
let ch = chan(p);
let builder = task::builder();
results += ~[task::future_result(builder)];
- task::run(builder, {||reduce_task(k, ch)});
+ task::run(builder, || reduce_task(k, ch) );
c = recv(p);
reducers.insert(k, c);
}
}
}
- for reducers.each_value {|v| send(v, done); }
+ for reducers.each_value |v| { send(v, done); }
- for results.each {|r| future::get(r); }
+ for results.each |r| { future::get(r); }
}
}
fn main() {
fn baz(_x: fn() -> int) {}
- for baz {|_e| } //! ERROR should return `bool`
+ for baz |_e| { } //! ERROR should return `bool`
}
fn main() {
let x = 3;
fn blah(_a: native fn()) {}
- blah({||
+ blah(|| {
log(debug, x); //! ERROR attempted dynamic environment capture
});
}
\ No newline at end of file
fn compute1() -> float {
let v = ~[0f, 1f, 2f, 3f];
- do vec::foldl(0f, v) { |x, y| x + y } - 10f
+ do vec::foldl(0f, v) |x, y| { x + y } - 10f
//!^ ERROR mismatched types: expected `()`
}
fn main() {
let i = 8;
- let f = coerce({|| log(error, i); });
+ let f = coerce(|| log(error, i) );
f();
}
let mut x = @{x: 17, y: 2};
let y = @{x: 5, y: 5};
- force({|| x <- y;});
+ force(|| x <- y );
}
// error-pattern:mismatched types: expected `()` but found `bool`
fn main() {
- for vec::each(~[0]) {|_i|
+ for vec::each(~[0]) |_i| {
true
}
}
\ No newline at end of file
let mut p = ~[mut 1];
- do borrow(p) {|| //! NOTE loan of mutable vec content granted here
+ do borrow(p) || { //! NOTE loan of mutable vec content granted here
p[0] = 5; //! ERROR assigning to mutable vec content prohibited due to outstanding loan
}
}
// Legal because the scope of the borrow does not include the
// modification:
let mut p = ~[mut 1];
- borrow(p, {||});
+ borrow(p, ||{});
p[0] = 5;
}
fn loop_in_block() {
let mut v = ~3, w = ~4;
let mut _x = &mut w;
- for uint::range(0u, 10u) {|_i|
+ for uint::range(0u, 10u) |_i| {
borrow(v); //! ERROR loan of mutable variable declared in an outer block as immutable conflicts with prior loan
_x = &mut v; //! NOTE prior loan as mutable granted here
}
let mut v = ~3, w = ~4;
let mut _x = &mut w;
- do at_most_once {||
+ do at_most_once || {
borrow(v); //! ERROR loan of mutable variable declared in an outer block as immutable conflicts with prior loan
_x = &mut v; //! NOTE prior loan as mutable granted here
}
fn box_imm() {
let mut v = ~3;
let _w = &mut v; //! NOTE loan of mutable local variable granted here
- do task::spawn { |move v|
+ do task::spawn |move v| {
//!^ ERROR moving out of mutable local variable prohibited due to outstanding loan
#debug["v=%d", *v];
}
fn box_imm() {
let mut v = ~3;
- do borrow(v) { |w| //! NOTE loan of mutable local variable granted here
+ do borrow(v) |w| { //! NOTE loan of mutable local variable granted here
v = ~4; //! ERROR assigning to mutable variable declared in an outer block prohibited due to outstanding loan
assert *v == 3;
assert *w == 4;
p.impurem();
// But in this case we do not honor the loan:
- do p.blockm {|| //! NOTE loan of mutable local variable granted here
+ do p.blockm || { //! NOTE loan of mutable local variable granted here
p.x = 10; //! ERROR assigning to mutable field prohibited due to outstanding loan
}
}
fn has_mut_vec_and_does_not_try_to_change_it() {
let v = ~[mut 1, 2, 3];
- do takes_imm_elt(&v[0]) {||
+ do takes_imm_elt(&v[0]) || {
}
}
fn has_mut_vec_but_tries_to_change_it() {
let v = ~[mut 1, 2, 3];
- do takes_imm_elt(&v[0]) {|| //! NOTE loan of mutable vec content granted here
+ do takes_imm_elt(&v[0]) || { //! NOTE loan of mutable vec content granted here
v[1] = 4; //! ERROR assigning to mutable vec content prohibited due to outstanding loan
}
}
fn has_mut_vec_and_tries_to_change_it() {
let v = ~[mut 1, 2, 3];
- do takes_const_elt(&const v[0]) {||
+ do takes_const_elt(&const v[0]) || {
v[1] = 4;
}
}
fn want_slice(v: &[int]) -> int {
let mut sum = 0;
- for vec::each(v) { |i| sum += i; }
+ for vec::each(v) |i| { sum += i; }
ret sum;
}
fn main() {
let x = @3;
- foo({|| bar(x); });
+ foo(|| bar(x) );
let x = @3;
- foo({|copy x| bar(x); }); //! ERROR cannot capture values explicitly with a block closure
+ foo(|copy x| bar(x) ); //! ERROR cannot capture values explicitly with a block closure
let x = @3;
- foo({|move x| bar(x); }); //! ERROR cannot capture values explicitly with a block closure
+ foo(|move x| bar(x) ); //! ERROR cannot capture values explicitly with a block closure
}
fn f(f: fn@(int) -> bool) -> bool { f(10i) }
fn main() {
- assert do f() { |i| i == 10i } == 10i; //! ERROR: expected `bool` but found `int`
+ assert do f() |i| { i == 10i } == 10i; //! ERROR: expected `bool` but found `int`
}
let s = "";
// error is that the value type in the hash map is var_info, not a box
- for enclosing.vars.each_value {|val|
+ for enclosing.vars.each_value |val| {
if bitv::get(v, val) { s += "foo"; }
}
ret s;
fn f<T>(_x: t<T>) {}
fn main() {
- let x: t<()> = { f: { || () } }; //! ERROR expressions with stack closure
+ let x: t<()> = { f: || () }; //! ERROR expressions with stack closure
f(x);
}
fn main() {
let i = 3u;
- for uint::range(0u, 10u) {|_x| test(i)}
+ for uint::range(0u, 10u) |_x| {test(i)}
}
impl monad<A> for ~[A] {
fn bind<B>(f: fn(A) -> ~[B]) {
let mut r = fail;
- for self.each {|elt| r += f(elt); }
+ for self.each |elt| { r += f(elt); }
//!^ WARNING unreachable expression
//!^^ ERROR the type of this value must be known
}
fn fail_len(v: ~[const int]) -> uint {
let mut i = fail;
- for v.each {|x| i += 1u; }
+ for v.each |x| { i += 1u; }
//!^ WARNING unreachable statement
//!^^ ERROR the type of this value must be known
ret i;
fn main() {
- do vec::iter(fail) {|i|
+ do vec::iter(fail) |i| {
log (debug, i * 2);
//!^ ERROR the type of this value must be known
};
drop { }
fn set_identity() {
- do closure { ||
+ do closure || {
setsockopt_bytes(self.sock) //! ERROR copying a noncopyable value
}
}
fn foo() {
// Here, i is *moved* into the closure: Not actually OK
let mut i = 0;
- do task::spawn {||
+ do task::spawn || {
use(i); //! ERROR mutable variables cannot be implicitly captured
}
}
// is mutable: bad
let mut i = 0;
while i < 10 {
- do task::spawn {||
+ do task::spawn || {
use(i); //! ERROR mutable variables cannot be implicitly captured
}
i += 1;
// Here, i is mutable, but *explicitly* copied:
let mut i = 0;
while i < 10 {
- do task::spawn {|copy i|
+ do task::spawn |copy i| {
use(i);
}
i += 1;
fn main() {
let i = 0;
- let ctr = fn@ () -> int { f2({|| i = i + 1; }); ret i; };
+ let ctr = fn@ () -> int { f2(|| i = i + 1 ); ret i; };
log(error, ctr());
log(error, ctr());
log(error, ctr());
+// xfail-test After the closure syntax change this started failing with the wrong error message
// error-pattern: not all control paths return
fn force(f: fn() -> int) -> int { f() }
-fn main() { log(error, force({|| })); }
+fn main() { log(error, force(|| {})); }
+// xfail-test After the closure syntax change this started failing with the wrong error message
fn main(_s: ~[str]) {
let a: ~[int] = ~[];
- do vec::each(a) { |_x| //! ERROR not all control paths return a value
+ do vec::each(a) |_x| { //! ERROR not all control paths return a value
}
}
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::arc(v);
- do task::spawn() {||
+ do task::spawn() || {
let v = *arc::get(&arc_v);
assert v[3] == 4;
};
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::arc(v);
- do task::spawn() {|move arc_v| //! NOTE move of variable occurred here
+ do task::spawn() |move arc_v| { //! NOTE move of variable occurred here
let v = *arc::get(&arc_v);
assert v[3] == 4;
};
let x = ~mut some(foo(comm::port()));
- do task::spawn {|move x| //! ERROR not a sendable value
+ do task::spawn |move x| { //! ERROR not a sendable value
let mut y = none;
*x <-> y;
log(error, y);
class cat {
priv {
let mut meows : uint;
- fn nap() { uint::range(1u, 10000u, {|_i|})}
+ fn nap() { uint::range(1u, 10000u, |_i|{})}
}
let how_hungry : int;
}
pure fn range2(from: uint, to: uint, f: fn(uint)) {
- do range(from, to) { |i|
+ do range(from, to) |i| {
f(i*2u);
}
}
}
pure fn range7(from: uint, to: uint) {
- do range(from, to) { |i|
+ do range(from, to) |i| {
print(i); //! ERROR access to impure function prohibited in pure context
}
}
}
pure fn range2(from: uint, to: uint, f: fn(uint)) {
- for range(from, to) { |i|
+ for range(from, to) |i| {
f(i*2u);
}
}
pure fn range3(from: uint, to: uint, f: {x: fn(uint)}) {
- for range(from, to) { |i|
+ for range(from, to) |i| {
f.x(i*2u); //! ERROR access to impure function prohibited
}
}
}
fn chase_cat() {
- do uint::range(0u, 10u) { |i|
+ for uint::range(0u, 10u) |i| {
let p: &static.mut uint = &mut self.food; //! ERROR mismatched types
*p = 3u;
}
y += ~[&mut z];
x += 1;
}
- vec::foldl(0, y, {|v, p| v + *p })
+ vec::foldl(0, y, |v, p| v + *p )
//!^ ERROR reference is not valid
//!^^ ERROR reference is not valid
//!^^^ ERROR reference is not valid
//!^ ERROR mismatched types: expected `&x.int` but found `&y.int`
fail;
}
- ) {|foo|
+ ) |foo| {
- let a: &x.int = foo(x, x, { |_x, _y, z| z });
- let b: &x.int = foo(x, a, { |_x, _y, z| z });
- let c: &x.int = foo(a, a, { |_x, _y, z| z });
+ let a: &x.int = foo(x, x, |_x, _y, z| z );
+ let b: &x.int = foo(x, a, |_x, _y, z| z );
+ let c: &x.int = foo(a, a, |_x, _y, z| z );
let z = 3i;
- let d: &x.int = foo(x, x, { |_x, _y, z| z });
- let e: &x.int = foo(x, &z, { |_x, _y, z| z });
- let f: &x.int = foo(&z, &z, { |_x, _y, z| z }); //! ERROR mismatched types: expected `&x.int` but found
+ let d: &x.int = foo(x, x, |_x, _y, z| z );
+ let e: &x.int = foo(x, &z, |_x, _y, z| z );
+ let f: &x.int = foo(&z, &z, |_x, _y, z| z ); //! ERROR mismatched types: expected `&x.int` but found
- foo(x, &z, { |x, _y, _z| x }); //! ERROR mismatched types: expected `&z.int` but found `&x.int`
- foo(x, &z, { |_x, y, _z| y }); //! ERROR mismatched types: expected `&z.int` but found `&<block at
+ foo(x, &z, |x, _y, _z| x ); //! ERROR mismatched types: expected `&z.int` but found `&x.int`
+ foo(x, &z, |_x, y, _z| y ); //! ERROR mismatched types: expected `&z.int` but found `&<block at
}
}
let mut r = ~[];
// Earlier versions of our type checker accepted this:
- vec::iter(v, {|&&inner: ~[T]|
+ vec::iter(v, |&&inner: ~[T]| {
//!^ ERROR values differ in mutability
r += inner;
});
+// FIXME: The disambiguation the pretty printer does here
+// is probably not necessary anymore
+
fn blk1(b: fn()) -> fn@() { ret fn@() { }; }
-fn test1() { (do blk1 {|| #debug["hi"]; })(); }
+fn test1() { (do blk1 || { #debug["hi"]; })(); }
fn id(f: fn() -> int) -> int { f() }
-fn wsucc(n: int) -> int { (do id {|| 1 }) - 0 }
+fn wsucc(n: int) -> int { (do id || { 1 }) - 0 }
fn main() { }
fn f(f: fn@(int)) { f(10) }
fn main() {
- do f { |i| assert i == 10 }
+ do f |i| { assert i == 10 }
}
// huge).
let x = ~[1u,2u,3u];
- do vec::unpack_slice(x) {|p, _len|
+ do vec::unpack_slice(x) |p, _len| {
let base = p as uint; // base = 0x1230 say
let idx = base / sys::size_of::<uint>(); // idx = 0x0246 say
#error("ov1 base = 0x%x", base);
}
fn main() {
- do iter::repeat(10u) {||
- do task::spawn {||
+ do iter::repeat(10u) || {
+ do task::spawn || {
let result = count(5u);
#debug("result = %?", result);
fail;
// error-pattern:moop
use std;
import uint;
-fn main() { uint::range(0u, 10u, {|_i| fail "moop"; }); }
+fn main() { for uint::range(0u, 10u) |_i| { fail "moop"; } }
// Don't leak when the landing pads need to request more stack
// than is allowed during normal execution
-fn useBlock(f: fn~() -> uint) { useBlock({|| 22u }) }
+fn useBlock(f: fn~() -> uint) { useBlock(|| 22u ) }
fn main() {
- useBlock({|| 22u });
+ useBlock(|| 22u );
}
import io::{reader, reader_util};
fn main() {
- do io::with_str_reader("") { |rdr|
+ do io::with_str_reader("") |rdr| {
alt rdr.read_char() { '=' { } _ { fail } }
}
}
fn main() {
let p = port::<int>();
- task::spawn({|| child(); });
+ task::spawn(|| child() );
let x = recv(p);
}
fn main() {
let p = port::<int>();
- task::spawn({|| child(); });
+ task::spawn(|| child() );
task::yield();
}
fn child() {
let p = port::<int>();
- task::spawn({|| grandchild(); });
+ task::spawn(|| grandchild() );
let x = recv(p);
}
fn main() {
let p = port::<int>();
- task::spawn({|| child(); });
+ task::spawn(|| child() );
let x = recv(p);
}
fn parent() {
let p = port::<int>();
- task::spawn({|| child(); });
+ task::spawn(|| child() );
let x = recv(p);
}
}
fn main() {
- task::spawn({|| sleeper(); });
- task::spawn({|| parent(); });
+ task::spawn(|| sleeper() );
+ task::spawn(|| parent() );
}
\ No newline at end of file
}
fn main() {
- do task::spawn {||
+ do task::spawn || {
let r = and_then_get_big_again(4);
getbig_call_c_and_fail(10000);
};
}
fn main() {
- do task::spawn {||
+ do task::spawn || {
getbig_and_fail(400);
};
}
\ No newline at end of file
}
fn main() {
- do task::spawn {||
+ do task::spawn || {
getbig_and_fail(1);
};
}
\ No newline at end of file
fn main() {
log(error, "whatever");
- do task::spawn {||
+ do task::spawn || {
let i = r(5);
};
fail;
fn f() {
fail;
}
- task::spawn({|| f(); });
+ task::spawn(|| f() );
}
\ No newline at end of file
}
fn main() {
- task::spawn({|| goodfail(); });
+ task::spawn(|| goodfail() );
let po = comm::port();
// We shouldn't be able to get past this recv since there's no
// message available
fn main() {
let a = @0;
- x({|_i|});
+ x(|_i| { } );
}
\ No newline at end of file
}
fn main() {
- x({|_x| fail; });
+ x(|_x| fail );
}
\ No newline at end of file
fn@(tasties: @str, macerate: fn(str)) {
macerate(*tasties);
- } (carrots, { |food|
+ } (carrots, |food| {
let mush = food + cheese;
let f = fn@() {
let chew = mush + cheese;
let map = map::hashmap(hash, eq);
let mut arr = ~[];
- for uint::range(0u, 10u) {|i|
+ for uint::range(0u, 10u) |i| {
arr += ~[@"key stuff"];
map.insert(arr, arr + ~[@"value stuff"]);
}
// issue #1926
let s = #ast(expr){__s};
let e = #ast(expr){__e};
- let call = #ast(expr){$(s).foo({|__e| $(e)})};
- check_pp(call, pprust::print_expr, "__s.foo({|__e| __e })")
+ let call = #ast(expr){$(s).foo(|__e| $(e) )};
+ check_pp(call, pprust::print_expr, "__s.foo(|__e| __e)")
}
fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: str) {
fn main() {
let mut x = true;
alt a {
- a { x = true; foo({|_i|}) }
+ a { x = true; foo(|_i| { } ) }
b { x = false; }
c { x = false; }
}
assert (f1(a, b, c) == 6);
assert (a.x == 0);
assert (b == 10);
- assert (f2(a.x, {|x| a.x = 50; }) == 0);
+ assert (f2(a.x, |x| a.x = 50 ) == 0);
assert (a.x == 50);
}
fn main(args: ~[str]) {
let vs: ~[str] = ~["hi", "there", "this", "is", "a", "vec"];
let vvs: ~[~[str]] = ~[args, vs];
- for vvs.each {|vs| for vs.each {|s| log(debug, s); } }
+ for vvs.each |vs| { for vs.each |s| { log(debug, s); } }
}
fn main() {
let mut sum = 0;
- for vec::each(~[1, 2, 3, 4, 5]) {|x| sum += x; }
+ for vec::each(~[1, 2, 3, 4, 5]) |x| { sum += x; }
assert (sum == 15);
}
// check the pretty printer:
io_ser_fn(io::stdout(), a1);
- let s = io::with_str_writer({|w| io_ser_fn(w, a1) });
+ let s = io::with_str_writer(|w| io_ser_fn(w, a1) );
#debug["s == %?", s];
assert s == expected;
fn main() {
let p = port();
let ch = chan(p);
- task::spawn({|| a(ch); });
- task::spawn({|| a(ch); });
+ task::spawn(|| a(ch) );
+ task::spawn(|| a(ch) );
let mut n: int = 0;
n = recv(p);
n = recv(p);
fn main() {
let p = port();
let ch = chan(p);
- task::spawn({|| a(ch); });
- task::spawn({|| b(ch); });
+ task::spawn(|| a(ch) );
+ task::spawn(|| b(ch) );
let mut n: int = 0;
n = recv(p);
n = recv(p);
let s: str = "hello there";
let p = comm::port();
let ch = comm::chan(p);
- task::spawn({|| a(ch); });
- task::spawn({|| b(ch); });
+ task::spawn(|| a(ch) );
+ task::spawn(|| b(ch) );
let mut x: int = 10;
x = g(n, s);
log(debug, x);
}
fn main() {
- let x = asSendfn({|| 22u});
+ let x = asSendfn(|| 22u);
assert(x == 22u);
- let x = asLambda({|| 22u});
+ let x = asLambda(|| 22u);
assert(x == 22u);
- let x = asBlock({|| 22u});
+ let x = asBlock(|| 22u);
assert(x == 22u);
}
fn main() {
let v = ~[-1f, 0f, 1f, 2f, 3f];
- // Trailing expressions require parentheses:
- let y = vec::foldl(0f, v, { |x, y| x + y }) + 10f;
+ // Trailing expressions don't require parentheses:
+ let y = do vec::foldl(0f, v) |x, y| { x + y } + 10f;
assert y == 15f;
}
fn main() {
fn f(i: fn() -> uint) -> uint { i() }
let v = ~[-1f, 0f, 1f, 2f, 3f];
- let z = do do vec::foldl(f, v) { |x, _y| x } { || 22u };
+ let z = do do vec::foldl(f, v) |x, _y| { x } || { 22u };
assert z == 22u;
}
fn main() {
fn f(i: uint) -> uint { i }
let v = ~[-1f, 0f, 1f, 2f, 3f];
- let z = do vec::foldl(f, v) { |x, _y| x } (22u);
+ let z = do vec::foldl(f, v) |x, _y| { x } (22u);
assert z == 22u;
}
fn w_semi(v: ~[int]) -> int {
// the semicolon causes compiler not to
// complain about the ignored return value:
- do vec::foldl(0, v) {|x,y| x+y};
+ do vec::foldl(0, v) |x,y| { x+y };
-10
}
fn w_paren1(v: ~[int]) -> int {
- (do vec::foldl(0, v) {|x,y| x+y}) - 10
+ (do vec::foldl(0, v) |x,y| { x+y }) - 10
}
fn w_paren2(v: ~[int]) -> int {
- (do vec::foldl(0, v) {|x,y| x+y} - 10)
+ (do vec::foldl(0, v) |x,y| { x+y} - 10)
}
fn w_ret(v: ~[int]) -> int {
- ret do vec::foldl(0, v) {|x,y| x+y} - 10;
+ ret do vec::foldl(0, v) |x,y| { x+y } - 10;
}
fn main() {
}
fn main() {
- let x_r = do call_any {|| 22u };
+ let x_r = do call_any || { 22u };
assert x_r == 22u;
}
}
fn main() {
- let x: fn@(uint) -> uint = to_lambda({ |x| x * 2u });
+ let x: fn@(uint) -> uint = to_lambda(|x| x * 2u );
let y = to_lambda(x);
let x_r = x(22u);
let v = ~[-1f, 0f, 1f, 2f, 3f];
// Statement form does not require parentheses:
- vec::iter(v, { |i|
+ do vec::iter(v) |i| {
log(info, i);
- });
+ }
// Usable at all:
- let mut any_negative = vec::any(v, { |e| float::is_negative(e) });
+ let mut any_negative = do vec::any(v) |e| { float::is_negative(e) };
assert any_negative;
// Higher precedence than assignments:
- any_negative = vec::any(v, { |e| float::is_negative(e) });
+ any_negative = do vec::any(v) |e| { float::is_negative(e) };
assert any_negative;
// Higher precedence than unary operations:
- let abs_v = vec::map(v, { |e| float::abs(e) });
- assert vec::all(abs_v, { |e| float::is_nonnegative(e) });
- assert !vec::any(abs_v, { |e| float::is_negative(e) });
+ let abs_v = do vec::map(v) |e| { float::abs(e) };
+ assert do vec::all(abs_v) |e| { float::is_nonnegative(e) };
+ assert !do vec::any(abs_v) |e| { float::is_negative(e) };
// Usable in funny statement-like forms:
- if !vec::any(v, { |e| float::is_positive(e) }) {
+ if !do vec::any(v) |e| { float::is_positive(e) } {
assert false;
}
- alt vec::all(v, { |e| float::is_negative(e) }) {
+ alt do vec::all(v) |e| { float::is_negative(e) } {
true { fail "incorrect answer."; }
false { }
}
alt 3 {
- _ if vec::any(v, { |e| float::is_negative(e) }) {
+ _ if do vec::any(v) |e| { float::is_negative(e) } {
}
_ {
fail "wrong answer.";
// Lower precedence than binary operations:
- let w = vec::foldl(0f, v, { |x, y| x + y }) + 10f;
- let y = vec::foldl(0f, v, { |x, y| x + y }) + 10f;
- let z = 10f + vec::foldl(0f, v, { |x, y| x + y });
+ let w = do vec::foldl(0f, v) |x, y| { x + y } + 10f;
+ let y = do vec::foldl(0f, v) |x, y| { x + y } + 10f;
+ let z = 10f + do vec::foldl(0f, v) |x, y| { x + y };
assert w == y;
assert y == z;
- // They are not allowed as the tail of a block without parentheses:
+ // In the tail of a block
let w =
- if true { vec::any(abs_v, { |e| float::is_nonnegative(e) }) }
+ if true { do vec::any(abs_v) |e| { float::is_nonnegative(e) } }
else { false };
assert w;
}
fn main() {
fn as_buf<T>(s: str, f: fn(str) -> T) -> T { f(s) }
- as_buf("foo", {|foo: str| -> () log(error, foo);});
+ as_buf("foo", |foo: str| -> () log(error, foo) );
}
-fn iter_vec<T>(v: ~[T], f: fn(T)) { for v.each {|x| f(x); } }
+fn iter_vec<T>(v: ~[T], f: fn(T)) { for v.each |x| { f(x); } }
fn main() {
let v = ~[1, 2, 3, 4, 5, 6, 7];
let mut odds = 0;
- iter_vec(v, {|i|
+ iter_vec(v, |i| {
log(error, i);
if i % 2 == 1 {
odds += 1;
-fn iter_vec<T>(v: ~[T], f: fn(T)) { for v.each {|x| f(x); } }
+fn iter_vec<T>(v: ~[T], f: fn(T)) { for v.each |x| { f(x); } }
fn main() {
let v = ~[1, 2, 3, 4, 5];
let mut sum = 0;
- iter_vec(v, {|i|
- iter_vec(v, {|j|
+ iter_vec(v, |i| {
+ iter_vec(v, |j| {
log(error, i * j);
sum += i * j;
});
let v =
vec::map2(~[1, 2, 3, 4, 5],
~[true, false, false, true, true],
- {|i, b| if b { -i } else { i } });
+ |i, b| if b { -i } else { i } );
log(error, v);
assert (v == ~[-1, 2, 3, -4, -5]);
}
fn test1(x: @~int) {
// Right now, at least, this induces a copy of the unique pointer:
- do borrow({*x}) { |p|
+ do borrow({*x}) |p| {
let x_a = ptr::addr_of(**x);
assert (x_a as uint) != (p as uint);
assert unsafe{*x_a} == *p;
fn want_slice(v: &[int]) -> int {
let mut sum = 0;
- for vec::each(v) { |i| sum += i; }
+ for vec::each(v) |i| { sum += i; }
ret sum;
}
fn main() {
let mut x = @{f: ~3};
- do borrow(x.f) {|b_x|
+ do borrow(x.f) |b_x| {
assert *b_x == 3;
assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x);
x = @{f: ~4};
fn main() {
let mut x = ~mut @{f: ~3};
- do borrow(x.f) {|b_x|
+ do borrow(x.f) |b_x| {
assert *b_x == 3;
assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x);
*x = @{f: ~4};
fn main() {
let mut x = @3;
- do borrow(x) {|b_x|
+ do borrow(x) |b_x| {
assert *b_x == 3;
assert ptr::addr_of(*x) == ptr::addr_of(*b_x);
x = @22;
fn main() {
let mut x = @{f: ~3};
- do borrow((*x).f) {|b_x|
+ do borrow((*x).f) |b_x| {
assert *b_x == 3;
assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x);
x = @{f: ~4};
assert (i == 10);
loop { i += 1; if i == 20 { break; } }
assert (i == 20);
- for vec::each(~[1, 2, 3, 4, 5, 6]) {|x|
+ for vec::each(~[1, 2, 3, 4, 5, 6]) |x| {
if x == 3 { break; } assert (x <= 3);
}
i = 0;
i += 1; if i % 2 == 0 { cont; } assert (i % 2 != 0);
if i >= 10 { break; }
}
- for vec::each(~[1, 2, 3, 4, 5, 6]) {|x|
+ for vec::each(~[1, 2, 3, 4, 5, 6]) |x| {
if x % 2 == 0 { cont; }
assert (x % 2 != 0);
}
let x = ~2;
let y = ptr::addr_of(*x) as uint;
- let lam_copy: fn@() -> uint = { |copy x| ptr::addr_of(*x) as uint };
- let lam_move: fn@() -> uint = { |move x| ptr::addr_of(*x) as uint };
+ let lam_copy: fn@() -> uint = |copy x| ptr::addr_of(*x) as uint;
+ let lam_move: fn@() -> uint = |move x| ptr::addr_of(*x) as uint;
assert lam_copy() != y;
assert lam_move() == y;
let x = ~4;
let y = ptr::addr_of(*x) as uint;
- let lam_copy: fn~() -> uint = { |copy x| ptr::addr_of(*x) as uint };
- let lam_move: fn~() -> uint = { |move x| ptr::addr_of(*x) as uint };
+ let lam_copy: fn~() -> uint = |copy x| ptr::addr_of(*x) as uint;
+ let lam_move: fn~() -> uint = |move x| ptr::addr_of(*x) as uint;
assert lam_copy() != y;
assert lam_move() == y;
}
//let bt0 = sys::frame_address();
//#debug["%?", bt0];
- do 3u.to(10u) {|i|
+ do 3u.to(10u) |i| {
io::print(#fmt["%u\n", i]);
//let bt1 = sys::frame_address();
fn main() {
//let bt0 = sys::rusti::frame_address(1u32);
//#debug["%?", bt0];
- do cci_iter_lib::iter(~[1, 2, 3]) {|i|
+ do cci_iter_lib::iter(~[1, 2, 3]) |i| {
io::print(#fmt["%d", i]);
//assert bt0 == sys::rusti::frame_address(2u32);
}
// actually working.
//let bt0 = sys::frame_address();
//#debug["%?", bt0];
- do iter(~[1u, 2u, 3u]) {|i|
+ do iter(~[1u, 2u, 3u]) |i| {
io::print(#fmt["%u\n", i]);
//let bt1 = sys::frame_address();
fn new_cx() -> ctx {
let p = port();
let ch = chan(p);
- let t = task::spawn({|| request_task(ch); });
+ let t = task::spawn(|| request_task(ch) );
let mut cx: ctx;
cx = recv(p);
ret cx;
fn child2(&&s: str) { }
-fn main() { let x = task::spawn({|| child2("hi"); }); }
+fn main() { let x = task::spawn(|| child2("hi") ); }
}
fn annoy_neighbors<T: noisy>(critter: T) {
- for uint::range(0u, 10u) {|i| critter.speak(); }
+ for uint::range(0u, 10u) |i| { critter.speak(); }
}
fn main() {
self.map = map;
}
- fn each(blk: fn(K) -> bool) { self.map.each({ |k, _v| blk(k)}) }
+ fn each(blk: fn(K) -> bool) { self.map.each(|k, _v| blk(k) ) }
fn size_hint() -> option<uint> { some(self.map.size()) }
fn eachi(blk: fn(uint, K) -> bool) { iter::eachi(self, blk) }
}
}
}
fn each_key(&&f: fn(&&int) -> bool) {
- for self.each {|k, _v| if !f(k) { break; } cont;};
+ for self.each |k, _v| { if !f(k) { break; } cont;};
}
fn each_value(&&f: fn(&&bool) -> bool) {
- for self.each {|_k, v| if !f(v) { break; } cont;};
+ for self.each |_k, v| { if !f(v) { break; } cont;};
}
}
fn main() {
let nyan : cat = cat(0, 2, "nyan");
- for uint::range(1u, 5u) {|_i| nyan.speak(); }
+ for uint::range(1u, 5u) |_i| { nyan.speak(); }
// cat returns true if uint input is greater than
// the number of meows so far
assert(nyan.get(1));
}
fn each_key(&&f: fn(&&int) -> bool) {
- for self.each {|k, _v| if !f(k) { break; } cont;};
+ for self.each |k, _v| { if !f(k) { break; } cont;};
}
fn each_value(&&f: fn(&&T) -> bool) {
- for self.each {|_k, v| if !f(v) { break; } cont;};
+ for self.each |_k, v| { if !f(v) { break; } cont;};
}
}
fn main() {
let nyan : cat<str> = cat(0, 2, "nyan");
- for uint::range(1u, 5u) {|_i| nyan.speak(); }
+ for uint::range(1u, 5u) |_i| { nyan.speak(); }
assert(nyan.find(1) == some("nyan"));
assert(nyan.find(10) == none);
let spotty : cat<cat_type> = cat(2, 57, tuxedo);
- for uint::range(0u, 6u) {|_i| spotty.speak(); }
+ for uint::range(0u, 6u) |_i| { spotty.speak(); }
assert(spotty.size() == 8u);
assert(spotty.contains_key(2));
assert(spotty.get(3) == tuxedo);
let nyan = cat(0u, 2, "nyan");
nyan.eat();
assert(!nyan.eat());
- for uint::range(1u, 10u) {|_i| nyan.speak(); };
+ for uint::range(1u, 10u) |_i| { nyan.speak(); };
assert(nyan.eat());
}
\ No newline at end of file
let nyan = cat(0u, 2, "nyan");
nyan.eat();
assert(!nyan.eat());
- for uint::range(1u, 10u) {|_i| make_speak(nyan); };
+ for uint::range(1u, 10u) |_i| { make_speak(nyan); };
assert(nyan.eat());
}
\ No newline at end of file
}
fn vec_includes<T>(xs: ~[T], x: T) -> bool {
- for each(xs) {|y| if y == x { ret true; }}
+ for each(xs) |y| { if y == x { ret true; }}
ret false;
}
let t : hashmap<body_part, uint> =
hashmap::<body_part, uint>(hsher, eqer);
self.bite_counts = t;
- do iter(~[finger, toe, nose, ear]) {|p|
+ do iter(~[finger, toe, nose, ear]) |p| {
self.bite_counts.insert(p, 0u);
};
}
let all = ~[chair, couch, bed];
log(error, self.scratched);
let mut rslt = none;
- for each(all) {|thing| if !self.scratched.contains(thing) {
+ for each(all) |thing| { if !self.scratched.contains(thing) {
self.scratched.push(thing);
ret some(thing); }}
rslt
#error("In bite()");
let all = ~[toe, nose, ear];
let mut min = finger;
- do iter(all) {|next|
+ do iter(all) |next| {
#debug("min = %?", min);
if self.bite_counts.get(next) < self.bite_counts.get(min) {
min = next;
}
fn annoy_neighbors<T: noisy>(critter: T) {
- for uint::range(0u, 10u) {|i|
+ for uint::range(0u, 10u) |i| {
let what = critter.speak();
#debug("%u %d", i, what);
}
let part = critter.bite();
#debug("%? %?", left, part);
if vec_includes(left, part) {
- left = vec::filter(left, {|p| p != part});
+ left = vec::filter(left, |p| p != part );
}
else {
ret false;
let nyan = cat(0u, 2, "nyan");
nyan.eat();
assert(!nyan.eat());
- for uint::range(1u, 10u) {|_i| nyan.speak(); };
+ for uint::range(1u, 10u) |_i| { nyan.speak(); };
assert(nyan.eat());
}
\ No newline at end of file
let nyan = cat(0u, 2, "nyan");
nyan.eat();
assert(!nyan.eat());
- for uint::range(1u, 10u) {|_i| nyan.speak(); };
+ for uint::range(1u, 10u) |_i| { nyan.speak(); };
assert(nyan.eat());
}
\ No newline at end of file
fn adder(+x: @int, +y: @int) -> int { ret *x + *y; }
fn failer() -> @int { fail; }
fn main() {
- assert(result::is_err(task::try({||
+ assert(result::is_err(task::try(|| {
adder(@2, failer()); ()
})));
}
fn main() {
let p = comm::port();
let ch = comm::chan(p);
- let t = task::spawn({|| child(ch); });
+ let t = task::spawn(|| child(ch) );
let y = recv(p);
#error("received");
log(error, y);
fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
- do task::spawn {||
+ do task::spawn || {
let result = count(1000u);
#debug("result = %?", result);
assert result == 1000u;
fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
- do task::spawn {||
+ do task::spawn || {
let result = count(12u);
#debug("result = %?", result);
assert result == 2048u;
}
fn main() {
- do iter::repeat(100u) {||
- do task::spawn {||
+ do iter::repeat(100u) || {
+ do task::spawn || {
assert count(5u) == 16u;
};
}
}
fn main() {
- do iter::repeat(10u) {||
- do task::spawn {||
+ do iter::repeat(10u) || {
+ do task::spawn || {
let result = count(5u);
#debug("result = %?", result);
assert result == 16u;
}
pure fn g() {
- // `f { || }` is considered pure, so `do f { || }` should be too
- do f { || }
+ // `f || { }` is considered pure, so `do f || { }` should be too
+ do f || { }
}
fn main() {
fn f(f: fn&(int)) { f(10) }
fn main() {
- do f() { |i| assert i == 10 }
+ do f() |i| { assert i == 10 }
}
fn f(f: fn@(int)) { f(10) }
fn main() {
- do f() { |i| assert i == 10 }
+ do f() |i| { assert i == 10 }
}
fn f(f: fn@(int) -> int) -> int { f(10) }
fn main() {
- assert do f() { |i| i } == 10;
+ assert do f() |i| { i } == 10;
}
fn f(f: fn@(int) -> int) -> int { f(10) }
fn main() {
- assert do f { |i| i } == 10;
+ assert do f |i| { i } == 10;
}
assert d.get() == exp;
assert d.len() == exp.len();
- for d.eachi { |i, e|
+ for d.eachi |i, e| {
assert e == exp[i];
}
fn main() {
- for vec::each(~[{x: 10, y: 20}, {x: 30, y: 0}]) {|elt|
+ for vec::each(~[{x: 10, y: 20}, {x: 30, y: 0}]) |elt| {
assert (elt.x + elt.y == 30);
}
}
-fn main() { let x: ~[int] = ~[]; for x.each {|_i| fail "moop"; } }
+fn main() { let x: ~[int] = ~[]; for x.each |_i| { fail "moop"; } }
fn main() {
let a: ~[mut int] = ~[mut -1, -1, -1, -1];
let mut p: int = 0;
- do two {|i|
- do two {|j| a[p] = 10 * i + j; p += 1; }
+ do two |i| {
+ do two |j| { a[p] = 10 * i + j; p += 1; }
}
assert (a[0] == 0);
assert (a[1] == 1);
fn main() {
let mut i: int = 10;
let mut j: int = 0;
- do pairs() {|p|
+ do pairs() |p| {
let (_0, _1) = p;
log(debug, _0);
log(debug, _1);
// -*- rust -*-
fn main() {
let mut sum: int = 0;
- do first_ten {|i| #debug("main"); log(debug, i); sum = sum + i; }
+ do first_ten |i| { #debug("main"); log(debug, i); sum = sum + i; }
#debug("sum");
log(debug, sum);
assert (sum == 45);
enum ctrl_proto { find_reducer(~[u8], chan<int>), mapper_done, }
fn start_mappers(ctrl: chan<ctrl_proto>, inputs: ~[str]) {
- for inputs.each {|i|
- do task::spawn {|| map_task(ctrl, i); }
+ for inputs.each |i| {
+ task::spawn(|| map_task(ctrl, i) );
}
}
}
}
- map(input, {|a,b|emit(intermediates, ctrl, a, b)});
+ map(input, |a,b| emit(intermediates, ctrl, a, b) );
send(ctrl, mapper_done);
}
impl <T> of map<T> for ~[T] {
fn map<U>(f: fn(T) -> U) -> ~[U] {
let mut r = ~[];
- for self.each {|x| r += ~[f(x)]; }
+ for self.each |x| { r += ~[f(x)]; }
r
}
}
fn foo<U, T: map<U>>(x: T) -> ~[str] {
- x.map({|_e| "hi" })
+ x.map(|_e| "hi" )
}
fn bar<U: to_str, T: map<U>>(x: T) -> ~[str] {
- x.map({|_e| _e.to_str() })
+ x.map(|_e| _e.to_str() )
}
fn main() {
impl <T: to_str> of to_str for ~[T] {
fn to_str() -> str {
- "[" + str::connect(vec::map(self, {|e| e.to_str()}), ", ") + "]"
+ "[" + str::connect(vec::map(self, |e| e.to_str() ), ", ") + "]"
}
}
fn eat_rec(_r: @~{a: int, b: fn@({x: int, y: int}) -> int}) {}
fn main() {
- eat_tup(~@(10, {|a| a.x}));
- eat_rec(@~{a: 10, b: {|a| a.x}});
+ eat_tup(~@(10, |a| a.x ));
+ eat_rec(@~{a: 10, b: |a| a.x });
}
}
fn main() {
- do rusti::frame_address {|addr|
+ do rusti::frame_address |addr| {
assert addr.is_not_null();
}
}
}
impl of iterable<uint> for fn@(fn(uint)) {
- fn iter(blk: fn(&&uint)) { self({ |i| blk(i) }) }
+ fn iter(blk: fn(&&uint)) { self( |i| blk(i) ) }
}
fn filter<A,IA:iterable<A>>(self: IA, prd: fn@(A) -> bool, blk: fn(A)) {
- do self.iter {|a|
+ do self.iter |a| {
if prd(a) { blk(a) }
}
}
fn foldl<A,B,IA:iterable<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
let mut b <- b0;
- do self.iter { |a|
+ do self.iter |a| {
b <- blk(b, a);
}
ret b;
}
fn main() {
- let range = {|a|range(0u, 1000u, a)};
- let filt = {|a|filter(
+ let range = |a| range(0u, 1000u, a);
+ let filt = |a| filter(
range,
- {|&&n: uint| n % 3u != 0u && n % 5u != 0u },
- a)};
- let sum = foldl(filt, 0u, {|accum, &&n: uint| accum + n });
+ |&&n: uint| n % 3u != 0u && n % 5u != 0u,
+ a);
+ let sum = foldl(filt, 0u, |accum, &&n: uint| accum + n );
io::println(#fmt("%u", sum));
}
\ No newline at end of file
drop { }
fn set_identity() {
- do closure { ||
+ do closure || {
setsockopt_bytes(copy self.sock)
}
}
fn grandchild(c: chan<int>) { send(c, 42); }
fn child(c: chan<int>) {
- task::spawn({|| grandchild(c); })
+ task::spawn(|| grandchild(c) )
}
fn main() {
let p = comm::port();
let ch = chan(p);
- task::spawn({|| child(ch); });
+ task::spawn(|| child(ch) );
let x: int = recv(p);
let ch = chan(p);
let recv_reader: port<chan<~[u8]>> = port();
let recv_reader_chan = chan(recv_reader);
- let pack = task::spawn({|| packager(recv_reader_chan, ch); });
+ let pack = task::spawn(|| packager(recv_reader_chan, ch) );
let source_chan: chan<~[u8]> = recv(recv_reader);
- let prod = task::spawn({|| producer(source_chan); });
+ let prod = task::spawn(|| producer(source_chan) );
loop {
let msg = recv(p);
}
let p = port();
let ch = chan(p);
- spawn({|| b(ch); });
+ spawn(|| b(ch) );
recv(p);
}
let mut i = 0;
}
fn main() {
- do iter::repeat(100u) {||
- spawn({|| a(); });
+ do iter::repeat(100u) || {
+ spawn(|| a() );
}
}
fn main() {
let mut c = 0u;
- for [1u, 2u, 3u, 4u, 5u]/_.eachi { |i, v|
+ for [1u, 2u, 3u, 4u, 5u]/_.eachi |i, v| {
assert (i + 1u) == v;
c += 1u;
}
assert c == 5u;
- for none::<uint>.eachi { |i, v| fail; }
+ for none::<uint>.eachi |i, v| { fail; }
let mut c = 0u;
- for some(1u).eachi { |i, v|
+ for some(1u).eachi |i, v| {
assert (i + 1u) == v;
c += 1u;
}
fn main() {
let mut sum: int = 0;
- range(0, 100, {|x| sum += x; });
+ range(0, 100, |x| sum += x );
log(debug, sum);
}
fn main() {
let p: port<~[u8]> = port();
let ch = chan(p);
- let prod = task::spawn({|| producer(ch); });
+ let prod = task::spawn(|| producer(ch) );
let data: ~[u8] = recv(p);
}
// Verify that blocks can't interfere with each other.
fn two_blocks(a: fn(), b: fn()) { a(); b(); a(); b(); }
let q = ~50;
- two_blocks({|| let a = q; assert *a == 50;},
- {|| let a = q; assert *a == 50;});
+ two_blocks(|| { let a = q; assert *a == 50;},
+ || { let a = q; assert *a == 50;});
}
fn apply<T>(s: str, f: fn(str) -> T) -> T {
fn g<T>(s: str, f: fn(str) -> T) -> T {f(s)}
- g(s, {|v| let r = f(v); r })
+ g(s, |v| { let r = f(v); r })
}
fn main() {}
fn invoke(f: fn@()) { f(); }
let k = ~22;
let _u = {a: k};
- invoke({||log(error, k);})
+ invoke(|| log(error, k) )
}
let ch = chan(p);
let mut y: int;
- task::spawn({|| child(ch); });
+ task::spawn(|| child(ch) );
y = recv(p);
#debug("received 1");
log(debug, y);
assert (y == 10);
- task::spawn({|| child(ch); });
+ task::spawn(|| child(ch) );
y = recv(p);
#debug("received 2");
log(debug, y);
fn main() {
let x = ~[1, 2, 3];
let mut y = 0;
- for x.each {|i| log(debug, i); y += i; }
+ for x.each |i| { log(debug, i); y += i; }
log(debug, y);
assert (y == 6);
let s = "hello there";
let mut i: int = 0;
- for str::each(s) {|c|
+ for str::each(s) |c| {
if i == 0 { assert (c == 'h' as u8); }
if i == 1 { assert (c == 'e' as u8); }
if i == 2 { assert (c == 'l' as u8); }
fn main() {
let x = ~[10, 20, 30];
let mut sum = 0;
- for x.each {|x| sum += x; }
+ for x.each |x| { sum += x; }
assert (sum == 60);
}
}
fn iloop() {
- task::spawn({|| die(); });
+ task::spawn(|| die() );
}
fn main() {
- for uint::range(0u, 100u) {|_i|
+ for uint::range(0u, 100u) |_i| {
let builder = task::builder();
task::unsupervise(builder);
- task::run(builder, {|| iloop(); });
+ task::run(builder, || iloop() );
}
}
\ No newline at end of file
-fn main(args: ~[str]) { for args.each {|s| log(debug, s); } }
+fn main(args: ~[str]) { for args.each |s| { log(debug, s); } }
} else {
let p = comm::port();
let ch = comm::chan(p);
- let child = task::spawn({|| sub(ch, id - 1); });
+ let child = task::spawn(|| sub(ch, id - 1) );
let y = comm::recv(p);
comm::send(parent, y + 1);
}
fn main() {
let p = comm::port();
let ch = comm::chan(p);
- let child = task::spawn({|| sub(ch, 200); });
+ let child = task::spawn(|| sub(ch, 200) );
let y = comm::recv(p);
#debug("transmission complete");
log(debug, y);
impl monad<A> for ~[A] {
fn bind<B>(f: fn(A) -> ~[B]) -> ~[B] {
let mut r = ~[];
- for self.each {|elt| r += f(elt); }
+ for self.each |elt| { r += f(elt); }
r
}
}
}
fn transform(x: option<int>) -> option<str> {
- x.bind({|n| some(n + 1)}).bind({|n| some(int::str(n))})
+ x.bind(|n| some(n + 1) ).bind(|n| some(int::str(n)) )
}
fn main() {
assert transform(some(10)) == some("11");
assert transform(none) == none;
- assert (~["hi"]).bind({|x| ~[x, x + "!"]}).bind({|x| ~[x, x + "?"]}) ==
+ assert (~["hi"]).bind(|x| ~[x, x + "!"] ).bind(|x| ~[x, x + "?"] ) ==
~["hi", "hi?", "hi!", "hi!?"];
}
fn main() {
let mut sz = 400u;
while sz < 500u {
- task::try({|| getbig(200) });
+ task::try(|| getbig(200) );
sz += 1u;
}
}
\ No newline at end of file
calllink10
];
let rng = rand::rng();
- for fns.each {|f|
+ for fns.each |f| {
let sz = rng.next() % 256u32 + 256u32;
let frame_backoff = rng.next() % 10u32 + 1u32;
- task::try({|| runtest(f, frame_backoff) });
+ task::try(|| runtest(f, frame_backoff) );
}
}
fn main() {
let x = ~{x: 1, y: 2, z: 3};
- for uint::range(0u, 10000u) {|_i|
+ for uint::range(0u, 10000u) |_i| {
assert (test(true, x) == 2);
}
assert (test(false, x) == 5);
fn main() {
let x = @{x: 1, y: 2, z: 3};
- for uint::range(0u, 10000u) {|i|
+ for uint::range(0u, 10000u) |i| {
assert (test(true, x) == 2);
}
assert (test(false, x) == 5);
};
task::set_opts(builder, opts);
task::unsupervise(builder);
- do task::run(builder) {||
+ do task::run(builder) || {
task::yield();
let builder = task::builder();
let opts = {
};
task::set_opts(builder, opts);
task::unsupervise(builder);
- do task::run(builder) {||
+ do task::run(builder) || {
task::yield();
run(i - 1);
task::yield();
alt some(src) {
some(src_id) {
- for uint::range(0u, 10u) {|i|
+ for uint::range(0u, 10u) |i| {
let yyy = src_id;
assert (yyy == 0u);
}
class cat {
priv {
let mut meows : uint;
- fn nap() { for uint::range(1u, 10u) {|_i|}}
+ fn nap() { for uint::range(1u, 10u) |_i| { }}
}
let how_hungry : int;
impl foo/& for &[int] {
fn sum() -> int {
let mut sum = 0;
- for vec::each(self) { |e| sum += e; }
+ for vec::each(self) |e| { sum += e; }
ret sum;
}
}
fn find_pos<T>(n: T, h: ~[T]) -> option<uint> {
let mut i = 0u;
- for iter(h) {|e|
+ for iter(h) |e| {
if e == n { ret some(i); }
i += 1u;
}
fn bail_deep(x: ~[~[bool]]) {
let mut seen = false;
- for iter(x) {|x|
- for iter(x) {|x|
+ for iter(x) |x| {
+ for iter(x) |x| {
assert !seen;
if x { seen = true; ret; }
}
}
fn ret_deep() -> str {
- for iter(~[1, 2]) {|e|
- for iter(~[3, 4]) {|x|
+ for iter(~[1, 2]) |e| {
+ for iter(~[3, 4]) |x| {
if e + x > 4 { ret "hi"; }
}
}
fn main() {
let mut last = 0;
- for vec::all(~[1, 2, 3, 4, 5, 6, 7]) {|e|
+ for vec::all(~[1, 2, 3, 4, 5, 6, 7]) |e| {
last = e;
if e == 5 { break; }
if e % 2 == 1 { cont; }
fn test_grow() {
let myport = port();
let mychan = chan(myport);
- for uint::range(0u, 100u) {|i|
+ for uint::range(0u, 100u) |i| {
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
comm::send(mychan, val);
}
fn test_shrink2() {
let myport = port();
let mychan = chan(myport);
- for uint::range(0u, 100u) {|_i|
+ for uint::range(0u, 100u) |_i| {
let val: record = {val1: 0u32, val2: 0u32, val3: 0u32};
send(mychan, val);
}
- for uint::range(0u, 100u) {|_i| let x = recv(myport); }
+ for uint::range(0u, 100u) |_i| { let x = recv(myport); }
}
fn test_rotate() {
let myport = port();
let mychan = chan(myport);
- for uint::range(0u, 100u) {|i|
+ for uint::range(0u, 100u) |i| {
let val = {val1: i as u32, val2: i as u32, val3: i as u32};
send(mychan, val);
let x = recv(myport);
fn test_rotate_grow() {
let myport = port::<record>();
let mychan = chan(myport);
- for uint::range(0u, 10u) {|j|
- for uint::range(0u, 10u) {|i|
+ for uint::range(0u, 10u) |j| {
+ for uint::range(0u, 10u) |i| {
let val: record =
{val1: i as u32, val2: i as u32, val3: i as u32};
send(mychan, val);
}
- for uint::range(0u, 10u) {|i|
+ for uint::range(0u, 10u) |i| {
let x = recv(myport);
assert (x.val1 == i as u32);
assert (x.val2 == i as u32);
}
fn iloop() {
- task::spawn({|| die(); });
+ task::spawn(|| die() );
let p = comm::port::<()>();
let c = comm::chan(p);
loop {
}
fn main() {
- for uint::range(0u, 16u) {|_i|
+ for uint::range(0u, 16u) |_i| {
let builder = task::builder();
task::unsupervise(builder);
- task::run(builder, {|| iloop(); });
+ task::run(builder, || iloop() );
}
}
\ No newline at end of file
let p = port();
let c = chan(p);
- do spawn() {||
+ do spawn() || {
let p = port();
c.send(chan(p));
let arg = fn~(a: A, b: B) -> pair<A,B> {
ret make_generic_record(a, b);
};
- task::spawn({|| f(arg); });
+ task::spawn(|| f(arg) );
}
fn test05() {
alt none::<int> {
some::<int>(_) {
- for c.each {|i|
+ for c.each |i| {
log(debug, a);
let a = 17;
b += ~[a];
}
fn main() {
- task::spawn({|| x("hello from first spawned fn", 65); });
- task::spawn({|| x("hello from second spawned fn", 66); });
- task::spawn({|| x("hello from third spawned fn", 67); });
+ task::spawn(|| x("hello from first spawned fn", 65) );
+ task::spawn(|| x("hello from second spawned fn", 66) );
+ task::spawn(|| x("hello from third spawned fn", 67) );
let mut i: int = 30;
while i > 0 { i = i - 1; #debug("parent sleeping"); yield(); }
}
fn main() {
let p = comm::port::<int>();
let ch = comm::chan(p);
- task::spawn({|| iotask(ch, "localhost"); });
+ task::spawn(|| iotask(ch, "localhost") );
}
import task;
fn main() {
- task::spawn({|| child(10); });
+ task::spawn(|| child(10) );
}
fn child(&&i: int) { log(error, i); assert (i == 10); }
use std;
import task::spawn;
-fn main() { spawn({|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)); }); }
+fn main() { spawn(|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); }
fn child(&&args: (int, int, int, int, int, int, int, int, int)) {
let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args;
impl util<T> for ~[T] {
fn length_() -> uint { vec::len(self) }
- fn iter_(f: fn(T)) { for self.each {|x| f(x); } }
+ fn iter_(f: fn(T)) { for self.each |x| { f(x); } }
fn map_<U>(f: fn(T) -> U) -> ~[U] {
let mut r = ~[];
- for self.each {|elt| r += ~[f(elt)]; }
+ for self.each |elt| { r += ~[f(elt)]; }
r
}
}
assert "hi".plus() == 200;
assert (~[1]).length_().str() == "1";
- assert (~[3, 4]).map_({|a| a + 4})[0] == 7;
- assert (~[3, 4]).map_::<uint>({|a| a as uint + 4u})[0] == 7u;
+ assert (~[3, 4]).map_(|a| a + 4 )[0] == 7;
+ assert (~[3, 4]).map_::<uint>(|a| a as uint + 4u )[0] == 7u;
let mut x = 0u;
- 10u.times({|_n| x += 2u;});
+ 10u.times(|_n| x += 2u );
assert x == 20u;
}
fn test05() {
let po = comm::port();
let ch = comm::chan(po);
- task::spawn({|| test05_start(ch); });
+ task::spawn(|| test05_start(ch) );
let mut value = comm::recv(po);
log(error, value);
value = comm::recv(po);
fn start() { #debug("Started / Finished task."); }
fn test00() {
- task::try({|| start() });
+ task::try(|| start() );
#debug("Completing.");
}
fn main() {
let p = comm::port();
let ch = comm::chan(p);
- let child = task::spawn({|| start(ch); });
+ let child = task::spawn(|| start(ch) );
let c = comm::recv(p);
comm::send(c, "A");
fn main() {
let p = comm::port();
let ch = comm::chan(p);
- let child = task::spawn({|| start(ch); });
+ let child = task::spawn(|| start(ch) );
let c = comm::recv(p);
}
let i: int = 0;
let builder = task::builder();
let r = task::future_result(builder);
- task::run(builder, {|| start(i); });
+ task::run(builder, || start(i) );
// Sleep long enough for the task to finish.
let mut i = 0;
#debug("Check that we don't deadlock.");
let p = comm::port::<int>();
let ch = comm::chan(p);
- task::try({|| start(ch, 0, 10) });
+ task::try(|| start(ch, 0, 10) );
#debug("Joined task");
}
let mut i = 10;
while (i > 0) {
log(debug, i);
- task::spawn({|copy i| child(i, ch); });
+ task::spawn(|copy i| child(i, ch) );
i = i - 1;
}
// the child's point of view the receiver may die. We should
// drop messages on the floor in this case, and not crash!
let ch = comm::chan(p);
- let child = task::spawn({|| start(ch, 10); });
+ let child = task::spawn(|| start(ch, 10) );
let c = comm::recv(p);
}
}
fn main() {
- task::spawn({|| f() });
+ task::spawn(|| f() );
}
\ No newline at end of file
while i < number_of_tasks {
let builder = task::builder();
results += ~[task::future_result(builder)];
- do task::run(builder) {|copy i|
+ do task::run(builder) |copy i| {
test00_start(ch, i, number_of_messages)
}
i = i + 1;
// Read from spawned tasks...
let mut sum = 0;
- for results.each {|r|
+ for results.each |r| {
i = 0;
while i < number_of_messages {
let value = recv(po);
}
// Join spawned tasks...
- for results.each {|r| future::get(r); }
+ for results.each |r| { future::get(r); }
#debug("Completed: Final number is: ");
log(error, sum);
let number_of_messages: int = 10;
let c = comm::chan(p);
- do task::spawn {||
+ do task::spawn || {
test00_start(c, number_of_messages * 0, number_of_messages);
}
- do task::spawn {||
+ do task::spawn || {
test00_start(c, number_of_messages * 1, number_of_messages);
}
- do task::spawn {||
+ do task::spawn || {
test00_start(c, number_of_messages * 2, number_of_messages);
}
- do task::spawn {||
+ do task::spawn || {
test00_start(c, number_of_messages * 3, number_of_messages);
}
let builder = task::builder();
let r = task::future_result(builder);
- do task::run(builder) {||
+ do task::run(builder) || {
test00_start(ch, number_of_messages);
}
// results in the string not being freed
fn starship(&&ch: comm::chan<str>) {
- for int::range(0, 10) { |_i|
+ for int::range(0, 10) |_i| {
comm::send(ch, "pew pew");
}
}
fn starbase() {
- for int::range(0, 10) { |_i|
+ for int::range(0, 10) |_i| {
let p = comm::port();
let c = comm::chan(p);
- task::spawn({|| starship(c);});
+ task::spawn(|| starship(c) );
task::yield();
}
}
fn main() {
- for int::range(0, 10) { |_i|
- task::spawn({|| starbase();});
+ for int::range(0, 10) |_i| {
+ task::spawn(|| starbase() );
}
}
\ No newline at end of file
i = i + 1;
let builder = task::builder();
results += ~[task::future_result(builder)];
- do task::run(builder) {|copy i|
+ do task::run(builder) |copy i| {
test00_start(ch, i, number_of_messages);
}
}
let mut sum: int = 0;
- for results.each {|r|
+ for results.each |r| {
i = 0;
while i < number_of_messages { sum += recv(po); i = i + 1; }
}
- for results.each {|r| future::get(r); }
+ for results.each |r| { future::get(r); }
#debug("Completed: Final number is: ");
assert (sum ==
fn test04() {
#debug("Spawning lots of tasks.");
let mut i: int = 4;
- while i > 0 { i = i - 1; task::spawn({|| test04_start(); }); }
+ while i > 0 { i = i - 1; task::spawn(|| test04_start() ); }
#debug("Finishing up.");
}
fn test05() {
let po = comm::port();
let ch = chan(po);
- task::spawn({|| test05_start(ch); });
+ task::spawn(|| test05_start(ch) );
let mut value: int;
value = recv(po);
value = recv(po);
i = i + 1;
let builder = task::builder();
results += ~[task::future_result(builder)];
- do task::run(builder) {|copy i|
+ do task::run(builder) |copy i| {
test06_start(i);
};
}
- for results.each {|r| future::get(r); }
+ for results.each |r| { future::get(r); }
}
// Unsupervise this task so the process doesn't return a failure status as
// a result of the main task being killed.
let f = supervised;
- task::try({|| supervised() });
+ task::try(|| supervised() );
}
fn main() {
let builder = task::builder();
task::unsupervise(builder);
- task::run(builder, {|| supervisor(); })
+ task::run(builder, || supervisor() )
}
// Local Variables:
use std;
import task;
fn main() {
- task::spawn({|| child("Hello"); });
+ task::spawn(|| child("Hello") );
}
fn child(&&s: str) {
fn test_fail() {
fn f() { let x: @int = fail; }
- task::try({|| f() });
+ task::try(|| f() );
}
fn test_fail_indirect() {
fn f() -> ! { fail; }
fn g() { let x: @int = f(); }
- task::try({|| g() });
+ task::try(|| g() );
}
fn main() {
let tests = __test::tests();
let shouldignore = option::get(
- vec::find(tests, {|t| t.name == "shouldignore"}));
+ vec::find(tests, |t| t.name == "shouldignore" ));
assert shouldignore.ignore == true;
let shouldnotignore = option::get(
- vec::find(tests, {|t| t.name == "shouldnotignore"}));
+ vec::find(tests, |t| t.name == "shouldnotignore" ));
assert shouldnotignore.ignore == false;
}
\ No newline at end of file
fn main() {
let mut i = 10;
- while i > 0 { task::spawn({|copy i| child(i); }); i = i - 1; }
+ while i > 0 { task::spawn(|copy i| child(i) ); i = i - 1; }
#debug("main thread exiting");
}
fn main() {
let builder = task::builder();
task::unsupervise(builder);
- do task::run(builder) {||
+ do task::run(builder) || {
fn f() { f() };
f();
};
}
fn create_index<T>(index: ~[{a: T, b: uint}], hash_fn: native fn(T) -> uint) {
- range(0u, 256u, {|_i| let bucket: ~[T] = ~[]; })
+ range(0u, 256u, |_i| { let bucket: ~[T] = ~[]; } )
}
fn main() { }
let ch = comm::chan(p);
let n = 100u;
let mut expected = 0u;
- for uint::range(0u, n) {|i|
- task::spawn({|| child(ch, i); });
+ for uint::range(0u, n) |i| {
+ task::spawn(|| child(ch, i) );
expected += i;
}
let mut actual = 0u;
- for uint::range(0u, n) {|_i|
+ for uint::range(0u, n) |_i| {
let j = comm::recv(p);
actual += *j;
}
fn main() {
let builder = task::builder();
task::unsupervise(builder);
- task::run(builder, {|| f(); });
+ task::run(builder, || f() );
}
\ No newline at end of file
let c = comm::chan(p);
let builder = task::builder();
task::unsupervise(builder);
- task::run(builder, {|| f(c); });
+ task::run(builder, || f(c) );
#error("hiiiiiiiii");
assert comm::recv(p);
}
\ No newline at end of file
fn main() {
let builder = task::builder();
task::unsupervise(builder);
- task::run(builder, {|| f(); });
+ task::run(builder, || f() );
}
\ No newline at end of file
fn main() {
let builder = task::builder();
task::unsupervise(builder);
- task::run(builder, {|| f(); });
+ task::run(builder, || f() );
}
\ No newline at end of file
fn check_str_eq(a: str, b: str) {
let mut i: int = 0;
- for str::each(a) {|ab|
+ for str::each(a) |ab| {
log(debug, i);
log(debug, ab);
let bb: u8 = b[i];
fn main() {
let builder = task::builder();
let result = task::future_result(builder);
- task::run(builder, {|| child(); });
+ task::run(builder, || child() );
#error("1");
yield();
#error("2");
fn main() {
let builder = task::builder();
let result = task::future_result(builder);
- task::run(builder, {|| child(); });
+ task::run(builder, || child() );
#error("1");
yield();
future::get(result);