diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-07-25 10:16:41 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-25 10:24:29 -0700 |
| commit | 8d7eb0598a9147f0ec92b1f333360e5e912ab546 (patch) | |
| tree | 00fac9cb2312d584689a6f99afab29692c6278cf | |
| parent | 431622e1e202467e0ba61cdf2df7ceb501926547 (diff) | |
rustdoc: Correctly handle local renamings
Previously a `pub use` would not rename the destination in rustdoc, it would always use the destination ident instead of the renamed ident.
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 15 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 6 | ||||
| -rw-r--r-- | src/librustdoc/visit_ast.rs | 26 |
3 files changed, 36 insertions, 11 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index e058f219c47..1e8964dd9db 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -39,7 +39,8 @@ use super::Clean; /// /// The returned value is `None` if the `id` could not be inlined, and `Some` /// of a vector of items if it was successfully expanded. -pub fn try_inline(id: ast::NodeId) -> Option<Vec<clean::Item>> { +pub fn try_inline(id: ast::NodeId, into: Option<ast::Ident>) + -> Option<Vec<clean::Item>> { let cx = ::ctxtkey.get().unwrap(); let tcx = match cx.maybe_typed { core::Typed(ref tycx) => tycx, @@ -51,7 +52,17 @@ pub fn try_inline(id: ast::NodeId) -> Option<Vec<clean::Item>> { }; let did = def.def_id(); if ast_util::is_local(did) { return None } - try_inline_def(&**cx, tcx, def) + try_inline_def(&**cx, tcx, def).map(|vec| { + vec.move_iter().map(|mut item| { + match into { + Some(into) if item.name.is_some() => { + item.name = Some(into.clean()); + } + _ => {} + } + item + }).collect() + }) } fn try_inline_def(cx: &core::DocContext, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5b59eed9321..953b736f38b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1763,7 +1763,7 @@ impl Clean<Vec<Item>> for ast::ViewItem { // to keep any non-inlineable reexports so they can be // listed in the documentation. let remaining = list.iter().filter(|path| { - match inline::try_inline(path.node.id()) { + match inline::try_inline(path.node.id(), None) { Some(items) => { ret.extend(items.move_iter()); false } @@ -1778,8 +1778,8 @@ impl Clean<Vec<Item>> for ast::ViewItem { ret.push(convert(&ast::ViewItemUse(box(GC) path))); } } - ast::ViewPathSimple(_, _, id) => { - match inline::try_inline(id) { + ast::ViewPathSimple(ident, _, id) => { + match inline::try_inline(id, Some(ident)) { Some(items) => ret.extend(items.move_iter()), None => ret.push(convert(&self.node)), } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 594a2353396..d28069da6ba 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -192,13 +192,16 @@ impl<'a> RustdocVisitor<'a> { om: &mut Module, please_inline: bool) -> Option<Gc<ast::ViewPath>> { match path.node { - ast::ViewPathSimple(_, _, id) => { - if self.resolve_id(id, false, om, please_inline) { return None } + ast::ViewPathSimple(dst, _, id) => { + if self.resolve_id(id, Some(dst), false, om, please_inline) { + return None + } } ast::ViewPathList(ref p, ref paths, ref b) => { let mut mine = Vec::new(); for path in paths.iter() { - if !self.resolve_id(path.node.id(), false, om, please_inline) { + if !self.resolve_id(path.node.id(), None, false, om, + please_inline) { mine.push(path.clone()); } } @@ -212,14 +215,16 @@ impl<'a> RustdocVisitor<'a> { // these are feature gated anyway ast::ViewPathGlob(_, id) => { - if self.resolve_id(id, true, om, please_inline) { return None } + if self.resolve_id(id, None, true, om, please_inline) { + return None + } } } return Some(path); } - fn resolve_id(&mut self, id: ast::NodeId, glob: bool, - om: &mut Module, please_inline: bool) -> bool { + fn resolve_id(&mut self, id: ast::NodeId, renamed: Option<ast::Ident>, + glob: bool, om: &mut Module, please_inline: bool) -> bool { let tcx = match self.cx.maybe_typed { core::Typed(ref tcx) => tcx, core::NotTyped(_) => return false @@ -235,6 +240,15 @@ impl<'a> RustdocVisitor<'a> { match tcx.map.get(def.node) { ast_map::NodeItem(it) => { + let it = match renamed { + Some(ident) => { + box(GC) ast::Item { + ident: ident, + ..(*it).clone() + } + } + None => it, + }; if glob { match it.node { ast::ItemMod(ref m) => { |
