Skip to content

Commit 8f82f43

Browse files
committed
---
yaml --- r: 3750 b: refs/heads/master c: 33ce116 h: refs/heads/master v: v3
1 parent b081dad commit 8f82f43

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 4319e7a6556b26cb1db6e933197bef5e97782c2e
2+
refs/heads/master: 33ce1164e20d8f0f87cc19eed7281786de72a424

trunk/src/comp/syntax/print/pprust.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,10 +986,57 @@ fn print_expr(&ps s, &@ast::expr expr) {
986986
print_expr(s, expr);
987987
pclose(s);
988988
}
989-
case (ast::expr_anon_obj(_, _)) {
990-
word(s.s, "anon obj");
991-
// FIXME (issue #499): nicer pretty-printing of anon objs
989+
case (ast::expr_anon_obj(?anon_obj, ?tps)) {
990+
head(s, "obj");
991+
print_type_params(s, tps);
992+
993+
// Fields
994+
popen(s);
995+
fn print_field(&ps s, &ast::anon_obj_field field) {
996+
ibox(s, indent_unit);
997+
print_mutability(s, field.mut);
998+
print_type(s, *field.ty);
999+
space(s.s);
1000+
word(s.s, field.ident);
1001+
word_space(s, "=");
1002+
print_expr(s, field.expr);
1003+
end(s);
1004+
}
1005+
fn get_span(&ast::anon_obj_field f) -> codemap::span {
1006+
ret f.ty.span;
1007+
}
1008+
alt (anon_obj.fields) {
1009+
case (none) { }
1010+
case (some(?fields)) {
1011+
commasep_cmnt_ivec(s, consistent, fields, print_field,
1012+
get_span);
1013+
}
1014+
}
1015+
pclose(s);
1016+
space(s.s);
1017+
bopen(s);
1018+
1019+
// Methods
1020+
for (@ast::method meth in anon_obj.methods) {
1021+
let ast::ty_param[] typarams = ~[];
1022+
hardbreak_if_not_bol(s);
1023+
maybe_print_comment(s, meth.span.lo);
1024+
print_fn(s, meth.node.meth.decl, meth.node.meth.proto,
1025+
meth.node.ident, typarams);
1026+
word(s.s, " ");
1027+
print_block(s, meth.node.meth.body);
1028+
}
1029+
space(s.s);
9921030

1031+
// With object
1032+
alt (anon_obj.with_obj) {
1033+
case (none) { }
1034+
case (some(?e)) {
1035+
word_space(s, "with");
1036+
print_expr(s, e);
1037+
}
1038+
}
1039+
bclose(s, expr.span);
9931040
}
9941041
}
9951042
s.ann.post(ann_node);

0 commit comments

Comments
 (0)