@@ -107,7 +107,7 @@ fn ty_to_str(ty: @ast::Ty, intr: @ident_interner) -> ~str {
107
107
}
108
108
109
109
fn pat_to_str ( pat : @ast:: pat , intr : @ident_interner ) -> ~str {
110
- to_str ( pat, print_pat , intr)
110
+ to_str ( pat, print_irrefutable_pat , intr)
111
111
}
112
112
113
113
fn expr_to_str ( e : @ast:: expr , intr : @ident_interner ) -> ~str {
@@ -1266,7 +1266,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
1266
1266
if first {
1267
1267
first = false;
1268
1268
} else { space(s.s); word_space(s, ~" |"); }
1269
- print_pat (s, *p);
1269
+ print_refutable_pat (s, *p);
1270
1270
}
1271
1271
space(s.s);
1272
1272
match arm.guard {
@@ -1461,7 +1461,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
1461
1461
}
1462
1462
1463
1463
fn print_local_decl ( s : ps , loc : @ast:: local ) {
1464
- print_pat ( s, loc. node . pat ) ;
1464
+ print_irrefutable_pat ( s, loc. node . pat ) ;
1465
1465
match loc. node . ty . node {
1466
1466
ast:: ty_infer => ( ) ,
1467
1467
_ => { word_space ( s, ~": ") ; print_type ( s, loc. node . ty ) ; }
@@ -1538,11 +1538,15 @@ fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) {
1538
1538
}
1539
1539
}
1540
1540
1541
- fn print_pat (s: ps, &&pat: @ast::pat) {
1542
- print_pat_full (s, pat, true )
1541
+ fn print_irrefutable_pat (s: ps, &&pat: @ast::pat) {
1542
+ print_pat (s, pat, false )
1543
1543
}
1544
1544
1545
- fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
1545
+ fn print_refutable_pat(s: ps, &&pat: @ast::pat) {
1546
+ print_pat(s, pat, true)
1547
+ }
1548
+
1549
+ fn print_pat(s: ps, &&pat: @ast::pat, refutable: bool) {
1546
1550
maybe_print_comment(s, pat.span.lo);
1547
1551
let ann_node = node_pat(s, pat);
1548
1552
(s.ann.pre)(ann_node);
@@ -1551,7 +1555,7 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
1551
1555
match pat.node {
1552
1556
ast::pat_wild => word(s.s, ~" _") ,
1553
1557
ast:: pat_ident( binding_mode, path, sub) => {
1554
- if print_binding_mode {
1558
+ if refutable {
1555
1559
match binding_mode {
1556
1560
ast:: bind_by_ref( mutbl) => {
1557
1561
word_nbsp( s, ~"ref ");
@@ -1570,7 +1574,7 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
1570
1574
match sub {
1571
1575
Some ( p) => {
1572
1576
word ( s. s , ~"@") ;
1573
- print_pat ( s, p) ;
1577
+ print_pat ( s, p, refutable ) ;
1574
1578
}
1575
1579
None => ( )
1576
1580
}
@@ -1582,23 +1586,26 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
1582
1586
Some ( args) => {
1583
1587
if args. is_not_empty ( ) {
1584
1588
popen ( s) ;
1585
- commasep ( s, inconsistent, args, print_pat) ;
1589
+ commasep ( s, inconsistent, args,
1590
+ |s, p| print_pat ( s, p, refutable) ) ;
1586
1591
pclose ( s) ;
1587
1592
} else { }
1588
1593
}
1589
1594
}
1590
1595
}
1591
1596
ast:: pat_rec ( fields, etc) => {
1592
1597
word( s. s , ~"{ ");
1593
- fn print_field(s: ps, f: ast::field_pat) {
1598
+ fn print_field(s: ps, f: ast::field_pat, refutable: bool ) {
1594
1599
cbox(s, indent_unit);
1595
1600
print_ident(s, f.ident);
1596
1601
word_space(s, ~" : ") ;
1597
- print_pat ( s, f. pat ) ;
1602
+ print_pat ( s, f. pat , refutable ) ;
1598
1603
end ( s) ;
1599
1604
}
1600
1605
fn get_span ( f : ast:: field_pat ) -> codemap:: span { return f. pat . span ; }
1601
- commasep_cmnt ( s, consistent, fields, print_field, get_span) ;
1606
+ commasep_cmnt ( s, consistent, fields,
1607
+ |s, f| print_field ( s, f, refutable) ,
1608
+ get_span) ;
1602
1609
if etc {
1603
1610
if vec:: len ( fields) != 0 u { word_space ( s, ~", "); }
1604
1611
word(s.s, ~" _") ;
@@ -1608,15 +1615,17 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
1608
1615
ast::pat_struct(path, fields, etc) => {
1609
1616
print_path(s, path, true);
1610
1617
word(s.s, ~" { ");
1611
- fn print_field(s: ps, f: ast::field_pat) {
1618
+ fn print_field(s: ps, f: ast::field_pat, refutable: bool ) {
1612
1619
cbox(s, indent_unit);
1613
1620
print_ident(s, f.ident);
1614
1621
word_space(s, ~" : ") ;
1615
- print_pat ( s, f. pat ) ;
1622
+ print_pat ( s, f. pat , refutable ) ;
1616
1623
end ( s) ;
1617
1624
}
1618
1625
fn get_span ( f : ast:: field_pat ) -> codemap:: span { return f. pat . span ; }
1619
- commasep_cmnt ( s, consistent, fields, print_field, get_span) ;
1626
+ commasep_cmnt ( s, consistent, fields,
1627
+ |s, f| print_field ( s, f, refutable) ,
1628
+ get_span) ;
1620
1629
if etc {
1621
1630
if vec:: len ( fields) != 0 u { word_space ( s, ~", "); }
1622
1631
word(s.s, ~" _") ;
@@ -1625,20 +1634,20 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
1625
1634
}
1626
1635
ast::pat_tup(elts) => {
1627
1636
popen(s);
1628
- commasep(s, inconsistent, elts, print_pat);
1637
+ commasep(s, inconsistent, elts, |s, p| print_pat(s, p, refutable) );
1629
1638
pclose(s);
1630
1639
}
1631
1640
ast::pat_box(inner) => {
1632
1641
word(s.s, ~" @") ;
1633
- print_pat ( s, inner) ;
1642
+ print_pat ( s, inner, refutable ) ;
1634
1643
}
1635
1644
ast:: pat_uniq ( inner) => {
1636
1645
word ( s. s , ~"~") ;
1637
- print_pat ( s, inner) ;
1646
+ print_pat ( s, inner, refutable ) ;
1638
1647
}
1639
1648
ast:: pat_region ( inner) => {
1640
1649
word ( s. s , ~"& ");
1641
- print_pat(s, inner);
1650
+ print_pat(s, inner, refutable );
1642
1651
}
1643
1652
ast::pat_lit(e) => print_expr(s, e),
1644
1653
ast::pat_range(begin, end) => {
@@ -1885,7 +1894,7 @@ fn print_arg(s: ps, input: ast::arg) {
1885
1894
ibox ( s, indent_unit) ;
1886
1895
print_arg_mode ( s, input. mode ) ;
1887
1896
match input. ty . node {
1888
- ast:: ty_infer => print_pat_full ( s, input. pat , false ) ,
1897
+ ast:: ty_infer => print_irrefutable_pat ( s, input. pat ) ,
1889
1898
_ => {
1890
1899
match input. pat . node {
1891
1900
ast:: pat_ident( _, path, _) if
@@ -1894,7 +1903,7 @@ fn print_arg(s: ps, input: ast::arg) {
1894
1903
// Do nothing.
1895
1904
}
1896
1905
_ => {
1897
- print_pat_full ( s, input. pat , false ) ;
1906
+ print_irrefutable_pat ( s, input. pat ) ;
1898
1907
word ( s. s , ~": ") ;
1899
1908
space ( s. s ) ;
1900
1909
}
0 commit comments