Skip to content

Commit 5dff7ac

Browse files
committed
---
yaml --- r: 7855 b: refs/heads/snap-stage3 c: 9f80a17 h: refs/heads/master i: 7853: 7865e3c 7851: 2b71799 7847: 21dfa8f 7839: 77b02f7 v: v3
1 parent 4468c1f commit 5dff7ac

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: e44467a47f2a85078a8af3cbc3765fec9261a850
4+
refs/heads/snap-stage3: 9f80a17c0ee501e89c41e270f0da61ca6056e77a
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/comp/syntax/print/pprust.rs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,34 @@ fn test_fun_to_str() {
117117
assert fun_to_str(decl, "a", []) == "fn a()";
118118
}
119119

120+
fn res_to_str(decl: ast::fn_decl, name: ast::ident,
121+
params: [ast::ty_param]) -> str {
122+
let buffer = io::mk_mem_buffer();
123+
let s = rust_printer(io::mem_buffer_writer(buffer));
124+
print_res(s, decl, name, params);
125+
end(s); // Close the head box
126+
end(s); // Close the outer box
127+
eof(s.s);
128+
io::mem_buffer_str(buffer)
129+
}
130+
131+
#[test]
132+
fn test_res_to_str() {
133+
let decl: ast::fn_decl = {
134+
inputs: [{
135+
mode: ast::by_val,
136+
ty: @ast_util::respan(ast_util::dummy_sp(), ast::ty_bool),
137+
ident: "b",
138+
id: 0
139+
}],
140+
output: @ast_util::respan(ast_util::dummy_sp(), ast::ty_nil),
141+
purity: ast::impure_fn,
142+
cf: ast::return_val,
143+
constraints: []
144+
};
145+
assert res_to_str(decl, "a", []) == "resource a(b: bool)";
146+
}
147+
120148
fn block_to_str(blk: ast::blk) -> str {
121149
let buffer = io::mk_mem_buffer();
122150
let s = rust_printer(io::mem_buffer_writer(buffer));
@@ -498,20 +526,25 @@ fn print_item(s: ps, &&item: @ast::item) {
498526
bclose(s, item.span);
499527
}
500528
ast::item_res(decl, tps, body, dt_id, ct_id) {
501-
head(s, "resource");
502-
word(s.s, item.ident);
503-
print_type_params(s, tps);
504-
popen(s);
505-
word_space(s, decl.inputs[0].ident + ":");
506-
print_type(s, decl.inputs[0].ty);
507-
pclose(s);
508-
space(s.s);
529+
print_res(s, decl, item.ident, tps);
509530
print_block(s, body);
510531
}
511532
}
512533
s.ann.post(ann_node);
513534
}
514535

536+
fn print_res(s: ps, decl: ast::fn_decl, name: ast::ident,
537+
typarams: [ast::ty_param]) {
538+
head(s, "resource");
539+
word(s.s, name);
540+
print_type_params(s, typarams);
541+
popen(s);
542+
word_space(s, decl.inputs[0].ident + ":");
543+
print_type(s, decl.inputs[0].ty);
544+
pclose(s);
545+
space(s.s);
546+
}
547+
515548
fn print_variant(s: ps, v: ast::variant) {
516549
word(s.s, v.node.name);
517550
if vec::len(v.node.args) > 0u {

0 commit comments

Comments
 (0)