From 110e7270ab7b0700ce714b8b1c7e509195dea2c4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 4 Aug 2018 00:02:46 +0200 Subject: [PATCH 1/8] Improve unstable message display --- src/librustdoc/html/static/rustdoc.css | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index b689e2fa3854e..db2509abc8e64 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -500,6 +500,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; From 67b7b2aa11bf32359756c75da721f1ad26f49403 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 16 Aug 2018 15:19:50 +0200 Subject: [PATCH 2/8] libtest terse format: show how far in we are --- src/libtest/formatters/terse.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libtest/formatters/terse.rs b/src/libtest/formatters/terse.rs index 22a06b9f605db..5b6b8ead4ef60 100644 --- a/src/libtest/formatters/terse.rs +++ b/src/libtest/formatters/terse.rs @@ -18,6 +18,7 @@ pub(crate) struct TerseFormatter { max_name_len: usize, test_count: usize, + total_test_count: usize, } impl TerseFormatter { @@ -33,6 +34,7 @@ impl TerseFormatter { max_name_len, is_multithreaded, test_count: 0, + total_test_count: 0, } } @@ -66,7 +68,8 @@ impl TerseFormatter { // 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 TerseFormatter { impl OutputFormatter for TerseFormatter { 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)) } From ffbb4078015ea0153e04991efa5565524cba0a8f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 20 Aug 2018 22:03:10 +0200 Subject: [PATCH 3/8] comment --- src/libtest/formatters/terse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtest/formatters/terse.rs b/src/libtest/formatters/terse.rs index 5b6b8ead4ef60..6f7dfee53facc 100644 --- a/src/libtest/formatters/terse.rs +++ b/src/libtest/formatters/terse.rs @@ -34,7 +34,7 @@ impl TerseFormatter { max_name_len, is_multithreaded, test_count: 0, - total_test_count: 0, + total_test_count: 0, // initialized later, when write_run_start is called } } From 917cdd295d2eed213c135d6f984c650f016ee3d6 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Thu, 23 Aug 2018 00:43:06 -0700 Subject: [PATCH 4/8] Automatically expand a section even after page load Fixes #52774 --- src/librustdoc/html/static/main.js | 48 ++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 70782973e426d..a5c93bc8230ee 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -223,8 +223,38 @@ } } } + + function expandSection() { + var hash = getPageId(); + if (hash === null) { + return; + } + + var elem = document.getElementById(hash); + if (elem && isHidden(elem.offsetParent)) { + var h3 = elem.parentNode.previousSibling; + + if (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"); + } + } + } + } + + function onHashChange(ev) { + highlightSourceLines(ev); + expandSection(); + } + highlightSourceLines(null); - window.onhashchange = highlightSourceLines; + window.onhashchange = onHashChange; // Gets the human-readable string for the virtual-key code of the // given KeyboardEvent, ev. @@ -2213,21 +2243,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(); } }()); From 1f441a0905700e6fa5cad76097afba52a8775435 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Thu, 23 Aug 2018 08:14:54 -0700 Subject: [PATCH 5/8] Check null-able variables before using them --- src/librustdoc/html/static/main.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index a5c93bc8230ee..7c0f58f4ee685 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -231,10 +231,9 @@ } var elem = document.getElementById(hash); - if (elem && isHidden(elem.offsetParent)) { + if (elem && elem.offsetParent && isHidden(elem.offsetParent)) { var h3 = elem.parentNode.previousSibling; - - if (h3.tagName !== 'H3') { + if (h3 && h3.tagName !== 'H3') { h3 = h3.previousSibling; // skip div.docblock } From 61fc7f18c3f3fed492ec117d25e9bcc3c5b52217 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 23 Aug 2018 23:50:05 +0200 Subject: [PATCH 6/8] Add struct keyword doc --- src/libstd/keyword_docs.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs index 4f6bda6cfe379..d70cf132b3c3a 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 { } From 2c61f3ce9e82fa5eb0cb780400b8d95cd5a76571 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Sat, 25 Aug 2018 03:34:04 -0700 Subject: [PATCH 7/8] Expand a collapsed element on onclick Doing the expansion on onhashchange seems too late. Fixes #48726 --- src/librustdoc/html/static/main.js | 37 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 7c0f58f4ee685..e994c85c7ec4b 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -224,14 +224,9 @@ } } - function expandSection() { - var hash = getPageId(); - if (hash === null) { - return; - } - - var elem = document.getElementById(hash); - if (elem && elem.offsetParent && isHidden(elem.offsetParent)) { + 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 @@ -247,13 +242,7 @@ } } - function onHashChange(ev) { - highlightSourceLines(ev); - expandSection(); - } - - highlightSourceLines(null); - window.onhashchange = onHashChange; + window.onhashchange = highlightSourceLines; // Gets the human-readable string for the virtual-key code of the // given KeyboardEvent, ev. @@ -346,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) { @@ -383,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(/^#/, '')); + } } }; @@ -2242,7 +2247,7 @@ autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true"); if (window.location.hash && window.location.hash.length > 0) { - expandSection(); + expandSection(window.location.hash.replace(/^#/, '')); } }()); From 1c888d51f997cc9358ce4d3e09bf7cbf8e5bdae3 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 25 Aug 2018 14:15:49 -0700 Subject: [PATCH 8/8] rustdoc: Fix gap on section anchor symbol when hovering. Fixes #49485 for section headings. --- src/librustdoc/html/static/rustdoc.css | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 57a111daa8977..2e7fd22105c55 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -545,10 +545,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 +743,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'; }