about summary refs log tree commit diff
path: root/src/rustdoc
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-01-18 21:50:35 -0800
committerBrian Anderson <banderson@mozilla.com>2012-01-18 21:50:35 -0800
commite9ddfbe3fd8a9606191ee3a5305bd50e8c9ae8ab (patch)
tree5701f876d0b48a51fff9c3d5005255cc0db1295f /src/rustdoc
parenta02a943cec35618b7fae32d9fd0f396566dc0635 (diff)
rustdoc: Ignore nil-typed return values
Diffstat (limited to 'src/rustdoc')
-rw-r--r--src/rustdoc/gen.rs35
-rw-r--r--src/rustdoc/tystr_pass.rs32
2 files changed, 46 insertions, 21 deletions
diff --git a/src/rustdoc/gen.rs b/src/rustdoc/gen.rs
index 2c3cb0ea903..26325e6ffbb 100644
--- a/src/rustdoc/gen.rs
+++ b/src/rustdoc/gen.rs
@@ -204,6 +204,27 @@ fn write_return(
     }
 }
 
+#[test]
+fn should_write_return_type_on_new_line() {
+    let markdown = test::render("fn a() -> int { }");
+    assert str::contains(markdown, "\nReturns `int`");
+}
+
+#[test]
+fn should_write_blank_line_between_return_type_and_next_header() {
+    let markdown = test::render(
+        "fn a() -> int { } \
+         fn b() -> int { }"
+    );
+    assert str::contains(markdown, "Returns `int`\n\n##");
+}
+
+#[test]
+fn should_not_write_return_type_when_there_is_none() {
+    let markdown = test::render("fn a() { }");
+    assert !str::contains(markdown, "Returns");
+}
+
 #[cfg(test)]
 mod test {
     fn render(source: str) -> str {
@@ -272,18 +293,4 @@ mod test {
         assert str::contains(markdown, "brief\n\ndesc");
     }
 
-    #[test]
-    fn should_write_return_type_on_new_line() {
-        let markdown = render("fn a() -> int { }");
-        assert str::contains(markdown, "\nReturns `int`");
-    }
-
-    #[test]
-    fn should_write_blank_line_between_return_type_and_next_header() {
-        let markdown = render(
-            "fn a() -> int { } \
-             fn b() -> int { }"
-        );
-        assert str::contains(markdown, "Returns `int`\n\n##");
-    }
 }
\ No newline at end of file
diff --git a/src/rustdoc/tystr_pass.rs b/src/rustdoc/tystr_pass.rs
index 7a1f5e1036e..cc0594d47fd 100644
--- a/src/rustdoc/tystr_pass.rs
+++ b/src/rustdoc/tystr_pass.rs
@@ -46,27 +46,36 @@ fn merge_ret_ty(
     fn_id: doc::ast_id,
     doc: option<doc::retdoc>
 ) -> option<doc::retdoc> {
-    let ty = get_ret_ty(srv, fn_id);
     alt doc {
       some(doc) {
         fail "unimplemented";
       }
       none. {
-        some({
-            desc: none,
-            ty: some(ty)
-        })
+        alt get_ret_ty(srv, fn_id) {
+          some(ty) {
+            some({
+                desc: none,
+                ty: some(ty)
+            })
+          }
+          none. { none }
+        }
       }
     }
 }
 
-fn get_ret_ty(srv: astsrv::srv, id: doc::ast_id) -> str {
+fn get_ret_ty(srv: astsrv::srv, id: doc::ast_id) -> option<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)
+            if decl.output.node != ast::ty_nil {
+                some(pprust::ty_to_str(decl.output))
+            } else {
+                // Nil-typed return values are not interesting
+                none
+            }
           }
         }
     }
@@ -81,6 +90,15 @@ fn should_add_fn_ret_types() {
     assert option::get(doc.topmod.fns[0].return).ty == some("int");
 }
 
+#[test]
+fn should_not_add_nil_ret_type() {
+    let source = "fn a() { }";
+    let srv = astsrv::mk_srv_from_str(source);
+    let doc = extract::from_srv(srv, "");
+    let doc = run(srv, doc);
+    assert doc.topmod.fns[0].return == none;
+}
+
 fn merge_arg_tys(
     srv: astsrv::srv,
     fn_id: doc::ast_id,