提交 59ebe6af 编写于 作者: P Patrick Walton

rustc: Make the pretty printer output commas after enum variants. Update all tests accordingly.

上级 c6278e53
......@@ -451,7 +451,7 @@ fn print_variant_arg(s: ps, arg: ast::variant_arg) {
}
_ {}
}
word(s.s, ";");
word(s.s, ",");
end(s);
maybe_print_trailing_comment(s, v.span, none::<uint>);
}
......
......@@ -8,7 +8,7 @@
import int;
import str;
enum bottle { none; dual; single; multiple(int); }
enum bottle { none, dual, single, multiple(int), }
fn show(b: bottle) {
alt b {
......
use std;
import int;
enum tree { nil; node(~tree, ~tree, int); }
enum tree { nil, node(~tree, ~tree, int), }
fn item_check(t: ~tree) -> int {
alt *t {
......
......@@ -25,7 +25,7 @@
type grid = [[mutable u8]];
// exported type of sudoku grids
enum grid_t { grid_ctor(grid); }
enum grid_t { grid_ctor(grid), }
// read a sudoku problem from file f
fn read_grid(f: io::reader) -> grid_t {
......
......@@ -52,11 +52,11 @@ mod map_reduce {
type reducer = fn@(str, getter);
enum ctrl_proto {
find_reducer(str, chan<chan<reduce_proto>>);
mapper_done;
find_reducer(str, chan<chan<reduce_proto>>),
mapper_done,
}
enum reduce_proto { emit_val(int); done; ref; release; }
enum reduce_proto { emit_val(int), done, ref, release, }
fn start_mappers(ctrl: chan<ctrl_proto>, -inputs: [str]) ->
[joinable_task] {
......
// error-pattern: mismatched types
enum a { A; }
enum b { B; }
enum a { A, }
enum b { B, }
fn main() { let x: a = A; alt x { B { } } }
// error-pattern: mismatched types
enum a { A(int); }
enum b { B(int); }
enum a { A(int), }
enum b { B(int), }
fn main() { let x: a = A(0); alt x { B(y) { } } }
......@@ -2,7 +2,7 @@
// error-pattern: unresolved
enum color { rgb(int, int, int); rgba(int, int, int, int); }
enum color { rgb(int, int, int), rgba(int, int, int, int), }
fn main() {
let red: color = rgb(255, 0, 0);
......
......@@ -6,7 +6,7 @@
mod foo {
export t;
enum t { t1; }
enum t { t1, }
}
fn main() { let x = foo::t1; }
......@@ -5,7 +5,7 @@ mod foo {
fn x() { }
enum y { y1; }
enum y { y1, }
}
fn main() { let z = foo::y1; }
......@@ -3,6 +3,6 @@
// error-pattern: enum of infinite size
enum mlist { cons(int, mlist); nil; }
enum mlist { cons(int, mlist), nil, }
fn main() { let a = cons(10, cons(11, nil)); }
\ No newline at end of file
// error-pattern:refutable pattern
enum xx { xx(int); yy; }
enum xx { xx(int), yy, }
fn main() {
let @{x: xx(x), y: y} = @{x: xx(10), y: 20};
......
// error-pattern:Declaration of thpppt shadows
enum ack { thpppt; ffff; }
enum ack { thpppt, ffff, }
fn main() {
let thpppt: int = 42;
......
// error-pattern:mismatched types
// From Issue #778
enum clam<T> { a(T); }
enum clam<T> { a(T), }
fn main() { let c; c = a(c); alt c { a::<int>(_) { } } }
// error-pattern: mismatched types
enum blah { a(int, int, uint); b(int, int); }
enum blah { a(int, int, uint), b(int, int), }
fn main() { alt a(1, 1, 2u) { a(_, x, y) | b(x, y) { } } }
......@@ -6,7 +6,7 @@
// error-pattern: mismatched types
enum bar { t1((), option::t<[int]>); t2; }
enum bar { t1((), option::t<[int]>), t2, }
fn foo(t: bar) -> int { alt t { t1(_, some(x)) { ret x * 3; } _ { fail; } } }
......
......@@ -5,7 +5,7 @@
// error-pattern: mismatched types
enum bar { t1((), option::t<[int]>); t2; }
enum bar { t1((), option::t<[int]>), t2, }
fn foo(t: bar) {
alt t {
......
//error-pattern: non-scalar cast
enum non_nullary {
nullary;
other(int);
nullary,
other(int),
}
fn main() {
......
......@@ -3,9 +3,9 @@
// black and white have the same discriminator value ...
enum color {
red = 0xff0000;
green = 0x00ff00;
blue = 0x0000ff;
black = 0x000000;
white = 0x000000;
red = 0xff0000,
green = 0x00ff00,
blue = 0x0000ff,
black = 0x000000,
white = 0x000000,
}
//error-pattern: discriminator values can only be used with a c-like enum
enum color {
red = 0xff0000;
green = 0x00ff00;
blue = 0x0000ff;
black = 0x000000;
white = 0xffffff;
other (str);
red = 0xff0000,
green = 0x00ff00,
blue = 0x0000ff,
black = 0x000000,
white = 0xffffff,
other (str),
}
//error-pattern: mismatched types
enum color {
red = 1u;
blue = 2;
red = 1u,
blue = 2,
}
fn main() {}
// error-pattern:unreachable pattern
enum foo { a(@foo, int); b(uint); }
enum foo { a(@foo, int), b(uint), }
fn main() { alt b(1u) { b(_) | a(@_, 1) { } a(_, 1) { } } }
// pp-exact
enum foo {
foo; // a foo.
bar;
foo, // a foo.
bar,
}
fn main() { }
......@@ -4,6 +4,6 @@
// -*- rust -*-
// error-pattern:non-exhaustive match failure
enum t { a; b; }
enum t { a, b, }
fn main() { let x = a; alt x { b { } } }
......@@ -5,7 +5,7 @@
import option;
import option::none;
enum sty { ty_nil; }
enum sty { ty_nil, }
type raw_t = {struct: sty, cname: option::t<str>, hash: uint};
......
enum option<T> { some(T); none; }
enum option<T> { some(T), none, }
type r<T> = {mutable v: [option<T>]};
......
mod m1 {
enum foo { foo1; foo2; }
enum foo { foo1, foo2, }
}
fn bar(x: m1::foo) { alt x { m1::foo1 { } } }
......
......@@ -5,7 +5,7 @@
import std::dbg;
enum t { make_t(@int); clam; }
enum t { make_t(@int), clam, }
fn foo(s: @int) {
let count = dbg::refcount(s);
......
enum maybe<T> { nothing; just(T); }
enum maybe<T> { nothing, just(T), }
fn foo(x: maybe<int>) {
alt x { nothing { #error("A"); } just(a) { #error("B"); } }
......
enum thing { a; b; c; }
enum thing { a, b, c, }
fn foo(it: block(int)) { it(10); }
......
......@@ -3,7 +3,7 @@
fn main() {
alt "test" { "not-test" { fail; } "test" { } _ { fail; } }
enum t { tag1(str); tag2; }
enum t { tag1(str), tag2, }
alt tag1("test") {
......
......@@ -3,9 +3,9 @@
// -*- rust -*-
enum color {
rgb(int, int, int);
rgba(int, int, int, int);
hsl(int, int, int);
rgb(int, int, int),
rgba(int, int, int, int),
hsl(int, int, int),
}
fn process(c: color) -> int {
......
type foo = {a: int, b: uint};
enum bar { u(@foo); w(int); }
enum bar { u(@foo), w(int), }
fn main() {
assert (alt u(@{a: 10, b: 40u}) {
......
......@@ -8,7 +8,7 @@
import comm::port;
import comm::recv;
enum request { quit; close(chan<bool>); }
enum request { quit, close(chan<bool>), }
type ctx = chan<request>;
......
......@@ -20,9 +20,9 @@
type t = bool;
#[cfg(bogus)]
enum tg { foo; }
enum tg { foo, }
enum tg { bar; }
enum tg { bar, }
#[cfg(bogus)]
resource r(i: int) { }
......
// -*- rust -*-
enum list { cons(int, @list); nil; }
enum list { cons(int, @list), nil, }
type bubu = {x: int, y: int};
......
enum taggy {
cons(@mutable taggy);
nil;
cons(@mutable taggy),
nil,
}
fn f() {
......
enum t { foo(@int); }
enum t { foo(@int), }
fn main() { let tt = foo(@10); alt tt { foo(z) { } } }
enum chan { chan_t; }
enum chan { chan_t, }
fn wrapper3(i: chan) {
assert i == chan_t;
......
// pp-exact
enum color { red = 1; green; blue; imaginary = -1; }
enum color { red = 1, green, blue, imaginary = -1, }
fn main() {
test_color(red, 1, "red");
......
......@@ -5,7 +5,7 @@ mod foo {
export t;
export f;
enum t { t1; }
enum t { t1, }
fn f() -> t { ret t1; }
}
......
......@@ -2,6 +2,6 @@
export foo;
export main;
enum list_cell<T> { cons(@list_cell<T>); }
enum list_cell<T> { cons(@list_cell<T>), }
fn main() { }
......@@ -2,7 +2,7 @@
mod foo {
export t1;
enum t { t1; }
enum t { t1, }
}
fn main() { let v = foo::t1; }
......@@ -6,7 +6,7 @@ mod foo {
export g;
// not exported
enum t { t1; t2; }
enum t { t1, t2, }
fn f() -> t { ret t1; }
......
......@@ -10,7 +10,7 @@ fn test_rec() {
}
fn test_tag() {
enum mood { happy; sad; }
enum mood { happy, sad, }
let rs = alt true { true { happy } false { sad } };
assert (rs == happy);
}
......
......@@ -10,7 +10,7 @@ fn test_rec() {
}
fn test_tag() {
enum mood { happy; sad; }
enum mood { happy, sad, }
let rs = if true { happy } else { sad };
assert (rs == happy);
}
......
enum wrapper<T> { wrapped(T); }
enum wrapper<T> { wrapped(T), }
fn main() { let w = wrapped([1, 2, 3, 4, 5]); }
enum list<T> { cons(@T, @list<T>); nil; }
enum list<T> { cons(@T, @list<T>), nil, }
fn main() {
let a: list<int> =
......
enum foo<T> { arm(T); }
enum foo<T> { arm(T), }
fn altfoo<T>(f: foo<T>) {
let hit = false;
......
......@@ -2,6 +2,6 @@
// This causes memory corruption in stage0.
enum thing<K> { some(K); }
enum thing<K> { some(K), }
fn main() { let x = some("hi"); }
enum clam<T> { a(T); }
enum clam<T> { a(T), }
fn main() { let c = a(3); }
......@@ -2,7 +2,7 @@
// -*- rust -*-
enum noption<T> { some(T); }
enum noption<T> { some(T), }
fn main() {
let nop: noption<int> = some::<int>(5);
......
enum option<T> { some(@T); none; }
enum option<T> { some(@T), none, }
fn main() { let a: option<int> = some::<int>(@10); a = none::<int>; }
......@@ -30,7 +30,7 @@ mod map_reduce {
type mapper = native fn(str, putter);
enum ctrl_proto { find_reducer([u8], chan<int>); mapper_done; }
enum ctrl_proto { find_reducer([u8], chan<int>), mapper_done, }
fn start_mappers(ctrl: chan<ctrl_proto>, inputs: [str]) {
for i: str in inputs {
......
......@@ -23,7 +23,7 @@ fn test_rec() {
fn test_tag() {
enum t {
t0(r);
t0(r),
}
let i = @mutable 0;
......
......@@ -7,7 +7,7 @@
import comm::recv;
import comm::send;
enum msg { closed; received([u8]); }
enum msg { closed, received([u8]), }
fn producer(c: chan<[u8]>) {
send(c, [1u8, 2u8, 3u8, 4u8]);
......
enum maybe_pointy {
no_pointy;
yes_pointy(@pointy);
no_pointy,
yes_pointy(@pointy),
}
type pointy = {
......
enum t { a; b(@int); }
enum t { a, b(@int), }
fn main() { let x = b(@10); x = a; }
......@@ -2,6 +2,6 @@
// -*- rust -*-
enum list { cons(int, @list); nil; }
enum list { cons(int, @list), nil, }
fn main() { cons(10, @cons(11, @cons(12, @nil))); }
......@@ -2,8 +2,8 @@
import std::list;
enum foo {
a(uint);
b(str);
a(uint),
b(str),
}
fn check_log<T>(exp: str, v: T) {
......
enum foo {
a(uint);
b(str);
c;
a(uint),
b(str),
c,
}
fn main() {
......
// Tests that shapes respect linearize_ty_params().
enum option<T> {
none;
some(T);
none,
some(T),
}
type smallintmap<T> = @{mutable v: [mutable option<T>]};
......
......@@ -4,7 +4,7 @@
type cell = {mutable c: @list};
enum list { link(@cell); nil; }
enum list { link(@cell), nil, }
fn main() {
let first: @cell = @{mutable c: @nil()};
......
// -*- rust -*-
enum mlist { cons(int, @mlist); nil; }
enum mlist { cons(int, @mlist), nil, }
fn main() { cons(10, @cons(11, @cons(12, @nil))); }
......@@ -2,12 +2,12 @@
// -*- rust -*-
enum colour { red; green; blue; }
enum colour { red, green, blue, }
enum tree { children(@list); leaf(colour); }
enum tree { children(@list), leaf(colour), }
enum list { cons(@tree, @list); nil; }
enum list { cons(@tree, @list), nil, }
enum small_list { kons(int, @small_list); neel; }
enum small_list { kons(int, @small_list), neel, }
fn main() { }
......@@ -6,7 +6,7 @@
import option::some;
import option::none;
enum t { foo(int, uint); bar(int, option::t<int>); }
enum t { foo(int, uint), bar(int, option::t<int>), }
fn nested(o: t) {
alt o {
......
enum blah { a; b; }
enum blah { a, b, }
fn or_alt(q: blah) -> int {
alt q { a | b { 42 } }
......
enum blah { a(int, int, uint); b(int, int); c; }
enum blah { a(int, int, uint), b(int, int), c, }
fn or_alt(q: blah) -> int {
alt q { a(x, y, _) | b(x, y) { ret x + y; } c { ret 0; } }
......
enum t1 { a(int); b(uint); }
enum t1 { a(int), b(uint), }
type t2 = {x: t1, y: int};
enum t3 { c(t2, uint); }
enum t3 { c(t2, uint), }
fn m(in: t3) -> int {
alt in {
......
......@@ -5,7 +5,7 @@
resource close_res(i: closable) { *i = false; }
enum option<T> { none; some(T); }
enum option<T> { none, some(T), }
fn sink(res: option<close_res>) { }
......
enum option<T> { none; some(T); }
enum option<T> { none, some(T), }
fn f<T: copy>() -> option<T> { ret none; }
......
......@@ -16,6 +16,6 @@ fn foo(c: [int]) {
}
}
enum t<T> { none; some(T); }
enum t<T> { none, some(T), }
fn main() { let x = 10; let x = x + 20; assert (x == 30); foo([]); }
......@@ -10,8 +10,8 @@
enum opt_span {
//hack (as opposed to option::t), to make `span` compile
os_none;
os_some(@span);
os_none,
os_some(@span),
}
type span = {lo: uint, hi: uint, expanded_from: opt_span};
type spanned<T> = { data: T, span: span };
......
enum opt<T> { none; }
enum opt<T> { none, }
fn main() {
let x = none::<int>;
......
enum clam<T> { a(T); }
enum clam<T> { a(T), }
fn main() { let c = a(2); alt c { a::<int>(_) { } } }
enum clam<T> { a(T); }
enum clam<T> { a(T), }
fn main() { }
......@@ -2,7 +2,7 @@
// -*- rust -*-
enum clam<T> { a(T, int); b; }
enum clam<T> { a(T, int), b, }
fn uhoh<T>(v: [clam<T>]) {
alt v[1] {
......
enum taggy { foo(@taggy); bar; }
enum taggy { foo(@taggy), bar, }
fn main() { assert (bar <= bar); }
enum foo { large; small; }
enum foo { large, small, }
fn main() {
let a = {x: 1, y: 2, z: 3};
......
// xfail-test
enum color { red; green; blue; black; white; }
enum color { red, green, blue, black, white, }
fn main() {
assert (uint::to_str(red as uint, 10) == #fmt["%?", red]);
......
// xfail-pretty Issue #1510
enum color {
red = 0xff0000;
green = 0x00ff00;
blue = 0x0000ff;
black = 0x000000;
white = 0xFFFFFF;
red = 0xff0000,
green = 0x00ff00,
blue = 0x0000ff,
black = 0x000000,
white = 0xFFFFFF,
}
fn main() {
......
......@@ -2,7 +2,7 @@
fn foo() {
fn zed(z: bar) { }
enum bar { nil; }
enum bar { nil, }
fn baz() { zed(nil); }
}
......
enum color {
red = 0xff0000;
green = 0x00ff00;
blue = 0x0000ff;
black = 0x000000;
white = 0xFFFFFF;
imaginary = -1;
red = 0xff0000,
green = 0x00ff00,
blue = 0x0000ff,
black = 0x000000,
white = 0xFFFFFF,
imaginary = -1,
}
fn main() {
......
......@@ -2,7 +2,7 @@
// -*- rust -*-
enum colour { red(int, int); green; }
enum colour { red(int, int), green, }
fn f() { let x = red(1, 2); let y = green; assert (x != y); }
......
......@@ -50,7 +50,7 @@ fn test_str() {
}
fn test_tag() {
enum t { tag1; tag2(int); tag3(int, u8, char); }
enum t { tag1, tag2(int), tag3(int, u8, char), }
let po = port();
let ch = chan(po);
send(ch, tag1);
......
enum maybe_pointy {
none;
p(@pointy);
none,
p(@pointy),
}
type pointy = {
......
enum maybe_pointy {
none;
p(@pointy);
none,
p(@pointy),
}
type pointy = {
......
fn main() {
enum t { t1(int); t2(int); }
enum t { t1(int), t2(int), }
let x = ~t1(10);
......
fn test1() {
enum bar { u(~int); w(int); }
enum bar { u(~int), w(int), }
let x = u(~10);
assert alt x {
......
type foo = {a: int, b: uint};
enum bar { u(~foo); w(int); }
enum bar { u(~foo), w(int), }
fn main() {
assert (alt u(~{a: 10, b: 40u}) {
......
enum bar { u(~int); w(int); }
enum bar { u(~int), w(int), }
fn main() {
assert alt u(~10) {
......
......@@ -6,6 +6,6 @@ fn foo<T>(o: myoption<T>) -> int {
ret x;
}
enum myoption<T> { none; some(T); }
enum myoption<T> { none, some(T), }
fn main() { log(debug, 5); }
......@@ -6,6 +6,6 @@ fn foo<T>(o: myoption<T>) -> int {
ret x;
}
enum myoption<T> { none; some(T); }
enum myoption<T> { none, some(T), }
fn main() { log(debug, 5); }
enum t { a; b(str); }
enum t { a, b(str), }
fn make(i: int) -> t {
if i > 10 { ret a; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册