Skip to content

Commit d78053e

Browse files
committed
syntax: try to fix pattern printing yet again, r=burningtree.
1 parent 4a3170a commit d78053e

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn ty_to_str(ty: @ast::Ty, intr: @ident_interner) -> ~str {
107107
}
108108

109109
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)
111111
}
112112

113113
fn expr_to_str(e: @ast::expr, intr: @ident_interner) -> ~str {
@@ -1266,7 +1266,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
12661266
if first {
12671267
first = false;
12681268
} else { space(s.s); word_space(s, ~"|"); }
1269-
print_pat(s, *p);
1269+
print_refutable_pat(s, *p);
12701270
}
12711271
space(s.s);
12721272
match arm.guard {
@@ -1461,7 +1461,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
14611461
}
14621462

14631463
fn print_local_decl(s: ps, loc: @ast::local) {
1464-
print_pat(s, loc.node.pat);
1464+
print_irrefutable_pat(s, loc.node.pat);
14651465
match loc.node.ty.node {
14661466
ast::ty_infer => (),
14671467
_ => { 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) {
15381538
}
15391539
}
15401540
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)
15431543
}
15441544
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) {
15461550
maybe_print_comment(s, pat.span.lo);
15471551
let ann_node = node_pat(s, pat);
15481552
(s.ann.pre)(ann_node);
@@ -1551,7 +1555,7 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
15511555
match pat.node {
15521556
ast::pat_wild => word(s.s, ~"_"),
15531557
ast::pat_ident(binding_mode, path, sub) => {
1554-
if print_binding_mode {
1558+
if refutable {
15551559
match binding_mode {
15561560
ast::bind_by_ref(mutbl) => {
15571561
word_nbsp(s, ~"ref");
@@ -1570,7 +1574,7 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
15701574
match sub {
15711575
Some(p) => {
15721576
word(s.s, ~"@");
1573-
print_pat(s, p);
1577+
print_pat(s, p, refutable);
15741578
}
15751579
None => ()
15761580
}
@@ -1582,23 +1586,26 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
15821586
Some(args) => {
15831587
if args.is_not_empty() {
15841588
popen(s);
1585-
commasep(s, inconsistent, args, print_pat);
1589+
commasep(s, inconsistent, args,
1590+
|s, p| print_pat(s, p, refutable));
15861591
pclose(s);
15871592
} else { }
15881593
}
15891594
}
15901595
}
15911596
ast::pat_rec(fields, etc) => {
15921597
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) {
15941599
cbox(s, indent_unit);
15951600
print_ident(s, f.ident);
15961601
word_space(s, ~":");
1597-
print_pat(s, f.pat);
1602+
print_pat(s, f.pat, refutable);
15981603
end(s);
15991604
}
16001605
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);
16021609
if etc {
16031610
if vec::len(fields) != 0u { word_space(s, ~","); }
16041611
word(s.s, ~"_");
@@ -1608,15 +1615,17 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
16081615
ast::pat_struct(path, fields, etc) => {
16091616
print_path(s, path, true);
16101617
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) {
16121619
cbox(s, indent_unit);
16131620
print_ident(s, f.ident);
16141621
word_space(s, ~":");
1615-
print_pat(s, f.pat);
1622+
print_pat(s, f.pat, refutable);
16161623
end(s);
16171624
}
16181625
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);
16201629
if etc {
16211630
if vec::len(fields) != 0u { word_space(s, ~","); }
16221631
word(s.s, ~"_");
@@ -1625,20 +1634,20 @@ fn print_pat_full(s: ps, &&pat: @ast::pat, print_binding_mode: bool) {
16251634
}
16261635
ast::pat_tup(elts) => {
16271636
popen(s);
1628-
commasep(s, inconsistent, elts, print_pat);
1637+
commasep(s, inconsistent, elts, |s, p| print_pat(s, p, refutable));
16291638
pclose(s);
16301639
}
16311640
ast::pat_box(inner) => {
16321641
word(s.s, ~"@");
1633-
print_pat(s, inner);
1642+
print_pat(s, inner, refutable);
16341643
}
16351644
ast::pat_uniq(inner) => {
16361645
word(s.s, ~"~");
1637-
print_pat(s, inner);
1646+
print_pat(s, inner, refutable);
16381647
}
16391648
ast::pat_region(inner) => {
16401649
word(s.s, ~"&");
1641-
print_pat(s, inner);
1650+
print_pat(s, inner, refutable);
16421651
}
16431652
ast::pat_lit(e) => print_expr(s, e),
16441653
ast::pat_range(begin, end) => {
@@ -1885,7 +1894,7 @@ fn print_arg(s: ps, input: ast::arg) {
18851894
ibox(s, indent_unit);
18861895
print_arg_mode(s, input.mode);
18871896
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),
18891898
_ => {
18901899
match input.pat.node {
18911900
ast::pat_ident(_, path, _) if
@@ -1894,7 +1903,7 @@ fn print_arg(s: ps, input: ast::arg) {
18941903
// Do nothing.
18951904
}
18961905
_ => {
1897-
print_pat_full(s, input.pat, false);
1906+
print_irrefutable_pat(s, input.pat);
18981907
word(s.s, ~":");
18991908
space(s.s);
19001909
}

src/test/run-pass-fulldeps/qquote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() {
6161
check_pp(ext_cx, *stmt2, pprust::print_stmt, ~"let x: int = 23;");
6262
6363
let pat = #ast[pat]{some(_)};
64-
check_pp(ext_cx, pat, pprust::print_pat, ~"some(_)");
64+
check_pp(ext_cx, pat, pprust::print_refutable_pat, ~"some(_)");
6565

6666
// issue #1785
6767
let x = #ast{1};

0 commit comments

Comments
 (0)