Skip to content

Commit 4c4ac05

Browse files
committed
rustdoc: Print type params in fn sigs. Closes #2021
1 parent 7dcac31 commit 4c4ac05

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/rustdoc/tystr_pass.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,28 @@ fn get_fn_sig(srv: astsrv::srv, fn_id: doc::ast_id) -> option<str> {
5050
alt check ctxt.ast_map.get(fn_id) {
5151
ast_map::node_item(@{
5252
ident: ident,
53-
node: ast::item_fn(decl, _, _), _
53+
node: ast::item_fn(decl, tys, _), _
5454
}, _) |
5555
ast_map::node_native_item(@{
5656
ident: ident,
57-
node: ast::native_item_fn(decl, _), _
57+
node: ast::native_item_fn(decl, tys), _
5858
}, _, _) {
59-
some(pprust::fun_to_str(decl, ident, []))
59+
some(pprust::fun_to_str(decl, ident, tys))
6060
}
6161
}
6262
}
6363
}
6464

6565
#[test]
6666
fn should_add_fn_sig() {
67-
let doc = test::mk_doc("fn a() -> int { }");
68-
assert doc.cratemod().fns()[0].sig == some("fn a() -> int");
67+
let doc = test::mk_doc("fn a<T>() -> int { }");
68+
assert doc.cratemod().fns()[0].sig == some("fn a<T>() -> int");
6969
}
7070

7171
#[test]
7272
fn should_add_native_fn_sig() {
73-
let doc = test::mk_doc("native mod a { fn a() -> int; }");
74-
assert doc.cratemod().nmods()[0].fns[0].sig == some("fn a() -> int");
73+
let doc = test::mk_doc("native mod a { fn a<T>() -> int; }");
74+
assert doc.cratemod().nmods()[0].fns[0].sig == some("fn a<T>() -> int");
7575
}
7676

7777
fn fold_const(
@@ -149,9 +149,9 @@ fn fold_res(
149149
sig: some(astsrv::exec(srv) {|ctxt|
150150
alt check ctxt.ast_map.get(doc.id()) {
151151
ast_map::node_item(@{
152-
node: ast::item_res(decl, _, _, _, _), _
152+
node: ast::item_res(decl, tys, _, _, _), _
153153
}, _) {
154-
pprust::res_to_str(decl, doc.name(), [])
154+
pprust::res_to_str(decl, doc.name(), tys)
155155
}
156156
}
157157
})
@@ -161,8 +161,9 @@ fn fold_res(
161161

162162
#[test]
163163
fn should_add_resource_sigs() {
164-
let doc = test::mk_doc("resource r(b: bool) { }");
165-
assert doc.cratemod().resources()[0].sig == some("resource r(b: bool)");
164+
let doc = test::mk_doc("resource r<T>(b: bool) { }");
165+
assert doc.cratemod().resources()[0].sig
166+
== some("resource r<T>(b: bool)");
166167
}
167168

168169
fn fold_iface(
@@ -202,7 +203,11 @@ fn get_method_sig(
202203
method.ident == method_name
203204
} {
204205
some(method) {
205-
some(pprust::fun_to_str(method.decl, method.ident, []))
206+
some(pprust::fun_to_str(
207+
method.decl,
208+
method.ident,
209+
method.tps
210+
))
206211
}
207212
}
208213
}
@@ -213,7 +218,11 @@ fn get_method_sig(
213218
method.ident == method_name
214219
} {
215220
some(method) {
216-
some(pprust::fun_to_str(method.decl, method.ident, []))
221+
some(pprust::fun_to_str(
222+
method.decl,
223+
method.ident,
224+
method.tps
225+
))
217226
}
218227
}
219228
}
@@ -223,8 +232,9 @@ fn get_method_sig(
223232

224233
#[test]
225234
fn should_add_iface_method_sigs() {
226-
let doc = test::mk_doc("iface i { fn a() -> int; }");
227-
assert doc.cratemod().ifaces()[0].methods[0].sig == some("fn a() -> int");
235+
let doc = test::mk_doc("iface i { fn a<T>() -> int; }");
236+
assert doc.cratemod().ifaces()[0].methods[0].sig
237+
== some("fn a<T>() -> int");
228238
}
229239

230240
fn fold_impl(
@@ -258,7 +268,7 @@ fn fold_impl(
258268

259269
#[test]
260270
fn should_add_impl_iface_ty() {
261-
let doc = test::mk_doc("impl i of j for int { fn a() { } }");
271+
let doc = test::mk_doc("impl i of j for int { fn a<T>() { } }");
262272
assert doc.cratemod().impls()[0].iface_ty == some("j");
263273
}
264274

@@ -276,8 +286,9 @@ fn should_add_impl_self_ty() {
276286

277287
#[test]
278288
fn should_add_impl_method_sigs() {
279-
let doc = test::mk_doc("impl i for int { fn a() -> int { fail } }");
280-
assert doc.cratemod().impls()[0].methods[0].sig == some("fn a() -> int");
289+
let doc = test::mk_doc("impl i for int { fn a<T>() -> int { fail } }");
290+
assert doc.cratemod().impls()[0].methods[0].sig
291+
== some("fn a<T>() -> int");
281292
}
282293

283294
fn fold_type(

0 commit comments

Comments
 (0)