about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Simulacrum <mark.simulacrum@gmail.com>2017-07-29 18:03:53 -0600
committerGitHub <noreply@github.com>2017-07-29 18:03:53 -0600
commit4122b6bd5bca5fecacd75d184d12153e8e4fc8a6 (patch)
treefa4fd4c7e63313fe796cfc3ccac52d8aa4b9e694
parente61e73fcc41a09d1d955169fa7ea5b0be65c1fcb (diff)
parentc9bdd518eb64c0072dae0df01ce67fedf728adb4 (diff)
downloadrust-4122b6bd5bca5fecacd75d184d12153e8e4fc8a6.tar.gz
rust-4122b6bd5bca5fecacd75d184d12153e8e4fc8a6.zip
Rollup merge of #43509 - QuietMisdreavus:method-src, r=GuillaumeGomez
rustdoc: add [src] links to associated functions inside an impl block

While impl blocks currently have a `[src]` link to show the source for the impl block as a whole, individual methods inside that impl block do not. This can pose a problem for structs with a lot of methods, like many in libstd. This change adds little `[src]` links to individual methods that point directly to the function in the bundled source.

fixes #12932

![methods on HashMap, showing the new src links](https://user-images.githubusercontent.com/5217170/28686066-9e7a19de-72cf-11e7-8e6b-b7d60fa33032.png)
-rw-r--r--src/librustdoc/html/render.rs10
-rw-r--r--src/librustdoc/html/static/rustdoc.css4
2 files changed, 13 insertions, 1 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index e89bd7aae9b..bf524705dc7 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -2962,7 +2962,15 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
                     write!(w, "<code>")?;
                     render_assoc_item(w, item, link.anchor(&id), ItemType::Impl)?;
                     write!(w, "</code>")?;
-                    render_stability_since_raw(w, item.stable_since(), outer_version)?;
+                    if let Some(l) = (Item { cx, item }).src_href() {
+                        write!(w, "</span><span class='out-of-band'>")?;
+                        write!(w, "<div class='ghost'></div>")?;
+                        render_stability_since_raw(w, item.stable_since(), outer_version)?;
+                        write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
+                               l, "goto source code")?;
+                    } else {
+                        render_stability_since_raw(w, item.stable_since(), outer_version)?;
+                    }
                     write!(w, "</span></h4>\n")?;
                 }
             }
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index 9314f57359a..858ef3bf411 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -297,6 +297,10 @@ h3.impl > .out-of-band {
 	font-size: 21px;
 }
 
+h4.method > .out-of-band {
+	font-size: 19px;
+}
+
 h4 > code, h3 > code, .invisible > code {
 	position: inherit;
 }