Skip to content

Commit d3b94f6

Browse files
committed
auto merge of #5193 : sethpink/rust/struct-tup-pp, r=catamorphism
- 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
2 parents 2f90112 + dcd2f73 commit d3b94f6

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/libsyntax/print/pprust.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -713,30 +713,26 @@ pub fn print_struct(s: @ps,
713713
ident: ast::ident,
714714
span: codemap::span) {
715715
print_ident(s, ident);
716-
nbsp(s);
717716
print_generics(s, generics);
718717
if ast_util::struct_def_is_tuple_like(struct_def) {
719-
popen(s);
720-
let mut first = true;
721-
for struct_def.fields.each |field| {
722-
if first {
723-
first = false;
724-
} else {
725-
word_space(s, ~",");
726-
}
727-
728-
match field.node.kind {
729-
ast::named_field(*) => fail!(~"unexpected named field"),
730-
ast::unnamed_field => {
731-
maybe_print_comment(s, field.span.lo);
732-
print_type(s, field.node.ty);
718+
if !struct_def.fields.is_empty() {
719+
popen(s);
720+
do commasep(s, inconsistent, struct_def.fields) |s, field| {
721+
match field.node.kind {
722+
ast::named_field(*) => fail!(~"unexpected named field"),
723+
ast::unnamed_field => {
724+
maybe_print_comment(s, field.span.lo);
725+
print_type(s, field.node.ty);
726+
}
733727
}
734728
}
729+
pclose(s);
735730
}
736-
pclose(s);
737731
word(s.s, ~";");
732+
end(s);
738733
end(s); // close the outer-box
739734
} else {
735+
nbsp(s);
740736
bopen(s);
741737
hardbreak_if_not_bol(s);
742738
do struct_def.dtor.iter |dtor| {

src/test/pretty/struct-tuple.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// pp-exact
2+
struct Foo;
3+
struct Bar(int, int);
4+
5+
fn main() {
6+
struct Foo2;
7+
struct Bar2(int, int, int);
8+
let a = Bar(5, 5);
9+
let b = Foo;
10+
}

0 commit comments

Comments
 (0)