]> git.lizzy.rs Git - rust.git/commitdiff
Unify rightside rendering
authorGuillaume Gomez <guillaume.gomez@huawei.com>
Wed, 24 Aug 2022 13:10:26 +0000 (15:10 +0200)
committerGuillaume Gomez <guillaume.gomez@huawei.com>
Wed, 24 Aug 2022 13:10:26 +0000 (15:10 +0200)
src/librustdoc/html/render/mod.rs
src/librustdoc/html/render/print_item.rs

index f9d6b4619cc77999e44c7151aa410464cf6ff2c3..04be6dbb6f712c3039f640d02288384e52288e25 100644 (file)
@@ -191,12 +191,6 @@ pub(crate) fn basename(&self) -> Result<String, Error> {
     }
 }
 
-fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) {
-    if let Some(l) = cx.src_href(item) {
-        write!(buf, "<a class=\"srclink\" href=\"{}\">source</a>", l)
-    }
-}
-
 #[derive(Debug, Eq, PartialEq, Hash)]
 struct ItemEntry {
     url: String,
@@ -1691,7 +1685,9 @@ fn render_rightside(
         const_stable_since,
     );
     let mut srclink = Buffer::empty_from(w);
-    write_srclink(cx, item, &mut srclink);
+    if let Some(l) = cx.src_href(item) {
+        write!(srclink, "<a class=\"srclink\" href=\"{}\">source</a>", l)
+    }
     if has_stability && !srclink.is_empty() {
         rightside.write_str(" · ");
     }
index 6d0a825fec866aa47a7c04bd4bdb29d5dd1a056c..a5668b318dcdc8f18a60e560e6754af8db65b54a 100644 (file)
@@ -18,7 +18,7 @@
 use super::{
     collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section,
     notable_traits_decl, render_assoc_item, render_assoc_items, render_attributes_in_code,
-    render_attributes_in_pre, render_impl, render_stability_since_raw, write_srclink,
+    render_attributes_in_pre, render_impl, render_rightside, render_stability_since_raw,
     AssocItemLink, Context, ImplRenderingParameters,
 };
 use crate::clean;
@@ -709,14 +709,7 @@ fn trait_item(w: &mut Buffer, cx: &mut Context<'_>, m: &clean::Item, t: &clean::
             write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
         }
         write!(w, "<div id=\"{}\" class=\"method has-srclink\">", id);
-        write!(w, "<div class=\"rightside\">");
-
-        let has_stability = render_stability_since(w, m, t, cx.tcx());
-        if has_stability {
-            w.write_str(" · ");
-        }
-        write_srclink(cx, m, w);
-        write!(w, "</div>");
+        render_rightside(w, cx, m, t, RenderMode::Normal);
         write!(w, "<h4 class=\"code-header\">");
         render_assoc_item(
             w,
@@ -1260,7 +1253,13 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
                 w.write_str(")");
             }
             w.write_str("</code>");
-            render_stability_since(w, variant, it, cx.tcx());
+            render_stability_since_raw(
+                w,
+                variant.stable_since(cx.tcx()),
+                variant.const_stability(cx.tcx()),
+                it.stable_since(cx.tcx()),
+                it.const_stable_since(cx.tcx()),
+            );
             w.write_str("</h3>");
 
             use crate::clean::Variant;
@@ -1591,21 +1590,6 @@ fn wrap_item<F>(w: &mut Buffer, item_name: &str, f: F)
     w.write_str("</code></pre>");
 }
 
-fn render_stability_since(
-    w: &mut Buffer,
-    item: &clean::Item,
-    containing_item: &clean::Item,
-    tcx: TyCtxt<'_>,
-) -> bool {
-    render_stability_since_raw(
-        w,
-        item.stable_since(tcx),
-        item.const_stability(tcx),
-        containing_item.stable_since(tcx),
-        containing_item.const_stable_since(tcx),
-    )
-}
-
 fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering {
     let lhss = format!("{}", lhs.inner_impl().print(false, cx));
     let rhss = format!("{}", rhs.inner_impl().print(false, cx));