@@ -617,7 +617,7 @@ fn print_struct(s: ps, struct_def: @ast::struct_def, tps: ~[ast::ty_param],
617
617
cbox ( s, indent_unit) ;
618
618
ibox ( s, 4 ) ;
619
619
word ( s. s , ~"new ( ");
620
- print_fn_args(s, ctor.node.dec, ~[]);
620
+ print_fn_args(s, ctor.node.dec, ~[], none );
621
621
word(s.s, ~" ) ") ;
622
622
space ( s. s ) ;
623
623
print_block ( s, ctor. node . body ) ;
@@ -1193,7 +1193,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
1193
1193
// head-box, will be closed by print-block at start
1194
1194
ibox(s, 0u);
1195
1195
word(s.s, fn_header_info_to_str(none, decl.purity, some(proto)));
1196
- print_fn_args_and_ret(s, decl, *cap_clause);
1196
+ print_fn_args_and_ret(s, decl, *cap_clause, none );
1197
1197
space(s.s);
1198
1198
print_block(s, body);
1199
1199
}
@@ -1522,33 +1522,64 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
1522
1522
s.ann.post(ann_node);
1523
1523
}
1524
1524
1525
+ fn print_self_ty(s: ps, self_ty: ast::self_ty_) {
1526
+ match self_ty {
1527
+ ast::sty_static | ast::sty_by_ref => {}
1528
+ ast::sty_value => { word(s.s, ~" self") ; }
1529
+ ast:: sty_region ( m) => {
1530
+ word ( s. s , ~"& "); print_mutability(s, m); word(s.s, ~" self") ;
1531
+ }
1532
+ ast:: sty_box ( m) => {
1533
+ word ( s. s , ~"@") ; print_mutability ( s, m) ; word ( s. s , ~"self ") ;
1534
+ }
1535
+ ast:: sty_uniq ( m) => {
1536
+ word ( s. s , ~"~") ; print_mutability ( s, m) ; word ( s. s , ~"self ") ;
1537
+ }
1538
+ }
1539
+ }
1540
+
1525
1541
fn print_fn( s: ps, decl: ast:: fn_decl, name: ast:: ident,
1526
1542
typarams: ~[ ast:: ty_param] ,
1527
1543
opt_self_ty: option<ast:: self_ty_>) {
1528
1544
head ( s, fn_header_info_to_str ( opt_self_ty, decl. purity , none) ) ;
1529
1545
word ( s. s , * name) ;
1530
1546
print_type_params ( s, typarams) ;
1531
- print_fn_args_and_ret(s, decl, ~[]);
1547
+ print_fn_args_and_ret ( s, decl, ~[ ] , opt_self_ty ) ;
1532
1548
}
1533
1549
1534
1550
fn print_fn_args ( s : ps , decl : ast:: fn_decl ,
1535
- cap_items: ~[ast::capture_item]) {
1536
- commasep(s, inconsistent, decl.inputs, print_arg);
1537
- if cap_items.is_not_empty() {
1538
- let mut first = decl.inputs.is_empty();
1539
- for cap_items.each |cap_item| {
1540
- if first { first = false; } else { word_space(s, ~" , "); }
1541
- if cap_item.is_move { word_nbsp(s, ~" move") }
1542
- else { word_nbsp( s, ~"copy") }
1543
- word( s. s , * cap_item. name ) ;
1544
- }
1551
+ cap_items : ~[ ast:: capture_item ] ,
1552
+ opt_self_ty : option < ast:: self_ty_ > ) {
1553
+ // It is unfortunate to duplicate the commasep logic, but we
1554
+ // we want the self type, the args, and the capture clauses all
1555
+ // in the same box.
1556
+ box ( s, 0 u, inconsistent) ;
1557
+ let mut first = true ;
1558
+ for opt_self_ty. each |self_ty| {
1559
+ first = false ;
1560
+ print_self_ty ( s, self_ty) ;
1561
+ }
1562
+
1563
+ for decl. inputs. each |arg| {
1564
+ if first { first = false ; } else { word_space ( s, ~", "); }
1565
+ print_arg(s, arg);
1545
1566
}
1567
+
1568
+ for cap_items.each |cap_item| {
1569
+ if first { first = false; } else { word_space(s, ~" , "); }
1570
+ if cap_item.is_move { word_nbsp(s, ~" move") }
1571
+ else { word_nbsp( s, ~"copy") }
1572
+ word ( s. s , * cap_item. name ) ;
1573
+ }
1574
+
1575
+ end ( s) ;
1546
1576
}
1547
1577
1548
1578
fn print_fn_args_and_ret ( s : ps , decl : ast:: fn_decl ,
1549
- cap_items : ~[ ast:: capture_item ] ) {
1579
+ cap_items : ~[ ast:: capture_item ] ,
1580
+ opt_self_ty : option < ast:: self_ty_ > ) {
1550
1581
popen ( s) ;
1551
- print_fn_args ( s, decl, cap_items) ;
1582
+ print_fn_args ( s, decl, cap_items, opt_self_ty ) ;
1552
1583
pclose ( s) ;
1553
1584
1554
1585
maybe_print_comment ( s, decl. output . span . lo ) ;
@@ -1562,7 +1593,7 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl,
1562
1593
fn print_fn_block_args ( s : ps , decl : ast:: fn_decl ,
1563
1594
cap_items : ~[ ast:: capture_item ] ) {
1564
1595
word ( s. s , ~"|");
1565
- print_fn_args(s, decl, cap_items);
1596
+ print_fn_args(s, decl, cap_items, none );
1566
1597
word(s.s, ~" |");
1567
1598
if decl.output.node != ast::ty_infer {
1568
1599
space_if_not_bol(s);
@@ -1741,9 +1772,24 @@ fn print_ty_fn(s: ps, opt_proto: option<ast::proto>,
1741
1772
match id { some( id) => { word ( s. s , ~" "); word(s.s, *id); } _ => () }
1742
1773
match tps { some(tps) => print_type_params(s, tps), _ => () }
1743
1774
zerobreak(s.s);
1775
+
1744
1776
popen(s);
1745
- commasep(s, inconsistent, decl.inputs, print_arg);
1777
+ // It is unfortunate to duplicate the commasep logic, but we
1778
+ // we want the self type, the args, and the capture clauses all
1779
+ // in the same box.
1780
+ box(s, 0u, inconsistent);
1781
+ let mut first = true;
1782
+ for opt_self_ty.each |self_ty| {
1783
+ first = false;
1784
+ print_self_ty(s, self_ty);
1785
+ }
1786
+ for decl.inputs.each |arg| {
1787
+ if first { first = false; } else { word_space(s, ~" , "); }
1788
+ print_arg(s, arg);
1789
+ }
1790
+ end(s);
1746
1791
pclose(s);
1792
+
1747
1793
maybe_print_comment(s, decl.output.span.lo);
1748
1794
if decl.output.node != ast::ty_nil {
1749
1795
space_if_not_bol(s);
0 commit comments