Skip to content

Commit 2911156

Browse files
committed
Pretty-print fn constraints more correctish
1 parent 637037f commit 2911156

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/comp/syntax/print/pprust.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl,
11351135
}
11361136
commasep(s, inconsistent, decl.inputs, print_arg);
11371137
pclose(s);
1138-
word(s.s, ast_constrs_str(constrs));
1138+
word(s.s, ast_fn_constrs_str(decl, constrs));
11391139
maybe_print_comment(s, decl.output.span.lo);
11401140
if decl.output.node != ast::ty_nil {
11411141
space_if_not_bol(s);
@@ -1290,7 +1290,7 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t[str],
12901290
}
12911291
end(s);
12921292
}
1293-
word(s.s, ast_constrs_str(constrs));
1293+
word(s.s, ast_ty_fn_constrs_str(constrs));
12941294
end(s);
12951295
}
12961296

@@ -1498,18 +1498,40 @@ fn constr_arg_to_str[T](f: &fn(&T) -> str , c: &ast::constr_arg_general_[T])
14981498
// (argh)
14991499
fn uint_to_str(i: &uint) -> str { ret uint::str(i); }
15001500
1501-
fn ast_constr_to_str(c: &@ast::constr) -> str {
1501+
fn ast_ty_fn_constr_to_str(c: &@ast::constr) -> str {
15021502
ret path_to_str(c.node.path) +
15031503
constr_args_to_str(uint_to_str, c.node.args);
15041504
}
15051505
15061506
// FIXME: fix repeated code
1507-
fn ast_constrs_str(constrs: &(@ast::constr)[]) -> str {
1507+
fn ast_ty_fn_constrs_str(constrs: &(@ast::constr)[]) -> str {
15081508
let s = "";
15091509
let colon = true;
15101510
for c: @ast::constr in constrs {
15111511
if colon { s += " : "; colon = false; } else { s += ", "; }
1512-
s += ast_constr_to_str(c);
1512+
s += ast_ty_fn_constr_to_str(c);
1513+
}
1514+
ret s;
1515+
}
1516+
1517+
fn fn_arg_idx_to_str(decl: &ast::fn_decl, idx: &uint) -> str {
1518+
decl.inputs.(idx).ident
1519+
}
1520+
1521+
fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> str {
1522+
let arg_to_str = bind fn_arg_idx_to_str(decl, _);
1523+
ret path_to_str(c.node.path) +
1524+
constr_args_to_str(arg_to_str, c.node.args);
1525+
}
1526+
1527+
// FIXME: fix repeated code
1528+
fn ast_fn_constrs_str(decl: &ast::fn_decl,
1529+
constrs: &(@ast::constr)[]) -> str {
1530+
let s = "";
1531+
let colon = true;
1532+
for c: @ast::constr in constrs {
1533+
if colon { s += " : "; colon = false; } else { s += ", "; }
1534+
s += ast_fn_constr_to_str(decl, c);
15131535
}
15141536
ret s;
15151537
}

src/test/run-fail/fn-constraint-claim.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// xfail-pretty
21
// error-pattern:quux
32
use std;
43
import std::str::*;

src/test/run-pass/typestate-transitive.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// xfail-pretty
2-
31
pred p(i: int) -> bool { true }
42

53
fn f(i: int) : p(i) -> int { i }

0 commit comments

Comments
 (0)