Skip to content

Commit 8d7eb05

Browse files
committed
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.
1 parent 431622e commit 8d7eb05

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ use super::Clean;
3939
///
4040
/// The returned value is `None` if the `id` could not be inlined, and `Some`
4141
/// of a vector of items if it was successfully expanded.
42-
pub fn try_inline(id: ast::NodeId) -> Option<Vec<clean::Item>> {
42+
pub fn try_inline(id: ast::NodeId, into: Option<ast::Ident>)
43+
-> Option<Vec<clean::Item>> {
4344
let cx = ::ctxtkey.get().unwrap();
4445
let tcx = match cx.maybe_typed {
4546
core::Typed(ref tycx) => tycx,
@@ -51,7 +52,17 @@ pub fn try_inline(id: ast::NodeId) -> Option<Vec<clean::Item>> {
5152
};
5253
let did = def.def_id();
5354
if ast_util::is_local(did) { return None }
54-
try_inline_def(&**cx, tcx, def)
55+
try_inline_def(&**cx, tcx, def).map(|vec| {
56+
vec.move_iter().map(|mut item| {
57+
match into {
58+
Some(into) if item.name.is_some() => {
59+
item.name = Some(into.clean());
60+
}
61+
_ => {}
62+
}
63+
item
64+
}).collect()
65+
})
5566
}
5667

5768
fn try_inline_def(cx: &core::DocContext,

src/librustdoc/clean/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ impl Clean<Vec<Item>> for ast::ViewItem {
17631763
// to keep any non-inlineable reexports so they can be
17641764
// listed in the documentation.
17651765
let remaining = list.iter().filter(|path| {
1766-
match inline::try_inline(path.node.id()) {
1766+
match inline::try_inline(path.node.id(), None) {
17671767
Some(items) => {
17681768
ret.extend(items.move_iter()); false
17691769
}
@@ -1778,8 +1778,8 @@ impl Clean<Vec<Item>> for ast::ViewItem {
17781778
ret.push(convert(&ast::ViewItemUse(box(GC) path)));
17791779
}
17801780
}
1781-
ast::ViewPathSimple(_, _, id) => {
1782-
match inline::try_inline(id) {
1781+
ast::ViewPathSimple(ident, _, id) => {
1782+
match inline::try_inline(id, Some(ident)) {
17831783
Some(items) => ret.extend(items.move_iter()),
17841784
None => ret.push(convert(&self.node)),
17851785
}

src/librustdoc/visit_ast.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,16 @@ impl<'a> RustdocVisitor<'a> {
192192
om: &mut Module,
193193
please_inline: bool) -> Option<Gc<ast::ViewPath>> {
194194
match path.node {
195-
ast::ViewPathSimple(_, _, id) => {
196-
if self.resolve_id(id, false, om, please_inline) { return None }
195+
ast::ViewPathSimple(dst, _, id) => {
196+
if self.resolve_id(id, Some(dst), false, om, please_inline) {
197+
return None
198+
}
197199
}
198200
ast::ViewPathList(ref p, ref paths, ref b) => {
199201
let mut mine = Vec::new();
200202
for path in paths.iter() {
201-
if !self.resolve_id(path.node.id(), false, om, please_inline) {
203+
if !self.resolve_id(path.node.id(), None, false, om,
204+
please_inline) {
202205
mine.push(path.clone());
203206
}
204207
}
@@ -212,14 +215,16 @@ impl<'a> RustdocVisitor<'a> {
212215

213216
// these are feature gated anyway
214217
ast::ViewPathGlob(_, id) => {
215-
if self.resolve_id(id, true, om, please_inline) { return None }
218+
if self.resolve_id(id, None, true, om, please_inline) {
219+
return None
220+
}
216221
}
217222
}
218223
return Some(path);
219224
}
220225

221-
fn resolve_id(&mut self, id: ast::NodeId, glob: bool,
222-
om: &mut Module, please_inline: bool) -> bool {
226+
fn resolve_id(&mut self, id: ast::NodeId, renamed: Option<ast::Ident>,
227+
glob: bool, om: &mut Module, please_inline: bool) -> bool {
223228
let tcx = match self.cx.maybe_typed {
224229
core::Typed(ref tcx) => tcx,
225230
core::NotTyped(_) => return false
@@ -235,6 +240,15 @@ impl<'a> RustdocVisitor<'a> {
235240

236241
match tcx.map.get(def.node) {
237242
ast_map::NodeItem(it) => {
243+
let it = match renamed {
244+
Some(ident) => {
245+
box(GC) ast::Item {
246+
ident: ident,
247+
..(*it).clone()
248+
}
249+
}
250+
None => it,
251+
};
238252
if glob {
239253
match it.node {
240254
ast::ItemMod(ref m) => {

0 commit comments

Comments
 (0)