Skip to content

Commit b4dcdee

Browse files
authored
Rollup merge of rust-lang#43979 - Jouan:Add-links-for-impls, r=GuillaumeGomez
Add links for impls Implements a solution for issue rust-lang#23552 r? @QuietMisdreavus
2 parents e9a6dcc + 4729f22 commit b4dcdee

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/librustdoc/html/render.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2956,7 +2956,13 @@ fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl,
29562956
fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLink,
29572957
render_mode: RenderMode, outer_version: Option<&str>) -> fmt::Result {
29582958
if render_mode == RenderMode::Normal {
2959-
write!(w, "<h3 class='impl'><span class='in-band'><code>{}</code>", i.inner_impl())?;
2959+
let id = derive_id(match i.inner_impl().trait_ {
2960+
Some(ref t) => format!("impl-{}", Escape(&format!("{:#}", t))),
2961+
None => "impl".to_string(),
2962+
});
2963+
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><code>{}</code>",
2964+
id, i.inner_impl())?;
2965+
write!(w, "<a href='#{}' class='anchor'></a>", id)?;
29602966
write!(w, "</span><span class='out-of-band'>")?;
29612967
let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]);
29622968
if let Some(l) = (Item { item: &i.impl_item, cx: cx }).src_href() {

src/librustdoc/html/static/rustdoc.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ a {
445445
.small-section-header:hover > .anchor {
446446
display: initial;
447447
}
448+
449+
.in-band:hover > .anchor {
450+
display: initial;
451+
}
448452
.anchor {
449453
display: none;
450454
}

src/librustdoc/html/static/styles/main.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ h1.fqn {
2626
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {
2727
border-bottom-color: #DDDDDD;
2828
}
29+
2930
.in-band {
3031
background-color: white;
3132
}
@@ -83,6 +84,11 @@ pre {
8384
}
8485

8586
:target { background: #FDFFD3; }
87+
88+
:target > .in-band {
89+
background: #FDFFD3;
90+
}
91+
8692
.content .highlighted {
8793
color: #000 !important;
8894
background-color: #ccc;

0 commit comments

Comments
 (0)