]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Correctly handle local renamings
authorAlex Crichton <alex@alexcrichton.com>
Fri, 25 Jul 2014 17:16:41 +0000 (10:16 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 25 Jul 2014 17:24:29 +0000 (10:24 -0700)
Previously a `pub use` would not rename the destination in rustdoc, it would
always use the destination ident instead of the renamed ident.

src/librustdoc/clean/inline.rs
src/librustdoc/clean/mod.rs
src/librustdoc/visit_ast.rs

index e058f219c47583b50261c44d13467fe72bc643a7..1e8964dd9db5eb5705acf8d5b5add947ca5732cf 100644 (file)
@@ -39,7 +39,8 @@
 ///
 /// 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,
index 5b59eed93216195dade50abc85b3a02cc1b20837..953b736f38b435375febc999fd4775ec1a5dadb8 100644 (file)
@@ -1763,7 +1763,7 @@ fn clean(&self) -> Vec<Item> {
                         // 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 @@ fn clean(&self) -> Vec<Item> {
                             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)),
                         }
index 594a235339669694357c7693e11a061dfa1cf6c7..d28069da6ba06e5acaf86e4f1a9e7d6e38d096f1 100644 (file)
@@ -192,13 +192,16 @@ fn visit_view_path(&mut self, path: Gc<ast::ViewPath>,
                        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 @@ fn visit_view_path(&mut self, path: Gc<ast::ViewPath>,
 
             // 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 @@ fn resolve_id(&mut self, id: ast::NodeId, glob: bool,
 
         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) => {