Skip to content

Commit 097b382

Browse files
Unify rightside rendering
1 parent 4a24f08 commit 097b382

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,6 @@ impl StylePath {
191191
}
192192
}
193193

194-
fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) {
195-
if let Some(l) = cx.src_href(item) {
196-
write!(buf, "<a class=\"srclink\" href=\"{}\">source</a>", l)
197-
}
198-
}
199-
200194
#[derive(Debug, Eq, PartialEq, Hash)]
201195
struct ItemEntry {
202196
url: String,
@@ -1691,7 +1685,9 @@ fn render_rightside(
16911685
const_stable_since,
16921686
);
16931687
let mut srclink = Buffer::empty_from(w);
1694-
write_srclink(cx, item, &mut srclink);
1688+
if let Some(l) = cx.src_href(item) {
1689+
write!(srclink, "<a class=\"srclink\" href=\"{}\">source</a>", l)
1690+
}
16951691
if has_stability && !srclink.is_empty() {
16961692
rightside.write_str(" · ");
16971693
}

src/librustdoc/html/render/print_item.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::rc::Rc;
1818
use super::{
1919
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section,
2020
notable_traits_decl, render_assoc_item, render_assoc_items, render_attributes_in_code,
21-
render_attributes_in_pre, render_impl, render_stability_since_raw, write_srclink,
21+
render_attributes_in_pre, render_impl, render_rightside, render_stability_since_raw,
2222
AssocItemLink, Context, ImplRenderingParameters,
2323
};
2424
use crate::clean;
@@ -709,14 +709,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
709709
write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
710710
}
711711
write!(w, "<div id=\"{}\" class=\"method has-srclink\">", id);
712-
write!(w, "<div class=\"rightside\">");
713-
714-
let has_stability = render_stability_since(w, m, t, cx.tcx());
715-
if has_stability {
716-
w.write_str(" · ");
717-
}
718-
write_srclink(cx, m, w);
719-
write!(w, "</div>");
712+
render_rightside(w, cx, m, t, RenderMode::Normal);
720713
write!(w, "<h4 class=\"code-header\">");
721714
render_assoc_item(
722715
w,
@@ -1260,7 +1253,13 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12601253
w.write_str(")");
12611254
}
12621255
w.write_str("</code>");
1263-
render_stability_since(w, variant, it, cx.tcx());
1256+
render_stability_since_raw(
1257+
w,
1258+
variant.stable_since(cx.tcx()),
1259+
variant.const_stability(cx.tcx()),
1260+
it.stable_since(cx.tcx()),
1261+
it.const_stable_since(cx.tcx()),
1262+
);
12641263
w.write_str("</h3>");
12651264

12661265
use crate::clean::Variant;
@@ -1591,21 +1590,6 @@ where
15911590
w.write_str("</code></pre>");
15921591
}
15931592

1594-
fn render_stability_since(
1595-
w: &mut Buffer,
1596-
item: &clean::Item,
1597-
containing_item: &clean::Item,
1598-
tcx: TyCtxt<'_>,
1599-
) -> bool {
1600-
render_stability_since_raw(
1601-
w,
1602-
item.stable_since(tcx),
1603-
item.const_stability(tcx),
1604-
containing_item.stable_since(tcx),
1605-
containing_item.const_stable_since(tcx),
1606-
)
1607-
}
1608-
16091593
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering {
16101594
let lhss = format!("{}", lhs.inner_impl().print(false, cx));
16111595
let rhss = format!("{}", rhs.inner_impl().print(false, cx));

0 commit comments

Comments
 (0)