about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2016-04-26 01:44:52 +0530
committerManish Goregaokar <manishsmail@gmail.com>2016-04-26 01:44:52 +0530
commitedbb0d5a9069e216cda56454f4e56028579b4264 (patch)
tree078e8f18afbff1ddb224239ab211e4eb5d35c9a5 /src/librustdoc/html
parentb50a2ff4d15324bebf6ce8a1661448195c213f5d (diff)
parent0b5b782e392f0e1d000a7e9fefaad9cbebc0e586 (diff)
downloadrust-edbb0d5a9069e216cda56454f4e56028579b4264.tar.gz
rust-edbb0d5a9069e216cda56454f4e56028579b4264.zip
Rollup merge of #33196 - mitaa:rdoc-crate-links, r=alexcrichton
rustdoc: Linkify extern crates

fixes #33178

r? @alexcrichton
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/format.rs33
-rw-r--r--src/librustdoc/html/render.rs7
2 files changed, 29 insertions, 11 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 26d82ccea5b..739da1b49d4 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -57,6 +57,11 @@ pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
 pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
 pub struct AbiSpace(pub Abi);
 
+pub struct HRef<'a> {
+    pub did: DefId,
+    pub text: &'a str,
+}
+
 impl<'a> VisSpace<'a> {
     pub fn get(self) -> &'a Option<clean::Visibility> {
         let VisSpace(v) = self; v
@@ -363,15 +368,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
             }
         }
     }
-
-    match href(did) {
-        Some((url, shortty, fqp)) => {
-            write!(w, "<a class='{}' href='{}' title='{}'>{}</a>",
-                   shortty, url, fqp.join("::"), last.name)?;
-        }
-        _ => write!(w, "{}", last.name)?,
-    }
-    write!(w, "{}", last.params)?;
+    write!(w, "{}{}", HRef::new(did, &last.name), last.params)?;
     Ok(())
 }
 
@@ -437,6 +434,24 @@ fn tybounds(w: &mut fmt::Formatter,
     }
 }
 
+impl<'a> HRef<'a> {
+    pub fn new(did: DefId, text: &'a str) -> HRef<'a> {
+        HRef { did: did, text: text }
+    }
+}
+
+impl<'a> fmt::Display for HRef<'a> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match href(self.did) {
+            Some((url, shortty, fqp)) => {
+                write!(f, "<a class='{}' href='{}' title='{}'>{}</a>",
+                       shortty, url, fqp.join("::"), self.text)
+            }
+            _ => write!(f, "{}", self.text),
+        }
+    }
+}
+
 impl fmt::Display for clean::Type {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 1cede9e6647..a8f1fe7d46f 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -1739,16 +1739,19 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
 
         match myitem.inner {
             clean::ExternCrateItem(ref name, ref src) => {
+                use html::format::HRef;
+
                 match *src {
                     Some(ref src) => {
                         write!(w, "<tr><td><code>{}extern crate {} as {};",
                                VisSpace(&myitem.visibility),
-                               src,
+                               HRef::new(myitem.def_id, src),
                                name)?
                     }
                     None => {
                         write!(w, "<tr><td><code>{}extern crate {};",
-                               VisSpace(&myitem.visibility), name)?
+                               VisSpace(&myitem.visibility),
+                               HRef::new(myitem.def_id, name))?
                     }
                 }
                 write!(w, "</code></td></tr>")?;