Fix pretty printer, which was ignoring ref in irrefutable patterns
This commit is contained in:
@@ -147,7 +147,7 @@ pub fn ty_to_str(ty: &ast::Ty, intr: @ident_interner) -> ~str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn pat_to_str(pat: &ast::pat, intr: @ident_interner) -> ~str {
|
pub fn pat_to_str(pat: &ast::pat, intr: @ident_interner) -> ~str {
|
||||||
to_str(pat, print_irrefutable_pat, intr)
|
to_str(pat, print_pat, intr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expr_to_str(e: &ast::expr, intr: @ident_interner) -> ~str {
|
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) {
|
|||||||
if first {
|
if first {
|
||||||
first = false;
|
first = false;
|
||||||
} else { space(s.s); word_space(s, "|"); }
|
} else { space(s.s); word_space(s, "|"); }
|
||||||
print_refutable_pat(s, *p);
|
print_pat(s, *p);
|
||||||
}
|
}
|
||||||
space(s.s);
|
space(s.s);
|
||||||
match arm.guard {
|
match arm.guard {
|
||||||
@@ -1434,7 +1434,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_local_decl(s: @ps, loc: &ast::local) {
|
pub fn print_local_decl(s: @ps, loc: &ast::local) {
|
||||||
print_irrefutable_pat(s, loc.node.pat);
|
print_pat(s, loc.node.pat);
|
||||||
match loc.node.ty.node {
|
match loc.node.ty.node {
|
||||||
ast::ty_infer => (),
|
ast::ty_infer => (),
|
||||||
_ => { word_space(s, ":"); print_type(s, &loc.node.ty); }
|
_ => { 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) {
|
|||||||
print_path_(s, path, colons_before_params, &None)
|
print_path_(s, path, colons_before_params, &None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_bounded_path(s: @ps, path: &ast::Path,
|
pub fn print_pat(s: @ps, pat: &ast::pat) {
|
||||||
bounds: &Option<OptVec<ast::TyParamBound>>) {
|
|
||||||
print_path_(s, path, false, bounds)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn print_irrefutable_pat(s: @ps, pat: &ast::pat) {
|
|
||||||
print_pat(s, pat, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn print_refutable_pat(s: @ps, pat: &ast::pat) {
|
|
||||||
print_pat(s, pat, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
|
|
||||||
maybe_print_comment(s, pat.span.lo);
|
maybe_print_comment(s, pat.span.lo);
|
||||||
let ann_node = node_pat(s, pat);
|
let ann_node = node_pat(s, pat);
|
||||||
(s.ann.pre)(ann_node);
|
(s.ann.pre)(ann_node);
|
||||||
@@ -1543,7 +1530,6 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
|
|||||||
match pat.node {
|
match pat.node {
|
||||||
ast::pat_wild => word(s.s, "_"),
|
ast::pat_wild => word(s.s, "_"),
|
||||||
ast::pat_ident(binding_mode, ref path, sub) => {
|
ast::pat_ident(binding_mode, ref path, sub) => {
|
||||||
if refutable {
|
|
||||||
match binding_mode {
|
match binding_mode {
|
||||||
ast::bind_by_ref(mutbl) => {
|
ast::bind_by_ref(mutbl) => {
|
||||||
word_nbsp(s, "ref");
|
word_nbsp(s, "ref");
|
||||||
@@ -1551,12 +1537,11 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
|
|||||||
}
|
}
|
||||||
ast::bind_infer => {}
|
ast::bind_infer => {}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
print_path(s, path, true);
|
print_path(s, path, true);
|
||||||
match sub {
|
match sub {
|
||||||
Some(p) => {
|
Some(p) => {
|
||||||
word(s.s, "@");
|
word(s.s, "@");
|
||||||
print_pat(s, p, refutable);
|
print_pat(s, p);
|
||||||
}
|
}
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
@@ -1569,7 +1554,7 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
|
|||||||
if !args.is_empty() {
|
if !args.is_empty() {
|
||||||
popen(s);
|
popen(s);
|
||||||
commasep(s, inconsistent, *args,
|
commasep(s, inconsistent, *args,
|
||||||
|s, &p| print_pat(s, p, refutable));
|
|s, &p| print_pat(s, p));
|
||||||
pclose(s);
|
pclose(s);
|
||||||
} else { }
|
} else { }
|
||||||
}
|
}
|
||||||
@@ -1578,16 +1563,16 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
|
|||||||
ast::pat_struct(ref path, ref fields, etc) => {
|
ast::pat_struct(ref path, ref fields, etc) => {
|
||||||
print_path(s, path, true);
|
print_path(s, path, true);
|
||||||
word(s.s, "{");
|
word(s.s, "{");
|
||||||
fn print_field(s: @ps, f: &ast::field_pat, refutable: bool) {
|
fn print_field(s: @ps, f: &ast::field_pat) {
|
||||||
cbox(s, indent_unit);
|
cbox(s, indent_unit);
|
||||||
print_ident(s, f.ident);
|
print_ident(s, f.ident);
|
||||||
word_space(s, ":");
|
word_space(s, ":");
|
||||||
print_pat(s, f.pat, refutable);
|
print_pat(s, f.pat);
|
||||||
end(s);
|
end(s);
|
||||||
}
|
}
|
||||||
fn get_span(f: &ast::field_pat) -> codemap::span { return f.pat.span; }
|
fn get_span(f: &ast::field_pat) -> codemap::span { return f.pat.span; }
|
||||||
commasep_cmnt(s, consistent, *fields,
|
commasep_cmnt(s, consistent, *fields,
|
||||||
|s, f| print_field(s,f,refutable),
|
|s, f| print_field(s,f),
|
||||||
get_span);
|
get_span);
|
||||||
if etc {
|
if etc {
|
||||||
if fields.len() != 0u { word_space(s, ","); }
|
if fields.len() != 0u { word_space(s, ","); }
|
||||||
@@ -1597,7 +1582,7 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
|
|||||||
}
|
}
|
||||||
ast::pat_tup(ref elts) => {
|
ast::pat_tup(ref elts) => {
|
||||||
popen(s);
|
popen(s);
|
||||||
commasep(s, inconsistent, *elts, |s, &p| print_pat(s, p, refutable));
|
commasep(s, inconsistent, *elts, |s, &p| print_pat(s, p));
|
||||||
if elts.len() == 1 {
|
if elts.len() == 1 {
|
||||||
word(s.s, ",");
|
word(s.s, ",");
|
||||||
}
|
}
|
||||||
@@ -1605,15 +1590,15 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
|
|||||||
}
|
}
|
||||||
ast::pat_box(inner) => {
|
ast::pat_box(inner) => {
|
||||||
word(s.s, "@");
|
word(s.s, "@");
|
||||||
print_pat(s, inner, refutable);
|
print_pat(s, inner);
|
||||||
}
|
}
|
||||||
ast::pat_uniq(inner) => {
|
ast::pat_uniq(inner) => {
|
||||||
word(s.s, "~");
|
word(s.s, "~");
|
||||||
print_pat(s, inner, refutable);
|
print_pat(s, inner);
|
||||||
}
|
}
|
||||||
ast::pat_region(inner) => {
|
ast::pat_region(inner) => {
|
||||||
word(s.s, "&");
|
word(s.s, "&");
|
||||||
print_pat(s, inner, refutable);
|
print_pat(s, inner);
|
||||||
}
|
}
|
||||||
ast::pat_lit(e) => print_expr(s, e),
|
ast::pat_lit(e) => print_expr(s, e),
|
||||||
ast::pat_range(begin, end) => {
|
ast::pat_range(begin, end) => {
|
||||||
@@ -1625,16 +1610,16 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) {
|
|||||||
ast::pat_vec(ref before, slice, ref after) => {
|
ast::pat_vec(ref before, slice, ref after) => {
|
||||||
word(s.s, "[");
|
word(s.s, "[");
|
||||||
do commasep(s, inconsistent, *before) |s, &p| {
|
do commasep(s, inconsistent, *before) |s, &p| {
|
||||||
print_pat(s, p, refutable);
|
print_pat(s, p);
|
||||||
}
|
}
|
||||||
for slice.iter().advance |&p| {
|
for slice.iter().advance |&p| {
|
||||||
if !before.is_empty() { word_space(s, ","); }
|
if !before.is_empty() { word_space(s, ","); }
|
||||||
word(s.s, "..");
|
word(s.s, "..");
|
||||||
print_pat(s, p, refutable);
|
print_pat(s, p);
|
||||||
if !after.is_empty() { word_space(s, ","); }
|
if !after.is_empty() { word_space(s, ","); }
|
||||||
}
|
}
|
||||||
do commasep(s, inconsistent, *after) |s, &p| {
|
do commasep(s, inconsistent, *after) |s, &p| {
|
||||||
print_pat(s, p, refutable);
|
print_pat(s, p);
|
||||||
}
|
}
|
||||||
word(s.s, "]");
|
word(s.s, "]");
|
||||||
}
|
}
|
||||||
@@ -1888,7 +1873,7 @@ pub fn print_arg(s: @ps, input: &ast::arg) {
|
|||||||
word_space(s, "mut");
|
word_space(s, "mut");
|
||||||
}
|
}
|
||||||
match input.ty.node {
|
match input.ty.node {
|
||||||
ast::ty_infer => print_irrefutable_pat(s, input.pat),
|
ast::ty_infer => print_pat(s, input.pat),
|
||||||
_ => {
|
_ => {
|
||||||
match input.pat.node {
|
match input.pat.node {
|
||||||
ast::pat_ident(_, ref path, _) if
|
ast::pat_ident(_, ref path, _) if
|
||||||
@@ -1897,7 +1882,7 @@ pub fn print_arg(s: @ps, input: &ast::arg) {
|
|||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
print_irrefutable_pat(s, input.pat);
|
print_pat(s, input.pat);
|
||||||
word(s.s, ":");
|
word(s.s, ":");
|
||||||
space(s.s);
|
space(s.s);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
|
|||||||
let mut pairs = ~[];
|
let mut pairs = ~[];
|
||||||
|
|
||||||
// map -> [(k,%)]
|
// map -> [(k,%)]
|
||||||
for mm.iter().advance |(&key, &val)| {
|
for mm.iter().advance |(key, &val)| {
|
||||||
pairs.push((key, pct(val, total)));
|
pairs.push((copy *key, pct(val, total)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let pairs_sorted = sortKV(pairs);
|
let pairs_sorted = sortKV(pairs);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ fn main() {
|
|||||||
check_pp(ext_cx, *stmt, pprust::print_stmt, ~"let x = 20;");
|
check_pp(ext_cx, *stmt, pprust::print_stmt, ~"let x = 20;");
|
||||||
|
|
||||||
let pat = quote_pat!(Some(_));
|
let pat = quote_pat!(Some(_));
|
||||||
check_pp(ext_cx, pat, pprust::print_refutable_pat, ~"Some(_)");
|
check_pp(ext_cx, pat, pprust::print_pat, ~"Some(_)");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user