Skip to content

Commit e39e347

Browse files
committed
rustdoc: Assign AST ids to mod docs
1 parent 5bbf72e commit e39e347

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/rustdoc/doc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type cratedoc = ~{
77
};
88

99
type moddoc = ~{
10+
id: ast_id,
1011
name: str,
1112
brief: option<str>,
1213
desc: option<str>,

src/rustdoc/extract.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,24 @@ fn top_moddoc_from_crate(
2929
crate: @ast::crate,
3030
default_name: str
3131
) -> doc::moddoc {
32-
moddoc_from_mod(crate.node.module, default_name)
32+
moddoc_from_mod(crate.node.module, default_name, ast::crate_node_id)
3333
}
3434

3535
fn moddoc_from_mod(
3636
module: ast::_mod,
37-
name: ast::ident
37+
name: ast::ident,
38+
id: ast::node_id
3839
) -> doc::moddoc {
3940
~{
41+
id: id,
4042
name: name,
4143
brief: none,
4244
desc: none,
4345
mods: doc::modlist(
4446
vec::filter_map(module.items) {|item|
4547
alt item.node {
4648
ast::item_mod(m) {
47-
some(moddoc_from_mod(m, item.ident))
49+
some(moddoc_from_mod(m, item.ident, item.id))
4850
}
4951
_ {
5052
none
@@ -133,6 +135,14 @@ mod tests {
133135
assert doc.topmod.mods[0].mods[0].mods[0].name == "c";
134136
}
135137

138+
#[test]
139+
fn extract_should_set_mod_ast_id() {
140+
let source = "mod a { }";
141+
let ast = parse::from_str(source);
142+
let doc = extract(ast, "");
143+
assert doc.topmod.mods[0].id != 0;
144+
}
145+
136146
#[test]
137147
fn extract_fns() {
138148
let source =

src/rustdoc/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn new_parse_sess() -> parser::parse_sess {
1111
let cm = codemap::new_codemap();
1212
let sess = @{
1313
cm: cm,
14-
mutable next_id: 0,
14+
mutable next_id: 1,
1515
diagnostic: diagnostic::mk_handler(cm, none)
1616
};
1717
ret sess;

src/rustdoc/rustdoc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fn test_run_passes() {
2626
) -> doc::cratedoc {
2727
~{
2828
topmod: ~{
29+
id: 0,
2930
name: doc.topmod.name + "two",
3031
brief: none,
3132
desc: none,
@@ -40,6 +41,7 @@ fn test_run_passes() {
4041
) -> doc::cratedoc {
4142
~{
4243
topmod: ~{
44+
id: 0,
4345
name: doc.topmod.name + "three",
4446
brief: none,
4547
desc: none,

0 commit comments

Comments
 (0)