From dcd2f735606ea952425760edce2ac55a32850341 Mon Sep 17 00:00:00 2001 From: Seth Pink Date: Sat, 2 Mar 2013 12:42:02 +1000 Subject: Fix some struct-tuple def prettyprint issues - Removed space between struct name and parentheses - Fixed indentation of the rest of the file (missing end) - Don't print parentheses for structs with no fields - Added test --- src/libsyntax/print/pprust.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 0f161a444bd..9bbed28b388 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -713,30 +713,26 @@ pub fn print_struct(s: @ps, ident: ast::ident, span: codemap::span) { print_ident(s, ident); - nbsp(s); print_generics(s, generics); if ast_util::struct_def_is_tuple_like(struct_def) { - popen(s); - let mut first = true; - for struct_def.fields.each |field| { - if first { - first = false; - } else { - word_space(s, ~","); - } - - match field.node.kind { - ast::named_field(*) => fail!(~"unexpected named field"), - ast::unnamed_field => { - maybe_print_comment(s, field.span.lo); - print_type(s, field.node.ty); + if !struct_def.fields.is_empty() { + popen(s); + do commasep(s, inconsistent, struct_def.fields) |s, field| { + match field.node.kind { + ast::named_field(*) => fail!(~"unexpected named field"), + ast::unnamed_field => { + maybe_print_comment(s, field.span.lo); + print_type(s, field.node.ty); + } } } + pclose(s); } - pclose(s); word(s.s, ~";"); + end(s); end(s); // close the outer-box } else { + nbsp(s); bopen(s); hardbreak_if_not_bol(s); do struct_def.dtor.iter |dtor| { -- cgit 1.4.1-3-g733a5