Skip to content

Commit affd83e

Browse files
committed
rustdoc: Find the path to all item types
1 parent f8f28e2 commit affd83e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/rustdoc/path_pass.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,29 @@ fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc {
1515
mutable path: []
1616
};
1717
let fold = fold::fold({
18-
fold_mod: fn~(
19-
f: fold::fold<ctxt>,
20-
d: doc::moddoc
21-
) -> doc::moddoc {
22-
fold_mod(f, d)
23-
}
18+
fold_item: fold_item,
19+
fold_mod: fold_mod
2420
with *fold::default_seq_fold(ctxt)
2521
});
2622
fold.fold_crate(fold, doc)
2723
}
2824

25+
fn fold_item(fold: fold::fold<ctxt>, doc: doc::itemdoc) -> doc::itemdoc {
26+
{
27+
path: fold.ctxt.path
28+
with doc
29+
}
30+
}
31+
2932
fn fold_mod(fold: fold::fold<ctxt>, doc: doc::moddoc) -> doc::moddoc {
3033
let is_topmod = doc.id() == rustc::syntax::ast::crate_node_id;
3134

3235
if !is_topmod { vec::push(fold.ctxt.path, doc.name()); }
3336
let doc = fold::default_seq_fold_mod(fold, doc);
3437
if !is_topmod { vec::pop(fold.ctxt.path); }
38+
3539
{
36-
item: {
37-
path: fold.ctxt.path
38-
with doc.item
39-
}
40+
item: fold.fold_item(fold, doc.item)
4041
with doc
4142
}
4243
}
@@ -47,6 +48,16 @@ fn should_record_mod_paths() {
4748
let srv = astsrv::mk_srv_from_str(source);
4849
let doc = extract::from_srv(srv, "");
4950
let doc = run(srv, doc);
51+
log(error, doc.topmod.mods()[0].mods()[0].mods()[0].path());
5052
assert doc.topmod.mods()[0].mods()[0].mods()[0].path() == ["a", "b"];
5153
assert doc.topmod.mods()[0].mods()[1].mods()[0].path() == ["a", "d"];
54+
}
55+
56+
#[test]
57+
fn should_record_fn_paths() {
58+
let source = "mod a { fn b() { } }";
59+
let srv = astsrv::mk_srv_from_str(source);
60+
let doc = extract::from_srv(srv, "");
61+
let doc = run(srv, doc);
62+
assert doc.topmod.mods()[0].fns()[0].path() == ["a"];
5263
}

0 commit comments

Comments
 (0)