diff --git a/src/comp/front/attr.rs b/src/comp/front/attr.rs index cb7b652a256..0c3fac3b46f 100644 --- a/src/comp/front/attr.rs +++ b/src/comp/front/attr.rs @@ -199,7 +199,7 @@ fn require_unique_names(sess: session::session, metas: [@ast::meta_item]) { } } -fn span(item: T) -> ast::spanned { +fn span(item: T) -> ast::spanned { ret {node: item, span: ast_util::dummy_sp()}; } diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs index 6bb6651294f..95c592eeada 100644 --- a/src/comp/front/test.rs +++ b/src/comp/front/test.rs @@ -196,7 +196,9 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item { ret @item; } -fn nospan(t: T) -> ast::spanned { ret {node: t, span: dummy_sp()}; } +fn nospan(t: T) -> ast::spanned { + ret {node: t, span: dummy_sp()}; +} fn mk_tests(cx: test_ctxt) -> @ast::item { let ret_ty = mk_test_desc_vec_ty(cx); diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index bee96f53f0d..8eb0ea64e49 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -389,7 +389,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer) -> // Path and definition ID indexing -fn create_index(index: [entry], hash_fn: fn(T) -> uint) -> +fn create_index(index: [entry], hash_fn: fn(T) -> uint) -> [@[entry]] { let buckets: [@mutable [entry]] = []; uint::range(0u, 256u) {|_i| buckets += [@mutable []]; }; diff --git a/src/comp/metadata/tydecode.rs b/src/comp/metadata/tydecode.rs index 8e71ff86f56..9034e5bb261 100644 --- a/src/comp/metadata/tydecode.rs +++ b/src/comp/metadata/tydecode.rs @@ -150,7 +150,7 @@ fn parse_ty_constr_arg(st: @pstate, sd: str_def) -> } } -fn parse_constr(st: @pstate, sd: str_def, pser: arg_parser) -> +fn parse_constr(st: @pstate, sd: str_def, pser: arg_parser) -> @ty::constr_general { let sp = ast_util::dummy_sp(); // FIXME: use a real span let args: [@sp_constr_arg] = []; diff --git a/src/comp/middle/ast_map.rs b/src/comp/middle/ast_map.rs index 240e14749e9..af4a5272246 100644 --- a/src/comp/middle/ast_map.rs +++ b/src/comp/middle/ast_map.rs @@ -74,7 +74,7 @@ fn map_expr(cx: ctx, ex: @expr) { cx.map.insert(ex.id, node_expr(ex)); } -fn new_smallintmap_int_adapter() -> std::map::hashmap { +fn new_smallintmap_int_adapter() -> std::map::hashmap { let key_idx = fn (&&key: int) -> uint { key as uint }; let idx_key = fn (idx: uint) -> int { idx as int }; ret new_smallintmap_adapter(key_idx, idx_key); @@ -85,11 +85,11 @@ fn new_smallintmap_int_adapter() -> std::map::hashmap { // the entire codebase adapting all the callsites to the different // interface. // FIXME: hashmap and smallintmap should support the same interface. -fn new_smallintmap_adapter(key_idx: fn(K) -> uint, - idx_key: fn(uint) -> K) +fn new_smallintmap_adapter(key_idx: fn(K) -> uint, + idx_key: fn(uint) -> K) -> std::map::hashmap { - obj adapter(map: smallintmap::smallintmap, + obj adapter(map: smallintmap::smallintmap, key_idx: fn(K) -> uint, idx_key: fn(uint) -> K) { diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index b5164b54c6c..9733d6e53fa 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -23,9 +23,7 @@ type def_id = {crate: crate_num, node: node_id}; const local_crate: crate_num = 0; -tag plicit { explicit(T); implicit(T); } - -type ty_param = {ident: ident, kind: plicit}; +type ty_param = {ident: ident, kind: kind}; tag def { def_fn(def_id, purity); diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index 6091b24ac1b..2af904bdef0 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -2,7 +2,9 @@ import std::{str, option}; import codemap::span; import ast::*; -fn respan(sp: span, t: T) -> spanned { ret {node: t, span: sp}; } +fn respan(sp: span, t: T) -> spanned { + ret {node: t, span: sp}; +} /* assuming that we're not in macro expansion */ fn mk_sp(lo: uint, hi: uint) -> span { @@ -186,7 +188,7 @@ fn eq_def_id(&&a: def_id, &&b: def_id) -> bool { a == b } -fn new_def_id_hash() -> std::map::hashmap { +fn new_def_id_hash() -> std::map::hashmap { std::map::mk_hashmap(hash_def_id, eq_def_id) } @@ -228,9 +230,7 @@ fn ret_by_ref(style: ret_style) -> bool { } } -fn ty_param_kind(tp: ty_param) -> kind { - alt tp.kind { ast::implicit(x) | ast::explicit(x) { x } } -} +fn ty_param_kind(tp: ty_param) -> kind { tp.kind } // Local Variables: // mode: rust diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index 252dd33a1f1..dd66c1bef92 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -103,7 +103,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: [@expr]) -> } } -fn option_flatten_map(f: fn@(T) -> option::t, v: [T]) -> +fn option_flatten_map(f: fn@(T) -> option::t, v: [T]) -> option::t<[U]> { let res = []; for elem: T in v { diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index d33bd89d5d8..2f6257f1064 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -219,7 +219,7 @@ fn expect_gt(p: parser) { } } -fn spanned(lo: uint, hi: uint, node: T) -> spanned { +fn spanned(lo: uint, hi: uint, node: T) -> spanned { ret {node: node, span: ast_util::mk_sp(lo, hi)}; } @@ -394,8 +394,8 @@ fn parse_constr_in_type(p: parser) -> @ast::ty_constr { } -fn parse_constrs(pser: block(parser) -> @ast::constr_general, - p: parser) -> +fn parse_constrs(pser: block(parser) -> @ast::constr_general, + p: parser) -> [@ast::constr_general] { let constrs: [@ast::constr_general] = []; while true { @@ -595,9 +595,9 @@ fn parse_fn_block_arg(p: parser) -> ast::arg { ret {mode: m, ty: t, ident: i, id: p.get_id()}; } -fn parse_seq_to_before_gt(sep: option::t, - f: block(parser) -> T, - p: parser) -> [T] { +fn parse_seq_to_before_gt(sep: option::t, + f: block(parser) -> T, + p: parser) -> [T] { let first = true; let v = []; while p.peek() != token::GT && p.peek() != token::BINOP(token::LSR) && @@ -612,16 +612,17 @@ fn parse_seq_to_before_gt(sep: option::t, ret v; } -fn parse_seq_to_gt(sep: option::t, f: block(parser) -> T, - p: parser) -> [T] { +fn parse_seq_to_gt(sep: option::t, + f: block(parser) -> T, p: parser) -> [T] { let v = parse_seq_to_before_gt(sep, f, p); expect_gt(p); ret v; } -fn parse_seq_lt_gt(sep: option::t, f: block(parser) -> T, - p: parser) -> spanned<[T]> { +fn parse_seq_lt_gt(sep: option::t, + f: block(parser) -> T, + p: parser) -> spanned<[T]> { let lo = p.get_lo_pos(); expect(p, token::LT); let result = parse_seq_to_before_gt::(sep, f, p); @@ -630,16 +631,16 @@ fn parse_seq_lt_gt(sep: option::t, f: block(parser) -> T, ret spanned(lo, hi, result); } -fn parse_seq_to_end(ket: token::token, sep: option::t, - f: block(parser) -> T, p: parser) -> [T] { +fn parse_seq_to_end(ket: token::token, sep: option::t, + f: block(parser) -> T, p: parser) -> [T] { let val = parse_seq_to_before_end(ket, sep, f, p); p.bump(); ret val; } -fn parse_seq_to_before_end(ket: token::token, - sep: option::t, - f: block(parser) -> T, p: parser) -> [T] { +fn parse_seq_to_before_end(ket: token::token, + sep: option::t, + f: block(parser) -> T, p: parser) -> [T] { let first: bool = true; let v: [T] = []; while p.peek() != ket { @@ -653,9 +654,9 @@ fn parse_seq_to_before_end(ket: token::token, } -fn parse_seq(bra: token::token, ket: token::token, - sep: option::t, f: block(parser) -> T, - p: parser) -> spanned<[T]> { +fn parse_seq(bra: token::token, ket: token::token, + sep: option::t, f: block(parser) -> T, + p: parser) -> spanned<[T]> { let lo = p.get_lo_pos(); expect(p, bra); let result = parse_seq_to_before_end::(ket, sep, f, p); @@ -1741,24 +1742,18 @@ fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk { ret spanned(lo, hi, bloc); } -fn parse_ty_param(p: parser, def: ast::kind) -> ast::ty_param { - // Accept both old and new kind names for now. FIXME remove this - let k = if eat_word(p, "send") | eat_word(p, "uniq") - { ast::explicit(ast::kind_sendable) } - else if eat_word(p, "copy") | eat_word(p, "shar") - { ast::explicit(ast::kind_copyable) } - else if eat_word(p, "nocopy") | eat_word(p, "pin") - { ast::explicit(ast::kind_noncopyable) } - else { ast::implicit(def) }; +fn parse_ty_param(p: parser) -> ast::ty_param { + let k = if eat_word(p, "send") { ast::kind_sendable } + else if eat_word(p, "copy") { ast::kind_copyable } + else { ast::kind_noncopyable }; ret {ident: parse_ident(p), kind: k}; } -fn parse_ty_params(p: parser, def: ast::kind) -> [ast::ty_param] { +fn parse_ty_params(p: parser) -> [ast::ty_param] { let ty_params: [ast::ty_param] = []; if p.peek() == token::LT { p.bump(); - ty_params = parse_seq_to_gt(some(token::COMMA), - {|p| parse_ty_param(p, def)}, p); + ty_params = parse_seq_to_gt(some(token::COMMA), parse_ty_param, p); } ret ty_params; } @@ -1811,7 +1806,7 @@ fn parse_fn(p: parser, proto: ast::proto, purity: ast::purity, fn parse_fn_header(p: parser) -> {ident: ast::ident, tps: [ast::ty_param]} { let id = parse_value_ident(p); - let ty_params = parse_ty_params(p, ast::kind_copyable); + let ty_params = parse_ty_params(p); ret {ident: id, tps: ty_params}; } @@ -1864,7 +1859,7 @@ fn parse_method(p: parser) -> @ast::method { fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); - let ty_params = parse_ty_params(p, ast::kind_copyable); + let ty_params = parse_ty_params(p); let fields: ast::spanned<[ast::obj_field]> = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_obj_field, p); @@ -1881,7 +1876,7 @@ fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item { fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); - let ty_params = parse_ty_params(p, ast::kind_noncopyable); + let ty_params = parse_ty_params(p); expect(p, token::LPAREN); let arg_ident = parse_value_ident(p); expect(p, token::COLON); @@ -2045,7 +2040,7 @@ fn parse_type_decl(p: parser) -> {lo: uint, ident: ast::ident} { fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item { let t = parse_type_decl(p); - let tps = parse_ty_params(p, ast::kind_noncopyable); + let tps = parse_ty_params(p); expect(p, token::EQ); let ty = parse_ty(p, false); let hi = p.get_hi_pos(); @@ -2056,7 +2051,7 @@ fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item { fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let id = parse_ident(p); - let ty_params = parse_ty_params(p, ast::kind_noncopyable); + let ty_params = parse_ty_params(p); let variants: [ast::variant] = []; // Newtype syntax if p.peek() == token::EQ { diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index dc09187e062..bf87410b885 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1167,12 +1167,11 @@ fn print_arg_mode(s: ps, m: ast::mode) { } } -fn print_kind(s: ps, kind: ast::plicit) { +fn print_kind(s: ps, kind: ast::kind) { alt kind { - ast::explicit(ast::kind_sendable.) { word_nbsp(s, "send"); } - ast::explicit(ast::kind_copyable.) { word_nbsp(s, "copy"); } - ast::explicit(ast::kind_noncopyable.) { word_nbsp(s, "nocopy"); } - ast::implicit(_) {} + ast::kind_sendable. { word_nbsp(s, "send"); } + ast::kind_copyable. { word_nbsp(s, "copy"); } + ast::kind_noncopyable. {} } } diff --git a/src/comp/syntax/util/interner.rs b/src/comp/syntax/util/interner.rs index c814f168a4a..6993eeee35e 100644 --- a/src/comp/syntax/util/interner.rs +++ b/src/comp/syntax/util/interner.rs @@ -11,12 +11,12 @@ type interner = hasher: hashfn, eqer: eqfn}; -fn mk(hasher: hashfn, eqer: eqfn) -> interner { +fn mk(hasher: hashfn, eqer: eqfn) -> interner { let m = map::mk_hashmap::(hasher, eqer); ret {map: m, mutable vect: [], hasher: hasher, eqer: eqer}; } -fn intern(itr: interner, val: T) -> uint { +fn intern(itr: interner, val: T) -> uint { alt itr.map.find(val) { some(idx) { ret idx; } none. { @@ -31,7 +31,7 @@ fn intern(itr: interner, val: T) -> uint { // |get| isn't "pure" in the traditional sense, because it can go from // failing to returning a value as items are interned. But for typestate, // where we first check a pred and then rely on it, ceasing to fail is ok. -pure fn get(itr: interner, idx: uint) -> T { +pure fn get(itr: interner, idx: uint) -> T { unchecked { itr.vect[idx] } diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs index b20f0c59f01..22c344e6200 100644 --- a/src/comp/util/common.rs +++ b/src/comp/util/common.rs @@ -21,7 +21,7 @@ fn hash_def(d: ast::def_id) -> uint { ret h; } -fn new_def_hash() -> std::map::hashmap { +fn new_def_hash() -> std::map::hashmap { let hasher: std::map::hashfn = hash_def; let eqer: std::map::eqfn = def_eq; ret std::map::mk_hashmap::(hasher, eqer); @@ -162,7 +162,7 @@ fn lit_in_range(l: @ast::lit, m1: @ast::lit, m2: @ast::lit) -> bool { } } -fn ranges_overlap(a1: T, a2: T, b1: T, b2: T) -> bool { +fn ranges_overlap(a1: T, a2: T, b1: T, b2: T) -> bool { let min1 = min(a1, a2); let max1 = max(a1, a2); let min2 = min(b1, b2); diff --git a/src/comp/util/filesearch.rs b/src/comp/util/filesearch.rs index 5e51f6c6840..bd9735034e3 100644 --- a/src/comp/util/filesearch.rs +++ b/src/comp/util/filesearch.rs @@ -55,7 +55,7 @@ fn mk_filesearch(maybe_sysroot: option::t, } // FIXME #1001: This can't be an obj method -fn search(filesearch: filesearch, pick: pick) -> option::t { +fn search(filesearch: filesearch, pick: pick) -> option::t { for lib_search_path in filesearch.lib_search_paths() { log #fmt["searching %s", lib_search_path]; for path in fs::list_dir(lib_search_path) { diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index febdee4b57e..d6c57424b1e 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -224,7 +224,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap, check_variants_T(crate, codemap, filename, "ty", stolen.tys, pprust::ty_to_str, replace_ty_in_crate, cx); } -fn check_variants_T( +fn check_variants_T( crate: ast::crate, codemap: codemap::codemap, filename: str, diff --git a/src/lib/comm.rs b/src/lib/comm.rs index 32f01b38f28..caa43bab29c 100644 --- a/src/lib/comm.rs +++ b/src/lib/comm.rs @@ -39,7 +39,7 @@ native mod rustrt { type void; type rust_port; - fn chan_id_send(t: *sys::type_desc, + fn chan_id_send(t: *sys::type_desc, target_task: task::task, target_port: port_id, data: T) -> ctypes::uintptr_t; @@ -52,7 +52,7 @@ native mod rustrt { #[abi = "rust-intrinsic"] native mod rusti { - fn recv(port: *rustrt::rust_port) -> T; + fn recv(port: *rustrt::rust_port) -> T; } type port_id = int; @@ -75,11 +75,11 @@ dropped. Channels may be duplicated and themselves transmitted over other channels. */ -tag chan { +tag chan { chan_t(task::task, port_id); } -resource port_ptr(po: *rustrt::rust_port) { +resource port_ptr(po: *rustrt::rust_port) { // Once the port is detached it's guaranteed not to receive further // messages rustrt::rust_port_detach(po); @@ -103,7 +103,7 @@ transmitted. If a port value is copied, both copies refer to the same port. Ports may be associated with multiple s. */ -tag port { port_t(@port_ptr); } +tag port { port_t(@port_ptr); } /* Function: send @@ -113,7 +113,7 @@ Sends data over a channel. The sent data is moved into the channel, whereupon the caller loses access to it. */ -fn send(ch: chan, -data: T) { +fn send(ch: chan, -data: T) { let chan_t(t, p) = ch; let res = rustrt::chan_id_send(sys::get_type_desc::(), t, p, data); if res != 0u unsafe { @@ -128,7 +128,7 @@ Function: port Constructs a port. */ -fn port() -> port { +fn port() -> port { port_t(@port_ptr(rustrt::new_port(sys::size_of::()))) } @@ -140,7 +140,7 @@ Receive from a port. If no data is available on the port then the task will block until data becomes available. */ -fn recv(p: port) -> T { ret rusti::recv(***p) } +fn recv(p: port) -> T { ret rusti::recv(***p) } /* Function: chan @@ -149,6 +149,6 @@ Constructs a channel. The channel is bound to the port used to construct it. */ -fn chan(p: port) -> chan { +fn chan(p: port) -> chan { chan_t(task::get_task(), rustrt::get_port_id(***p)) } diff --git a/src/lib/deque.rs b/src/lib/deque.rs index ce48c30aae6..7c0a13bb5f8 100644 --- a/src/lib/deque.rs +++ b/src/lib/deque.rs @@ -33,7 +33,7 @@ Section: Functions /* Function: create */ -fn create() -> t { +fn create() -> t { type cell = option::t; let initial_capacity: uint = 32u; // 2^5 @@ -41,7 +41,7 @@ fn create() -> t { * Grow is only called on full elts, so nelts is also len(elts), unlike * elsewhere. */ - fn grow(nelts: uint, lo: uint, elts: [mutable cell]) -> + fn grow(nelts: uint, lo: uint, elts: [mutable cell]) -> [mutable cell] { assert (nelts == vec::len(elts)); let rv = [mutable]; @@ -60,7 +60,7 @@ fn create() -> t { fn get(elts: [mutable cell], i: uint) -> T { ret alt elts[i] { option::some(t) { t } _ { fail } }; } - obj deque(mutable nelts: uint, + obj deque(mutable nelts: uint, mutable lo: uint, mutable hi: uint, mutable elts: [mutable cell]) { diff --git a/src/lib/either.rs b/src/lib/either.rs index c043520380b..89d47b20746 100644 --- a/src/lib/either.rs +++ b/src/lib/either.rs @@ -39,7 +39,7 @@ Function: lefts Extracts from a vector of either all the left values. */ -fn lefts(eithers: [t]) -> [T] { +fn lefts(eithers: [t]) -> [T] { let result: [T] = []; for elt: t in eithers { alt elt { left(l) { result += [l]; } _ {/* fallthrough */ } } @@ -52,7 +52,7 @@ Function: rights Extracts from a vector of either all the right values */ -fn rights(eithers: [t]) -> [U] { +fn rights(eithers: [t]) -> [U] { let result: [U] = []; for elt: t in eithers { alt elt { right(r) { result += [r]; } _ {/* fallthrough */ } } @@ -68,7 +68,8 @@ Extracts from a vector of either all the left values and right values Returns a structure containing a vector of left values and a vector of right values. */ -fn partition(eithers: [t]) -> {lefts: [T], rights: [U]} { +fn partition(eithers: [t]) + -> {lefts: [T], rights: [U]} { let lefts: [T] = []; let rights: [U] = []; for elt: t in eithers { diff --git a/src/lib/fun_treemap.rs b/src/lib/fun_treemap.rs index 1126a13d449..1f4e6b9491a 100644 --- a/src/lib/fun_treemap.rs +++ b/src/lib/fun_treemap.rs @@ -50,7 +50,7 @@ Function: insert Insert a value into the map */ -fn insert(m: treemap, k: K, v: V) -> treemap { +fn insert(m: treemap, k: K, v: V) -> treemap { @alt m { @empty. { node(@k, @v, @empty, @empty) } @node(@kk, vv, left, right) { @@ -68,7 +68,7 @@ Function: find Find a value based on the key */ -fn find(m: treemap, k: K) -> option { +fn find(m: treemap, k: K) -> option { alt *m { empty. { none } node(@kk, @v, left, right) { @@ -84,7 +84,7 @@ Function: traverse Visit all pairs in the map in order. */ -fn traverse(m: treemap, f: block(K, V)) { +fn traverse(m: treemap, f: block(K, V)) { alt *m { empty. { } node(@k, @v, _, _) { diff --git a/src/lib/list.rs b/src/lib/list.rs index 300a5c72a67..ab712091819 100644 --- a/src/lib/list.rs +++ b/src/lib/list.rs @@ -25,7 +25,7 @@ Function: from_vec Create a list from a vector */ -fn from_vec(v: [const T]) -> list { +fn from_vec(v: [const T]) -> list { *vec::foldr({ |h, t| @cons(h, t) }, @nil::, v) } @@ -44,7 +44,7 @@ ls - The list to fold z - The initial value f - The function to apply */ -fn foldl(ls: list, z: T, f: block(T, U) -> T) -> T { +fn foldl(ls: list, z: T, f: block(T, U) -> T) -> T { let accum: T = z; let ls = ls; while true { @@ -65,7 +65,8 @@ Apply function `f` to each element of `v`, starting from the first. When function `f` returns true then an option containing the element is returned. If `f` matches no elements then none is returned. */ -fn find(ls: list, f: block(T) -> option::t) -> option::t { +fn find(ls: list, f: block(T) -> option::t) + -> option::t { let ls = ls; while true { alt ls { @@ -83,7 +84,7 @@ Function: has Returns true if a list contains an element with the given value */ -fn has(ls: list, elt: T) -> bool { +fn has(ls: list, elt: T) -> bool { let ls = ls; while true { alt ls { @@ -99,7 +100,7 @@ Function: len Returns the length of a list */ -fn len(ls: list) -> uint { +fn len(ls: list) -> uint { fn count(&&u: uint, _t: T) -> uint { ret u + 1u; } ret foldl(ls, 0u, bind count(_, _)); } @@ -109,7 +110,7 @@ Function: tail Returns all but the first element of a list */ -fn tail(ls: list) -> list { +fn tail(ls: list) -> list { alt ls { cons(_, tl) { ret *tl; } nil. { fail "list empty" } } } @@ -118,7 +119,7 @@ Function: head Returns the first element of a list */ -fn head(ls: list) -> T { +fn head(ls: list) -> T { alt ls { cons(hd, _) { ret hd; } nil. { fail "list empty" } } } @@ -127,7 +128,7 @@ Function: append Appends one list to another */ -fn append(l: list, m: list) -> list { +fn append(l: list, m: list) -> list { alt l { nil. { ret m; } cons(x, xs) { let rest = append(*xs, m); ret cons(x, @rest); } diff --git a/src/lib/map.rs b/src/lib/map.rs index 70d72d120e8..c802b5b889f 100644 --- a/src/lib/map.rs +++ b/src/lib/map.rs @@ -114,12 +114,13 @@ Parameters: hasher - The hash function for key type K eqer - The equality function for key type K */ -fn mk_hashmap(hasher: hashfn, eqer: eqfn) -> hashmap { +fn mk_hashmap(hasher: hashfn, eqer: eqfn) + -> hashmap { let initial_capacity: uint = 32u; // 2^5 let load_factor: util::rational = {num: 3, den: 4}; - tag bucket { nil; deleted; some(K, V); } - fn make_buckets(nbkts: uint) -> [mutable bucket] { + tag bucket { nil; deleted; some(K, V); } + fn make_buckets(nbkts: uint) -> [mutable bucket] { ret vec::init_elt_mut::>(nil::, nbkts); } // Derive two hash functions from the one given by taking the upper @@ -146,9 +147,9 @@ fn mk_hashmap(hasher: hashfn, eqer: eqfn) -> hashmap { * will fail. */ - fn insert_common(hasher: hashfn, eqer: eqfn, - bkts: [mutable bucket], nbkts: uint, key: K, - val: V) -> bool { + fn insert_common(hasher: hashfn, eqer: eqfn, + bkts: [mutable bucket], + nbkts: uint, key: K, val: V) -> bool { let i: uint = 0u; let h: uint = hasher(key); while i < nbkts { @@ -166,9 +167,9 @@ fn mk_hashmap(hasher: hashfn, eqer: eqfn) -> hashmap { } fail; // full table } - fn find_common(hasher: hashfn, eqer: eqfn, - bkts: [mutable bucket], nbkts: uint, key: K) -> - option::t { + fn find_common(hasher: hashfn, eqer: eqfn, + bkts: [mutable bucket], + nbkts: uint, key: K) -> option::t { let i: uint = 0u; let h: uint = hasher(key); while i < nbkts { @@ -187,9 +188,11 @@ fn mk_hashmap(hasher: hashfn, eqer: eqfn) -> hashmap { } ret option::none; } - fn rehash(hasher: hashfn, eqer: eqfn, - oldbkts: [mutable bucket], _noldbkts: uint, - newbkts: [mutable bucket], nnewbkts: uint) { + fn rehash(hasher: hashfn, eqer: eqfn, + oldbkts: [mutable bucket], + _noldbkts: uint, + newbkts: [mutable bucket], + nnewbkts: uint) { for b: bucket in oldbkts { alt b { some(k_, v_) { @@ -201,7 +204,7 @@ fn mk_hashmap(hasher: hashfn, eqer: eqfn) -> hashmap { } } } - obj hashmap(hasher: hashfn, + obj hashmap(hasher: hashfn, eqer: eqfn, mutable bkts: [mutable bucket], mutable nbkts: uint, @@ -291,7 +294,7 @@ Function: new_str_hash Construct a hashmap for string keys */ -fn new_str_hash() -> hashmap { +fn new_str_hash() -> hashmap { ret mk_hashmap(str::hash, str::eq); } @@ -300,7 +303,7 @@ Function: new_int_hash Construct a hashmap for int keys */ -fn new_int_hash() -> hashmap { +fn new_int_hash() -> hashmap { fn hash_int(&&x: int) -> uint { ret x as uint; } fn eq_int(&&a: int, &&b: int) -> bool { ret a == b; } ret mk_hashmap(hash_int, eq_int); @@ -311,7 +314,7 @@ Function: new_uint_hash Construct a hashmap for uint keys */ -fn new_uint_hash() -> hashmap { +fn new_uint_hash() -> hashmap { fn hash_uint(&&x: uint) -> uint { ret x; } fn eq_uint(&&a: uint, &&b: uint) -> bool { ret a == b; } ret mk_hashmap(hash_uint, eq_uint); diff --git a/src/lib/math.rs b/src/lib/math.rs index 6c6a30a0b8e..47cfdef323e 100644 --- a/src/lib/math.rs +++ b/src/lib/math.rs @@ -73,11 +73,11 @@ Function: min Returns the minimum of two values */ -fn min(x: T, y: T) -> T { x < y ? x : y } +fn min(x: T, y: T) -> T { x < y ? x : y } /* Function: max Returns the maximum of two values */ -fn max(x: T, y: T) -> T { x < y ? y : x } +fn max(x: T, y: T) -> T { x < y ? y : x } diff --git a/src/lib/result.rs b/src/lib/result.rs index cb703385a40..550f53470bb 100644 --- a/src/lib/result.rs +++ b/src/lib/result.rs @@ -103,7 +103,8 @@ Example: > }) */ -fn chain(res: t, op: block(T) -> t) -> t { +fn chain(res: t, op: block(T) -> t) + -> t { alt res { ok(t) { op(t) } err(e) { err(e) } diff --git a/src/lib/smallintmap.rs b/src/lib/smallintmap.rs index f9e59820294..4702a2adab4 100644 --- a/src/lib/smallintmap.rs +++ b/src/lib/smallintmap.rs @@ -29,7 +29,7 @@ Function: insert Add a value to the map. If the map already contains a value for the specified key then the original value is replaced. */ -fn insert(m: smallintmap, key: uint, val: T) { +fn insert(m: smallintmap, key: uint, val: T) { vec::grow_set::>(m.v, key, none::, some::(val)); } @@ -39,7 +39,7 @@ Function: find Get the value for the specified key. If the key does not exist in the map then returns none. */ -fn find(m: smallintmap, key: uint) -> option::t { +fn find(m: smallintmap, key: uint) -> option::t { if key < vec::len::>(m.v) { ret m.v[key]; } ret none::; } @@ -53,10 +53,10 @@ Failure: If the key does not exist in the map */ -fn get(m: smallintmap, key: uint) -> T { - alt find::(m, key) { - none::. { log_err "smallintmap::get(): key not present"; fail; } - some::(v) { ret v; } +fn get(m: smallintmap, key: uint) -> T { + alt find(m, key) { + none. { log_err "smallintmap::get(): key not present"; fail; } + some(v) { ret v; } } } @@ -65,13 +65,13 @@ Method: contains_key Returns true if the map contains a value for the specified key */ -fn contains_key(m: smallintmap, key: uint) -> bool { +fn contains_key(m: smallintmap, key: uint) -> bool { ret !option::is_none(find::(m, key)); } // FIXME: Are these really useful? -fn truncate(m: smallintmap, len: uint) { +fn truncate(m: smallintmap, len: uint) { m.v = vec::slice_mut::>(m.v, 0u, len); } diff --git a/src/lib/sort.rs b/src/lib/sort.rs index f183b73c342..38ab4f3cfb1 100644 --- a/src/lib/sort.rs +++ b/src/lib/sort.rs @@ -20,8 +20,8 @@ Merge sort. Returns a new vector containing the sorted list. Has worst case O(n log n) performance, best case O(n), but is not space efficient. This is a stable sort. */ -fn merge_sort(le: lteq, v: [const T]) -> [T] { - fn merge(le: lteq, a: [T], b: [T]) -> [T] { +fn merge_sort(le: lteq, v: [const T]) -> [T] { + fn merge(le: lteq, a: [T], b: [T]) -> [T] { let rs: [T] = []; let a_len: uint = len::(a); let a_ix: uint = 0u; @@ -46,30 +46,24 @@ fn merge_sort(le: lteq, v: [const T]) -> [T] { ret merge::(le, merge_sort::(le, a), merge_sort::(le, b)); } -fn swap(arr: [mutable T], x: uint, y: uint) { - let a = arr[x]; - arr[x] = arr[y]; - arr[y] = a; -} - -fn part(compare_func: lteq, arr: [mutable T], left: uint, right: uint, - pivot: uint) -> uint { +fn part(compare_func: lteq, arr: [mutable T], left: uint, + right: uint, pivot: uint) -> uint { let pivot_value = arr[pivot]; - swap::(arr, pivot, right); + arr[pivot] <-> arr[right]; let storage_index: uint = left; let i: uint = left; while i < right { - if compare_func({ arr[i] }, pivot_value) { - swap::(arr, i, storage_index); + if compare_func(copy arr[i], pivot_value) { + arr[i] <-> arr[storage_index]; storage_index += 1u; } i += 1u; } - swap::(arr, storage_index, right); + arr[storage_index] <-> arr[right]; ret storage_index; } -fn qsort(compare_func: lteq, arr: [mutable T], left: uint, +fn qsort(compare_func: lteq, arr: [mutable T], left: uint, right: uint) { if right > left { let pivot = (left + right) / 2u; @@ -90,13 +84,13 @@ Quicksort. Sorts a mutable vector in place. Has worst case O(n^2) performance, average case O(n log n). This is an unstable sort. */ -fn quick_sort(compare_func: lteq, arr: [mutable T]) { +fn quick_sort(compare_func: lteq, arr: [mutable T]) { if len::(arr) == 0u { ret; } qsort::(compare_func, arr, 0u, len::(arr) - 1u); } -fn qsort3(compare_func_lt: lteq, compare_func_eq: lteq, - arr: [mutable T], left: int, right: int) { +fn qsort3(compare_func_lt: lteq, compare_func_eq: lteq, + arr: [mutable T], left: int, right: int) { if right <= left { ret; } let v: T = arr[right]; let i: int = left - 1; @@ -105,36 +99,36 @@ fn qsort3(compare_func_lt: lteq, compare_func_eq: lteq, let q: int = j; while true { i += 1; - while compare_func_lt({ arr[i] }, v) { i += 1; } + while compare_func_lt(copy arr[i], v) { i += 1; } j -= 1; - while compare_func_lt(v, { arr[j] }) { + while compare_func_lt(v, copy arr[j]) { if j == left { break; } j -= 1; } if i >= j { break; } - swap::(arr, i as uint, j as uint); - if compare_func_eq({ arr[i] }, v) { + arr[i] <-> arr[j]; + if compare_func_eq(copy arr[i], v) { p += 1; - swap::(arr, p as uint, i as uint); + arr[p] <-> arr[i]; } - if compare_func_eq(v, { arr[j] }) { + if compare_func_eq(v, copy arr[j]) { q -= 1; - swap::(arr, j as uint, q as uint); + arr[j] <-> arr[q]; } } - swap::(arr, i as uint, right as uint); + arr[i] <-> arr[right]; j = i - 1; i += 1; let k: int = left; while k < p { - swap::(arr, k as uint, j as uint); + arr[k] <-> arr[j]; k += 1; j -= 1; if k == len::(arr) as int { break; } } k = right - 1; while k > q { - swap::(arr, i as uint, k as uint); + arr[i] <-> arr[k]; k -= 1; i += 1; if k == 0 { break; } @@ -156,8 +150,8 @@ According to these slides this is the algorithm of choice for This is an unstable sort. */ -fn quick_sort3(compare_func_lt: lteq, compare_func_eq: lteq, - arr: [mutable T]) { +fn quick_sort3(compare_func_lt: lteq, compare_func_eq: lteq, + arr: [mutable T]) { if len::(arr) == 0u { ret; } qsort3::(compare_func_lt, compare_func_eq, arr, 0, (len::(arr) as int) - 1); diff --git a/src/lib/task.rs b/src/lib/task.rs index e1dcb038f02..d5cda975a3a 100644 --- a/src/lib/task.rs +++ b/src/lib/task.rs @@ -232,7 +232,7 @@ Returns: A handle to the new task */ -fn spawn(-data: T, f: fn(T)) -> task { +fn spawn(-data: T, f: fn(T)) -> task { spawn_inner(data, f, none) } @@ -245,7 +245,7 @@ termination Immediately before termination, either on success or failure, the spawned task will send a message on the provided channel. */ -fn spawn_notify(-data: T, f: fn(T), +fn spawn_notify(-data: T, f: fn(T), notify: comm::chan) -> task { spawn_inner(data, f, some(notify)) } @@ -259,7 +259,7 @@ This is a convenience wrapper around spawn_notify which, when paired with can be easily used to spawn a task then wait for it to complete. */ -fn spawn_joinable(-data: T, f: fn(T)) -> joinable_task { +fn spawn_joinable(-data: T, f: fn(T)) -> joinable_task { let p = comm::port::(); let id = spawn_notify(data, f, comm::chan::(p)); ret (id, p); @@ -275,11 +275,11 @@ fn spawn_joinable(-data: T, f: fn(T)) -> joinable_task { // // After the transition this should all be rewritten. -fn spawn_inner(-data: T, f: fn(T), +fn spawn_inner(-data: T, f: fn(T), notify: option>) -> task unsafe { - fn wrapper(-data: *u8, f: fn(T)) unsafe { + fn wrapper(-data: *u8, f: fn(T)) unsafe { let data: ~T = unsafe::reinterpret_cast(data); f(*data); } diff --git a/src/lib/test.rs b/src/lib/test.rs index 240138d5104..d827d775831 100644 --- a/src/lib/test.rs +++ b/src/lib/test.rs @@ -109,8 +109,8 @@ fn run_tests_console(opts: test_opts, run_tests_console_(opts, tests, default_test_to_task) } -fn run_tests_console_(opts: test_opts, tests: [test_desc], - to_task: test_to_task) -> bool { +fn run_tests_console_(opts: test_opts, tests: [test_desc], + to_task: test_to_task) -> bool { type test_state = @{out: io::writer, @@ -121,7 +121,7 @@ fn run_tests_console_(opts: test_opts, tests: [test_desc], mutable ignored: uint, mutable failures: [test_desc]}; - fn callback(event: testevent, st: test_state) { + fn callback(event: testevent, st: test_state) { alt event { te_filtered(filtered_tests) { st.total = vec::len(filtered_tests); @@ -214,9 +214,9 @@ tag testevent { te_result(test_desc, test_result); } -fn run_tests(opts: test_opts, tests: [test_desc], - to_task: test_to_task, - callback: fn@(testevent)) { +fn run_tests(opts: test_opts, tests: [test_desc], + to_task: test_to_task, + callback: fn@(testevent)) { let filtered_tests = filter_tests(opts, tests); callback(te_filtered(filtered_tests)); @@ -248,8 +248,8 @@ fn run_tests(opts: test_opts, tests: [test_desc], fn get_concurrency() -> uint { rustrt::sched_threads() } -fn filter_tests(opts: test_opts, - tests: [test_desc]) -> [test_desc] { +fn filter_tests(opts: test_opts, + tests: [test_desc]) -> [test_desc] { let filtered = tests; // Remove tests that don't match the test filter @@ -262,7 +262,7 @@ fn filter_tests(opts: test_opts, option::none. { "" } }; - fn filter_fn(test: test_desc, filter_str: str) -> + fn filter_fn(test: test_desc, filter_str: str) -> option::t> { if str::find(test.name, filter_str) >= 0 { ret option::some(test); @@ -278,7 +278,7 @@ fn filter_tests(opts: test_opts, filtered = if !opts.run_ignored { filtered } else { - fn filter(test: test_desc) -> option::t> { + fn filter(test: test_desc) -> option::t> { if test.ignore { ret option::some({name: test.name, fn: test.fn, @@ -304,8 +304,8 @@ fn filter_tests(opts: test_opts, type test_future = {test: test_desc, wait: fn@() -> test_result}; -fn run_test(test: test_desc, - to_task: test_to_task) -> test_future { +fn run_test(test: test_desc, + to_task: test_to_task) -> test_future { if test.ignore { ret {test: test, wait: fn () -> test_result { tr_ignored }}; } diff --git a/src/lib/treemap.rs b/src/lib/treemap.rs index 84fff4992f0..35d87cd518f 100644 --- a/src/lib/treemap.rs +++ b/src/lib/treemap.rs @@ -44,7 +44,7 @@ Function: insert Insert a value into the map */ -fn insert(m: treemap, k: K, v: V) { +fn insert(m: treemap, k: K, v: V) { alt m { @empty. { *m = node(@k, @v, @mutable empty, @mutable empty); } @node(@kk, _, _, _) { @@ -63,7 +63,7 @@ Function: find Find a value based on the key */ -fn find(m: treemap, k: K) -> option { +fn find(m: treemap, k: K) -> option { alt *m { empty. { none } node(@kk, @v, _, _) { diff --git a/src/lib/vec.rs b/src/lib/vec.rs index 2ae7f2247b1..77d4c10dbe0 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -121,7 +121,7 @@ Creates and initializes an immutable vector. Creates an immutable vector of size `n_elts` and initializes the elements to the value `t`. */ -fn init_elt(t: T, n_elts: uint) -> [T] { +fn init_elt(t: T, n_elts: uint) -> [T] { let v = []; reserve(v, n_elts); let i: uint = 0u; @@ -138,7 +138,7 @@ Creates and initializes a mutable vector. Creates a mutable vector of size `n_elts` and initializes the elements to the value `t`. */ -fn init_elt_mut(t: T, n_elts: uint) -> [mutable T] { +fn init_elt_mut(t: T, n_elts: uint) -> [mutable T] { let v = [mutable]; reserve(v, n_elts); let i: uint = 0u; @@ -153,7 +153,7 @@ Function: to_mut Produces a mutable vector from an immutable vector. */ -fn to_mut(v: [T]) -> [mutable T] { +fn to_mut(v: [T]) -> [mutable T] { let vres = [mutable]; for t: T in v { vres += [mutable t]; } ret vres; @@ -165,7 +165,7 @@ Function: from_mut Produces an immutable vector from a mutable vector. */ -fn from_mut(v: [mutable T]) -> [T] { +fn from_mut(v: [mutable T]) -> [T] { let vres = []; for t: T in v { vres += [t]; } ret vres; @@ -181,7 +181,7 @@ Returns the first element of a vector Predicates: (v) */ -fn head(v: [const T]) : is_not_empty(v) -> T { ret v[0]; } +fn head(v: [const T]) : is_not_empty(v) -> T { ret v[0]; } /* Function: tail @@ -191,7 +191,7 @@ Returns all but the first element of a vector Predicates: (v) */ -fn tail(v: [const T]) : is_not_empty(v) -> [T] { +fn tail(v: [const T]) : is_not_empty(v) -> [T] { ret slice(v, 1u, len(v)); } @@ -206,7 +206,7 @@ Returns all but the last elemnt of a vector Preconditions: `v` is not empty */ -fn init(v: [const T]) -> [T] { +fn init(v: [const T]) -> [T] { assert len(v) != 0u; slice(v, 0u, len(v) - 1u) } @@ -221,7 +221,7 @@ Returns: An option containing the last element of `v` if `v` is not empty, or none if `v` is empty. */ -fn last(v: [const T]) -> option::t { +fn last(v: [const T]) -> option::t { if len(v) == 0u { ret none; } ret some(v[len(v) - 1u]); } @@ -234,7 +234,7 @@ Returns the last element of a non-empty vector `v` Predicates: (v) */ -fn last_total(v: [const T]) : is_not_empty(v) -> T { +fn last_total(v: [const T]) : is_not_empty(v) -> T { ret v[len(v) - 1u]; } @@ -243,7 +243,7 @@ Function: slice Returns a copy of the elements from [`start`..`end`) from `v`. */ -fn slice(v: [const T], start: uint, end: uint) -> [T] { +fn slice(v: [const T], start: uint, end: uint) -> [T] { assert (start <= end); assert (end <= len(v)); let result = []; @@ -259,7 +259,7 @@ Function: slice_mut Returns a copy of the elements from [`start`..`end`) from `v`. */ -fn slice_mut(v: [const T], start: uint, end: uint) -> [mutable T] { +fn slice_mut(v: [const T], start: uint, end: uint) -> [mutable T] { assert (start <= end); assert (end <= len(v)); let result = [mutable]; @@ -277,7 +277,7 @@ Function: shift Removes the first element from a vector and return it */ -fn shift(&v: [const T]) -> T { +fn shift(&v: [const T]) -> T { let ln = len::(v); assert (ln > 0u); let e = v[0]; @@ -291,7 +291,7 @@ Function: pop Remove the last element from a vector and return it */ -fn pop(&v: [const T]) -> T { +fn pop(&v: [const T]) -> T { let ln = len(v); assert (ln > 0u); ln -= 1u; @@ -316,7 +316,7 @@ v - The vector to grow n - The number of elements to add initval - The value for the new elements */ -fn grow(&v: [T], n: uint, initval: T) { +fn grow(&v: [T], n: uint, initval: T) { reserve(v, next_power_of_two(len(v) + n)); let i: uint = 0u; while i < n { v += [initval]; i += 1u; } @@ -335,7 +335,7 @@ v - The vector to grow n - The number of elements to add initval - The value for the new elements */ -fn grow_mut(&v: [mutable T], n: uint, initval: T) { +fn grow_mut(&v: [mutable T], n: uint, initval: T) { reserve(v, next_power_of_two(len(v) + n)); let i: uint = 0u; while i < n { v += [mutable initval]; i += 1u; } @@ -371,7 +371,7 @@ Sets the element at position `index` to `val`. If `index` is past the end of the vector, expands the vector by replicating `initval` to fill the intervening space. */ -fn grow_set(&v: [mutable T], index: uint, initval: T, val: T) { +fn grow_set(&v: [mutable T], index: uint, initval: T, val: T) { if index >= len(v) { grow_mut(v, index - len(v) + 1u, initval); } v[index] = val; } @@ -384,12 +384,12 @@ Function: map Apply a function to each element of a vector and return the results */ -fn map(f: block(T) -> U, v: [const T]) -> [U] { +fn map(f: block(T) -> U, v: [const T]) -> [U] { let result = []; reserve(result, len(v)); for elem: T in v { - let elem2 = elem; // satisfies alias checker - result += [f(elem2)]; + // copy satisfies alias checker + result += [f(copy elem)]; } ret result; } @@ -399,12 +399,12 @@ Function: map2 Apply a function to each pair of elements and return the results */ -fn map2(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] { - let v0_len = len::(v0); - if v0_len != len::(v1) { fail; } +fn map2(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] { + let v0_len = len(v0); + if v0_len != len(v1) { fail; } let u: [V] = []; let i = 0u; - while i < v0_len { u += [f({ v0[i] }, { v1[i] })]; i += 1u; } + while i < v0_len { u += [f(copy v0[i], copy v1[i])]; i += 1u; } ret u; } @@ -416,11 +416,11 @@ Apply a function to each element of a vector and return the results If function `f` returns `none` then that element is excluded from the resulting vector. */ -fn filter_map(f: block(T) -> option::t, v: [const T]) -> [U] { +fn filter_map(f: block(T) -> option::t, v: [const T]) + -> [U] { let result = []; for elem: T in v { - let elem2 = elem; // satisfies alias checker - alt f(elem2) { + alt f(copy elem) { none. {/* no-op */ } some(result_elem) { result += [result_elem]; } } @@ -437,13 +437,10 @@ holds. Apply function `f` to each element of `v` and return a vector containing only those elements for which `f` returned true. */ -fn filter(f: block(T) -> bool, v: [const T]) -> [T] { +fn filter(f: block(T) -> bool, v: [T]) -> [T] { let result = []; for elem: T in v { - let elem2 = elem; // satisfies alias checker - if f(elem2) { - result += [elem2]; - } + if f(elem) { result += [elem]; } } ret result; } @@ -454,8 +451,7 @@ Function: concat Concatenate a vector of vectors. Flattens a vector of vectors of T into a single vector of T. */ -fn concat(v: [const [const T]]) -> [T] { - // FIXME: So much copying +fn concat(v: [const [const T]]) -> [T] { let new: [T] = []; for inner: [T] in v { new += inner; } ret new; @@ -466,7 +462,7 @@ Function: foldl Reduce a vector from left to right */ -fn foldl(p: block(T, U) -> T, z: T, v: [const U]) -> T { +fn foldl(p: block(T, U) -> T, z: T, v: [const U]) -> T { let accum = z; iter(v) { |elt| accum = p(accum, elt); @@ -479,7 +475,7 @@ Function: foldr Reduce a vector from right to left */ -fn foldr(p: block(T, U) -> U, z: U, v: [const T]) -> U { +fn foldr(p: block(T, U) -> U, z: U, v: [const T]) -> U { let accum = z; riter(v) { |elt| accum = p(elt, accum); @@ -541,7 +537,7 @@ Apply function `f` to each element of `v`, starting from the first. When function `f` returns true then an option containing the element is returned. If `f` matches no elements then none is returned. */ -fn find(f: block(T) -> bool, v: [T]) -> option::t { +fn find(f: block(T) -> bool, v: [T]) -> option::t { for elt: T in v { if f(elt) { ret some(elt); } } ret none; } @@ -587,7 +583,7 @@ vector contains the first element of the i-th tuple of the input vector, and the i-th element of the second vector contains the second element of the i-th tuple of the input vector. */ -fn unzip(v: [(T, U)]) -> ([T], [U]) { +fn unzip(v: [(T, U)]) -> ([T], [U]) { let as = [], bs = []; for (a, b) in v { as += [a]; bs += [b]; } ret (as, bs); @@ -605,7 +601,7 @@ Preconditions: (v, u) */ -fn zip(v: [T], u: [U]) : same_length(v, u) -> [(T, U)] { +fn zip(v: [T], u: [U]) : same_length(v, u) -> [(T, U)] { let zipped = []; let sz = len(v), i = 0u; assert (sz == len(u)); @@ -624,9 +620,7 @@ a - The index of the first element b - The index of the second element */ fn swap(v: [mutable T], a: uint, b: uint) { - let t: T = v[a]; - v[a] = v[b]; - v[b] = t; + v[a] <-> v[b]; } /* @@ -637,7 +631,7 @@ Reverse the order of elements in a vector, in place fn reverse(v: [mutable T]) { let i: uint = 0u; let ln = len::(v); - while i < ln / 2u { swap(v, i, ln - i - 1u); i += 1u; } + while i < ln / 2u { v[i] <-> v[ln - i - 1u]; i += 1u; } } @@ -646,7 +640,7 @@ Function: reversed Returns a vector with the order of elements reversed */ -fn reversed(v: [const T]) -> [T] { +fn reversed(v: [const T]) -> [T] { let rs: [T] = []; let i = len::(v); if i == 0u { ret rs; } else { i -= 1u; } @@ -746,7 +740,7 @@ is sorted then the permutations are lexicographically sorted). The total number of permutations produced is `len(v)!`. If `v` contains repeated elements, then some permutations are repeated. */ -fn permute(v: [const T], put: block([T])) { +fn permute(v: [const T], put: block([T])) { let ln = len(v); if ln == 0u { put([]); diff --git a/src/test/bench/task-perf-word-count-generic.rs b/src/test/bench/task-perf-word-count-generic.rs index af2a4e2889d..5f6c1e92309 100644 --- a/src/test/bench/task-perf-word-count-generic.rs +++ b/src/test/bench/task-perf-word-count-generic.rs @@ -55,25 +55,25 @@ mod map_reduce { export reducer; export map_reduce; - type putter = fn(K, V); + type putter = fn(K, V); // FIXME: the first K1 parameter should probably be a -, but that // doesn't parse at the moment. - type mapper = fn(K1, putter); + type mapper = fn(K1, putter); - type getter = fn() -> option; + type getter = fn() -> option; - type reducer = fn(K, getter); + type reducer = fn(K, getter); - tag ctrl_proto { + tag ctrl_proto { find_reducer(K, chan>>); mapper_done; } - tag reduce_proto { emit_val(V); done; ref; release; } + tag reduce_proto { emit_val(V); done; ref; release; } - fn start_mappers(map: mapper, + fn start_mappers(map: mapper, ctrl: chan>, inputs: [K1]) -> [joinable_task] { let tasks = []; @@ -84,15 +84,15 @@ mod map_reduce { ret tasks; } - fn map_task(-map: mapper, + fn map_task(-map: mapper, -ctrl: chan>, -input: K1) { // log_err "map_task " + input; let intermediates = treemap::init(); - fn emit(im: treemap::treemap>>, + fn emit(im: treemap::treemap>>, ctrl: chan>, key: K2, val: V) { let c; alt treemap::find(im, key) { @@ -110,15 +110,15 @@ mod map_reduce { map(input, bind emit(intermediates, ctrl, _, _)); - fn finish(_k: K, v: chan>) { + fn finish(_k: K, v: chan>) { send(v, release); } treemap::traverse(intermediates, finish); send(ctrl, mapper_done); } - fn reduce_task(-reduce: reducer, -key: K, + fn reduce_task(-reduce: reducer, -key: K, -out: chan>>) { let p = port(); @@ -127,7 +127,7 @@ mod map_reduce { let ref_count = 0; let is_done = false; - fn get(p: port>, + fn get(p: port>, &ref_count: int, &is_done: bool) -> option { while !is_done || ref_count > 0 { @@ -150,8 +150,8 @@ mod map_reduce { reduce(key, bind get(p, ref_count, is_done)); } - fn map_reduce(map: mapper, reduce: reducer, + fn map_reduce(map: mapper, reduce: reducer, inputs: [K1]) { let ctrl = port(); @@ -194,7 +194,7 @@ mod map_reduce { } } - fn finish(_k: K, v: chan>) { + fn finish(_k: K, v: chan>) { send(v, done); } treemap::traverse(reducers, finish); diff --git a/src/test/compile-fail/block-copy.rs b/src/test/compile-fail/block-copy.rs index 12bc0a0b2b9..b14bb3ddedd 100644 --- a/src/test/compile-fail/block-copy.rs +++ b/src/test/compile-fail/block-copy.rs @@ -1,5 +1,4 @@ -// error-pattern: needed shared type, got pinned type block -// xfail-test +// error-pattern: copying a noncopyable value fn lol(f: block()) -> block() { ret f; } fn main() { let i = 8; let f = lol(block () { log_err i; }); f(); } diff --git a/src/test/compile-fail/copy-a-resource.rs b/src/test/compile-fail/copy-a-resource.rs index f9e38941aa6..46807e05252 100644 --- a/src/test/compile-fail/copy-a-resource.rs +++ b/src/test/compile-fail/copy-a-resource.rs @@ -1,6 +1,5 @@ -// error-pattern:cannot copy pinned type foo -// xfail-test +// error-pattern: copying a noncopyable value resource foo(i: int) { } -fn main() { let x <- foo(10); let y = x; } +fn main() { let x <- foo(10); let y = x; log_err x; } diff --git a/src/test/compile-fail/copy-res-into-box.rs b/src/test/compile-fail/copy-res-into-box.rs deleted file mode 100644 index b4038b61d3e..00000000000 --- a/src/test/compile-fail/copy-res-into-box.rs +++ /dev/null @@ -1,16 +0,0 @@ -// error-pattern:mismatched kinds for '@' operand -// xfail-test -resource r(i: @mutable int) { - *i = *i + 1; -} - -fn main() { - let i = @mutable 0; - { - let j <- r(i); - // No no no no no - let k <- @j; - } - log_err *i; - assert *i == 2; -} \ No newline at end of file diff --git a/src/test/compile-fail/copy-res-into-rec.rs b/src/test/compile-fail/copy-res-into-rec.rs deleted file mode 100644 index 0fec1ba8a04..00000000000 --- a/src/test/compile-fail/copy-res-into-rec.rs +++ /dev/null @@ -1,16 +0,0 @@ -// error-pattern:mismatched kinds for record field -// xfail-test -resource r(i: @mutable int) { - *i = *i + 1; -} - -fn main() { - let i = @mutable 0; - { - let j <- r(i); - // No no no no no - let k <- {x: j}; - } - log_err *i; - assert *i == 2; -} \ No newline at end of file diff --git a/src/test/compile-fail/copy-res-into-tup.rs b/src/test/compile-fail/copy-res-into-tup.rs deleted file mode 100644 index e9318ae4280..00000000000 --- a/src/test/compile-fail/copy-res-into-tup.rs +++ /dev/null @@ -1,16 +0,0 @@ -// error-pattern:mismatched kinds for tuple parameter -// xfail-test -resource r(i: @mutable int) { - *i = *i + 1; -} - -fn main() { - let i = @mutable 0; - { - let j <- r(i); - // No no no no no - let k <- (j, 0); - } - log_err *i; - assert *i == 2; -} \ No newline at end of file diff --git a/src/test/compile-fail/copy-res-into-unique.rs b/src/test/compile-fail/copy-res-into-unique.rs deleted file mode 100644 index 6fa1e852b4a..00000000000 --- a/src/test/compile-fail/copy-res-into-unique.rs +++ /dev/null @@ -1,16 +0,0 @@ -// error-pattern:mismatched kinds for '~' operand -// xfail-test -resource r(i: @mutable int) { - *i = *i + 1; -} - -fn main() { - let i = @mutable 0; - { - let j <- r(i); - // No no no no no - let k <- ~j; - } - log_err *i; - assert *i == 2; -} \ No newline at end of file diff --git a/src/test/compile-fail/fn-compare-mismatch.rs b/src/test/compile-fail/fn-compare-mismatch.rs index b844e7308b6..56238a6026f 100644 --- a/src/test/compile-fail/fn-compare-mismatch.rs +++ b/src/test/compile-fail/fn-compare-mismatch.rs @@ -1,4 +1,4 @@ -// error-pattern:expected fn() but found fn(+int) +// error-pattern:expected fn() but found fn(++int) fn main() { fn f() { } diff --git a/src/test/compile-fail/param-by-value.rs b/src/test/compile-fail/param-by-value.rs index 5e8321cb11f..2587e35219c 100644 --- a/src/test/compile-fail/param-by-value.rs +++ b/src/test/compile-fail/param-by-value.rs @@ -1,4 +1,4 @@ // error-pattern:can not pass a dynamically-sized type by value -fn f(+_x: T) {} +fn f(++_x: T) {} fn main() {} diff --git a/src/test/compile-fail/pinned-deep-copy.rs b/src/test/compile-fail/pinned-deep-copy.rs index 9e8081ca6ce..3d6c6f0c6eb 100644 --- a/src/test/compile-fail/pinned-deep-copy.rs +++ b/src/test/compile-fail/pinned-deep-copy.rs @@ -1,5 +1,4 @@ -// error-pattern: cannot copy pinned type ~~~{y: r} -// xfail-test +// error-pattern: copying a noncopyable value resource r(i: @mutable int) { *i = *i + 1; @@ -11,6 +10,7 @@ fn main() { // Can't do this copy let x = ~~~{y: r(i)}; let z = x; + log x; } log_err *i; } \ No newline at end of file diff --git a/src/test/compile-fail/resource-let2.rs b/src/test/compile-fail/resource-let2.rs deleted file mode 100644 index 17855a30bd0..00000000000 --- a/src/test/compile-fail/resource-let2.rs +++ /dev/null @@ -1,10 +0,0 @@ -// error-pattern: mismatched kind -// xfail-test - -resource r(b: bool) { -} - -fn main() { - let i <- r(true); - let j = i; -} \ No newline at end of file diff --git a/src/test/compile-fail/unique-pinned-nocopy.rs b/src/test/compile-fail/unique-pinned-nocopy.rs index 612dd0dda03..6bde4cbc6a4 100644 --- a/src/test/compile-fail/unique-pinned-nocopy.rs +++ b/src/test/compile-fail/unique-pinned-nocopy.rs @@ -1,11 +1,10 @@ -// error-pattern: mismatched kind -// xfail-test +// error-pattern: copying a noncopyable value resource r(b: bool) { } fn main() { let i <- ~r(true); - let j; - j = i; + let j = i; + log i; } \ No newline at end of file diff --git a/src/test/compile-fail/unique-swap2.rs b/src/test/compile-fail/unique-swap2.rs deleted file mode 100644 index 2a653010701..00000000000 --- a/src/test/compile-fail/unique-swap2.rs +++ /dev/null @@ -1,37 +0,0 @@ -// error-pattern:needed shared type, got pinned type ~r -// xfail-test - -resource r(i: @mutable int) { - *i += 1; -} - -fn test1() { - let i = @mutable 100; - let j = @mutable 200; - { - let x <- ~r(i); - let y <- ~r(j); - // This is currently not allowed because ~resource is pinned. - // Note that ~resource is supposed to be shared. - x <-> y; - assert ***x == 200; - assert ***y == 100; - } - assert *i == 101; - assert *j == 201; -} - -fn test2() { - let i = @mutable 0; - { - let x <- ~r(i); - let y <- ~r(i); - x <-> y; - } - assert *i == 2; -} - -fn main() { - test1(); - test2(); -} \ No newline at end of file diff --git a/src/test/compile-fail/unique-unique-kind.rs b/src/test/compile-fail/unique-unique-kind.rs index b20c552a011..ad172f7ae83 100644 --- a/src/test/compile-fail/unique-unique-kind.rs +++ b/src/test/compile-fail/unique-unique-kind.rs @@ -1,7 +1,6 @@ -// error-pattern: needed unique type -// xfail-test +// error-pattern: instantiating a sendable type parameter with a copyable type -fn f(i: T) { +fn f(i: T) { } fn main() { diff --git a/src/test/compile-fail/unique-vec-res.rs b/src/test/compile-fail/unique-vec-res.rs index 434b18bbb06..0b16c513350 100644 --- a/src/test/compile-fail/unique-vec-res.rs +++ b/src/test/compile-fail/unique-vec-res.rs @@ -1,12 +1,10 @@ -// error-pattern: needed shared type, got pinned type ~r -// xfail-test +// error-pattern: copying a noncopyable value resource r(i: @mutable int) { *i = *i + 1; } -fn f(i: [T], j: [T]) { - // Shouldn't be able to do this copy of j +fn f(+i: [T], +j: [T]) { let k = i + j; } @@ -16,6 +14,6 @@ fn main() { let r1 <- [~r(i1)]; let r2 <- [~r(i2)]; f(r1, r2); - log_err *i1; - log_err *i2; + log (r2, *i1); + log (r1, *i2); } \ No newline at end of file diff --git a/src/test/compile-fail/use-after-send.rs b/src/test/compile-fail/use-after-send.rs index 7a70292f526..e625ef138d4 100644 --- a/src/test/compile-fail/use-after-send.rs +++ b/src/test/compile-fail/use-after-send.rs @@ -1,5 +1,5 @@ // error-pattern: Unsatisfied precondition constraint -fn send(ch: _chan, -data: T) { log ch; log data; fail; } +fn send(ch: _chan, -data: T) { log ch; log data; fail; } type _chan = int; // Tests that "log message;" is flagged as using diff --git a/src/test/compile-fail/vec-pinned-nocopy-2.rs b/src/test/compile-fail/vec-pinned-nocopy-2.rs deleted file mode 100644 index 168429b6c8f..00000000000 --- a/src/test/compile-fail/vec-pinned-nocopy-2.rs +++ /dev/null @@ -1,10 +0,0 @@ -// error-pattern: mismatched kind -// xfail-test - -resource r(b: bool) { -} - -fn main() { - let i <- [r(true)]; - i += [r(true)]; -} \ No newline at end of file diff --git a/src/test/compile-fail/vec-pinned-nocopy-3.rs b/src/test/compile-fail/vec-pinned-nocopy-3.rs deleted file mode 100644 index 54493ea4536..00000000000 --- a/src/test/compile-fail/vec-pinned-nocopy-3.rs +++ /dev/null @@ -1,11 +0,0 @@ -// error-pattern: mismatched kind -// xfail-test - -resource r(b: bool) { -} - -fn main() { - let i <- [r(true)]; - let j; - j <- copy [r(true)]; -} \ No newline at end of file diff --git a/src/test/compile-fail/vec-pinned-nocopy.rs b/src/test/compile-fail/vec-pinned-nocopy.rs deleted file mode 100644 index 91dfb4fd6f0..00000000000 --- a/src/test/compile-fail/vec-pinned-nocopy.rs +++ /dev/null @@ -1,11 +0,0 @@ -// error-pattern: mismatched kind -// xfail-test - -resource r(b: bool) { -} - -fn main() { - let i <- [r(true)]; - let j; - j = i; -} \ No newline at end of file diff --git a/src/test/compile-fail/vec-res-add.rs b/src/test/compile-fail/vec-res-add.rs index 3d240a76480..818080a6e55 100644 --- a/src/test/compile-fail/vec-res-add.rs +++ b/src/test/compile-fail/vec-res-add.rs @@ -1,12 +1,11 @@ -// error-pattern:mismatched kinds -// xfail-test +// error-pattern: copying a noncopyable value -resource r(i: int) { -} +resource r(_i: int) { } fn main() { // This can't make sense as it would copy the resources let i <- [r(0)]; let j <- [r(1)]; let k = i + j; -} \ No newline at end of file + log j; +} diff --git a/src/test/run-fail/bug-811.rs b/src/test/run-fail/bug-811.rs index 95041c72ca8..a257a903fd2 100644 --- a/src/test/run-fail/bug-811.rs +++ b/src/test/run-fail/bug-811.rs @@ -4,8 +4,8 @@ fn test00_start(ch: chan_t, message: int) { send(ch, copy message); } type task_id = int; type port_id = int; -type chan_t = {task: task_id, port: port_id}; +type chan_t = {task: task_id, port: port_id}; -fn send(ch: chan_t, -data: T) { fail; } +fn send(ch: chan_t, -data: T) { fail; } fn main() { fail "quux"; } diff --git a/src/test/run-fail/port-type.rs b/src/test/run-fail/port-type.rs index e9a4e0679b7..e227b3d4c93 100644 --- a/src/test/run-fail/port-type.rs +++ b/src/test/run-fail/port-type.rs @@ -5,7 +5,7 @@ import std::comm::port; import std::comm::send; import std::comm::recv; -fn echo(c: chan, oc: chan>) { +fn echo(c: chan, oc: chan>) { // Tests that the type argument in port gets // visited let p = port::(); diff --git a/src/test/run-pass/auto-instantiate.rs b/src/test/run-pass/auto-instantiate.rs index 4900df4aed0..e701427a8a3 100644 --- a/src/test/run-pass/auto-instantiate.rs +++ b/src/test/run-pass/auto-instantiate.rs @@ -2,6 +2,6 @@ // -*- rust -*- -fn f(x: T, y: U) -> {a: T, b: U} { ret {a: x, b: y}; } +fn f(x: T, y: U) -> {a: T, b: U} { ret {a: x, b: y}; } fn main() { log f({x: 3, y: 4, z: 5}, 4).a.x; log f(5, 6).a; } diff --git a/src/test/run-pass/bind-generic.rs b/src/test/run-pass/bind-generic.rs index 888c5021b3f..882a54f603b 100644 --- a/src/test/run-pass/bind-generic.rs +++ b/src/test/run-pass/bind-generic.rs @@ -1,4 +1,4 @@ -fn wrapper3(i: T, j: int) { +fn wrapper3(i: T, j: int) { log i; log j; // This is a regression test that the spawn3 thunk to wrapper3 @@ -6,7 +6,7 @@ fn wrapper3(i: T, j: int) { assert j == 123456789; } -fn spawn3(i: T, j: int) { +fn spawn3(i: T, j: int) { let wrapped = bind wrapper3(i, j); wrapped(); } diff --git a/src/test/run-pass/box-unbox.rs b/src/test/run-pass/box-unbox.rs index 5dc0c670dca..56bcbb717ad 100644 --- a/src/test/run-pass/box-unbox.rs +++ b/src/test/run-pass/box-unbox.rs @@ -1,8 +1,8 @@ -type box = {c: @T}; +type box = {c: @T}; -fn unbox(b: box) -> T { ret *b.c; } +fn unbox(b: box) -> T { ret *b.c; } fn main() { let foo: int = 17; diff --git a/src/test/run-pass/expr-block-generic-box2.rs b/src/test/run-pass/expr-block-generic-box2.rs index 9a54cd20a8b..ba98b8546a1 100644 --- a/src/test/run-pass/expr-block-generic-box2.rs +++ b/src/test/run-pass/expr-block-generic-box2.rs @@ -4,7 +4,7 @@ // -*- rust -*- type compare = fn@(T, T) -> bool; -fn test_generic(expected: T, eq: compare) { +fn test_generic(expected: T, eq: compare) { let actual: T = { expected }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-block-generic-unique1.rs b/src/test/run-pass/expr-block-generic-unique1.rs index 1055cd16221..436689f68aa 100644 --- a/src/test/run-pass/expr-block-generic-unique1.rs +++ b/src/test/run-pass/expr-block-generic-unique1.rs @@ -3,7 +3,7 @@ // -*- rust -*- type compare = fn@(~T, ~T) -> bool; -fn test_generic(expected: ~T, eq: compare) { +fn test_generic(expected: ~T, eq: compare) { let actual: ~T = { expected }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-block-generic-unique2.rs b/src/test/run-pass/expr-block-generic-unique2.rs index 3325c8f2384..fba64608186 100644 --- a/src/test/run-pass/expr-block-generic-unique2.rs +++ b/src/test/run-pass/expr-block-generic-unique2.rs @@ -4,7 +4,7 @@ // -*- rust -*- type compare = fn@(T, T) -> bool; -fn test_generic(expected: T, eq: compare) { +fn test_generic(expected: T, eq: compare) { let actual: T = { expected }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-block-generic.rs b/src/test/run-pass/expr-block-generic.rs index 8e270a56edd..4424d144e15 100644 --- a/src/test/run-pass/expr-block-generic.rs +++ b/src/test/run-pass/expr-block-generic.rs @@ -6,7 +6,7 @@ // Tests for standalone blocks as expressions with dynamic type sizes type compare = fn@(T, T) -> bool; -fn test_generic(expected: T, eq: compare) { +fn test_generic(expected: T, eq: compare) { let actual: T = { expected }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-if-generic-box2.rs b/src/test/run-pass/expr-if-generic-box2.rs index 549d3a69aea..da00556eb4e 100644 --- a/src/test/run-pass/expr-if-generic-box2.rs +++ b/src/test/run-pass/expr-if-generic-box2.rs @@ -4,7 +4,7 @@ // -*- rust -*- type compare = fn@(T, T) -> bool; -fn test_generic(expected: T, not_expected: T, eq: compare) { +fn test_generic(expected: T, not_expected: T, eq: compare) { let actual: T = if true { expected } else { not_expected }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-if-generic.rs b/src/test/run-pass/expr-if-generic.rs index b2b62523e55..f98a8742cc2 100644 --- a/src/test/run-pass/expr-if-generic.rs +++ b/src/test/run-pass/expr-if-generic.rs @@ -6,7 +6,7 @@ // Tests for if as expressions with dynamic type sizes type compare = fn@(T, T) -> bool; -fn test_generic(expected: T, not_expected: T, eq: compare) { +fn test_generic(expected: T, not_expected: T, eq: compare) { let actual: T = if true { expected } else { not_expected }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/fixed-point-bind-unique.rs b/src/test/run-pass/fixed-point-bind-unique.rs index 6fe82172814..bbfc3f53f26 100644 --- a/src/test/run-pass/fixed-point-bind-unique.rs +++ b/src/test/run-pass/fixed-point-bind-unique.rs @@ -1,8 +1,8 @@ -fn fix_help(f: fn(fn@(A) -> B, A) -> B, x: A) -> B { +fn fix_help(f: fn(fn@(A) -> B, A) -> B, x: A) -> B { ret f(bind fix_help(f, _), x); } -fn fix(f: fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B { +fn fix(f: fn(fn@(A) -> B, A) -> B) -> fn@(A) -> B { ret bind fix_help(f, _); } diff --git a/src/test/run-pass/fn-bare-spawn.rs b/src/test/run-pass/fn-bare-spawn.rs index e0da008d75c..59a57b8597c 100644 --- a/src/test/run-pass/fn-bare-spawn.rs +++ b/src/test/run-pass/fn-bare-spawn.rs @@ -1,6 +1,6 @@ // This is what the signature to spawn should look like with bare functions -fn spawn(val: T, f: fn(T)) { +fn spawn(val: T, f: fn(T)) { f(val); } diff --git a/src/test/run-pass/foreach-unique-drop.rs b/src/test/run-pass/foreach-unique-drop.rs index 6778f2597ed..5b696a0efe9 100644 --- a/src/test/run-pass/foreach-unique-drop.rs +++ b/src/test/run-pass/foreach-unique-drop.rs @@ -1,5 +1,5 @@ -obj ob(k: K) { +obj ob(k: K) { fn foo(it: block(~{a: K})) { it(~{a: k}); } } diff --git a/src/test/run-pass/generic-alias-box.rs b/src/test/run-pass/generic-alias-box.rs index 9624eca31ac..470815996ce 100644 --- a/src/test/run-pass/generic-alias-box.rs +++ b/src/test/run-pass/generic-alias-box.rs @@ -1,6 +1,6 @@ -fn id(t: T) -> T { ret t; } +fn id(t: T) -> T { ret t; } fn main() { let expected = @100; diff --git a/src/test/run-pass/generic-alias-unique.rs b/src/test/run-pass/generic-alias-unique.rs index d1b7598d35e..1ca044ef162 100644 --- a/src/test/run-pass/generic-alias-unique.rs +++ b/src/test/run-pass/generic-alias-unique.rs @@ -1,6 +1,6 @@ -fn id(t: T) -> T { ret t; } +fn id(t: T) -> T { ret t; } fn main() { let expected = ~100; diff --git a/src/test/run-pass/generic-bind-2.rs b/src/test/run-pass/generic-bind-2.rs index 8b03cc68f0f..c633cb2d08a 100644 --- a/src/test/run-pass/generic-bind-2.rs +++ b/src/test/run-pass/generic-bind-2.rs @@ -1,6 +1,6 @@ -fn id(t: T) -> T { ret t; } +fn id(t: T) -> T { ret t; } fn main() { let t = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7}; diff --git a/src/test/run-pass/generic-bind.rs b/src/test/run-pass/generic-bind.rs index 47e0ffc973e..8464bfb0241 100644 --- a/src/test/run-pass/generic-bind.rs +++ b/src/test/run-pass/generic-bind.rs @@ -1,6 +1,6 @@ -fn id(t: T) -> T { ret t; } +fn id(t: T) -> T { ret t; } fn main() { let t = {_0: 1, _1: 2, _2: 3, _3: 4, _4: 5, _5: 6, _6: 7}; diff --git a/src/test/run-pass/generic-box.rs b/src/test/run-pass/generic-box.rs index 3e37834f47b..87465ae6a93 100644 --- a/src/test/run-pass/generic-box.rs +++ b/src/test/run-pass/generic-box.rs @@ -1,6 +1,6 @@ -fn box(x: {x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { ret @x; } +fn box(x: {x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { ret @x; } fn main() { let x: @{x: int, y: int, z: int} = box::({x: 1, y: 2, z: 3}); diff --git a/src/test/run-pass/generic-derived-type.rs b/src/test/run-pass/generic-derived-type.rs index 50834dd2b1f..05f311167cf 100644 --- a/src/test/run-pass/generic-derived-type.rs +++ b/src/test/run-pass/generic-derived-type.rs @@ -1,8 +1,8 @@ -fn g(x: X) -> X { ret x; } +fn g(x: X) -> X { ret x; } -fn f(t: T) -> {a: T, b: T} { +fn f(t: T) -> {a: T, b: T} { type pair = {a: T, b: T}; let x: pair = {a: t, b: t}; diff --git a/src/test/run-pass/generic-drop-glue.rs b/src/test/run-pass/generic-drop-glue.rs index ad89b7fe556..ced0ecfbe9e 100644 --- a/src/test/run-pass/generic-drop-glue.rs +++ b/src/test/run-pass/generic-drop-glue.rs @@ -1,5 +1,5 @@ -fn f(t: T) { let t1: T = t; } +fn f(t: T) { let t1: T = t; } fn main() { let x = {x: @10, y: @12}; f(x); } diff --git a/src/test/run-pass/generic-exterior-box.rs b/src/test/run-pass/generic-exterior-box.rs index 7573bff74e8..41315e15643 100644 --- a/src/test/run-pass/generic-exterior-box.rs +++ b/src/test/run-pass/generic-exterior-box.rs @@ -1,8 +1,8 @@ -type recbox = {x: @T}; +type recbox = {x: @T}; -fn reclift(t: T) -> recbox { ret {x: @t}; } +fn reclift(t: T) -> recbox { ret {x: @t}; } fn main() { let foo: int = 17; diff --git a/src/test/run-pass/generic-exterior-unique.rs b/src/test/run-pass/generic-exterior-unique.rs index 09c2a5daead..1a97c134748 100644 --- a/src/test/run-pass/generic-exterior-unique.rs +++ b/src/test/run-pass/generic-exterior-unique.rs @@ -1,6 +1,6 @@ -type recbox = {x: ~T}; +type recbox = {x: ~T}; -fn reclift(t: T) -> recbox { ret {x: ~t}; } +fn reclift(t: T) -> recbox { ret {x: ~t}; } fn main() { let foo: int = 17; diff --git a/src/test/run-pass/generic-fn-infer.rs b/src/test/run-pass/generic-fn-infer.rs index d45722ccc94..57d4052e5a0 100644 --- a/src/test/run-pass/generic-fn-infer.rs +++ b/src/test/run-pass/generic-fn-infer.rs @@ -4,6 +4,6 @@ // -*- rust -*- // Issue #45: infer type parameters in function applications -fn id(x: T) -> T { ret x; } +fn id(x: T) -> T { ret x; } fn main() { let x: int = 42; let y: int = id(x); assert (x == y); } diff --git a/src/test/run-pass/generic-fn-unique.rs b/src/test/run-pass/generic-fn-unique.rs index 28f3fcec1e4..49cc7600315 100644 --- a/src/test/run-pass/generic-fn-unique.rs +++ b/src/test/run-pass/generic-fn-unique.rs @@ -1,4 +1,4 @@ -fn f(x: ~T) -> ~T { ret x; } +fn f(x: ~T) -> ~T { ret x; } fn main() { let x = f(~3); log *x; } diff --git a/src/test/run-pass/generic-fn.rs b/src/test/run-pass/generic-fn.rs index 9dbd6dd156c..63350c44273 100644 --- a/src/test/run-pass/generic-fn.rs +++ b/src/test/run-pass/generic-fn.rs @@ -2,7 +2,7 @@ // -*- rust -*- -fn id(x: T) -> T { ret x; } +fn id(x: T) -> T { ret x; } type triple = {x: int, y: int, z: int}; diff --git a/src/test/run-pass/generic-obj-with-derived-type.rs b/src/test/run-pass/generic-obj-with-derived-type.rs index 435a61e165f..5aa6769da64 100644 --- a/src/test/run-pass/generic-obj-with-derived-type.rs +++ b/src/test/run-pass/generic-obj-with-derived-type.rs @@ -1,6 +1,6 @@ -obj handle(data: T) { +obj handle(data: T) { fn get() -> T { ret data; } } diff --git a/src/test/run-pass/generic-obj.rs b/src/test/run-pass/generic-obj.rs index eb3d7793e8b..fa90e5863b6 100644 --- a/src/test/run-pass/generic-obj.rs +++ b/src/test/run-pass/generic-obj.rs @@ -1,6 +1,6 @@ -obj buf(data: {_0: T, _1: T, _2: T}) { +obj buf(data: {_0: T, _1: T, _2: T}) { fn get(i: int) -> T { if i == 0 { ret data._0; diff --git a/src/test/run-pass/generic-tup.rs b/src/test/run-pass/generic-tup.rs index e85de5dd485..7134c96d4e2 100644 --- a/src/test/run-pass/generic-tup.rs +++ b/src/test/run-pass/generic-tup.rs @@ -1,4 +1,4 @@ -fn get_third(t: (T, T, T)) -> T { let (_, _, x) = t; ret x; } +fn get_third(t: (T, T, T)) -> T { let (_, _, x) = t; ret x; } fn main() { log get_third((1, 2, 3)); diff --git a/src/test/run-pass/generic-unique.rs b/src/test/run-pass/generic-unique.rs index 29a40dd4c1f..3b6b19ce450 100644 --- a/src/test/run-pass/generic-unique.rs +++ b/src/test/run-pass/generic-unique.rs @@ -1,5 +1,5 @@ -fn box(x: {x: T, y: T, z: T}) -> ~{x: T, y: T, z: T} { ret ~x; } +fn box(x: {x: T, y: T, z: T}) -> ~{x: T, y: T, z: T} { ret ~x; } fn main() { let x: ~{x: int, y: int, z: int} = box::({x: 1, y: 2, z: 3}); diff --git a/src/test/run-pass/issue-333.rs b/src/test/run-pass/issue-333.rs index 0a01845841a..793df760b4b 100644 --- a/src/test/run-pass/issue-333.rs +++ b/src/test/run-pass/issue-333.rs @@ -1,5 +1,5 @@ -fn quux(x: T) -> T { let f = bind id::(_); ret f(x); } +fn quux(x: T) -> T { let f = bind id::(_); ret f(x); } -fn id(x: T) -> T { ret x; } +fn id(x: T) -> T { ret x; } fn main() { assert (quux(10) == 10); } diff --git a/src/test/run-pass/ivec-add.rs b/src/test/run-pass/ivec-add.rs index f9378b21317..9e45b028386 100644 --- a/src/test/run-pass/ivec-add.rs +++ b/src/test/run-pass/ivec-add.rs @@ -1,4 +1,4 @@ -fn double(a: T) -> [T] { ret [a] + [a]; } +fn double(a: T) -> [T] { ret [a] + [a]; } fn double_int(a: int) -> [int] { ret [a] + [a]; } diff --git a/src/test/run-pass/newtype-polymorphic.rs b/src/test/run-pass/newtype-polymorphic.rs index e08ace6947d..5bb2171dfd2 100644 --- a/src/test/run-pass/newtype-polymorphic.rs +++ b/src/test/run-pass/newtype-polymorphic.rs @@ -1,8 +1,8 @@ tag myvec = [X]; -fn myvec_deref(mv: myvec) -> [X] { ret *mv; } +fn myvec_deref(mv: myvec) -> [X] { ret *mv; } -fn myvec_elt(mv: myvec) -> X { ret mv[0]; } +fn myvec_elt(mv: myvec) -> X { ret mv[0]; } fn main() { let mv = myvec([1, 2, 3]); diff --git a/src/test/run-pass/non-boolean-pure-fns.rs b/src/test/run-pass/non-boolean-pure-fns.rs index 6bd044c9574..3a85cba6162 100644 --- a/src/test/run-pass/non-boolean-pure-fns.rs +++ b/src/test/run-pass/non-boolean-pure-fns.rs @@ -2,19 +2,19 @@ use std; import std::list::*; -pure fn pure_length_go(ls: list, acc: uint) -> uint { +pure fn pure_length_go(ls: list, acc: uint) -> uint { alt ls { nil. { acc } cons(_, tl) { pure_length_go(*tl, acc + 1u) } } } -pure fn pure_length(ls: list) -> uint { pure_length_go(ls, 0u) } +pure fn pure_length(ls: list) -> uint { pure_length_go(ls, 0u) } -pure fn nonempty_list(ls: list) -> bool { pure_length(ls) > 0u } +pure fn nonempty_list(ls: list) -> bool { pure_length(ls) > 0u } // Of course, the compiler can't take advantage of the // knowledge that ls is a cons node. Future work. // Also, this is pretty contrived since nonempty_list // could be a "tag refinement", if we implement those. -fn safe_head(ls: list) : nonempty_list(ls) -> T { head(ls) } +fn safe_head(ls: list) : nonempty_list(ls) -> T { head(ls) } fn main() { let mylist = cons(@1u, @nil); diff --git a/src/test/run-pass/obj-return-polytypes.rs b/src/test/run-pass/obj-return-polytypes.rs index e8747f1a95b..ebfcf37e79d 100644 --- a/src/test/run-pass/obj-return-polytypes.rs +++ b/src/test/run-pass/obj-return-polytypes.rs @@ -6,7 +6,7 @@ tag clam { signed(int); unsigned(uint); } fn getclam() -> clam { ret signed::(42); } -obj impatience() { +obj impatience() { fn moreclam() -> clam { be getclam::(); } } diff --git a/src/test/run-pass/resource-in-struct.rs b/src/test/run-pass/resource-in-struct.rs index 96cc02337cc..758beb3d9e1 100644 --- a/src/test/run-pass/resource-in-struct.rs +++ b/src/test/run-pass/resource-in-struct.rs @@ -5,7 +5,7 @@ type closable = @mutable bool; resource close_res(i: closable) { *i = false; } -tag option { none; some(T); } +tag option { none; some(T); } fn sink(res: option) { } diff --git a/src/test/run-pass/ret-none.rs b/src/test/run-pass/ret-none.rs index b56db9f9c70..fe91c15c72d 100644 --- a/src/test/run-pass/ret-none.rs +++ b/src/test/run-pass/ret-none.rs @@ -2,6 +2,6 @@ tag option { none; some(T); } -fn f() -> option { ret none; } +fn f() -> option { ret none; } fn main() { f::(); } diff --git a/src/test/run-pass/send-type-inference.rs b/src/test/run-pass/send-type-inference.rs index 0cc9a45d062..aad9a0696d1 100644 --- a/src/test/run-pass/send-type-inference.rs +++ b/src/test/run-pass/send-type-inference.rs @@ -4,9 +4,9 @@ import std::comm::send; import std::comm::port; // tests that ctrl's type gets inferred properly -type command = {key: K, val: V}; +type command = {key: K, val: V}; -fn cache_server(c: chan>>) { +fn cache_server(c: chan>>) { let ctrl = port(); send(c, chan(ctrl)); } diff --git a/src/test/run-pass/type-param-constraints.rs b/src/test/run-pass/type-param-constraints.rs index 445632e33b5..b6d76bc9d7c 100644 --- a/src/test/run-pass/type-param-constraints.rs +++ b/src/test/run-pass/type-param-constraints.rs @@ -1,6 +1,6 @@ -fn p_foo(pinned: T) { } -fn s_foo(shared: T) { } -fn u_foo(unique: T) { } +fn p_foo(pinned: T) { } +fn s_foo(shared: T) { } +fn u_foo(unique: T) { } resource r(i: int) { } diff --git a/src/test/run-pass/unchecked-predicates.rs b/src/test/run-pass/unchecked-predicates.rs index e33c080e64f..a4c80b57549 100644 --- a/src/test/run-pass/unchecked-predicates.rs +++ b/src/test/run-pass/unchecked-predicates.rs @@ -5,24 +5,24 @@ import std::list::*; // Can't easily be written as a "pure fn" because there's // no syntax for specifying that f is pure. -fn pure_foldl(ls: list, u: U, f: block(T, U) -> U) -> U { +fn pure_foldl(ls: list, u: U, f: block(T, U) -> U) -> U { alt ls { nil. { u } cons(hd, tl) { f(hd, pure_foldl(*tl, f(hd, u), f)) } } } // Shows how to use an "unchecked" block to call a general // fn from a pure fn -pure fn pure_length(ls: list) -> uint { +pure fn pure_length(ls: list) -> uint { fn count(_t: T, &&u: uint) -> uint { u + 1u } unchecked{ pure_foldl(ls, 0u, bind count(_, _)) } } -pure fn nonempty_list(ls: list) -> bool { pure_length(ls) > 0u } +pure fn nonempty_list(ls: list) -> bool { pure_length(ls) > 0u } // Of course, the compiler can't take advantage of the // knowledge that ls is a cons node. Future work. // Also, this is pretty contrived since nonempty_list // could be a "tag refinement", if we implement those. -fn safe_head(ls: list) : nonempty_list(ls) -> T { head(ls) } +fn safe_head(ls: list) : nonempty_list(ls) -> T { head(ls) } fn main() { let mylist = cons(@1u, @nil); diff --git a/src/test/run-pass/unique-assign-generic.rs b/src/test/run-pass/unique-assign-generic.rs index dfff2490b05..372cca1c667 100644 --- a/src/test/run-pass/unique-assign-generic.rs +++ b/src/test/run-pass/unique-assign-generic.rs @@ -1,4 +1,4 @@ -fn f(t: T) -> T { +fn f(t: T) -> T { let t1 = t; t1 } diff --git a/src/test/run-pass/unique-generic-assign.rs b/src/test/run-pass/unique-generic-assign.rs index 3f692a59db7..4370bb4a791 100644 --- a/src/test/run-pass/unique-generic-assign.rs +++ b/src/test/run-pass/unique-generic-assign.rs @@ -1,6 +1,6 @@ // Issue #976 -fn f(x: ~T) { +fn f(x: ~T) { let _x2 = x; } fn main() { } diff --git a/src/test/run-pass/unique-kinds.rs b/src/test/run-pass/unique-kinds.rs index da8babb0b9a..ab88437331c 100644 --- a/src/test/run-pass/unique-kinds.rs +++ b/src/test/run-pass/unique-kinds.rs @@ -1,10 +1,10 @@ -fn unique() { +fn sendable() { - fn f(i: T, j: T) { + fn f(i: T, j: T) { assert i == j; } - fn g(i: T, j: T) { + fn g(i: T, j: T) { assert i != j; } @@ -16,7 +16,25 @@ fn unique() { g(i, j); } -fn shared() { +fn copyable() { + + fn f(i: T, j: T) { + assert i == j; + } + + fn g(i: T, j: T) { + assert i != j; + } + + let i = ~100; + let j = ~100; + f(i, j); + let i = ~100; + let j = ~101; + g(i, j); +} + +fn noncopyable() { fn f(i: T, j: T) { assert i == j; @@ -34,26 +52,8 @@ fn shared() { g(i, j); } -fn pinned() { - - fn f(i: T, j: T) { - assert i == j; - } - - fn g(i: T, j: T) { - assert i != j; - } - - let i = ~100; - let j = ~100; - f(i, j); - let i = ~100; - let j = ~101; - g(i, j); -} - fn main() { - unique(); - shared(); - pinned(); -} \ No newline at end of file + sendable(); + copyable(); + noncopyable(); +} diff --git a/src/test/run-pass/vec-push.rs b/src/test/run-pass/vec-push.rs index 8cdd5e82f18..92da692e482 100644 --- a/src/test/run-pass/vec-push.rs +++ b/src/test/run-pass/vec-push.rs @@ -1,5 +1,5 @@ -fn push(&v: [const T], t: T) { v += [t]; } +fn push(&v: [const T], t: T) { v += [t]; } fn main() { let v = [1, 2, 3]; push(v, 1); } diff --git a/src/test/stdtest/deque.rs b/src/test/stdtest/deque.rs index fac7aa3a853..7a488475b9d 100644 --- a/src/test/stdtest/deque.rs +++ b/src/test/stdtest/deque.rs @@ -81,7 +81,7 @@ fn test_boxes(a: @int, b: @int, c: @int, d: @int) { type eqfn = fn@(T, T) -> bool; -fn test_parameterized(e: eqfn, a: T, b: T, c: T, d: T) { +fn test_parameterized(e: eqfn, a: T, b: T, c: T, d: T) { let deq: deque::t = deque::create::(); assert (deq.size() == 0u); deq.add_front(a); diff --git a/src/test/stdtest/task.rs b/src/test/stdtest/task.rs index 4e968e57942..a444fbbcc08 100644 --- a/src/test/stdtest/task.rs +++ b/src/test/stdtest/task.rs @@ -68,7 +68,7 @@ fn test_join_convenient() { #[ignore] fn spawn_polymorphic() { // FIXME #1038: Can't spawn palymorphic functions - /*fn foo(x: T) { log_err x; } + /*fn foo(x: T) { log_err x; } task::spawn(true, foo); task::spawn(42, foo);*/