about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-08-26 20:10:43 +0000
committerbors <bors@rust-lang.org>2018-08-26 20:10:43 +0000
commit7219130677c4fe4310c9729cbc0b4c6e9c9b42fc (patch)
tree7c8c16f550330eacb35373dba2da56a0754e1f88 /src
parentcaed80ba4ba8d9f4d3fa8aa9af6c4092d779cd9d (diff)
parentf9eef71986741c91161c88b9f7a3bf80796f44a3 (diff)
Auto merge of #53717 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #53043 (Improve unstable message display)
 - #53428 (libtest terse format: show how far in we are)
 - #53626 (Automatically expand a section even after page load)
 - #53651 (Add struct keyword doc)
 - #53706 (rustdoc: Fix gap on section anchor symbol when hovering.)

Failed merges:

 - #53472 (Use FxHash{Map,Set} instead of the default Hash{Map,Set} everywhere in rustc.)

r? @ghost
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/static/main.js52
-rw-r--r--src/librustdoc/html/static/rustdoc.css18
-rw-r--r--src/libstd/keyword_docs.rs21
-rw-r--r--src/libtest/formatters/terse.rs6
4 files changed, 77 insertions, 20 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 5e78e8fe569..88c25567d29 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -223,7 +223,25 @@
             }
         }
     }
-    highlightSourceLines(null);
+
+    function expandSection(id) {
+        var elem = document.getElementById(id);
+        if (elem && isHidden(elem)) {
+            var h3 = elem.parentNode.previousSibling;
+            if (h3 && h3.tagName !== 'H3') {
+                h3 = h3.previousSibling; // skip div.docblock
+            }
+
+            if (h3) {
+                var collapses = h3.getElementsByClassName("collapse-toggle");
+                if (collapses.length > 0) {
+                    // The element is not visible, we need to make it appear!
+                    collapseDocs(collapses[0], "show");
+                }
+            }
+        }
+    }
+
     window.onhashchange = highlightSourceLines;
 
     // Gets the human-readable string for the virtual-key code of the
@@ -317,6 +335,15 @@
         }
     }
 
+    function findParentElement(elem, tagName) {
+        do {
+            if (elem && elem.tagName === tagName) {
+                return elem;
+            }
+        } while (elem = elem.parentNode);
+        return null;
+    }
+
     document.onkeypress = handleShortcut;
     document.onkeydown = handleShortcut;
     document.onclick = function(ev) {
@@ -354,6 +381,13 @@
         } else if (!hasClass(document.getElementById("help"), "hidden")) {
             addClass(document.getElementById("help"), "hidden");
             removeClass(document.body, "blur");
+        } else {
+            // Making a collapsed element visible on onhashchange seems
+            // too late
+            var a = findParentElement(ev.target, 'A');
+            if (a && a.hash) {
+                expandSection(a.hash.replace(/^#/, ''));
+            }
         }
     };
 
@@ -2213,21 +2247,7 @@
     autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
 
     if (window.location.hash && window.location.hash.length > 0) {
-        var hash = getPageId();
-        if (hash !== null) {
-            var elem = document.getElementById(hash);
-            if (elem && elem.offsetParent === null) {
-                if (elem.parentNode && elem.parentNode.previousSibling) {
-                    var collapses = elem.parentNode
-                                        .previousSibling
-                                        .getElementsByClassName("collapse-toggle");
-                    if (collapses.length > 0) {
-                        // The element is not visible, we need to make it appear!
-                        collapseDocs(collapses[0], "show");
-                    }
-                }
-            }
-        }
+        expandSection(window.location.hash.replace(/^#/, ''));
     }
 }());
 
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index 57a111daa89..ffe6a40b369 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -497,6 +497,19 @@ h4 > code, h3 > code, .invisible > code {
 	font-size: 90%;
 }
 
+.content .stability {
+	position: relative;
+	margin-left: 33px;
+	margin-top: -13px;
+}
+.content .stability::before {
+	content: '˪';
+	font-size: 30px;
+	position: absolute;
+	top: -9px;
+	left: -13px;
+}
+
 nav {
 	border-bottom: 1px solid;
 	padding-bottom: 10px;
@@ -545,10 +558,8 @@ a {
 	left: -5px;
 }
 .small-section-header > .anchor {
-	left: -20px;
-}
-.small-section-header > .anchor:not(.field) {
 	left: -28px;
+	padding-right: 10px; /* avoid gap that causes hover to disappear */
 }
 .anchor:before {
 	content: '\2002\00a7\2002';
@@ -745,6 +756,7 @@ a.test-arrow:hover{
 .section-header:hover a:before {
 	position: absolute;
 	left: -25px;
+	padding-right: 10px; /* avoid gap that causes hover to disappear */
 	content: '\2002\00a7\2002';
 }
 
diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs
index 4f6bda6cfe3..d70cf132b3c 100644
--- a/src/libstd/keyword_docs.rs
+++ b/src/libstd/keyword_docs.rs
@@ -56,3 +56,24 @@ mod fn_keyword { }
 ///
 /// [book]: https://doc.rust-lang.org/book/second-edition/ch03-01-variables-and-mutability.html
 mod let_keyword { }
+
+#[doc(keyword = "struct")]
+//
+/// The `struct` keyword.
+///
+/// The `struct` keyword is used to define a struct type.
+///
+/// Example:
+///
+/// ```
+/// struct Foo {
+///     field1: u32,
+///     field2: String,
+/// }
+/// ```
+///
+/// There are different kinds of structs. For more information, take a look at the
+/// [Rust Book][book].
+///
+/// [book]: https://doc.rust-lang.org/book/second-edition/ch05-01-defining-structs.html
+mod struct_keyword { }
diff --git a/src/libtest/formatters/terse.rs b/src/libtest/formatters/terse.rs
index 22a06b9f605..6f7dfee53fa 100644
--- a/src/libtest/formatters/terse.rs
+++ b/src/libtest/formatters/terse.rs
@@ -18,6 +18,7 @@ pub(crate) struct TerseFormatter<T> {
     max_name_len: usize,
 
     test_count: usize,
+    total_test_count: usize,
 }
 
 impl<T: Write> TerseFormatter<T> {
@@ -33,6 +34,7 @@ impl<T: Write> TerseFormatter<T> {
             max_name_len,
             is_multithreaded,
             test_count: 0,
+            total_test_count: 0, // initialized later, when write_run_start is called
         }
     }
 
@@ -66,7 +68,8 @@ impl<T: Write> TerseFormatter<T> {
             // we insert a new line every 100 dots in order to flush the
             // screen when dealing with line-buffered output (e.g. piping to
             // `stamp` in the rust CI).
-            self.write_plain("\n")?;
+            let out = format!(" {}/{}\n", self.test_count+1, self.total_test_count);
+            self.write_plain(&out)?;
         }
 
         self.test_count += 1;
@@ -160,6 +163,7 @@ impl<T: Write> TerseFormatter<T> {
 
 impl<T: Write> OutputFormatter for TerseFormatter<T> {
     fn write_run_start(&mut self, test_count: usize) -> io::Result<()> {
+        self.total_test_count = test_count;
         let noun = if test_count != 1 { "tests" } else { "test" };
         self.write_plain(&format!("\nrunning {} {}\n", test_count, noun))
     }