Skip to content

Commit

Permalink
rustdoc: Correctly handle local renamings
Browse files Browse the repository at this point in the history
Previously a `pub use` would not rename the destination in rustdoc, it would
always use the destination ident instead of the renamed ident.
  • Loading branch information
alexcrichton committed Jul 25, 2014
1 parent 431622e commit 8d7eb05
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
15 changes: 13 additions & 2 deletions src/librustdoc/clean/inline.rs
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -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
}
Expand All @@ -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)),
}
Expand Down
26 changes: 20 additions & 6 deletions src/librustdoc/visit_ast.rs
Expand Up @@ -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());
}
}
Expand All @@ -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
Expand All @@ -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) => {
Expand Down

0 comments on commit 8d7eb05

Please sign in to comment.