Skip to content

Commit 4596436

Browse files
committed
add anchors links on hover to items from trait impl
1 parent e1b6bb2 commit 4596436

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/librustdoc/html/render/mod.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -1453,12 +1453,13 @@ fn render_impl(
14531453
} else {
14541454
(true, " hidden")
14551455
};
1456+
let in_trait_class = if trait_.is_some() { " trait-impl" } else { "" };
14561457
match *item.kind {
14571458
clean::MethodItem(..) | clean::TyMethodItem(_) => {
14581459
// Only render when the method is not static or we allow static methods
14591460
if render_method_item {
14601461
let id = cx.derive_id(format!("{}.{}", item_type, name));
1461-
write!(w, "<h4 id=\"{}\" class=\"{}{}\">", id, item_type, extra_class);
1462+
write!(w, "<h4 id=\"{}\" class=\"{}{}{}\">", id, item_type, extra_class, in_trait_class);
14621463
w.write_str("<code>");
14631464
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl, cx);
14641465
w.write_str("</code>");
@@ -1469,13 +1470,14 @@ fn render_impl(
14691470
outer_version,
14701471
outer_const_version,
14711472
);
1473+
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
14721474
write_srclink(cx, item, w);
14731475
w.write_str("</h4>");
14741476
}
14751477
}
14761478
clean::TypedefItem(ref tydef, _) => {
14771479
let id = cx.derive_id(format!("{}.{}", ItemType::AssocType, name));
1478-
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, extra_class);
1480+
write!(w, "<h4 id=\"{}\" class=\"{}{}{}\"><code>", id, item_type, extra_class, in_trait_class);
14791481
assoc_type(
14801482
w,
14811483
item,
@@ -1486,11 +1488,13 @@ fn render_impl(
14861488
cx.cache(),
14871489
tcx,
14881490
);
1489-
w.write_str("</code></h4>");
1491+
w.write_str("</code>");
1492+
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1493+
w.write_str("</h4>");
14901494
}
14911495
clean::AssocConstItem(ref ty, ref default) => {
14921496
let id = cx.derive_id(format!("{}.{}", item_type, name));
1493-
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, extra_class);
1497+
write!(w, "<h4 id=\"{}\" class=\"{}{}{}\"><code>", id, item_type, extra_class, in_trait_class);
14941498
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), "", cx);
14951499
w.write_str("</code>");
14961500
render_stability_since_raw(
@@ -1500,12 +1504,13 @@ fn render_impl(
15001504
outer_version,
15011505
outer_const_version,
15021506
);
1507+
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
15031508
write_srclink(cx, item, w);
15041509
w.write_str("</h4>");
15051510
}
15061511
clean::AssocTypeItem(ref bounds, ref default) => {
15071512
let id = cx.derive_id(format!("{}.{}", item_type, name));
1508-
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, extra_class);
1513+
write!(w, "<h4 id=\"{}\" class=\"{}{}{}\"><code>", id, item_type, extra_class, in_trait_class);
15091514
assoc_type(
15101515
w,
15111516
item,
@@ -1516,7 +1521,9 @@ fn render_impl(
15161521
cx.cache(),
15171522
tcx,
15181523
);
1519-
w.write_str("</code></h4>");
1524+
w.write_str("</code>");
1525+
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1526+
w.write_str("</h4>");
15201527
}
15211528
clean::StrippedItem(..) => return,
15221529
_ => panic!("can't make docs for trait item with name {:?}", item.name),

src/librustdoc/html/static/rustdoc.css

+3-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ h3.impl, h3.method, h4.method, h3.type, h4.type, h4.associatedconstant {
133133
margin-bottom: 10px;
134134
position: relative;
135135
}
136-
h3.impl, h3.method, h3.type {
136+
h3.impl, h3.method, h4.method.trait-impl, h3.type, h4.type.trait-impl, h4.associatedconstant.trait-impl {
137137
padding-left: 15px;
138138
}
139139

@@ -655,7 +655,8 @@ a {
655655
display: initial;
656656
}
657657

658-
.in-band:hover > .anchor, .impl:hover > .anchor {
658+
.in-band:hover > .anchor, .impl:hover > .anchor, .method.trait-impl:hover > .anchor,
659+
.type.trait-impl:hover > .anchor, .associatedconstant.trait-impl:hover > .anchor {
659660
display: inline-block;
660661
position: absolute;
661662
}

0 commit comments

Comments
 (0)