Skip to content

Commit 4122b6b

Browse files
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)
2 parents e61e73f + c9bdd51 commit 4122b6b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/librustdoc/html/render.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2962,7 +2962,15 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
29622962
write!(w, "<code>")?;
29632963
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl)?;
29642964
write!(w, "</code>")?;
2965-
render_stability_since_raw(w, item.stable_since(), outer_version)?;
2965+
if let Some(l) = (Item { cx, item }).src_href() {
2966+
write!(w, "</span><span class='out-of-band'>")?;
2967+
write!(w, "<div class='ghost'></div>")?;
2968+
render_stability_since_raw(w, item.stable_since(), outer_version)?;
2969+
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
2970+
l, "goto source code")?;
2971+
} else {
2972+
render_stability_since_raw(w, item.stable_since(), outer_version)?;
2973+
}
29662974
write!(w, "</span></h4>\n")?;
29672975
}
29682976
}

src/librustdoc/html/static/rustdoc.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ h3.impl > .out-of-band {
297297
font-size: 21px;
298298
}
299299

300+
h4.method > .out-of-band {
301+
font-size: 19px;
302+
}
303+
300304
h4 > code, h3 > code, .invisible > code {
301305
position: inherit;
302306
}

0 commit comments

Comments
 (0)