Skip to content

Commit da2a7e5

Browse files
committed
Simple refactoring in the pretty printer.
Introduce a proto_to_str function to find the string representation of a given proto instead of casing on the proto in multiple places.
1 parent 9bd9456 commit da2a7e5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/comp/syntax/print/pprust.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
848848
bclose(s, expr.span);
849849
}
850850
case (ast::expr_fn(?f)) {
851-
head(s, "fn");
851+
head(s, proto_to_str(f.proto));
852852
print_fn_args_and_ret(s, f.decl);
853853
space(s.s);
854854
print_block(s, f.body);
@@ -1147,9 +1147,7 @@ fn print_fn(&ps s, ast::fn_decl decl, ast::proto proto, str name,
11471147
&ast::ty_param[] typarams) {
11481148
alt (decl.purity) {
11491149
case (ast::impure_fn) {
1150-
if (proto == ast::proto_iter) {
1151-
head(s, "iter");
1152-
} else { head(s, "fn"); }
1150+
head(s, proto_to_str(proto));
11531151
}
11541152
case (_) { head(s, "pred"); }
11551153
}
@@ -1308,9 +1306,7 @@ fn print_ty_fn(&ps s, &ast::proto proto, &option::t[str] id,
13081306
&ast::ty_arg[] inputs, &@ast::ty output,
13091307
&ast::controlflow cf, &(@ast::constr)[] constrs) {
13101308
ibox(s, indent_unit);
1311-
if (proto == ast::proto_fn) {
1312-
word(s.s, "fn");
1313-
} else { word(s.s, "iter"); }
1309+
word(s.s, proto_to_str(proto));
13141310
alt (id) {
13151311
case (some(?id)) { word(s.s, " "); word(s.s, id); }
13161312
case (_) { }
@@ -1565,6 +1561,13 @@ fn ast_constrs_str(&(@ast::constr)[] constrs) -> str {
15651561
ret s;
15661562
}
15671563

1564+
fn proto_to_str(&ast::proto p) -> str {
1565+
ret alt (p) {
1566+
ast::proto_fn { "fn" }
1567+
ast::proto_iter { "iter" }
1568+
};
1569+
}
1570+
15681571
//
15691572
// Local Variables:
15701573
// mode: rust

0 commit comments

Comments
 (0)