diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-08-06 17:14:32 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-07 12:23:43 -0700 |
| commit | 2772b2e5c7f85e230bcae13c49eb1386afc6cd0e (patch) | |
| tree | 6161076f339dc2adeffcfbc8bcb6e86882b7b16d | |
| parent | abf4421e7c2fce4e768eb20c126989501081f4f9 (diff) | |
| download | rust-2772b2e5c7f85e230bcae13c49eb1386afc6cd0e.tar.gz rust-2772b2e5c7f85e230bcae13c49eb1386afc6cd0e.zip | |
syntax: Make match arm parsing more restrictive again
Require comma separators for all expression types except the plain block
36 files changed, 107 insertions, 156 deletions
diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 9d410c03d6a..0d96e029fb7 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -30,18 +30,18 @@ impl private_methods<T> for dlist_node<T> { some(neighbour) => match neighbour.prev { some(me) => if !box::ptr_eq(*self, *me) { fail ~"Asymmetric next-link in dlist node." - } + }, none => fail ~"One-way next-link in dlist node." - } + }, none => () } match self.prev { some(neighbour) => match neighbour.next { some(me) => if !box::ptr_eq(*me, *self) { fail ~"Asymmetric prev-link in dlist node." - } + }, none => fail ~"One-way prev-link in dlist node." - } + }, none => () } } diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 07bbff42b94..516b3f3c929 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -445,7 +445,7 @@ fn homedir() -> option<path> { some(p) } else { secondary() - } + }, none => secondary() }; diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 4fa3d18c2a7..9bdff829264 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -425,7 +425,7 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>) } blocked => if first { fail ~"blocking on already blocked packet" - } + }, full => { let mut payload = none; payload <-> p.payload; @@ -717,7 +717,7 @@ struct send_packet_buffered<T: send, Tbuffer: send> { let header = ptr::addr_of(packet.header); //forget(packet); header - } + }, none => fail ~"packet already consumed" } } @@ -778,7 +778,7 @@ struct recv_packet_buffered<T: send, Tbuffer: send> : selectable { let header = ptr::addr_of(packet.header); //forget(packet); header - } + }, none => fail ~"packet already consumed" } } diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index 04dc25a2c11..e865bac41ed 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -118,7 +118,7 @@ mod linear { match buckets[i] { some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) { return found_entry(i); - } + }, none => return found_hole(i) } }; diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 4b1fa4bfac9..b0189139f42 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -186,9 +186,9 @@ class bitv { intersect => s.intersect(s1), assign => s.become(s1), difference => s.difference(s1) - } + }, big(s1) => self.die() - } + }, big(s) => match other.rep { small(_) => self.die(), big(s1) => match op { @@ -282,7 +282,7 @@ class bitv { small(b) => match v1.rep { small(b1) => b.equals(b1), _ => false - } + }, big(s) => match v1.rep { big(s1) => s.equals(s1), small(_) => return false diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index 8293e4f215c..c7d0d1e5be8 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -242,11 +242,11 @@ mod tests { one(a1) => match b { one(b1) => return a1 == b1, _ => return false - } + }, two(a1, a2) => match b { two(b1, b2) => return a1 == b1 && a2 == b2, _ => return false - } + }, three(a1, a2, a3) => match b { three(b1, b2, b3) => return a1 == b1 && a2 == b2 && a3 == b3, _ => return false @@ -258,11 +258,11 @@ mod tests { onepar::<T>(a1) => match b { onepar::<T>(b1) => return a1 == b1, _ => return false - } + }, twopar::<T>(a1, a2) => match b { twopar::<T>(b1, b2) => return a1 == b1 && a2 == b2, _ => return false - } + }, threepar::<T>(a1, a2, a3) => match b { threepar::<T>(b1, b2, b3) => { return a1 == b1 && a2 == b2 && a3 == b3 diff --git a/src/libstd/json.rs b/src/libstd/json.rs index f3ca79be02b..882c6147b24 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -172,7 +172,7 @@ impl parser for parser { '"' => match self.parse_str() { ok(s) => ok(string(s)), err(e) => err(e) - } + }, '[' => self.parse_list(), '{' => self.parse_object(), _ => self.error(~"invalid syntax") diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index d0b08212952..00c489c1daa 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -54,7 +54,7 @@ fn format_addr(ip: ip_addr) -> ~str { fail ~"failed to convert inner sockaddr_in address to str" } result - } + }, ipv6(addr) => unsafe { let result = uv_ip6_name(&addr); if result == ~"" { diff --git a/src/libstd/serialization.rs b/src/libstd/serialization.rs index 86421ea3e74..ce9b73af471 100644 --- a/src/libstd/serialization.rs +++ b/src/libstd/serialization.rs @@ -245,7 +245,7 @@ fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) { do s.emit_enum(~"option") { match v { none => 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) { diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 6ed2a397b3f..de9af5d44f4 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -104,7 +104,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> { let mut idx = 0u, l = self.v.len(); while idx < l { match self.v.get_elt(idx) { - some(elt) => if !it(idx, elt) { break } + some(elt) => if !it(idx, elt) { break }, none => () } idx += 1u; @@ -120,7 +120,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> { let mut idx = 0u, l = self.v.len(); while idx < l { match self.v.get_elt(idx) { - some(elt) => if !it(&idx, &elt) { break } + some(elt) => if !it(&idx, &elt) { break }, none => () } idx += 1u; diff --git a/src/libstd/test.rs b/src/libstd/test.rs index b67d7e66402..6dd0ec209f5 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -146,7 +146,7 @@ fn run_tests_console(opts: test_opts, result::err(s) => { fail(fmt!{"can't open output file: %s", s}) } - } + }, none => none }; diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 3a4b5f3ccd9..b654b0f1d4f 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -220,7 +220,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { ]) { some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } none => err(~"Invalid day") - } + }, 'a' => match match_strs(s, pos, ~[ (~"Sun", 0_i32), (~"Mon", 1_i32), @@ -232,7 +232,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { ]) { some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } none => err(~"Invalid day") - } + }, 'B' => match match_strs(s, pos, ~[ (~"January", 0_i32), (~"February", 1_i32), @@ -249,7 +249,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { ]) { some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) } none => err(~"Invalid month") - } + }, 'b' | 'h' => match match_strs(s, pos, ~[ (~"Jan", 0_i32), (~"Feb", 1_i32), @@ -266,7 +266,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { ]) { some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) } none => err(~"Invalid month") - } + }, 'C' => match match_digits(s, pos, 2u, false) { some(item) => { let (v, pos) = item; @@ -274,7 +274,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { ok(pos) } none => err(~"Invalid year") - } + }, 'c' => { parse_type(s, pos, 'a', tm) .chain(|pos| parse_char(s, pos, ' ')) @@ -296,11 +296,11 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { 'd' => match match_digits(s, pos, 2u, false) { some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) } none => err(~"Invalid day of the month") - } + }, 'e' => match match_digits(s, pos, 2u, true) { some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) } none => err(~"Invalid day of the month") - } + }, 'F' => { parse_type(s, pos, 'Y', tm) .chain(|pos| parse_char(s, pos, '-')) @@ -379,13 +379,13 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) } none => err(~"Invalid hour") - } + }, 'p' => match match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) { some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) } none => err(~"Invalid hour") - } + }, 'R' => { parse_type(s, pos, 'H', tm) .chain(|pos| parse_char(s, pos, ':')) @@ -542,7 +542,7 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { '%' => match parse_type(s, pos, rdr.read_char(), tm) { ok(next) => pos = next, err(e) => { result = err(e); break; } - } + }, c => { if c != ch { break } pos = next; @@ -581,7 +581,7 @@ fn strftime(format: ~str, tm: tm) -> ~str { 4 => ~"Thursday", 5 => ~"Friday", 6 => ~"Saturday" - } + }, 'a' => match check tm.tm_wday as int { 0 => ~"Sun", 1 => ~"Mon", @@ -590,7 +590,7 @@ fn strftime(format: ~str, tm: tm) -> ~str { 4 => ~"Thu", 5 => ~"Fri", 6 => ~"Sat" - } + }, 'B' => match check tm.tm_mon as int { 0 => ~"January", 1 => ~"February", @@ -604,7 +604,7 @@ fn strftime(format: ~str, tm: tm) -> ~str { 9 => ~"October", 10 => ~"November", 11 => ~"December" - } + }, 'b' | 'h' => match check tm.tm_mon as int { 0 => ~"Jan", 1 => ~"Feb", @@ -618,7 +618,7 @@ fn strftime(format: ~str, tm: tm) -> ~str { 9 => ~"Oct", 10 => ~"Nov", 11 => ~"Dec", - } + }, 'C' => fmt!{"%02d", (tm.tm_year as int + 1900) / 100}, 'c' => { fmt!{"%s %s %s %s %s", @@ -662,8 +662,8 @@ fn strftime(format: ~str, tm: tm) -> ~str { 'M' => fmt!{"%02d", tm.tm_min as int}, 'm' => fmt!{"%02d", tm.tm_mon as int + 1}, 'n' => ~"\n", - 'P' => if tm.tm_hour as int < 12 { ~"am" } else { ~"pm" } - 'p' => if tm.tm_hour as int < 12 { ~"AM" } else { ~"PM" } + 'P' => if tm.tm_hour as int < 12 { ~"am" } else { ~"pm" }, + 'p' => if tm.tm_hour as int < 12 { ~"AM" } else { ~"PM" }, 'R' => { fmt!{"%s:%s", parse_type('H', tm), diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 2c774abff57..acd62b6a536 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -270,7 +270,7 @@ fn map_view_item(vi: @view_item, cx: ctx, _v: vt) { } }; cx.map.insert(id, node_export(vp, extend(cx, name))); - } + }, _ => () } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 45556e941d4..deb8bb5963d 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -192,7 +192,7 @@ fn is_exported(i: ident, m: _mod) -> bool { local = true; parent_enum = some(/* FIXME (#2543) */ copy it.ident); } - } + }, _ => () } if local { break; } @@ -476,7 +476,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { visit_item: fn@(i: @item) { vfn(i.id); match i.node { - item_enum(vs, _) => for vs.each |v| { vfn(v.node.id); } + item_enum(vs, _) => for vs.each |v| { vfn(v.node.id); }, _ => () } }, @@ -603,10 +603,10 @@ fn walk_pat(pat: @pat, it: fn(@pat)) { match pat.node { pat_ident(_, pth, some(p)) => walk_pat(p, it), pat_rec(fields, _) | pat_struct(_, fields, _) => - for fields.each |f| { walk_pat(f.pat, it) } + 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(_, _) => () diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 0838a1a70d9..65c2e00faca 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -130,7 +130,7 @@ fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@~str> { ast::meta_name_value(_, v) => match v.node { ast::lit_str(s) => option::some(s), _ => option::none - } + }, _ => option::none } } @@ -207,11 +207,11 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool { ast::meta_word(na) => match b.node { ast::meta_word(nb) => na == nb, _ => false - } + }, ast::meta_name_value(na, va) => match b.node { ast::meta_name_value(nb, vb) => na == nb && va.node == vb.node, _ => false - } + }, ast::meta_list(na, la) => { // ~[Fixme-sorting] @@ -257,7 +257,7 @@ fn last_meta_item_value_str_by_name( some(item) => match attr::get_meta_item_value_str(item) { some(value) => some(value), none => none - } + }, none => none } } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 79ef81f78c1..0f163e73c81 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -214,7 +214,7 @@ fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str { ast::expr_lit(l) => match l.node { ast::lit_str(s) => return *s, _ => cx.span_fatal(l.span, error) - } + }, _ => cx.span_fatal(expr.span, error) } } @@ -257,7 +257,7 @@ fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _ => { cx.span_fatal(sp, fmt!{"#%s: malformed invocation", name}) } - } + }, none => cx.span_fatal(sp, fmt!{"#%s: missing arguments", name}) } } @@ -302,7 +302,7 @@ fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree]) } _ => fail ~"badly-structured parse result" } - } + }, _ => fail ~"badly-structured parse result" }; diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 19b5fefc1cf..f8966196749 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -84,7 +84,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, ty_hex(c) => match c { case_upper => rt_type = ~"ty_hex_upper", case_lower => rt_type = ~"ty_hex_lower" - } + }, ty_bits => rt_type = ~"ty_bits", ty_octal => rt_type = ~"ty_octal", _ => rt_type = ~"ty_default" @@ -125,7 +125,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, ty_int(s) => match s { signed => return true, unsigned => return false - } + }, ty_float => return true, _ => return false } @@ -173,7 +173,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, unsigned => { return make_conv_call(cx, arg.span, ~"uint", cnv, arg) } - } + }, ty_bool => return make_conv_call(cx, arg.span, ~"bool", cnv, arg), ty_char => return make_conv_call(cx, arg.span, ~"char", cnv, arg), ty_hex(_) => { @@ -224,12 +224,12 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, ty_int(s) => match s { signed => debug!{"type: signed"}, unsigned => debug!{"type: unsigned"} - } + }, ty_bits => debug!{"type: bits"}, ty_hex(cs) => match cs { case_upper => debug!{"type: uhex"}, case_lower => debug!{"type: lhex"}, - } + }, ty_octal => debug!{"type: octal"}, ty_float => debug!{"type: float"}, ty_poly => debug!{"type: poly"} diff --git a/src/libsyntax/ext/qquote.rs b/src/libsyntax/ext/qquote.rs index 491d6104c7b..8d219ec4395 100644 --- a/src/libsyntax/ext/qquote.rs +++ b/src/libsyntax/ext/qquote.rs @@ -312,7 +312,7 @@ fn replace_expr(repls: ~[fragment], ast::expr_mac({node: mac_var(i), _}) => match (repls[i]) { from_expr(r) => (r.node, r.span), _ => fail /* fixme error message */ - } + }, _ => orig(e,s,fld) } } @@ -326,7 +326,7 @@ fn replace_ty(repls: ~[fragment], ast::ty_mac({node: mac_var(i), _}) => match (repls[i]) { from_ty(r) => (r.node, r.span), _ => fail /* fixme error message */ - } + }, _ => orig(e,s,fld) } } diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs index bdb0c663fc7..426fea346b9 100644 --- a/src/libsyntax/ext/simplext.rs +++ b/src/libsyntax/ext/simplext.rs @@ -77,7 +77,7 @@ fn elts_to_ell(cx: ext_ctxt, elts: ~[@expr]) -> post: vec::slice(elts, idx + 1u, vec::len(elts))}); } _ => () - } + }, _ => () } idx += 1u; @@ -518,7 +518,7 @@ fn block_to_ident(blk: blk_) -> option<ident> { some(expr) => match expr.node { expr_path(pth) => path_to_ident(pth), _ => none - } + }, none => none } } @@ -530,7 +530,7 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) { match_expr(e) => match e.node { expr_mac(mac) => fn_m(mac), _ => none - } + }, _ => cx.bug(~"broken traversal in p_t_s_r") } } @@ -650,7 +650,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, ~"macro name must be " + ~"consistent"); } - } + }, none => cx.span_fatal(pth.span, ~"macro name must not be a path") } diff --git a/src/libsyntax/ext/tt/earley_parser.rs b/src/libsyntax/ext/tt/earley_parser.rs index f1c7ebb7dad..d84eb3ec488 100644 --- a/src/libsyntax/ext/tt/earley_parser.rs +++ b/src/libsyntax/ext/tt/earley_parser.rs @@ -322,7 +322,7 @@ fn parse_nt(p: parser, name: ~str) -> nonterminal { ~"item" => match p.parse_item(~[]) { some(i) => token::nt_item(i), none => p.fatal(~"expected an item keyword") - } + }, ~"block" => token::nt_block(p.parse_block()), ~"stmt" => token::nt_stmt(p.parse_stmt(~[])), ~"pat" => token::nt_pat(p.parse_pat(true)), @@ -333,7 +333,7 @@ fn parse_nt(p: parser, name: ~str) -> nonterminal { token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) } _ => p.fatal(~"expected ident, found " + token::to_str(*p.reader.interner(), copy p.token)) - } + }, ~"path" => token::nt_path(p.parse_path_with_tps(false)), ~"tt" => { p.quote_depth += 1u; //but in theory, non-quoted tts might be useful diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 38599907e6f..a77c613cb60 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -13,6 +13,13 @@ fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { } } +fn expr_is_simple_block(e: @ast::expr) -> bool { + match e.node { + ast::expr_block({node: {rules: ast::default_blk, _}, _}) => true, + _ => false + } +} + fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { match stmt.node { ast::stmt_decl(d, _) => { @@ -52,7 +59,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool { @{node: ast::lit_int(_, ast::ty_i), _} | @{node: ast::lit_int_unsuffixed(_), _} => true, _ => false - } + }, ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) | ast::expr_move(_, sub) | ast::expr_copy(sub) | ast::expr_assign(_, sub) | @@ -63,7 +70,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool { ast::expr_fail(osub) | ast::expr_ret(osub) => match osub { some(ex) => ends_in_lit_int(ex), _ => false - } + }, _ => false } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5b889b4ad96..c675af6803c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -963,7 +963,7 @@ class parser { hi = self.span.hi; ex = expr_vstore(self.mk_expr(lo, hi, ex), vstore_fixed(v)); } - } + }, _ => () } @@ -1579,7 +1579,7 @@ class parser { let expr = self.parse_expr_res(RESTRICT_STMT_EXPR); let require_comma = - classify::expr_requires_semi_to_be_stmt(expr) + !classify::expr_is_simple_block(expr) && self.token != token::RBRACE; if require_comma { @@ -1839,7 +1839,7 @@ class parser { (token::COMMA), |p| p.parse_pat(refutable)); } - } + }, _ => () } // at this point, we're not sure whether it's a diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index b31e63a9f68..865af11ee8b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -649,7 +649,7 @@ fn print_item(s: ps, &&item: @ast::item) { /// expression arguments as expressions). It can be done! I think. fn print_tt(s: ps, tt: ast::token_tree) { match tt { - ast::tt_delim(tts) => for tts.each() |tt_elt| { print_tt(s, tt_elt); } + ast::tt_delim(tts) => for tts.each() |tt_elt| { print_tt(s, tt_elt); }, ast::tt_tok(_, tk) => { match tk { parse::token::IDENT(*) => { // don't let idents run together @@ -953,7 +953,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) { print_vstore(s, v); print_expr(s, e); } - } + }, ast::expr_vec(exprs, mutbl) => { ibox(s, indent_unit); word(s.s, ~"["); @@ -1114,7 +1114,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) { some(expr) => { end(s); // close the ibox for the pattern print_expr(s, expr); - if expr_requires_semi_to_be_stmt(expr) + if !expr_is_simple_block(expr) && i < len - 1 { word(s.s, ~","); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 08572e83f6e..db84e0974ff 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -93,7 +93,7 @@ fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) { cdir_src_mod(_, _) => (), cdir_dir_mod(_, cdirs, _) => for cdirs.each |cdir| { visit_crate_directive(cdir, e, v); - } + }, cdir_view_item(vi) => v.visit_view_item(vi, e, v), cdir_syntax(_) => () } @@ -191,10 +191,10 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) { } ty_rec(flds) => 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_fn(_, bounds, decl) => { for decl.inputs.each |a| { v.visit_ty(a.ty, e, v); } visit_ty_param_bounds(bounds, e, v); @@ -222,7 +222,7 @@ fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { } pat_rec(fields, _) => for fields.each |f| { v.visit_pat(f.pat, e, v) - } + }, pat_struct(path, fields, _) => { visit_path(path, e, v); for fields.each |f| { @@ -231,7 +231,7 @@ fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { } 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); @@ -339,7 +339,7 @@ fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { match d.node { decl_local(locs) => for locs.each |loc| { v.visit_local(loc, e, v) - } + }, decl_item(it) => v.visit_item(it, e, v) } } @@ -380,7 +380,7 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { 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); diff --git a/src/rustc/middle/check_const.rs b/src/rustc/middle/check_const.rs index 36b0908f435..0cddd359b55 100644 --- a/src/rustc/middle/check_const.rs +++ b/src/rustc/middle/check_const.rs @@ -46,7 +46,7 @@ fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) { } match p.node { // Let through plain ~-string literals here - pat_lit(a) => if !is_str(a) { v.visit_expr(a, true, v); } + pat_lit(a) => if !is_str(a) { v.visit_expr(a, true, v); }, pat_range(a, b) => { if !is_str(a) { v.visit_expr(a, true, v); } if !is_str(b) { v.visit_expr(b, true, v); } diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs index f1ba8375276..0daec1693f1 100644 --- a/src/rustc/middle/liveness.rs +++ b/src/rustc/middle/liveness.rs @@ -1190,7 +1190,7 @@ class liveness { expr_field(e, nm, _) => match self.as_self_field(e, nm) { some(_) => succ, none => self.propagate_through_expr(e, succ) - } + }, _ => self.propagate_through_expr(expr, succ) } } @@ -1208,7 +1208,7 @@ class liveness { ln } none => succ - } + }, // We do not track other lvalues, so just propagate through // to their subcomponents. Also, it may happen that diff --git a/src/rustc/middle/pat_util.rs b/src/rustc/middle/pat_util.rs index c147973e69e..0b625a63d5a 100644 --- a/src/rustc/middle/pat_util.rs +++ b/src/rustc/middle/pat_util.rs @@ -27,7 +27,7 @@ fn pat_is_variant(dm: resolve3::DefMap, pat: @pat) -> bool { pat_ident(_, _, none) => match dm.find(pat.id) { some(def_variant(_, _)) => true, _ => false - } + }, _ => false } } diff --git a/src/rustc/middle/resolve3.rs b/src/rustc/middle/resolve3.rs index cf8d1f348c9..15ebe1c14d0 100644 --- a/src/rustc/middle/resolve3.rs +++ b/src/rustc/middle/resolve3.rs @@ -582,7 +582,7 @@ class NameBindings { none => return none, some(def_id) => return some(def_mod(def_id)) } - } + }, ImplNS => { // Danger: Be careful what you use this for! def_ty is not // necessarily the right def. diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 16c08641e17..2993d23d180 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -2851,7 +2851,7 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr, let bcx = trans_loop_body(cx, e, ret_flag, save_in(scratch)); {bcx: bcx, val: scratch, kind: lv_temporary} } - } + }, none => { trans_temp_lval(cx, e) } diff --git a/src/rustc/middle/trans/debuginfo.rs b/src/rustc/middle/trans/debuginfo.rs index 1a207a5313c..325ce55d28f 100644 --- a/src/rustc/middle/trans/debuginfo.rs +++ b/src/rustc/middle/trans/debuginfo.rs @@ -300,14 +300,14 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: ast::prim_ty, span: span) ast::ty_i16 => (~"i16", DW_ATE_signed), ast::ty_i32 => (~"i32", DW_ATE_signed), ast::ty_i64 => (~"i64", DW_ATE_signed) - } + }, ast::ty_uint(m) => match m { ast::ty_u => (~"uint", DW_ATE_unsigned), ast::ty_u8 => (~"u8", DW_ATE_unsigned_char), ast::ty_u16 => (~"u16", DW_ATE_unsigned), ast::ty_u32 => (~"u32", DW_ATE_unsigned), ast::ty_u64 => (~"u64", DW_ATE_unsigned) - } + }, ast::ty_float(m) => match m { ast::ty_f => (~"float", DW_ATE_float), ast::ty_f32 => (~"f32", DW_ATE_float), diff --git a/src/rustc/middle/trans/foreign.rs b/src/rustc/middle/trans/foreign.rs index 27f7c8c0183..3eac4a7e663 100644 --- a/src/rustc/middle/trans/foreign.rs +++ b/src/rustc/middle/trans/foreign.rs @@ -1165,7 +1165,7 @@ fn abi_of_foreign_fn(ccx: @crate_ctxt, i: @ast::foreign_item) match attr::first_attr_value_str_by_name(i.attrs, ~"abi") { none => match check ccx.tcx.items.get(i.id) { ast_map::node_foreign_item(_, abi, _) => abi - } + }, some(_) => match attr::foreign_abi(i.attrs) { either::right(abi) => abi, either::left(msg) => ccx.sess.span_fatal(i.span, msg) diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 5c22e155828..1f79774256d 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -612,7 +612,7 @@ fn mk_t(cx: ctxt, st: sty) -> t { mk_t_with_id(cx, st, none) } fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t { let key = {struct: st, o_def_id: o_def_id}; match cx.interner.find(key) { - some(t) => unsafe { return unsafe::reinterpret_cast(t); } + some(t) => unsafe { return unsafe::reinterpret_cast(t); }, _ => () } let mut flags = 0u; @@ -655,8 +655,8 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t { flags |= rflags(r); flags |= get(m.ty).flags; } - ty_rec(flds) => for flds.each |f| { flags |= get(f.mt.ty).flags; } - ty_tup(ts) => for ts.each |tt| { flags |= get(tt).flags; } + ty_rec(flds) => for flds.each |f| { flags |= get(f.mt.ty).flags; }, + ty_tup(ts) => for ts.each |tt| { flags |= get(tt).flags; }, ty_fn(f) => { for f.inputs.each |a| { flags |= get(a.ty).flags; } flags |= get(f.output).flags; @@ -2189,19 +2189,19 @@ pure fn hash_type_structure(st: sty) -> uint { ast::ty_i16 => 5u, ast::ty_i32 => 6u, ast::ty_i64 => 7u - } + }, ty_uint(t) => match t { ast::ty_u => 8u, ast::ty_u8 => 9u, ast::ty_u16 => 10u, ast::ty_u32 => 11u, ast::ty_u64 => 12u - } + }, ty_float(t) => match t { ast::ty_f => 13u, ast::ty_f32 => 14u, ast::ty_f64 => 15u - } + }, ty_estr(_) => 16u, ty_enum(did, substs) => { let mut h = hash_def(18u, did); @@ -2473,7 +2473,7 @@ fn canon<T:copy>(tbl: hashmap<ast::node_id, ast::inferable<T>>, if cm1 != m1 { tbl.insert(id, cm1); } cm1 } - } + }, _ => m0 } } diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index 2c6be53601c..1012542c6ad 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -1319,7 +1319,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, ast::box(_) | ast::uniq(_) => match sty { ty::ty_box(mt) | ty::ty_uniq(mt) => some(mt.ty), _ => none - } + }, ast::not | ast::neg => expected, ast::deref => none } @@ -1430,7 +1430,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr.span, ~"`return;` in function returning non-nil"); } - } + }, some(e) => { check_expr_with(fcx, e, ret_ty); } } fcx.write_bot(id); @@ -1933,7 +1933,7 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool { match decl.node { ast::decl_local(ls) => for ls.each |l| { bot |= check_decl_local(fcx, l); - } + }, ast::decl_item(_) => {/* ignore for now */ } } } diff --git a/src/rustc/middle/typeck/check/regionmanip.rs b/src/rustc/middle/typeck/check/regionmanip.rs index b9073f97399..2e3003ed687 100644 --- a/src/rustc/middle/typeck/check/regionmanip.rs +++ b/src/rustc/middle/typeck/check/regionmanip.rs @@ -48,7 +48,7 @@ fn replace_bound_regions_in_fn_ty( some(s) => match check t_self { some(t) => some({self_ty: t, node_id: s.node_id}) // this 'none' case shouldn't happen - } + }, none => none }; diff --git a/src/rustc/middle/typeck/infer.rs b/src/rustc/middle/typeck/infer.rs index 42291ea30c7..b4c28b19354 100644 --- a/src/rustc/middle/typeck/infer.rs +++ b/src/rustc/middle/typeck/infer.rs @@ -258,14 +258,14 @@ fn convert_integral_ty_to_int_ty_set(tcx: ty::ctxt, t: ty::t) ast::ty_i => int_ty_set(INT_TY_SET_i), ast::ty_char => tcx.sess.bug( ~"char type passed to convert_integral_ty_to_int_ty_set()") - } + }, ty_uint(uint_ty) => match uint_ty { ast::ty_u8 => int_ty_set(INT_TY_SET_u8), ast::ty_u16 => int_ty_set(INT_TY_SET_u16), ast::ty_u32 => int_ty_set(INT_TY_SET_u32), ast::ty_u64 => int_ty_set(INT_TY_SET_u64), ast::ty_u => int_ty_set(INT_TY_SET_u) - } + }, _ => tcx.sess.bug(~"non-integral type passed to \ convert_integral_ty_to_int_ty_set()") } diff --git a/src/test/run-pass/alt-arrows-blocky-commas.rs b/src/test/run-pass/alt-arrows-blocky-commas.rs deleted file mode 100644 index 289018013d3..00000000000 --- a/src/test/run-pass/alt-arrows-blocky-commas.rs +++ /dev/null @@ -1,56 +0,0 @@ -// no-reformat -// Testing the presense or absense of commas separating block-structure -// match arm expressions - -fn fun(_f: fn()) { -} - -fn it(_f: fn() -> bool) { -} - -fn main() { - - match 0 { - 00 => { - } - 01 => if true { - } else { - } - 03 => match 0 { - _ => () - } - 04 => do fun { - } - 05 => for it { - } - 06 => while false { - } - 07 => loop { - } - 08 => unsafe { - } - 09 => unchecked { - } - 10 => { - }, - 11 => if true { - } else { - }, - 13 => match 0 { - _ => () - }, - 14 => do fun { - }, - 15 => for it { - }, - 16 => while false { - }, - 17 => loop { - }, - 18 => unsafe { - }, - 19 => unchecked { - }, - _ => () - } -} \ No newline at end of file |
