Skip to content

Commit 5de1391

Browse files
committed
Factor out render_rightside
This covers rendering of stability_since and the srclink across methods and trait implementations, so their DOM representation is consistent.
1 parent 593d6d1 commit 5de1391

File tree

3 files changed

+30
-54
lines changed

3 files changed

+30
-54
lines changed

src/librustdoc/html/render/mod.rs

+30-43
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,6 @@ fn render_impl(
12941294
) {
12951295
let item_type = item.type_();
12961296
let name = item.name.as_ref().unwrap();
1297-
let tcx = cx.tcx();
12981297

12991298
let render_method_item = match render_mode {
13001299
RenderMode::Normal => true,
@@ -1363,6 +1362,7 @@ fn render_impl(
13631362
"<div id=\"{}\" class=\"{}{} has-srclink\">",
13641363
id, item_type, in_trait_class,
13651364
);
1365+
render_rightside(w, cx, item, outer_version, outer_const_version);
13661366
w.write_str("<code>");
13671367
render_assoc_item(
13681368
w,
@@ -1372,15 +1372,7 @@ fn render_impl(
13721372
cx,
13731373
);
13741374
w.write_str("</code>");
1375-
render_stability_since_raw(
1376-
w,
1377-
item.stable_since(tcx).as_deref(),
1378-
item.const_stable_since(tcx).as_deref(),
1379-
outer_version,
1380-
outer_const_version,
1381-
);
13821375
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1383-
write_srclink(cx, item, w);
13841376
w.write_str("</div>");
13851377
}
13861378
}
@@ -1413,6 +1405,7 @@ fn render_impl(
14131405
"<div id=\"{}\" class=\"{}{} has-srclink\"><code>",
14141406
id, item_type, in_trait_class
14151407
);
1408+
render_rightside(w, cx, item, outer_version, outer_const_version);
14161409
assoc_const(
14171410
w,
14181411
item,
@@ -1423,15 +1416,7 @@ fn render_impl(
14231416
cx,
14241417
);
14251418
w.write_str("</code>");
1426-
render_stability_since_raw(
1427-
w,
1428-
item.stable_since(tcx).as_deref(),
1429-
item.const_stable_since(tcx).as_deref(),
1430-
outer_version,
1431-
outer_const_version,
1432-
);
14331419
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1434-
write_srclink(cx, item, w);
14351420
w.write_str("</div>");
14361421
}
14371422
clean::AssocTypeItem(ref bounds, ref default) => {
@@ -1590,6 +1575,28 @@ fn render_impl(
15901575
w.write_str(&close_tags);
15911576
}
15921577

1578+
fn render_rightside(
1579+
w: &mut Buffer,
1580+
cx: &Context<'_>,
1581+
item: &clean::Item,
1582+
outer_version: Option<&str>,
1583+
outer_const_version: Option<&str>,
1584+
) {
1585+
let tcx = cx.tcx();
1586+
1587+
write!(w, "<div class=\"rightside\">");
1588+
render_stability_since_raw(
1589+
w,
1590+
item.stable_since(tcx).as_deref(),
1591+
item.const_stable_since(tcx).as_deref(),
1592+
outer_version,
1593+
outer_const_version,
1594+
);
1595+
1596+
write_srclink(cx, item, w);
1597+
w.write_str("</div>");
1598+
}
1599+
15931600
pub(crate) fn render_impl_summary(
15941601
w: &mut Buffer,
15951602
cx: &Context<'_>,
@@ -1604,7 +1611,6 @@ pub(crate) fn render_impl_summary(
16041611
// in documentation pages for trait with automatic implementations like "Send" and "Sync".
16051612
aliases: &[String],
16061613
) {
1607-
let tcx = cx.tcx();
16081614
let id = cx.derive_id(match i.inner_impl().trait_ {
16091615
Some(ref t) => {
16101616
if is_on_foreign_type {
@@ -1620,13 +1626,11 @@ pub(crate) fn render_impl_summary(
16201626
} else {
16211627
format!(" data-aliases=\"{}\"", aliases.join(","))
16221628
};
1629+
write!(w, "<div id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases);
1630+
render_rightside(w, cx, &i.impl_item, outer_version, outer_const_version);
1631+
write!(w, "<code class=\"in-band\">");
1632+
16231633
if let Some(use_absolute) = use_absolute {
1624-
write!(
1625-
w,
1626-
"<div id=\"{}\" class=\"impl has-srclink\"{}>\
1627-
<code class=\"in-band\">",
1628-
id, aliases
1629-
);
16301634
write!(w, "{}", i.inner_impl().print(use_absolute, cx));
16311635
if show_def_docs {
16321636
for it in &i.inner_impl().items {
@@ -1637,28 +1641,11 @@ pub(crate) fn render_impl_summary(
16371641
}
16381642
}
16391643
}
1640-
w.write_str("</code>");
16411644
} else {
1642-
write!(
1643-
w,
1644-
"<div id=\"{}\" class=\"impl has-srclink\"{}>\
1645-
<code class=\"in-band\">{}</code>",
1646-
id,
1647-
aliases,
1648-
i.inner_impl().print(false, cx)
1649-
);
1645+
write!(w, "{}", i.inner_impl().print(false, cx));
16501646
}
1647+
write!(w, "</code>");
16511648
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1652-
write!(w, "<div class=\"rightside\">");
1653-
render_stability_since_raw(
1654-
w,
1655-
i.impl_item.stable_since(tcx).as_deref(),
1656-
i.impl_item.const_stable_since(tcx).as_deref(),
1657-
outer_version,
1658-
outer_const_version,
1659-
);
1660-
write_srclink(cx, &i.impl_item, w);
1661-
w.write_str("</div>"); // end of "rightside"
16621649

16631650
let is_trait = i.inner_impl().trait_.is_some();
16641651
if is_trait {

src/librustdoc/html/static/rustdoc.css

-8
Original file line numberDiff line numberDiff line change
@@ -899,9 +899,6 @@ body.blur > :not(#help) {
899899
.since {
900900
font-weight: normal;
901901
font-size: initial;
902-
position: absolute;
903-
right: 0;
904-
top: 0;
905902
}
906903

907904
.impl-items .since, .impl .since, .methods .since {
@@ -1606,11 +1603,6 @@ details.undocumented[open] > summary::before {
16061603
margin-left: 0;
16071604
}
16081605

1609-
.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant,
1610-
.impl-items > .associatedtype {
1611-
display: flex;
1612-
}
1613-
16141606
.anchor {
16151607
display: none !important;
16161608
}

src/test/rustdoc-gui/hash-item-expansion.goml

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.borrow
33
// In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)".
44
assert: ("#blanket-implementations-list > details:nth-child(2)", "open", "")
5-
// Please note the "\" below is needed because otherwise ".borrow" would be interpreted as
6-
// a class selector.
7-
assert: ("#method\.borrow", {"display": "flex"})
85
// We first check that the impl block is open by default.
96
assert: ("#implementations + details", "open", "")
107
// We collapse it.

0 commit comments

Comments
 (0)