libsyntax: Fix pretty printing of tuple structs. Attempt to put out fire. rs=rustbot
This commit is contained in:
parent
c851d2a1bc
commit
c7ec183b34
1 changed files with 51 additions and 26 deletions
|
@ -672,36 +672,61 @@ fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param],
|
||||||
commasep(s, inconsistent, struct_def.traits, |s, p|
|
commasep(s, inconsistent, struct_def.traits, |s, p|
|
||||||
print_path(s, p.path, false));
|
print_path(s, p.path, false));
|
||||||
}
|
}
|
||||||
bopen(s);
|
if ast_util::struct_def_is_tuple_like(struct_def) {
|
||||||
hardbreak_if_not_bol(s);
|
popen(s);
|
||||||
do struct_def.dtor.iter |dtor| {
|
let mut first = true;
|
||||||
hardbreak_if_not_bol(s);
|
for struct_def.fields.each |field| {
|
||||||
maybe_print_comment(s, dtor.span.lo);
|
if first {
|
||||||
print_outer_attributes(s, dtor.node.attrs);
|
first = false;
|
||||||
head(s, ~"drop");
|
} else {
|
||||||
print_block(s, dtor.node.body);
|
word_space(s, ~",");
|
||||||
}
|
}
|
||||||
for struct_def.fields.each |field| {
|
|
||||||
match field.node.kind {
|
match field.node.kind {
|
||||||
ast::unnamed_field => {} // We don't print here.
|
ast::named_field(*) => fail ~"unexpected named field",
|
||||||
ast::named_field(ident, mutability, visibility) => {
|
ast::unnamed_field => {
|
||||||
hardbreak_if_not_bol(s);
|
maybe_print_comment(s, field.span.lo);
|
||||||
maybe_print_comment(s, field.span.lo);
|
print_type(s, field.node.ty);
|
||||||
print_visibility(s, visibility);
|
|
||||||
if mutability == ast::class_mutable {
|
|
||||||
word_nbsp(s, ~"mut");
|
|
||||||
}
|
}
|
||||||
print_ident(s, ident);
|
|
||||||
word_nbsp(s, ~":");
|
|
||||||
print_type(s, field.node.ty);
|
|
||||||
word(s.s, ~",");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pclose(s);
|
||||||
|
word(s.s, ~";");
|
||||||
|
end(s); // close the outer-box
|
||||||
|
} else {
|
||||||
|
bopen(s);
|
||||||
|
hardbreak_if_not_bol(s);
|
||||||
|
do struct_def.dtor.iter |dtor| {
|
||||||
|
hardbreak_if_not_bol(s);
|
||||||
|
maybe_print_comment(s, dtor.span.lo);
|
||||||
|
print_outer_attributes(s, dtor.node.attrs);
|
||||||
|
head(s, ~"drop");
|
||||||
|
print_block(s, dtor.node.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
for struct_def.fields.each |field| {
|
||||||
|
match field.node.kind {
|
||||||
|
ast::unnamed_field => fail ~"unexpected unnamed field",
|
||||||
|
ast::named_field(ident, mutability, visibility) => {
|
||||||
|
hardbreak_if_not_bol(s);
|
||||||
|
maybe_print_comment(s, field.span.lo);
|
||||||
|
print_visibility(s, visibility);
|
||||||
|
if mutability == ast::class_mutable {
|
||||||
|
word_nbsp(s, ~"mut");
|
||||||
|
}
|
||||||
|
print_ident(s, ident);
|
||||||
|
word_nbsp(s, ~":");
|
||||||
|
print_type(s, field.node.ty);
|
||||||
|
word(s.s, ~",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for struct_def.methods.each |method| {
|
||||||
|
print_method(s, *method);
|
||||||
|
}
|
||||||
|
bclose(s, span);
|
||||||
}
|
}
|
||||||
for struct_def.methods.each |method| {
|
|
||||||
print_method(s, *method);
|
|
||||||
}
|
|
||||||
bclose(s, span);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This doesn't deserve to be called "pretty" printing, but it should be
|
/// This doesn't deserve to be called "pretty" printing, but it should be
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue