Skip to content

Commit ab86bad

Browse files
committed
rustdoc: Build const docs from AST consts
1 parent 6ee7ff5 commit ab86bad

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/rustdoc/extract.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ fn moddoc_from_mod(
6666
}
6767
}
6868
}),
69-
consts: doc::constlist([])
69+
consts: doc::constlist(
70+
vec::filter_map(module.items) {|item|
71+
alt item.node {
72+
ast::item_const(_, _) {
73+
some(constdoc_from_const(item.ident, item.id))
74+
}
75+
_ {
76+
none
77+
}
78+
}
79+
})
7080
}
7181
}
7282

@@ -111,6 +121,26 @@ fn argdoc_from_arg(arg: ast::arg) -> doc::argdoc {
111121
}
112122
}
113123

124+
fn constdoc_from_const(
125+
name: ast::ident,
126+
id: ast::node_id
127+
) -> doc::constdoc {
128+
~{
129+
id: id,
130+
name: name,
131+
ty: none
132+
}
133+
}
134+
135+
#[test]
136+
fn should_extract_const_name_and_id() {
137+
let source = "const a: int = 0;";
138+
let ast = parse::from_str(source);
139+
let doc = extract(ast, "");
140+
assert doc.topmod.consts[0].id != 0;
141+
assert doc.topmod.consts[0].name == "a";
142+
}
143+
114144
#[cfg(test)]
115145
mod tests {
116146

0 commit comments

Comments
 (0)