Skip to content

Commit 7186153

Browse files
committed
---
yaml --- r: 13801 b: refs/heads/try c: b7b8455 h: refs/heads/master i: 13799: d5922f5 v: v3
1 parent a86cec5 commit 7186153

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 1586cce0ea1082f4716b50520ed9cb40941f7fad
5+
refs/heads/try: b7b8455e540a4acca4c602f248534e264b45664d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/comp/syntax/print/pprust.rs

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ fn attribute_to_str(attr: ast::attribute) -> str {
137137
be to_str(attr, print_attribute);
138138
}
139139

140+
fn variant_to_str(var: ast::variant) -> str {
141+
be to_str(var, print_variant);
142+
}
143+
144+
#[test]
145+
fn test_variant_to_str() {
146+
let var = ast_util::respan(ast_util::dummy_sp(), {
147+
name: "principle_skinner",
148+
attrs: [],
149+
args: [],
150+
id: 0,
151+
disr_expr: none
152+
});
153+
154+
let varstr = variant_to_str(var);
155+
assert varstr == "principle_skinner";
156+
}
157+
140158
fn cbox(s: ps, u: uint) { s.boxes += [pp::consistent]; pp::cbox(s.s, u); }
141159

142160
fn box(s: ps, u: uint, b: pp::breaks) { s.boxes += [b]; pp::box(s.s, u, b); }
@@ -436,23 +454,7 @@ fn print_item(s: ps, &&item: @ast::item) {
436454
maybe_print_comment(s, v.span.lo);
437455
print_outer_attributes(s, v.node.attrs);
438456
ibox(s, indent_unit);
439-
word(s.s, v.node.name);
440-
if vec::len(v.node.args) > 0u {
441-
popen(s);
442-
fn print_variant_arg(s: ps, arg: ast::variant_arg) {
443-
print_type(s, arg.ty);
444-
}
445-
commasep(s, consistent, v.node.args, print_variant_arg);
446-
pclose(s);
447-
}
448-
alt v.node.disr_expr {
449-
some(d) {
450-
space(s.s);
451-
word_space(s, "=");
452-
print_expr(s, d);
453-
}
454-
_ {}
455-
}
457+
print_variant(s, v);
456458
word(s.s, ",");
457459
end(s);
458460
maybe_print_trailing_comment(s, v.span, none::<uint>);
@@ -510,6 +512,26 @@ fn print_item(s: ps, &&item: @ast::item) {
510512
s.ann.post(ann_node);
511513
}
512514

515+
fn print_variant(s: ps, v: ast::variant) {
516+
word(s.s, v.node.name);
517+
if vec::len(v.node.args) > 0u {
518+
popen(s);
519+
fn print_variant_arg(s: ps, arg: ast::variant_arg) {
520+
print_type(s, arg.ty);
521+
}
522+
commasep(s, consistent, v.node.args, print_variant_arg);
523+
pclose(s);
524+
}
525+
alt v.node.disr_expr {
526+
some(d) {
527+
space(s.s);
528+
word_space(s, "=");
529+
print_expr(s, d);
530+
}
531+
_ {}
532+
}
533+
}
534+
513535
fn print_ty_method(s: ps, m: ast::ty_method) {
514536
hardbreak_if_not_bol(s);
515537
cbox(s, indent_unit);

0 commit comments

Comments
 (0)