Skip to content

Commit 801c058

Browse files
committed
---
yaml --- r: 4697 b: refs/heads/master c: 9e08446 h: refs/heads/master i: 4695: 4f46c17 v: v3
1 parent e43ca9b commit 801c058

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
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: 9eb798e9658888b3988e49fe2ce5005af9f6589e
2+
refs/heads/master: 9e084469afd3b922d631d98296a68023a5763a71

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ fn head(s: &ps, w: str) {
161161
fn bopen(s: &ps) {
162162
word(s.s, "{");
163163
end(s); // close the head-box
164-
165164
}
166165

167166
fn bclose_(s: &ps, span: codemap::span, indented: uint) {
@@ -578,15 +577,21 @@ fn print_stmt(s: &ps, st: &ast::stmt) {
578577
}
579578

580579
fn print_block(s: &ps, blk: &ast::blk) {
581-
print_possibly_embedded_block(s, blk, false, indent_unit);
580+
print_possibly_embedded_block(s, blk, block_normal, indent_unit);
582581
}
583582

584-
fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: bool,
583+
tag embed_type { block_macro; block_block_fn; block_normal; }
584+
585+
fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type,
585586
indented: uint) {
586587
maybe_print_comment(s, blk.span.lo);
587588
let ann_node = node_block(s, blk);
588589
s.ann.pre(ann_node);
589-
if embedded { word(s.s, "#{"); end(s); } else { bopen(s); }
590+
alt embedded {
591+
block_macro. { word(s.s, "#{"); end(s); }
592+
block_block_fn. { end(s); }
593+
block_normal. { bopen(s); }
594+
}
590595

591596
let last_stmt = option::none;
592597
for st: @ast::stmt in blk.node.stmts {
@@ -699,7 +704,7 @@ fn print_mac(s: &ps, m: &ast::mac) {
699704
word(s.s, ">");
700705
}
701706
ast::mac_embed_block(blk) {
702-
print_possibly_embedded_block(s, blk, true, indent_unit);
707+
print_possibly_embedded_block(s, blk, block_normal, indent_unit);
703708
}
704709
ast::mac_ellipsis. { word(s.s, "..."); }
705710
}
@@ -863,16 +868,29 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
863868
print_pat(s, p);
864869
}
865870
space(s.s);
866-
print_possibly_embedded_block(s, arm.body, false,
871+
print_possibly_embedded_block(s, arm.body, block_normal,
867872
alt_indent_unit);
868873
}
869874
bclose_(s, expr.span, alt_indent_unit);
870875
}
871876
ast::expr_fn(f) {
872-
head(s, proto_to_str(f.proto));
873-
print_fn_args_and_ret(s, f.decl, ~[]);
874-
space(s.s);
875-
print_block(s, f.body);
877+
// If the return type is the magic ty_infer, then we need to
878+
// pretty print as a lambda-block
879+
if f.decl.output.node == ast::ty_infer {
880+
// containing cbox, will be closed by print-block at }
881+
cbox(s, indent_unit);
882+
// head-box, will be closed by print-block at start
883+
ibox(s, 0u);
884+
word(s.s, "{");
885+
print_fn_block_args(s, f.decl);
886+
print_possibly_embedded_block(s, f.body,
887+
block_block_fn, indent_unit);
888+
} else {
889+
head(s, proto_to_str(f.proto));
890+
print_fn_args_and_ret(s, f.decl, ~[]);
891+
space(s.s);
892+
print_block(s, f.body);
893+
}
876894
}
877895
ast::expr_block(blk) {
878896
// containing cbox, will be closed by print-block at }
@@ -1194,6 +1212,19 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl,
11941212
}
11951213
}
11961214

1215+
fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) {
1216+
word(s.s, "|");
1217+
fn print_arg(s: &ps, x: &ast::arg) {
1218+
ibox(s, indent_unit);
1219+
print_alias(s, x.mode);
1220+
word(s.s, x.ident);
1221+
end(s);
1222+
}
1223+
commasep(s, inconsistent, decl.inputs, print_arg);
1224+
word(s.s, "|");
1225+
maybe_print_comment(s, decl.output.span.lo);
1226+
}
1227+
11971228
fn print_alias(s: &ps, m: ast::mode) {
11981229
alt m {
11991230
ast::alias(true) { word_space(s, "&mutable"); }

0 commit comments

Comments
 (0)