Skip to content

Commit d65c863

Browse files
Fix hover on impls
1 parent c318691 commit d65c863

File tree

4 files changed

+47
-39
lines changed

4 files changed

+47
-39
lines changed

src/librustdoc/html/render.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,7 +2678,6 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
26782678

26792679
fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter,
26802680
implementor_dups: &FxHashMap<&str, (DefId, bool)>) -> fmt::Result {
2681-
write!(w, "<li><table class='table-display'><tbody><tr><td><code>")?;
26822681
// If there's already another implementor that has the same abbridged name, use the
26832682
// full path, for example in `std::iter::ExactSizeIterator`
26842683
let use_absolute = match implementor.inner_impl().for_ {
@@ -2689,22 +2688,8 @@ fn render_implementor(cx: &Context, implementor: &Impl, w: &mut fmt::Formatter,
26892688
} => implementor_dups[path.last_name()].1,
26902689
_ => false,
26912690
};
2692-
fmt_impl_for_trait_page(&implementor.inner_impl(), w, use_absolute)?;
2693-
for it in &implementor.inner_impl().items {
2694-
if let clean::TypedefItem(ref tydef, _) = it.inner {
2695-
write!(w, "<span class=\"where fmt-newline\"> ")?;
2696-
assoc_type(w, it, &[], Some(&tydef.type_), AssocItemLink::Anchor(None))?;
2697-
write!(w, ";</span>")?;
2698-
}
2699-
}
2700-
write!(w, "</code><td>")?;
2701-
if let Some(l) = (Item { cx, item: &implementor.impl_item }).src_href() {
2702-
write!(w, "<div class='out-of-band'>")?;
2703-
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
2704-
l, "goto source code")?;
2705-
write!(w, "</div>")?;
2706-
}
2707-
writeln!(w, "</td></tr></tbody></table></li>")?;
2691+
render_impl(w, cx, implementor, AssocItemLink::Anchor(None), RenderMode::Normal,
2692+
implementor.impl_item.stable_since(), true, Some(use_absolute))?;
27082693
Ok(())
27092694
}
27102695

@@ -2715,7 +2700,7 @@ fn render_impls(cx: &Context, w: &mut fmt::Formatter,
27152700
let did = i.trait_did().unwrap();
27162701
let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
27172702
render_impl(w, cx, i, assoc_link,
2718-
RenderMode::Normal, containing_item.stable_since(), true)?;
2703+
RenderMode::Normal, containing_item.stable_since(), true, None)?;
27192704
}
27202705
Ok(())
27212706
}
@@ -2964,7 +2949,8 @@ fn item_trait(
29642949
&implementor.inner_impl().provided_trait_methods
29652950
);
29662951
render_impl(w, cx, &implementor, assoc_link,
2967-
RenderMode::Normal, implementor.impl_item.stable_since(), false)?;
2952+
RenderMode::Normal, implementor.impl_item.stable_since(), false,
2953+
None)?;
29682954
}
29692955
}
29702956
}
@@ -2973,7 +2959,7 @@ fn item_trait(
29732959
for implementor in concrete {
29742960
render_implementor(cx, implementor, w, &implementor_dups)?;
29752961
}
2976-
write!(w, "</ul>")?;
2962+
write!(w, "</div>")?;
29772963

29782964
if t.auto {
29792965
write!(w, "{}", synthetic_impl_header)?;
@@ -2983,17 +2969,17 @@ fn item_trait(
29832969
);
29842970
render_implementor(cx, implementor, w, &implementor_dups)?;
29852971
}
2986-
write!(w, "</ul>")?;
2972+
write!(w, "</div>")?;
29872973
}
29882974
} else {
29892975
// even without any implementations to write in, we still want the heading and list, so the
29902976
// implementors javascript file pulled in below has somewhere to write the impls into
29912977
write!(w, "{}", impl_header)?;
2992-
write!(w, "</ul>")?;
2978+
write!(w, "</div>")?;
29932979

29942980
if t.auto {
29952981
write!(w, "{}", synthetic_impl_header)?;
2996-
write!(w, "</ul>")?;
2982+
write!(w, "</div>")?;
29972983
}
29982984
}
29992985
write!(w, r#"<script type="text/javascript">window.inlined_types=new Set({});</script>"#,
@@ -3616,7 +3602,7 @@ fn render_assoc_items(w: &mut fmt::Formatter,
36163602
};
36173603
for i in &non_trait {
36183604
render_impl(w, cx, i, AssocItemLink::Anchor(None), render_mode,
3619-
containing_item.stable_since(), true)?;
3605+
containing_item.stable_since(), true, None)?;
36203606
}
36213607
}
36223608
if let AssocItemRender::DerefFor { .. } = what {
@@ -3797,15 +3783,29 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
37973783

37983784
fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLink,
37993785
render_mode: RenderMode, outer_version: Option<&str>,
3800-
show_def_docs: bool) -> fmt::Result {
3786+
show_def_docs: bool, use_absolute: Option<bool>) -> fmt::Result {
38013787
if render_mode == RenderMode::Normal {
38023788
let id = cx.derive_id(match i.inner_impl().trait_ {
38033789
Some(ref t) => format!("impl-{}", small_url_encode(&format!("{:#}", t))),
38043790
None => "impl".to_string(),
38053791
});
3806-
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
3807-
<tbody><tr><td><code>{}</code>",
3808-
id, i.inner_impl())?;
3792+
if let Some(use_absolute) = use_absolute {
3793+
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
3794+
<tbody><tr><td><code>", id)?;
3795+
fmt_impl_for_trait_page(&i.inner_impl(), w, use_absolute)?;
3796+
for it in &i.inner_impl().items {
3797+
if let clean::TypedefItem(ref tydef, _) = it.inner {
3798+
write!(w, "<span class=\"where fmt-newline\"> ")?;
3799+
assoc_type(w, it, &vec![], Some(&tydef.type_), AssocItemLink::Anchor(None))?;
3800+
write!(w, ";</span>")?;
3801+
}
3802+
}
3803+
write!(w, "</code>")?;
3804+
} else {
3805+
write!(w, "<h3 id='{}' class='impl'><span class='in-band'><table class='table-display'>\
3806+
<tbody><tr><td><code>{}</code>",
3807+
id, i.inner_impl())?;
3808+
}
38093809
write!(w, "<a href='#{}' class='anchor'></a>", id)?;
38103810
write!(w, "</span></td><td><span class='out-of-band'>")?;
38113811
let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]);

src/librustdoc/html/static/rustdoc.css

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ h3.impl, h3.method, h3.type {
114114

115115
h1, h2, h3, h4,
116116
.sidebar, a.source, .search-input, .content table :not(code)>a,
117-
.collapse-toggle, ul.item-list > li > .out-of-band {
117+
.collapse-toggle, div.item-list .out-of-band {
118118
font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
119119
}
120120

@@ -367,10 +367,6 @@ h4.method > .out-of-band {
367367
font-size: 19px;
368368
}
369369

370-
ul.item-list > li > .out-of-band {
371-
font-size: 19px;
372-
}
373-
374370
h4 > code, h3 > code, .invisible > code {
375371
max-width: calc(100% - 41px);
376372
display: block;
@@ -436,10 +432,6 @@ h4 > code, h3 > code, .invisible > code {
436432
padding: 0;
437433
}
438434

439-
.content .item-list li {
440-
margin-bottom: 1em;
441-
}
442-
443435
.content .multi-column {
444436
-moz-column-count: 5;
445437
-moz-column-gap: 2.5em;
@@ -473,6 +465,11 @@ h4 > code, h3 > code, .invisible > code {
473465
.content .impl-items .docblock, .content .impl-items .stability {
474466
margin-bottom: .6em;
475467
}
468+
469+
.content .impl-items > .stability {
470+
margin-left: 40px;
471+
}
472+
476473
.content .docblock > .impl-items {
477474
margin-left: 20px;
478475
margin-top: -34px;
@@ -1363,6 +1360,15 @@ kbd {
13631360
font-size: 19px;
13641361
display: block;
13651362
}
1363+
#implementors-list > .impl-items .table-display .out-of-band {
1364+
font-size: 17px;
1365+
}
1366+
1367+
.table-display td:hover .anchor {
1368+
display: block;
1369+
top: 2px;
1370+
left: -5px;
1371+
}
13661372

13671373
#main > ul {
13681374
padding-left: 10px;

src/test/rustdoc/doc-cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub mod unix_only {
3636
// @has doc_cfg/unix_only/trait.ArmOnly.html \
3737
// '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
3838
// 'This is supported on Unix and ARM only.'
39-
// @count - '//*[@class="stab portability"]' 2
39+
// @count - '//*[@class="stab portability"]' 3
4040
#[doc(cfg(target_arch = "arm"))]
4141
pub trait ArmOnly {
4242
fn unix_and_arm_only_function();

src/test/rustdoc/issue-29503.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
12+
1113
use std::fmt;
1214

1315
// @has issue_29503/trait.MyTrait.html
1416
pub trait MyTrait {
1517
fn my_string(&self) -> String;
1618
}
1719

18-
// @has - "//ul[@id='implementors-list']/li" "impl<T> MyTrait for T where T: Debug"
20+
// @has - "//div[@id='implementors-list']/h3[@id='impl-MyTrait']//code" "impl<T> MyTrait for T where T: Debug"
1921
impl<T> MyTrait for T where T: fmt::Debug {
2022
fn my_string(&self) -> String {
2123
format!("{:?}", self)

0 commit comments

Comments
 (0)