Skip to content

Commit e9ddfbe

Browse files
committed
rustdoc: Ignore nil-typed return values
1 parent a02a943 commit e9ddfbe

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

src/rustdoc/gen.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,27 @@ fn write_return(
204204
}
205205
}
206206

207+
#[test]
208+
fn should_write_return_type_on_new_line() {
209+
let markdown = test::render("fn a() -> int { }");
210+
assert str::contains(markdown, "\nReturns `int`");
211+
}
212+
213+
#[test]
214+
fn should_write_blank_line_between_return_type_and_next_header() {
215+
let markdown = test::render(
216+
"fn a() -> int { } \
217+
fn b() -> int { }"
218+
);
219+
assert str::contains(markdown, "Returns `int`\n\n##");
220+
}
221+
222+
#[test]
223+
fn should_not_write_return_type_when_there_is_none() {
224+
let markdown = test::render("fn a() { }");
225+
assert !str::contains(markdown, "Returns");
226+
}
227+
207228
#[cfg(test)]
208229
mod test {
209230
fn render(source: str) -> str {
@@ -272,18 +293,4 @@ mod test {
272293
assert str::contains(markdown, "brief\n\ndesc");
273294
}
274295

275-
#[test]
276-
fn should_write_return_type_on_new_line() {
277-
let markdown = render("fn a() -> int { }");
278-
assert str::contains(markdown, "\nReturns `int`");
279-
}
280-
281-
#[test]
282-
fn should_write_blank_line_between_return_type_and_next_header() {
283-
let markdown = render(
284-
"fn a() -> int { } \
285-
fn b() -> int { }"
286-
);
287-
assert str::contains(markdown, "Returns `int`\n\n##");
288-
}
289296
}

src/rustdoc/tystr_pass.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,36 @@ fn merge_ret_ty(
4646
fn_id: doc::ast_id,
4747
doc: option<doc::retdoc>
4848
) -> option<doc::retdoc> {
49-
let ty = get_ret_ty(srv, fn_id);
5049
alt doc {
5150
some(doc) {
5251
fail "unimplemented";
5352
}
5453
none. {
55-
some({
56-
desc: none,
57-
ty: some(ty)
58-
})
54+
alt get_ret_ty(srv, fn_id) {
55+
some(ty) {
56+
some({
57+
desc: none,
58+
ty: some(ty)
59+
})
60+
}
61+
none. { none }
62+
}
5963
}
6064
}
6165
}
6266

63-
fn get_ret_ty(srv: astsrv::srv, id: doc::ast_id) -> str {
67+
fn get_ret_ty(srv: astsrv::srv, id: doc::ast_id) -> option<str> {
6468
astsrv::exec(srv) {|ctxt|
6569
alt ctxt.map.get(id) {
6670
ast_map::node_item(@{
6771
node: ast::item_fn(decl, _, _), _
6872
}) {
69-
pprust::ty_to_str(decl.output)
73+
if decl.output.node != ast::ty_nil {
74+
some(pprust::ty_to_str(decl.output))
75+
} else {
76+
// Nil-typed return values are not interesting
77+
none
78+
}
7079
}
7180
}
7281
}
@@ -81,6 +90,15 @@ fn should_add_fn_ret_types() {
8190
assert option::get(doc.topmod.fns[0].return).ty == some("int");
8291
}
8392

93+
#[test]
94+
fn should_not_add_nil_ret_type() {
95+
let source = "fn a() { }";
96+
let srv = astsrv::mk_srv_from_str(source);
97+
let doc = extract::from_srv(srv, "");
98+
let doc = run(srv, doc);
99+
assert doc.topmod.fns[0].return == none;
100+
}
101+
84102
fn merge_arg_tys(
85103
srv: astsrv::srv,
86104
fn_id: doc::ast_id,

0 commit comments

Comments
 (0)