Skip to content

Commit 00779af

Browse files
Always display stability version even if it's the same as the containing item
1 parent b29a1e0 commit 00779af

File tree

3 files changed

+14
-61
lines changed

3 files changed

+14
-61
lines changed

src/librustdoc/clean/types.rs

-7
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,6 @@ impl Item {
592592
}
593593
}
594594

595-
pub(crate) fn const_stable_since(&self, tcx: TyCtxt<'_>) -> Option<StableSince> {
596-
match self.const_stability(tcx)?.level {
597-
StabilityLevel::Stable { since, .. } => Some(since),
598-
StabilityLevel::Unstable { .. } => None,
599-
}
600-
}
601-
602595
pub(crate) fn is_non_exhaustive(&self) -> bool {
603596
self.attrs.other_attrs.iter().any(|a| a.has_name(sym::non_exhaustive))
604597
}

src/librustdoc/html/render/mod.rs

+13-49
Original file line numberDiff line numberDiff line change
@@ -940,32 +940,20 @@ fn assoc_method(
940940
/// consequence of the above rules.
941941
fn render_stability_since_raw_with_extra(
942942
w: &mut Buffer,
943-
ver: Option<StableSince>,
943+
stable_version: Option<StableSince>,
944944
const_stability: Option<ConstStability>,
945-
containing_ver: Option<StableSince>,
946-
containing_const_ver: Option<StableSince>,
947945
extra_class: &str,
948946
) -> bool {
949-
let stable_version = if ver != containing_ver
950-
&& let Some(ver) = &ver
951-
{
952-
since_to_string(ver)
953-
} else {
954-
None
955-
};
956-
957947
let mut title = String::new();
958948
let mut stability = String::new();
959949

960-
if let Some(ver) = stable_version {
961-
stability.push_str(ver.as_str());
962-
title.push_str(&format!("Stable since Rust version {ver}"));
950+
if let Some(version) = stable_version.and_then(|version| since_to_string(&version)) {
951+
stability.push_str(&version);
952+
title.push_str(&format!("Stable since Rust version {version}"));
963953
}
964954

965955
let const_title_and_stability = match const_stability {
966-
Some(ConstStability { level: StabilityLevel::Stable { since, .. }, .. })
967-
if Some(since) != containing_const_ver =>
968-
{
956+
Some(ConstStability { level: StabilityLevel::Stable { since, .. }, .. }) => {
969957
since_to_string(&since)
970958
.map(|since| (format!("const since {since}"), format!("const: {since}")))
971959
}
@@ -1020,17 +1008,8 @@ fn render_stability_since_raw(
10201008
w: &mut Buffer,
10211009
ver: Option<StableSince>,
10221010
const_stability: Option<ConstStability>,
1023-
containing_ver: Option<StableSince>,
1024-
containing_const_ver: Option<StableSince>,
10251011
) -> bool {
1026-
render_stability_since_raw_with_extra(
1027-
w,
1028-
ver,
1029-
const_stability,
1030-
containing_ver,
1031-
containing_const_ver,
1032-
"",
1033-
)
1012+
render_stability_since_raw_with_extra(w, ver, const_stability, "")
10341013
}
10351014

10361015
fn render_assoc_item(
@@ -1520,7 +1499,6 @@ fn render_impl(
15201499
cx: &mut Context<'_>,
15211500
item: &clean::Item,
15221501
parent: &clean::Item,
1523-
containing_item: &clean::Item,
15241502
link: AssocItemLink<'_>,
15251503
render_mode: RenderMode,
15261504
is_default_item: bool,
@@ -1615,7 +1593,7 @@ fn render_impl(
16151593
})
16161594
.map(|item| format!("{}.{name}", item.type_()));
16171595
write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
1618-
render_rightside(w, cx, item, containing_item, render_mode);
1596+
render_rightside(w, cx, item, render_mode);
16191597
if trait_.is_some() {
16201598
// Anchors are only used on trait impls.
16211599
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
@@ -1637,7 +1615,7 @@ fn render_impl(
16371615
let source_id = format!("{item_type}.{name}");
16381616
let id = cx.derive_id(&source_id);
16391617
write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
1640-
render_rightside(w, cx, item, containing_item, render_mode);
1618+
render_rightside(w, cx, item, render_mode);
16411619
if trait_.is_some() {
16421620
// Anchors are only used on trait impls.
16431621
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
@@ -1723,7 +1701,6 @@ fn render_impl(
17231701
cx,
17241702
trait_item,
17251703
if trait_.is_some() { &i.impl_item } else { parent },
1726-
parent,
17271704
link,
17281705
render_mode,
17291706
false,
@@ -1739,7 +1716,6 @@ fn render_impl(
17391716
t: &clean::Trait,
17401717
i: &clean::Impl,
17411718
parent: &clean::Item,
1742-
containing_item: &clean::Item,
17431719
render_mode: RenderMode,
17441720
rendering_params: ImplRenderingParameters,
17451721
) {
@@ -1767,7 +1743,6 @@ fn render_impl(
17671743
cx,
17681744
trait_item,
17691745
parent,
1770-
containing_item,
17711746
assoc_link,
17721747
render_mode,
17731748
true,
@@ -1790,7 +1765,6 @@ fn render_impl(
17901765
t,
17911766
i.inner_impl(),
17921767
&i.impl_item,
1793-
parent,
17941768
render_mode,
17951769
rendering_params,
17961770
);
@@ -1812,7 +1786,6 @@ fn render_impl(
18121786
cx,
18131787
i,
18141788
parent,
1815-
parent,
18161789
rendering_params.show_def_docs,
18171790
use_absolute,
18181791
aliases,
@@ -1860,20 +1833,14 @@ fn render_impl(
18601833

18611834
// Render the items that appear on the right side of methods, impls, and
18621835
// associated types. For example "1.0.0 (const: 1.39.0) · source".
1863-
fn render_rightside(
1864-
w: &mut Buffer,
1865-
cx: &Context<'_>,
1866-
item: &clean::Item,
1867-
containing_item: &clean::Item,
1868-
render_mode: RenderMode,
1869-
) {
1836+
fn render_rightside(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, render_mode: RenderMode) {
18701837
let tcx = cx.tcx();
18711838

18721839
// FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove
18731840
// this condition.
1874-
let (const_stability, const_stable_since) = match render_mode {
1875-
RenderMode::Normal => (item.const_stability(tcx), containing_item.const_stable_since(tcx)),
1876-
RenderMode::ForDeref { .. } => (None, None),
1841+
let const_stability = match render_mode {
1842+
RenderMode::Normal => item.const_stability(tcx),
1843+
RenderMode::ForDeref { .. } => None,
18771844
};
18781845
let src_href = cx.src_href(item);
18791846
let has_src_ref = src_href.is_some();
@@ -1883,8 +1850,6 @@ fn render_rightside(
18831850
&mut rightside,
18841851
item.stable_since(tcx),
18851852
const_stability,
1886-
containing_item.stable_since(tcx),
1887-
const_stable_since,
18881853
if has_src_ref { "" } else { " rightside" },
18891854
);
18901855
if let Some(link) = src_href {
@@ -1906,7 +1871,6 @@ pub(crate) fn render_impl_summary(
19061871
cx: &mut Context<'_>,
19071872
i: &Impl,
19081873
parent: &clean::Item,
1909-
containing_item: &clean::Item,
19101874
show_def_docs: bool,
19111875
use_absolute: Option<bool>,
19121876
// This argument is used to reference same type with different paths to avoid duplication
@@ -1921,7 +1885,7 @@ pub(crate) fn render_impl_summary(
19211885
format!(" data-aliases=\"{}\"", aliases.join(","))
19221886
};
19231887
write!(w, "<section id=\"{id}\" class=\"impl\"{aliases}>");
1924-
render_rightside(w, cx, &i.impl_item, containing_item, RenderMode::Normal);
1888+
render_rightside(w, cx, &i.impl_item, RenderMode::Normal);
19251889
write!(
19261890
w,
19271891
"<a href=\"#{id}\" class=\"anchor\">§</a>\

src/librustdoc/html/render/print_item.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ pub(super) fn print_item(
223223
&mut stability_since_raw,
224224
item.stable_since(cx.tcx()),
225225
item.const_stability(cx.tcx()),
226-
None,
227-
None,
228226
);
229227
let stability_since_raw: String = stability_since_raw.into_inner();
230228

@@ -846,7 +844,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
846844
write!(w, "<details class=\"toggle{method_toggle_class}\" open><summary>");
847845
}
848846
write!(w, "<section id=\"{id}\" class=\"method\">");
849-
render_rightside(w, cx, m, t, RenderMode::Normal);
847+
render_rightside(w, cx, m, RenderMode::Normal);
850848
write!(w, "<h4 class=\"code-header\">");
851849
render_assoc_item(
852850
w,
@@ -1707,8 +1705,6 @@ fn item_variants(
17071705
w,
17081706
variant.stable_since(tcx),
17091707
variant.const_stability(tcx),
1710-
it.stable_since(tcx),
1711-
it.const_stable_since(tcx),
17121708
" rightside",
17131709
);
17141710
w.write_str("<h3 class=\"code-header\">");

0 commit comments

Comments
 (0)