Skip to content

Commit 1601005

Browse files
committed
rustdoc: Add types for native functions
1 parent 2576a3c commit 1601005

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/rustdoc/tystr_pass.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ fn get_fn_sig(srv: astsrv::srv, fn_id: doc::ast_id) -> option<str> {
4848
alt check ctxt.ast_map.get(fn_id) {
4949
ast_map::node_item(@{
5050
ident: ident,
51-
node: ast::item_fn(decl, _, blk), _
51+
node: ast::item_fn(decl, _, _), _
52+
}, _) |
53+
ast_map::node_native_item(@{
54+
ident: ident,
55+
node: ast::native_item_fn(decl, _), _
5256
}, _) {
5357
some(pprust::fun_to_str(decl, ident, []))
5458
}
@@ -62,6 +66,12 @@ fn should_add_fn_sig() {
6266
assert doc.topmod.fns()[0].sig == some("fn a() -> int");
6367
}
6468

69+
#[test]
70+
fn should_add_native_fn_sig() {
71+
let doc = test::mk_doc("native mod a { fn a() -> int; }");
72+
assert doc.topmod.nmods()[0].fns[0].sig == some("fn a() -> int");
73+
}
74+
6575
fn merge_ret_ty(
6676
srv: astsrv::srv,
6777
fn_id: doc::ast_id,
@@ -83,6 +93,9 @@ fn get_ret_ty(srv: astsrv::srv, fn_id: doc::ast_id) -> option<str> {
8393
alt check ctxt.ast_map.get(fn_id) {
8494
ast_map::node_item(@{
8595
node: ast::item_fn(decl, _, _), _
96+
}, _) |
97+
ast_map::node_native_item(@{
98+
node: ast::native_item_fn(decl, _), _
8699
}, _) {
87100
ret_ty_to_str(decl)
88101
}
@@ -111,6 +124,12 @@ fn should_not_add_nil_ret_type() {
111124
assert doc.topmod.fns()[0].return.ty == none;
112125
}
113126

127+
#[test]
128+
fn should_add_native_fn_ret_types() {
129+
let doc = test::mk_doc("native mod a { fn a() -> int; }");
130+
assert doc.topmod.nmods()[0].fns[0].return.ty == some("int");
131+
}
132+
114133
fn merge_arg_tys(
115134
srv: astsrv::srv,
116135
fn_id: doc::ast_id,
@@ -135,6 +154,9 @@ fn get_arg_tys(srv: astsrv::srv, fn_id: doc::ast_id) -> [(str, str)] {
135154
}, _) |
136155
ast_map::node_item(@{
137156
node: ast::item_res(decl, _, _, _, _), _
157+
}, _) |
158+
ast_map::node_native_item(@{
159+
node: ast::native_item_fn(decl, _), _
138160
}, _) {
139161
decl_arg_tys(decl)
140162
}
@@ -156,6 +178,12 @@ fn should_add_arg_types() {
156178
assert fn_.args[1].ty == some("bool");
157179
}
158180

181+
#[test]
182+
fn should_add_native_fn_arg_types() {
183+
let doc = test::mk_doc("native mod a { fn a(b: int); }");
184+
assert doc.topmod.nmods()[0].fns[0].args[0].ty == some("int");
185+
}
186+
159187
fn fold_const(
160188
fold: fold::fold<astsrv::srv>,
161189
doc: doc::constdoc

0 commit comments

Comments
 (0)