Skip to content

Commit 6e3cf9c

Browse files
committedAug 26, 2018
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
2 parents caed80b + f9eef71 commit 6e3cf9c

File tree

4 files changed

+77
-20
lines changed

4 files changed

+77
-20
lines changed
 

‎src/librustdoc/html/static/main.js

+36-16
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,25 @@
223223
}
224224
}
225225
}
226-
highlightSourceLines(null);
226+
227+
function expandSection(id) {
228+
var elem = document.getElementById(id);
229+
if (elem && isHidden(elem)) {
230+
var h3 = elem.parentNode.previousSibling;
231+
if (h3 && h3.tagName !== 'H3') {
232+
h3 = h3.previousSibling; // skip div.docblock
233+
}
234+
235+
if (h3) {
236+
var collapses = h3.getElementsByClassName("collapse-toggle");
237+
if (collapses.length > 0) {
238+
// The element is not visible, we need to make it appear!
239+
collapseDocs(collapses[0], "show");
240+
}
241+
}
242+
}
243+
}
244+
227245
window.onhashchange = highlightSourceLines;
228246

229247
// Gets the human-readable string for the virtual-key code of the
@@ -317,6 +335,15 @@
317335
}
318336
}
319337

338+
function findParentElement(elem, tagName) {
339+
do {
340+
if (elem && elem.tagName === tagName) {
341+
return elem;
342+
}
343+
} while (elem = elem.parentNode);
344+
return null;
345+
}
346+
320347
document.onkeypress = handleShortcut;
321348
document.onkeydown = handleShortcut;
322349
document.onclick = function(ev) {
@@ -354,6 +381,13 @@
354381
} else if (!hasClass(document.getElementById("help"), "hidden")) {
355382
addClass(document.getElementById("help"), "hidden");
356383
removeClass(document.body, "blur");
384+
} else {
385+
// Making a collapsed element visible on onhashchange seems
386+
// too late
387+
var a = findParentElement(ev.target, 'A');
388+
if (a && a.hash) {
389+
expandSection(a.hash.replace(/^#/, ''));
390+
}
357391
}
358392
};
359393

@@ -2213,21 +2247,7 @@
22132247
autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
22142248

22152249
if (window.location.hash && window.location.hash.length > 0) {
2216-
var hash = getPageId();
2217-
if (hash !== null) {
2218-
var elem = document.getElementById(hash);
2219-
if (elem && elem.offsetParent === null) {
2220-
if (elem.parentNode && elem.parentNode.previousSibling) {
2221-
var collapses = elem.parentNode
2222-
.previousSibling
2223-
.getElementsByClassName("collapse-toggle");
2224-
if (collapses.length > 0) {
2225-
// The element is not visible, we need to make it appear!
2226-
collapseDocs(collapses[0], "show");
2227-
}
2228-
}
2229-
}
2230-
}
2250+
expandSection(window.location.hash.replace(/^#/, ''));
22312251
}
22322252
}());
22332253

‎src/librustdoc/html/static/rustdoc.css

+15-3
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,19 @@ h4 > code, h3 > code, .invisible > code {
497497
font-size: 90%;
498498
}
499499

500+
.content .stability {
501+
position: relative;
502+
margin-left: 33px;
503+
margin-top: -13px;
504+
}
505+
.content .stability::before {
506+
content: '˪';
507+
font-size: 30px;
508+
position: absolute;
509+
top: -9px;
510+
left: -13px;
511+
}
512+
500513
nav {
501514
border-bottom: 1px solid;
502515
padding-bottom: 10px;
@@ -545,10 +558,8 @@ a {
545558
left: -5px;
546559
}
547560
.small-section-header > .anchor {
548-
left: -20px;
549-
}
550-
.small-section-header > .anchor:not(.field) {
551561
left: -28px;
562+
padding-right: 10px; /* avoid gap that causes hover to disappear */
552563
}
553564
.anchor:before {
554565
content: '\2002\00a7\2002';
@@ -745,6 +756,7 @@ a.test-arrow:hover{
745756
.section-header:hover a:before {
746757
position: absolute;
747758
left: -25px;
759+
padding-right: 10px; /* avoid gap that causes hover to disappear */
748760
content: '\2002\00a7\2002';
749761
}
750762

‎src/libstd/keyword_docs.rs

+21
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,24 @@ mod fn_keyword { }
5656
///
5757
/// [book]: https://doc.rust-lang.org/book/second-edition/ch03-01-variables-and-mutability.html
5858
mod let_keyword { }
59+
60+
#[doc(keyword = "struct")]
61+
//
62+
/// The `struct` keyword.
63+
///
64+
/// The `struct` keyword is used to define a struct type.
65+
///
66+
/// Example:
67+
///
68+
/// ```
69+
/// struct Foo {
70+
/// field1: u32,
71+
/// field2: String,
72+
/// }
73+
/// ```
74+
///
75+
/// There are different kinds of structs. For more information, take a look at the
76+
/// [Rust Book][book].
77+
///
78+
/// [book]: https://doc.rust-lang.org/book/second-edition/ch05-01-defining-structs.html
79+
mod struct_keyword { }

‎src/libtest/formatters/terse.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(crate) struct TerseFormatter<T> {
1818
max_name_len: usize,
1919

2020
test_count: usize,
21+
total_test_count: usize,
2122
}
2223

2324
impl<T: Write> TerseFormatter<T> {
@@ -33,6 +34,7 @@ impl<T: Write> TerseFormatter<T> {
3334
max_name_len,
3435
is_multithreaded,
3536
test_count: 0,
37+
total_test_count: 0, // initialized later, when write_run_start is called
3638
}
3739
}
3840

@@ -66,7 +68,8 @@ impl<T: Write> TerseFormatter<T> {
6668
// we insert a new line every 100 dots in order to flush the
6769
// screen when dealing with line-buffered output (e.g. piping to
6870
// `stamp` in the rust CI).
69-
self.write_plain("\n")?;
71+
let out = format!(" {}/{}\n", self.test_count+1, self.total_test_count);
72+
self.write_plain(&out)?;
7073
}
7174

7275
self.test_count += 1;
@@ -160,6 +163,7 @@ impl<T: Write> TerseFormatter<T> {
160163

161164
impl<T: Write> OutputFormatter for TerseFormatter<T> {
162165
fn write_run_start(&mut self, test_count: usize) -> io::Result<()> {
166+
self.total_test_count = test_count;
163167
let noun = if test_count != 1 { "tests" } else { "test" };
164168
self.write_plain(&format!("\nrunning {} {}\n", test_count, noun))
165169
}

0 commit comments

Comments
 (0)
Please sign in to comment.