rustdoc: Don't prune reexports
This commit is contained in:
parent
9b009ea23d
commit
396540f19d
@ -27,6 +27,8 @@ type itemdoc = {
|
||||
path: [str],
|
||||
brief: option<str>,
|
||||
desc: option<str>,
|
||||
// Indicates that this node is a reexport of a different item
|
||||
reexport: bool
|
||||
};
|
||||
|
||||
type moddoc = {
|
||||
|
@ -40,6 +40,7 @@ fn mk_itemdoc(id: ast::node_id, name: ast::ident) -> doc::itemdoc {
|
||||
path: [],
|
||||
brief: none,
|
||||
desc: none,
|
||||
reexport: false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,8 @@ fn exported_items_from(
|
||||
}
|
||||
_ { itemtag }
|
||||
};
|
||||
if is_exported(srv, itemtag.name()) {
|
||||
|
||||
if itemtag.item().reexport || is_exported(srv, itemtag.name()) {
|
||||
some(itemtag)
|
||||
} else {
|
||||
none
|
||||
@ -226,6 +227,21 @@ fn should_prune_unexported_types() {
|
||||
assert vec::is_empty(doc.topmod.types());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_prune_reexports() {
|
||||
fn mk_doc(source: str) -> doc::cratedoc {
|
||||
astsrv::from_str(source) {|srv|
|
||||
let doc = extract::from_srv(srv, "");
|
||||
let doc = reexport_pass::mk_pass()(srv, doc);
|
||||
run(srv, doc)
|
||||
}
|
||||
}
|
||||
let doc = mk_doc("import a::b; \
|
||||
export b; \
|
||||
mod a { fn b() { } }");
|
||||
assert vec::is_not_empty(doc.topmod.fns());
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
fn mk_doc(source: str) -> doc::cratedoc {
|
||||
|
@ -212,70 +212,71 @@ fn merge_reexports(
|
||||
some(name_docs) {
|
||||
vec::foldl([], name_docs) {|v, name_doc|
|
||||
let (name, doc) = name_doc;
|
||||
v + [rename_doc(doc, name)]
|
||||
v + [reexport_doc(doc, name)]
|
||||
}
|
||||
}
|
||||
none { [] }
|
||||
}
|
||||
}
|
||||
|
||||
fn rename_doc(doc: doc::itemtag, name: str) -> doc::itemtag {
|
||||
fn reexport_doc(doc: doc::itemtag, name: str) -> doc::itemtag {
|
||||
alt doc {
|
||||
doc::modtag(doc @ {item, _}) {
|
||||
doc::modtag({
|
||||
item: rename(item, name)
|
||||
item: reexport(item, name)
|
||||
with doc
|
||||
})
|
||||
}
|
||||
doc::nmodtag(_) { fail }
|
||||
doc::consttag(doc @ {item, _}) {
|
||||
doc::consttag({
|
||||
item: rename(item, name)
|
||||
item: reexport(item, name)
|
||||
with doc
|
||||
})
|
||||
}
|
||||
doc::fntag(doc @ {item, _}) {
|
||||
doc::fntag({
|
||||
item: rename(item, name)
|
||||
item: reexport(item, name)
|
||||
with doc
|
||||
})
|
||||
}
|
||||
doc::enumtag(doc @ {item, _}) {
|
||||
doc::enumtag({
|
||||
item: rename(item, name)
|
||||
item: reexport(item, name)
|
||||
with doc
|
||||
})
|
||||
}
|
||||
doc::restag(doc @ {item, _}) {
|
||||
doc::restag({
|
||||
item: rename(item, name)
|
||||
item: reexport(item, name)
|
||||
with doc
|
||||
})
|
||||
}
|
||||
doc::ifacetag(doc @ {item, _}) {
|
||||
doc::ifacetag({
|
||||
item: rename(item, name)
|
||||
item: reexport(item, name)
|
||||
with doc
|
||||
})
|
||||
}
|
||||
doc::impltag(doc @ {item, _}) {
|
||||
doc::impltag({
|
||||
item: rename(item, name)
|
||||
item: reexport(item, name)
|
||||
with doc
|
||||
})
|
||||
}
|
||||
doc::tytag(doc @ {item, _}) {
|
||||
doc::tytag({
|
||||
item: rename(item, name)
|
||||
item: reexport(item, name)
|
||||
with doc
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rename(doc: doc::itemdoc, name: str) -> doc::itemdoc {
|
||||
fn reexport(doc: doc::itemdoc, name: str) -> doc::itemdoc {
|
||||
{
|
||||
name: name
|
||||
name: name,
|
||||
reexport: true
|
||||
with doc
|
||||
}
|
||||
}
|
||||
@ -289,6 +290,14 @@ fn should_duplicate_reexported_items() {
|
||||
assert doc.topmod.mods()[1].fns()[0].name() == "b";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_mark_reepxorts_as_such() {
|
||||
let source = "mod a { export b; fn b() { } } \
|
||||
mod c { import a::b; export b; }";
|
||||
let doc = test::mk_doc(source);
|
||||
assert doc.topmod.mods()[1].fns()[0].item.reexport == true;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_duplicate_multiple_reexported_items() {
|
||||
let source = "mod a { \
|
||||
|
@ -97,6 +97,7 @@ fn run(source_file: str) {
|
||||
astsrv::from_file(source_file) {|srv|
|
||||
let doc = extract::from_srv(srv, default_name);
|
||||
run_passes(srv, doc, [
|
||||
reexport_pass::mk_pass(),
|
||||
prune_unexported_pass::mk_pass(),
|
||||
tystr_pass::mk_pass(),
|
||||
path_pass::mk_pass(),
|
||||
@ -107,7 +108,6 @@ fn run(source_file: str) {
|
||||
desc_to_brief_pass::mk_pass(),
|
||||
trim_pass::mk_pass(),
|
||||
unindent_pass::mk_pass(),
|
||||
reexport_pass::mk_pass(),
|
||||
sort_item_name_pass::mk_pass(),
|
||||
sort_item_type_pass::mk_pass(),
|
||||
markdown_pass::mk_pass {|f| f(std::io:: stdout()) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user