From 00779af94e2b2260047f1598cf7196ecf01447d0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 29 Nov 2023 12:10:02 +0100 Subject: [PATCH] Always display stability version even if it's the same as the containing item --- src/librustdoc/clean/types.rs | 7 --- src/librustdoc/html/render/mod.rs | 62 +++++------------------- src/librustdoc/html/render/print_item.rs | 6 +-- 3 files changed, 14 insertions(+), 61 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index f079d01bd8422..f40923a4b07ca 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -592,13 +592,6 @@ impl Item { } } - pub(crate) fn const_stable_since(&self, tcx: TyCtxt<'_>) -> Option { - match self.const_stability(tcx)?.level { - StabilityLevel::Stable { since, .. } => Some(since), - StabilityLevel::Unstable { .. } => None, - } - } - pub(crate) fn is_non_exhaustive(&self) -> bool { self.attrs.other_attrs.iter().any(|a| a.has_name(sym::non_exhaustive)) } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index ff5c761208b45..f37c3704fe36c 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -940,32 +940,20 @@ fn assoc_method( /// consequence of the above rules. fn render_stability_since_raw_with_extra( w: &mut Buffer, - ver: Option, + stable_version: Option, const_stability: Option, - containing_ver: Option, - containing_const_ver: Option, extra_class: &str, ) -> bool { - let stable_version = if ver != containing_ver - && let Some(ver) = &ver - { - since_to_string(ver) - } else { - None - }; - let mut title = String::new(); let mut stability = String::new(); - if let Some(ver) = stable_version { - stability.push_str(ver.as_str()); - title.push_str(&format!("Stable since Rust version {ver}")); + if let Some(version) = stable_version.and_then(|version| since_to_string(&version)) { + stability.push_str(&version); + title.push_str(&format!("Stable since Rust version {version}")); } let const_title_and_stability = match const_stability { - Some(ConstStability { level: StabilityLevel::Stable { since, .. }, .. }) - if Some(since) != containing_const_ver => - { + Some(ConstStability { level: StabilityLevel::Stable { since, .. }, .. }) => { since_to_string(&since) .map(|since| (format!("const since {since}"), format!("const: {since}"))) } @@ -1020,17 +1008,8 @@ fn render_stability_since_raw( w: &mut Buffer, ver: Option, const_stability: Option, - containing_ver: Option, - containing_const_ver: Option, ) -> bool { - render_stability_since_raw_with_extra( - w, - ver, - const_stability, - containing_ver, - containing_const_ver, - "", - ) + render_stability_since_raw_with_extra(w, ver, const_stability, "") } fn render_assoc_item( @@ -1520,7 +1499,6 @@ fn render_impl( cx: &mut Context<'_>, item: &clean::Item, parent: &clean::Item, - containing_item: &clean::Item, link: AssocItemLink<'_>, render_mode: RenderMode, is_default_item: bool, @@ -1615,7 +1593,7 @@ fn render_impl( }) .map(|item| format!("{}.{name}", item.type_())); write!(w, "
"); - render_rightside(w, cx, item, containing_item, render_mode); + render_rightside(w, cx, item, render_mode); if trait_.is_some() { // Anchors are only used on trait impls. write!(w, "§"); @@ -1637,7 +1615,7 @@ fn render_impl( let source_id = format!("{item_type}.{name}"); let id = cx.derive_id(&source_id); write!(w, "
"); - render_rightside(w, cx, item, containing_item, render_mode); + render_rightside(w, cx, item, render_mode); if trait_.is_some() { // Anchors are only used on trait impls. write!(w, "§"); @@ -1723,7 +1701,6 @@ fn render_impl( cx, trait_item, if trait_.is_some() { &i.impl_item } else { parent }, - parent, link, render_mode, false, @@ -1739,7 +1716,6 @@ fn render_impl( t: &clean::Trait, i: &clean::Impl, parent: &clean::Item, - containing_item: &clean::Item, render_mode: RenderMode, rendering_params: ImplRenderingParameters, ) { @@ -1767,7 +1743,6 @@ fn render_impl( cx, trait_item, parent, - containing_item, assoc_link, render_mode, true, @@ -1790,7 +1765,6 @@ fn render_impl( t, i.inner_impl(), &i.impl_item, - parent, render_mode, rendering_params, ); @@ -1812,7 +1786,6 @@ fn render_impl( cx, i, parent, - parent, rendering_params.show_def_docs, use_absolute, aliases, @@ -1860,20 +1833,14 @@ fn render_impl( // Render the items that appear on the right side of methods, impls, and // associated types. For example "1.0.0 (const: 1.39.0) · source". -fn render_rightside( - w: &mut Buffer, - cx: &Context<'_>, - item: &clean::Item, - containing_item: &clean::Item, - render_mode: RenderMode, -) { +fn render_rightside(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, render_mode: RenderMode) { let tcx = cx.tcx(); // FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove // this condition. - let (const_stability, const_stable_since) = match render_mode { - RenderMode::Normal => (item.const_stability(tcx), containing_item.const_stable_since(tcx)), - RenderMode::ForDeref { .. } => (None, None), + let const_stability = match render_mode { + RenderMode::Normal => item.const_stability(tcx), + RenderMode::ForDeref { .. } => None, }; let src_href = cx.src_href(item); let has_src_ref = src_href.is_some(); @@ -1883,8 +1850,6 @@ fn render_rightside( &mut rightside, item.stable_since(tcx), const_stability, - containing_item.stable_since(tcx), - const_stable_since, if has_src_ref { "" } else { " rightside" }, ); if let Some(link) = src_href { @@ -1906,7 +1871,6 @@ pub(crate) fn render_impl_summary( cx: &mut Context<'_>, i: &Impl, parent: &clean::Item, - containing_item: &clean::Item, show_def_docs: bool, use_absolute: Option, // This argument is used to reference same type with different paths to avoid duplication @@ -1921,7 +1885,7 @@ pub(crate) fn render_impl_summary( format!(" data-aliases=\"{}\"", aliases.join(",")) }; write!(w, "
"); - render_rightside(w, cx, &i.impl_item, containing_item, RenderMode::Normal); + render_rightside(w, cx, &i.impl_item, RenderMode::Normal); write!( w, "§\ diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 14387e0d45dfe..c402aa52ce1e2 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -223,8 +223,6 @@ pub(super) fn print_item( &mut stability_since_raw, item.stable_since(cx.tcx()), item.const_stability(cx.tcx()), - None, - None, ); let stability_since_raw: String = stability_since_raw.into_inner(); @@ -846,7 +844,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: write!(w, "
"); } write!(w, "
"); - render_rightside(w, cx, m, t, RenderMode::Normal); + render_rightside(w, cx, m, RenderMode::Normal); write!(w, "

"); render_assoc_item( w, @@ -1707,8 +1705,6 @@ fn item_variants( w, variant.stable_since(tcx), variant.const_stability(tcx), - it.stable_since(tcx), - it.const_stable_since(tcx), " rightside", ); w.write_str("

");