提交 f3fa7c15 编写于 作者: B Brian Anderson

rustdoc: Extract functions from tystr_pass::fold_fn

上级 cbd7e8ed
......@@ -33,49 +33,49 @@ fn fold_fn(
) -> doc::fndoc {
let srv = fold.ctxt;
let ret_ty = get_ret_ty(srv, doc.id);
fn add_ret_ty(
doc: option<doc::retdoc>,
tystr: str
) -> option<doc::retdoc> {
alt doc {
some(doc) {
fail "unimplemented";
}
none. {
some({
desc: none,
ty: some(tystr)
})
}
}
~{
return: merge_ret_ty(doc.return, ret_ty)
with *doc
}
}
let retty = astsrv::exec(srv) {|ctxt|
alt ctxt.map.get(doc.id) {
fn get_ret_ty(srv: astsrv::srv, id: doc::ast_id) -> str {
astsrv::exec(srv) {|ctxt|
alt ctxt.map.get(id) {
ast_map::node_item(@{
node: ast::item_fn(decl, _, _), _
}) {
pprust::ty_to_str(decl.output)
}
}
};
~{
return: add_ret_ty(doc.return, retty)
with *doc
}
}
#[cfg(test)]
mod tests {
#[test]
fn should_add_fn_ret_types() {
let source = "fn a() -> int { }";
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
assert option::get(doc.topmod.fns[0].return).ty == some("int");
fn merge_ret_ty(
doc: option<doc::retdoc>,
tystr: str
) -> option<doc::retdoc> {
alt doc {
some(doc) {
fail "unimplemented";
}
none. {
some({
desc: none,
ty: some(tystr)
})
}
}
}
#[test]
fn should_add_fn_ret_types() {
let source = "fn a() -> int { }";
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
assert option::get(doc.topmod.fns[0].return).ty == some("int");
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册