Updated wording and placement of non-exhaustive notice so it is collapsed by default and easier to understand.

This commit is contained in:
David Wood 2018-07-18 20:27:25 +01:00
parent d0d33a0335
commit 959a13d53e
No known key found for this signature in database
GPG Key ID: 01760B4F9F53F154
5 changed files with 37 additions and 18 deletions

View File

@ -2268,24 +2268,26 @@ fn document_non_exhaustive_header(item: &clean::Item) -> &str {
fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result { fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
if item.is_non_exhaustive() { if item.is_non_exhaustive() {
write!(w, "<p class='non-exhaustive'>")?; write!(w, "<div class='docblock non-exhaustive non-exhaustive-{}'>", {
if item.is_struct() { "struct" } else if item.is_enum() { "enum" } else { "type" }
})?;
if item.is_struct() { if item.is_struct() {
write!(w, "This struct is marked as non-exhaustive as additional fields may be \ write!(w, "Non-exhaustive structs could have additional fields added in future. \
added in the future. This means that this struct cannot be constructed in \ Therefore, non-exhaustive structs cannot be constructed in external crates \
external crates using the traditional <code>Struct {{ .. }}</code> syntax; using the traditional <code>Struct {{ .. }}</code> syntax; cannot be \
cannot be matched against without a wildcard <code>..</code>; and \ matched against without a wildcard <code>..</code>; and \
functional-record-updates do not work on this struct.")?; functional-record-updates do not work.")?;
} else if item.is_enum() { } else if item.is_enum() {
write!(w, "This enum is marked as non-exhaustive, and additional variants may be \ write!(w, "Non-exhaustive enums could have additional variants added in future. \
added in the future. When matching over values of this type, an extra \ Therefore, when matching against variants of non-exhaustive enums, an \
<code>_</code> arm must be added to account for future extensions.")?; extra wildcard arm must be added to account for any future variants.")?;
} else { } else {
write!(w, "This type will require a wildcard arm in any match statements or \ write!(w, "This type will require a wildcard arm in any match statements or \
constructors.")?; constructors.")?;
} }
write!(w, "</p>")?; write!(w, "</div>")?;
} }
Ok(()) Ok(())

View File

@ -1993,7 +1993,7 @@
onEach(e.getElementsByClassName('associatedconstant'), func); onEach(e.getElementsByClassName('associatedconstant'), func);
}); });
function createToggle(otherMessage, extraClass) { function createToggle(otherMessage, fontSize, extraClass) {
var span = document.createElement('span'); var span = document.createElement('span');
span.className = 'toggle-label'; span.className = 'toggle-label';
span.style.display = 'none'; span.style.display = 'none';
@ -2001,7 +2001,10 @@
span.innerHTML = '&nbsp;Expand&nbsp;description'; span.innerHTML = '&nbsp;Expand&nbsp;description';
} else { } else {
span.innerHTML = otherMessage; span.innerHTML = otherMessage;
span.style.fontSize = '20px'; }
if (fontSize) {
span.style.fontSize = fontSize;
} }
var mainToggle = toggle.cloneNode(true); var mainToggle = toggle.cloneNode(true);
@ -2040,13 +2043,27 @@
} }
if (e.parentNode.id === "main") { if (e.parentNode.id === "main") {
var otherMessage; var otherMessage;
var fontSize;
var extraClass; var extraClass;
if (hasClass(e, "type-decl")) { if (hasClass(e, "type-decl")) {
fontSize = "20px";
otherMessage = '&nbsp;Show&nbsp;declaration'; otherMessage = '&nbsp;Show&nbsp;declaration';
} else if (hasClass(e, "non-exhaustive")) {
otherMessage = '&nbsp;This&nbsp;';
if (hasClass(e, "non-exhaustive-struct")) {
otherMessage += 'struct';
} else if (hasClass(e, "non-exhaustive-enum")) {
otherMessage += 'enum';
} else if (hasClass(e, "non-exhaustive-type")) {
otherMessage += 'type';
}
otherMessage += '&nbsp;is&nbsp;marked&nbsp;as&nbsp;non-exhaustive';
} else if (hasClass(e.childNodes[0], "impl-items")) { } else if (hasClass(e.childNodes[0], "impl-items")) {
extraClass = "marg-left"; extraClass = "marg-left";
} }
e.parentNode.insertBefore(createToggle(otherMessage, extraClass), e);
e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass), e);
if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") { if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") {
collapseDocs(e.previousSibling.childNodes[0], "toggle"); collapseDocs(e.previousSibling.childNodes[0], "toggle");
} }

View File

@ -1358,4 +1358,8 @@ kbd {
} }
#all-types > p { #all-types > p {
margin: 5px 0; margin: 5px 0;
} }
.non-exhaustive {
margin-bottom: 1em;
}

View File

@ -148,8 +148,6 @@ pre {
.content .fnname{ color: #2BAB63; } .content .fnname{ color: #2BAB63; }
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; } .content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; }
.non-exhaustive { color: #DDD; margin-bottom: 1em; }
pre.rust .comment { color: #8d8d8b; } pre.rust .comment { color: #8d8d8b; }
pre.rust .doccomment { color: #8ca375; } pre.rust .doccomment { color: #8ca375; }

View File

@ -148,8 +148,6 @@ pre {
.content .fnname { color: #9a6e31; } .content .fnname { color: #9a6e31; }
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; } .content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; }
.non-exhaustive { color: #222; margin-bottom: 1em; }
pre.rust .comment { color: #8E908C; } pre.rust .comment { color: #8E908C; }
pre.rust .doccomment { color: #4D4D4C; } pre.rust .doccomment { color: #4D4D4C; }