Skip to content

Commit 7794961

Browse files
committed
---
yaml --- r: 7340 b: refs/heads/master c: c4de718 h: refs/heads/master v: v3
1 parent a5f0982 commit 7794961

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 497814642f2ce491baa79f310932f358757ad2fc
2+
refs/heads/master: c4de718f378d6be0c52e77971045f1bff3af4664

trunk/src/rustdoc/rustdoc.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ mod extract;
1212
mod attr_parser;
1313
mod doc;
1414
mod gen;
15-
mod fold;
15+
mod fold;
16+
mod tystr_pass;

trunk/src/rustdoc/tystr_pass.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import rustc::syntax::ast;
2+
3+
export run;
4+
5+
fn run(doc: doc::cratedoc, crate: @ast::crate) -> doc::cratedoc {
6+
let fold = fold::fold({
7+
fold_fn: fn~(
8+
f: fold::fold<@ast::crate>,
9+
d: doc::fndoc
10+
) -> doc::fndoc {
11+
fold_fn(f, d)
12+
}
13+
with *fold::default_seq_fold(crate)
14+
});
15+
fold.fold_crate(fold, doc)
16+
}
17+
18+
fn fold_fn(
19+
fold: fold::fold<@ast::crate>,
20+
doc: doc::fndoc
21+
) -> doc::fndoc {
22+
import rustc::middle::ast_map;
23+
import rustc::syntax::print::pprust;
24+
25+
let crate = fold.ctxt;
26+
27+
let map = ast_map::map_crate(*crate);
28+
29+
fn add_ret_ty(
30+
doc: option<doc::retdoc>,
31+
tystr: str
32+
) -> option<doc::retdoc> {
33+
alt doc {
34+
some(doc) {
35+
fail "unimplemented";
36+
}
37+
none. {
38+
some({
39+
desc: none,
40+
ty: some(tystr)
41+
})
42+
}
43+
}
44+
}
45+
46+
~{
47+
return: alt map.get(doc.id) {
48+
ast_map::node_item(@{
49+
node: ast::item_fn(decl, _, _), _
50+
}) {
51+
add_ret_ty(doc.return, pprust::ty_to_str(decl.output))
52+
}
53+
}
54+
with *doc
55+
}
56+
}
57+
58+
#[cfg(test)]
59+
mod tests {
60+
61+
#[test]
62+
fn should_add_fn_ret_types() {
63+
let source = "fn a() -> int { }";
64+
let ast = parse::from_str(source);
65+
let doc = extract::extract(ast, "");
66+
let doc = run(doc, ast);
67+
assert option::get(doc.topmod.fns[0].return).ty == some("int");
68+
}
69+
}

0 commit comments

Comments
 (0)