@@ -161,7 +161,6 @@ fn head(s: &ps, w: str) {
161
161
fn bopen ( s : & ps ) {
162
162
word ( s. s , "{" ) ;
163
163
end ( s) ; // close the head-box
164
-
165
164
}
166
165
167
166
fn bclose_ ( s : & ps , span : codemap:: span , indented : uint ) {
@@ -578,15 +577,21 @@ fn print_stmt(s: &ps, st: &ast::stmt) {
578
577
}
579
578
580
579
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) ;
582
581
}
583
582
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 ,
585
586
indented : uint ) {
586
587
maybe_print_comment ( s, blk. span . lo ) ;
587
588
let ann_node = node_block ( s, blk) ;
588
589
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
+ }
590
595
591
596
let last_stmt = option:: none;
592
597
for st: @ast:: stmt in blk. node . stmts {
@@ -699,7 +704,7 @@ fn print_mac(s: &ps, m: &ast::mac) {
699
704
word ( s. s , ">" ) ;
700
705
}
701
706
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) ;
703
708
}
704
709
ast:: mac_ellipsis. { word ( s. s , "..." ) ; }
705
710
}
@@ -863,16 +868,29 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
863
868
print_pat ( s, p) ;
864
869
}
865
870
space ( s. s ) ;
866
- print_possibly_embedded_block ( s, arm. body , false ,
871
+ print_possibly_embedded_block ( s, arm. body , block_normal ,
867
872
alt_indent_unit) ;
868
873
}
869
874
bclose_ ( s, expr. span , alt_indent_unit) ;
870
875
}
871
876
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, 0 u) ;
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
+ }
876
894
}
877
895
ast:: expr_block ( blk) {
878
896
// 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,
1194
1212
}
1195
1213
}
1196
1214
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
+
1197
1228
fn print_alias ( s : & ps , m : ast:: mode ) {
1198
1229
alt m {
1199
1230
ast : : alias ( true ) { word_space ( s, "&mutable" ) ; }
0 commit comments