Skip to content

Commit f3fa7c1

Browse files
committed
rustdoc: Extract functions from tystr_pass::fold_fn
1 parent cbd7e8e commit f3fa7c1

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/rustdoc/tystr_pass.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,49 @@ fn fold_fn(
3333
) -> doc::fndoc {
3434

3535
let srv = fold.ctxt;
36+
let ret_ty = get_ret_ty(srv, doc.id);
3637

37-
fn add_ret_ty(
38-
doc: option<doc::retdoc>,
39-
tystr: str
40-
) -> option<doc::retdoc> {
41-
alt doc {
42-
some(doc) {
43-
fail "unimplemented";
44-
}
45-
none. {
46-
some({
47-
desc: none,
48-
ty: some(tystr)
49-
})
50-
}
51-
}
38+
~{
39+
return: merge_ret_ty(doc.return, ret_ty)
40+
with *doc
5241
}
42+
}
5343

54-
let retty = astsrv::exec(srv) {|ctxt|
55-
alt ctxt.map.get(doc.id) {
44+
fn get_ret_ty(srv: astsrv::srv, id: doc::ast_id) -> str {
45+
astsrv::exec(srv) {|ctxt|
46+
alt ctxt.map.get(id) {
5647
ast_map::node_item(@{
5748
node: ast::item_fn(decl, _, _), _
5849
}) {
5950
pprust::ty_to_str(decl.output)
6051
}
6152
}
62-
};
63-
64-
~{
65-
return: add_ret_ty(doc.return, retty)
66-
with *doc
6753
}
6854
}
6955

70-
#[cfg(test)]
71-
mod tests {
72-
73-
#[test]
74-
fn should_add_fn_ret_types() {
75-
let source = "fn a() -> int { }";
76-
let srv = astsrv::mk_srv_from_str(source);
77-
let doc = extract::from_srv(srv, "");
78-
let doc = run(srv, doc);
79-
assert option::get(doc.topmod.fns[0].return).ty == some("int");
56+
fn merge_ret_ty(
57+
doc: option<doc::retdoc>,
58+
tystr: str
59+
) -> option<doc::retdoc> {
60+
alt doc {
61+
some(doc) {
62+
fail "unimplemented";
63+
}
64+
none. {
65+
some({
66+
desc: none,
67+
ty: some(tystr)
68+
})
69+
}
8070
}
8171
}
72+
73+
#[test]
74+
fn should_add_fn_ret_types() {
75+
let source = "fn a() -> int { }";
76+
let srv = astsrv::mk_srv_from_str(source);
77+
let doc = extract::from_srv(srv, "");
78+
let doc = run(srv, doc);
79+
assert option::get(doc.topmod.fns[0].return).ty == some("int");
80+
}
81+

0 commit comments

Comments
 (0)