Skip to content

Commit 28cce24

Browse files
committed
syntax: try to fix pattern printing harder, r=burningtree.
1 parent 5bdbfa4 commit 28cce24

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,10 @@ fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) {
15391539
}
15401540
15411541
fn print_pat(s: ps, &&pat: @ast::pat) {
1542+
print_pat_full(s, pat, true)
1543+
}
1544+
1545+
fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
15421546
maybe_print_comment(s, pat.span.lo);
15431547
let ann_node = node_pat(s, pat);
15441548
(s.ann.pre)(ann_node);
@@ -1547,24 +1551,29 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
15471551
match pat.node {
15481552
ast::pat_wild => word(s.s, ~"_"),
15491553
ast::pat_ident(binding_mode, path, sub) => {
1550-
match binding_mode {
1551-
ast::bind_by_ref(mutbl) => {
1552-
word_nbsp(s, ~"ref");
1553-
print_mutability(s, mutbl);
1554-
}
1555-
ast::bind_by_move => {
1556-
word_nbsp(s, ~"move");
1554+
if print_binding_mode {
1555+
match binding_mode {
1556+
ast::bind_by_ref(mutbl) => {
1557+
word_nbsp(s, ~"ref");
1558+
print_mutability(s, mutbl);
1559+
}
1560+
ast::bind_by_move => {
1561+
word_nbsp(s, ~"move");
1562+
}
1563+
ast::bind_by_value => {
1564+
word_nbsp(s, ~"copy");
1565+
}
1566+
ast::bind_by_implicit_ref => {}
1567+
}
15571568
}
1558-
ast::bind_by_value => {
1559-
word_nbsp(s, ~"copy");
1569+
print_path(s, path, true);
1570+
match sub {
1571+
Some(p) => {
1572+
word(s.s, ~"@");
1573+
print_pat(s, p);
1574+
}
1575+
None => ()
15601576
}
1561-
ast::bind_by_implicit_ref => {}
1562-
}
1563-
print_path(s, path, true);
1564-
match sub {
1565-
Some(p) => { word(s.s, ~"@"); print_pat(s, p); }
1566-
None => ()
1567-
}
15681577
}
15691578
ast::pat_enum(path, args_) => {
15701579
print_path(s, path, true);
@@ -1619,8 +1628,14 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
16191628
commasep(s, inconsistent, elts, print_pat);
16201629
pclose(s);
16211630
}
1622-
ast::pat_box(inner) => { word(s.s, ~"@"); print_pat(s, inner); }
1623-
ast::pat_uniq(inner) => { word(s.s, ~"~"); print_pat(s, inner); }
1631+
ast::pat_box(inner) => {
1632+
word(s.s, ~"@");
1633+
print_pat(s, inner);
1634+
}
1635+
ast::pat_uniq(inner) => {
1636+
word(s.s, ~"~");
1637+
print_pat(s, inner);
1638+
}
16241639
ast::pat_region(inner) => {
16251640
word(s.s, ~"&");
16261641
print_pat(s, inner);
@@ -1870,7 +1885,7 @@ fn print_arg(s: ps, input: ast::arg) {
18701885
ibox(s, indent_unit);
18711886
print_arg_mode(s, input.mode);
18721887
match input.ty.node {
1873-
ast::ty_infer => print_pat(s, input.pat),
1888+
ast::ty_infer => print_pat_full(s, input.pat, false),
18741889
_ => {
18751890
match input.pat.node {
18761891
ast::pat_ident(_, path, _) if
@@ -1879,7 +1894,7 @@ fn print_arg(s: ps, input: ast::arg) {
18791894
// Do nothing.
18801895
}
18811896
_ => {
1882-
print_pat(s, input.pat);
1897+
print_pat_full(s, input.pat, false);
18831898
word(s.s, ~":");
18841899
space(s.s);
18851900
}

0 commit comments

Comments
 (0)