auto merge of #5002 : catamorphism/rust/one-tuples, r=graydon

r? @graydon - This is for greater uniformity (for example, macros that generate
tuples). rustc already supported 1-tuple patterns, but there was no
way to construct a 1-tuple term.

@graydon , as far as your comment on #4898 - it did turn out to be solvable inside the macro (since @luqmana already fixed it using structs instead), but I still think it's a good idea to allow 1-tuples, for uniformity. I don't think anyone is likely to trip over it, and I'm not too worried that it changes the amount of ambiguity.
This commit is contained in:
bors
2013-02-19 09:14:33 -08:00
6 changed files with 69 additions and 11 deletions

View File

@@ -414,6 +414,9 @@ pub fn print_type_ex(s: @ps, &&ty: @ast::Ty, print_colons: bool) {
ast::ty_tup(elts) => {
popen(s);
commasep(s, inconsistent, elts, print_type);
if elts.len() == 1 {
word(s.s, ~",");
}
pclose(s);
}
ast::ty_bare_fn(f) => {
@@ -1199,6 +1202,9 @@ pub fn print_expr(s: @ps, &&expr: @ast::expr) {
ast::expr_tup(exprs) => {
popen(s);
commasep_exprs(s, inconsistent, exprs);
if exprs.len() == 1 {
word(s.s, ~",");
}
pclose(s);
}
ast::expr_call(func, args, sugar) => {
@@ -1634,6 +1640,9 @@ pub fn print_pat(s: @ps, &&pat: @ast::pat, refutable: bool) {
ast::pat_tup(elts) => {
popen(s);
commasep(s, inconsistent, elts, |s, p| print_pat(s, p, refutable));
if elts.len() == 1 {
word(s.s, ~",");
}
pclose(s);
}
ast::pat_box(inner) => {