about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Hoffman-Andrews <github@hoffman-andrews.com>2021-06-12 00:25:26 -0700
committerJacob Hoffman-Andrews <github@hoffman-andrews.com>2021-06-16 22:46:53 -0700
commit5de1391b88007a1d4f7b1517657a86aae352af1e (patch)
treee893244668a85360558152b16cc19f3017fa93f0
parent593d6d1cb15c55c88319470dabb40126c7b7f1e2 (diff)
downloadrust-5de1391b88007a1d4f7b1517657a86aae352af1e.tar.gz
rust-5de1391b88007a1d4f7b1517657a86aae352af1e.zip
Factor out render_rightside
This covers rendering of stability_since and the srclink across methods
and trait implementations, so their DOM representation is consistent.
-rw-r--r--src/librustdoc/html/render/mod.rs73
-rw-r--r--src/librustdoc/html/static/rustdoc.css8
-rw-r--r--src/test/rustdoc-gui/hash-item-expansion.goml3
3 files changed, 30 insertions, 54 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index df8cc94d3ee..a210d0c843c 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -1294,7 +1294,6 @@ fn render_impl(
     ) {
         let item_type = item.type_();
         let name = item.name.as_ref().unwrap();
-        let tcx = cx.tcx();
 
         let render_method_item = match render_mode {
             RenderMode::Normal => true,
@@ -1363,6 +1362,7 @@ fn render_impl(
                         "<div id=\"{}\" class=\"{}{} has-srclink\">",
                         id, item_type, in_trait_class,
                     );
+                    render_rightside(w, cx, item, outer_version, outer_const_version);
                     w.write_str("<code>");
                     render_assoc_item(
                         w,
@@ -1372,15 +1372,7 @@ fn render_impl(
                         cx,
                     );
                     w.write_str("</code>");
-                    render_stability_since_raw(
-                        w,
-                        item.stable_since(tcx).as_deref(),
-                        item.const_stable_since(tcx).as_deref(),
-                        outer_version,
-                        outer_const_version,
-                    );
                     write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
-                    write_srclink(cx, item, w);
                     w.write_str("</div>");
                 }
             }
@@ -1413,6 +1405,7 @@ fn render_impl(
                     "<div id=\"{}\" class=\"{}{} has-srclink\"><code>",
                     id, item_type, in_trait_class
                 );
+                render_rightside(w, cx, item, outer_version, outer_const_version);
                 assoc_const(
                     w,
                     item,
@@ -1423,15 +1416,7 @@ fn render_impl(
                     cx,
                 );
                 w.write_str("</code>");
-                render_stability_since_raw(
-                    w,
-                    item.stable_since(tcx).as_deref(),
-                    item.const_stable_since(tcx).as_deref(),
-                    outer_version,
-                    outer_const_version,
-                );
                 write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
-                write_srclink(cx, item, w);
                 w.write_str("</div>");
             }
             clean::AssocTypeItem(ref bounds, ref default) => {
@@ -1590,6 +1575,28 @@ fn render_impl(
     w.write_str(&close_tags);
 }
 
+fn render_rightside(
+    w: &mut Buffer,
+    cx: &Context<'_>,
+    item: &clean::Item,
+    outer_version: Option<&str>,
+    outer_const_version: Option<&str>,
+) {
+    let tcx = cx.tcx();
+
+    write!(w, "<div class=\"rightside\">");
+    render_stability_since_raw(
+        w,
+        item.stable_since(tcx).as_deref(),
+        item.const_stable_since(tcx).as_deref(),
+        outer_version,
+        outer_const_version,
+    );
+
+    write_srclink(cx, item, w);
+    w.write_str("</div>");
+}
+
 pub(crate) fn render_impl_summary(
     w: &mut Buffer,
     cx: &Context<'_>,
@@ -1604,7 +1611,6 @@ pub(crate) fn render_impl_summary(
     // in documentation pages for trait with automatic implementations like "Send" and "Sync".
     aliases: &[String],
 ) {
-    let tcx = cx.tcx();
     let id = cx.derive_id(match i.inner_impl().trait_ {
         Some(ref t) => {
             if is_on_foreign_type {
@@ -1620,13 +1626,11 @@ pub(crate) fn render_impl_summary(
     } else {
         format!(" data-aliases=\"{}\"", aliases.join(","))
     };
+    write!(w, "<div id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases);
+    render_rightside(w, cx, &i.impl_item, outer_version, outer_const_version);
+    write!(w, "<code class=\"in-band\">");
+
     if let Some(use_absolute) = use_absolute {
-        write!(
-            w,
-            "<div id=\"{}\" class=\"impl has-srclink\"{}>\
-                     <code class=\"in-band\">",
-            id, aliases
-        );
         write!(w, "{}", i.inner_impl().print(use_absolute, cx));
         if show_def_docs {
             for it in &i.inner_impl().items {
@@ -1637,28 +1641,11 @@ pub(crate) fn render_impl_summary(
                 }
             }
         }
-        w.write_str("</code>");
     } else {
-        write!(
-            w,
-            "<div id=\"{}\" class=\"impl has-srclink\"{}>\
-                     <code class=\"in-band\">{}</code>",
-            id,
-            aliases,
-            i.inner_impl().print(false, cx)
-        );
+        write!(w, "{}", i.inner_impl().print(false, cx));
     }
+    write!(w, "</code>");
     write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
-    write!(w, "<div class=\"rightside\">");
-    render_stability_since_raw(
-        w,
-        i.impl_item.stable_since(tcx).as_deref(),
-        i.impl_item.const_stable_since(tcx).as_deref(),
-        outer_version,
-        outer_const_version,
-    );
-    write_srclink(cx, &i.impl_item, w);
-    w.write_str("</div>"); // end of "rightside"
 
     let is_trait = i.inner_impl().trait_.is_some();
     if is_trait {
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index e084ee9ca7e..e6646586c41 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -899,9 +899,6 @@ body.blur > :not(#help) {
 .since {
 	font-weight: normal;
 	font-size: initial;
-	position: absolute;
-	right: 0;
-	top: 0;
 }
 
 .impl-items .since, .impl .since, .methods .since {
@@ -1606,11 +1603,6 @@ details.undocumented[open] > summary::before {
 		margin-left: 0;
 	}
 
-	.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant,
-	.impl-items > .associatedtype {
-		display: flex;
-	}
-
 	.anchor {
 		display: none !important;
 	}
diff --git a/src/test/rustdoc-gui/hash-item-expansion.goml b/src/test/rustdoc-gui/hash-item-expansion.goml
index 1248d11200e..d5f9d4fc58b 100644
--- a/src/test/rustdoc-gui/hash-item-expansion.goml
+++ b/src/test/rustdoc-gui/hash-item-expansion.goml
@@ -2,9 +2,6 @@
 goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.borrow
 // In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)".
 assert: ("#blanket-implementations-list > details:nth-child(2)", "open", "")
-// Please note the "\" below is needed because otherwise ".borrow" would be interpreted as
-// a class selector.
-assert: ("#method\.borrow", {"display": "flex"})
 // We first check that the impl block is open by default.
 assert: ("#implementations + details", "open", "")
 // We collapse it.