Skip to content

Commit 50e95ea

Browse files
committed
Fix pretty printer, which was ignoring ref in irrefutable patterns
1 parent 682e746 commit 50e95ea

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn ty_to_str(ty: &ast::Ty, intr: @ident_interner) -> ~str {
147147
}
148148

149149
pub fn pat_to_str(pat: &ast::pat, intr: @ident_interner) -> ~str {
150-
to_str(pat, print_irrefutable_pat, intr)
150+
to_str(pat, print_pat, intr)
151151
}
152152

153153
pub fn expr_to_str(e: &ast::expr, intr: @ident_interner) -> ~str {
@@ -1240,7 +1240,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) {
12401240
if first {
12411241
first = false;
12421242
} else { space(s.s); word_space(s, "|"); }
1243-
print_refutable_pat(s, *p);
1243+
print_pat(s, *p);
12441244
}
12451245
space(s.s);
12461246
match arm.guard {
@@ -1434,7 +1434,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) {
14341434
}
14351435

14361436
pub fn print_local_decl(s: @ps, loc: &ast::local) {
1437-
print_irrefutable_pat(s, loc.node.pat);
1437+
print_pat(s, loc.node.pat);
14381438
match loc.node.ty.node {
14391439
ast::ty_infer => (),
14401440
_ => { word_space(s, ":"); print_type(s, &loc.node.ty); }
@@ -1521,20 +1521,7 @@ pub fn print_path(s: @ps, path: &ast::Path, colons_before_params: bool) {
15211521
print_path_(s, path, colons_before_params, &None)
15221522
}
15231523

1524-
pub fn print_bounded_path(s: @ps, path: &ast::Path,
1525-
bounds: &Option<OptVec<ast::TyParamBound>>) {
1526-
print_path_(s, path, false, bounds)
1527-
}
1528-
1529-
pub fn print_irrefutable_pat(s: @ps, pat: &ast::pat) {
1530-
print_pat(s, pat, false)
1531-
}
1532-
1533-
pub fn print_refutable_pat(s: @ps, pat: &ast::pat) {
1534-
print_pat(s, pat, true)
1535-
}
1536-
1537-
pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
1524+
pub fn print_pat(s: @ps, pat: &ast::pat) {
15381525
maybe_print_comment(s, pat.span.lo);
15391526
let ann_node = node_pat(s, pat);
15401527
(s.ann.pre)(ann_node);
@@ -1543,20 +1530,18 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
15431530
match pat.node {
15441531
ast::pat_wild => word(s.s, "_"),
15451532
ast::pat_ident(binding_mode, ref path, sub) => {
1546-
if refutable {
1547-
match binding_mode {
1548-
ast::bind_by_ref(mutbl) => {
1549-
word_nbsp(s, "ref");
1550-
print_mutability(s, mutbl);
1551-
}
1552-
ast::bind_infer => {}
1533+
match binding_mode {
1534+
ast::bind_by_ref(mutbl) => {
1535+
word_nbsp(s, "ref");
1536+
print_mutability(s, mutbl);
15531537
}
1538+
ast::bind_infer => {}
15541539
}
15551540
print_path(s, path, true);
15561541
match sub {
15571542
Some(p) => {
15581543
word(s.s, "@");
1559-
print_pat(s, p, refutable);
1544+
print_pat(s, p);
15601545
}
15611546
None => ()
15621547
}
@@ -1569,7 +1554,7 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
15691554
if !args.is_empty() {
15701555
popen(s);
15711556
commasep(s, inconsistent, *args,
1572-
|s, &p| print_pat(s, p, refutable));
1557+
|s, &p| print_pat(s, p));
15731558
pclose(s);
15741559
} else { }
15751560
}
@@ -1578,16 +1563,16 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
15781563
ast::pat_struct(ref path, ref fields, etc) => {
15791564
print_path(s, path, true);
15801565
word(s.s, "{");
1581-
fn print_field(s: @ps, f: &ast::field_pat, refutable: bool) {
1566+
fn print_field(s: @ps, f: &ast::field_pat) {
15821567
cbox(s, indent_unit);
15831568
print_ident(s, f.ident);
15841569
word_space(s, ":");
1585-
print_pat(s, f.pat, refutable);
1570+
print_pat(s, f.pat);
15861571
end(s);
15871572
}
15881573
fn get_span(f: &ast::field_pat) -> codemap::span { return f.pat.span; }
15891574
commasep_cmnt(s, consistent, *fields,
1590-
|s, f| print_field(s,f,refutable),
1575+
|s, f| print_field(s,f),
15911576
get_span);
15921577
if etc {
15931578
if fields.len() != 0u { word_space(s, ","); }
@@ -1597,23 +1582,23 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
15971582
}
15981583
ast::pat_tup(ref elts) => {
15991584
popen(s);
1600-
commasep(s, inconsistent, *elts, |s, &p| print_pat(s, p, refutable));
1585+
commasep(s, inconsistent, *elts, |s, &p| print_pat(s, p));
16011586
if elts.len() == 1 {
16021587
word(s.s, ",");
16031588
}
16041589
pclose(s);
16051590
}
16061591
ast::pat_box(inner) => {
16071592
word(s.s, "@");
1608-
print_pat(s, inner, refutable);
1593+
print_pat(s, inner);
16091594
}
16101595
ast::pat_uniq(inner) => {
16111596
word(s.s, "~");
1612-
print_pat(s, inner, refutable);
1597+
print_pat(s, inner);
16131598
}
16141599
ast::pat_region(inner) => {
16151600
word(s.s, "&");
1616-
print_pat(s, inner, refutable);
1601+
print_pat(s, inner);
16171602
}
16181603
ast::pat_lit(e) => print_expr(s, e),
16191604
ast::pat_range(begin, end) => {
@@ -1625,16 +1610,16 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
16251610
ast::pat_vec(ref before, slice, ref after) => {
16261611
word(s.s, "[");
16271612
do commasep(s, inconsistent, *before) |s, &p| {
1628-
print_pat(s, p, refutable);
1613+
print_pat(s, p);
16291614
}
16301615
for slice.iter().advance |&p| {
16311616
if !before.is_empty() { word_space(s, ","); }
16321617
word(s.s, "..");
1633-
print_pat(s, p, refutable);
1618+
print_pat(s, p);
16341619
if !after.is_empty() { word_space(s, ","); }
16351620
}
16361621
do commasep(s, inconsistent, *after) |s, &p| {
1637-
print_pat(s, p, refutable);
1622+
print_pat(s, p);
16381623
}
16391624
word(s.s, "]");
16401625
}
@@ -1888,7 +1873,7 @@ pub fn print_arg(s: @ps, input: &ast::arg) {
18881873
word_space(s, "mut");
18891874
}
18901875
match input.ty.node {
1891-
ast::ty_infer => print_irrefutable_pat(s, input.pat),
1876+
ast::ty_infer => print_pat(s, input.pat),
18921877
_ => {
18931878
match input.pat.node {
18941879
ast::pat_ident(_, ref path, _) if
@@ -1897,7 +1882,7 @@ pub fn print_arg(s: @ps, input: &ast::arg) {
18971882
// Do nothing.
18981883
}
18991884
_ => {
1900-
print_irrefutable_pat(s, input.pat);
1885+
print_pat(s, input.pat);
19011886
word(s.s, ":");
19021887
space(s.s);
19031888
}

src/test/bench/shootout-k-nucleotide-pipes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
5656
let mut pairs = ~[];
5757

5858
// map -> [(k,%)]
59-
for mm.iter().advance |(&key, &val)| {
60-
pairs.push((key, pct(val, total)));
59+
for mm.iter().advance |(key, &val)| {
60+
pairs.push((copy *key, pct(val, total)));
6161
}
6262

6363
let pairs_sorted = sortKV(pairs);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn main() {
6868
check_pp(ext_cx, *stmt, pprust::print_stmt, ~"let x = 20;");
6969
7070
let pat = quote_pat!(Some(_));
71-
check_pp(ext_cx, pat, pprust::print_refutable_pat, ~"Some(_)");
71+
check_pp(ext_cx, pat, pprust::print_pat, ~"Some(_)");
7272

7373
}
7474

0 commit comments

Comments
 (0)