diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-02-23 18:06:26 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-02-23 18:06:43 -0800 |
| commit | 710258cc76a72cb68732179bc10a81adc44c66a6 (patch) | |
| tree | b7bd8f81ee5bebbe84b780171836ba3442c7d435 /src/rustdoc | |
| parent | d44ca0923a5545113c96a8953f880090f334872c (diff) | |
| download | rust-710258cc76a72cb68732179bc10a81adc44c66a6.tar.gz rust-710258cc76a72cb68732179bc10a81adc44c66a6.zip | |
rustdoc: Make reexports work in the crate module
Diffstat (limited to 'src/rustdoc')
| -rw-r--r-- | src/rustdoc/doc.rs | 3 | ||||
| -rw-r--r-- | src/rustdoc/reexport_pass.rs | 30 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/rustdoc/doc.rs b/src/rustdoc/doc.rs index e8095c54c6e..5c3b2eb5255 100644 --- a/src/rustdoc/doc.rs +++ b/src/rustdoc/doc.rs @@ -2,6 +2,9 @@ type ast_id = int; +// FIXME: We currently give topmod the name of the crate. There would +// probably be fewer special cases if the crate had its own name and +// topmod's name was the empty string. type cratedoc = { topmod: moddoc, }; diff --git a/src/rustdoc/reexport_pass.rs b/src/rustdoc/reexport_pass.rs index 544d8b4c919..0e9c251991b 100644 --- a/src/rustdoc/reexport_pass.rs +++ b/src/rustdoc/reexport_pass.rs @@ -188,7 +188,16 @@ fn merge_reexports( fn fold_mod(fold: fold::fold<path_map>, doc: doc::moddoc) -> doc::moddoc { let doc = fold::default_seq_fold_mod(fold, doc); - let path = doc.path() + [doc.name()]; + let is_topmod = doc.id() == rustc::syntax::ast::crate_node_id; + + // In the case of the top mod, it really doesn't have a name; + // the name we have here is actually the crate name + let path = if is_topmod { + doc.path() + } else { + doc.path() + [doc.name()] + }; + let new_items = get_new_items(path, fold.ctxt); #debug("merging into %?: %?", path, new_items); @@ -309,6 +318,25 @@ fn should_rename_items_reexported_with_different_names() { assert doc.topmod.mods()[1].fns()[0].name() == "x"; } +#[test] +fn should_reexport_in_topmod() { + fn mk_doc(source: str) -> doc::cratedoc { + astsrv::from_str(source) {|srv| + let doc = extract::from_srv(srv, "core"); + let doc = path_pass::mk_pass()(srv, doc); + run(srv, doc) + } + } + let source = "import option::{some, none}; \ + import option = option::t; \ + export option, some, none; \ + mod option { \ + enum t { some, none } \ + }"; + let doc = mk_doc(source); + assert doc.topmod.enums()[0].name() == "option"; +} + #[cfg(test)] mod test { fn mk_doc(source: str) -> doc::cratedoc { |
