Skip to content

Commit 959a13d

Browse files
committed
Updated wording and placement of non-exhaustive notice so it is collapsed by default and easier to understand.
1 parent d0d33a0 commit 959a13d

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

src/librustdoc/html/render.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -2268,24 +2268,26 @@ fn document_non_exhaustive_header(item: &clean::Item) -> &str {
22682268

22692269
fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
22702270
if item.is_non_exhaustive() {
2271-
write!(w, "<p class='non-exhaustive'>")?;
2271+
write!(w, "<div class='docblock non-exhaustive non-exhaustive-{}'>", {
2272+
if item.is_struct() { "struct" } else if item.is_enum() { "enum" } else { "type" }
2273+
})?;
22722274

22732275
if item.is_struct() {
2274-
write!(w, "This struct is marked as non-exhaustive as additional fields may be \
2275-
added in the future. This means that this struct cannot be constructed in \
2276-
external crates using the traditional <code>Struct {{ .. }}</code> syntax;
2277-
cannot be matched against without a wildcard <code>..</code>; and \
2278-
functional-record-updates do not work on this struct.")?;
2276+
write!(w, "Non-exhaustive structs could have additional fields added in future. \
2277+
Therefore, non-exhaustive structs cannot be constructed in external crates \
2278+
using the traditional <code>Struct {{ .. }}</code> syntax; cannot be \
2279+
matched against without a wildcard <code>..</code>; and \
2280+
functional-record-updates do not work.")?;
22792281
} else if item.is_enum() {
2280-
write!(w, "This enum is marked as non-exhaustive, and additional variants may be \
2281-
added in the future. When matching over values of this type, an extra \
2282-
<code>_</code> arm must be added to account for future extensions.")?;
2282+
write!(w, "Non-exhaustive enums could have additional variants added in future. \
2283+
Therefore, when matching against variants of non-exhaustive enums, an \
2284+
extra wildcard arm must be added to account for any future variants.")?;
22832285
} else {
22842286
write!(w, "This type will require a wildcard arm in any match statements or \
22852287
constructors.")?;
22862288
}
22872289

2288-
write!(w, "</p>")?;
2290+
write!(w, "</div>")?;
22892291
}
22902292

22912293
Ok(())

src/librustdoc/html/static/main.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -1993,15 +1993,18 @@
19931993
onEach(e.getElementsByClassName('associatedconstant'), func);
19941994
});
19951995

1996-
function createToggle(otherMessage, extraClass) {
1996+
function createToggle(otherMessage, fontSize, extraClass) {
19971997
var span = document.createElement('span');
19981998
span.className = 'toggle-label';
19991999
span.style.display = 'none';
20002000
if (!otherMessage) {
20012001
span.innerHTML = '&nbsp;Expand&nbsp;description';
20022002
} else {
20032003
span.innerHTML = otherMessage;
2004-
span.style.fontSize = '20px';
2004+
}
2005+
2006+
if (fontSize) {
2007+
span.style.fontSize = fontSize;
20052008
}
20062009

20072010
var mainToggle = toggle.cloneNode(true);
@@ -2040,13 +2043,27 @@
20402043
}
20412044
if (e.parentNode.id === "main") {
20422045
var otherMessage;
2046+
var fontSize;
20432047
var extraClass;
2048+
20442049
if (hasClass(e, "type-decl")) {
2050+
fontSize = "20px";
20452051
otherMessage = '&nbsp;Show&nbsp;declaration';
2052+
} else if (hasClass(e, "non-exhaustive")) {
2053+
otherMessage = '&nbsp;This&nbsp;';
2054+
if (hasClass(e, "non-exhaustive-struct")) {
2055+
otherMessage += 'struct';
2056+
} else if (hasClass(e, "non-exhaustive-enum")) {
2057+
otherMessage += 'enum';
2058+
} else if (hasClass(e, "non-exhaustive-type")) {
2059+
otherMessage += 'type';
2060+
}
2061+
otherMessage += '&nbsp;is&nbsp;marked&nbsp;as&nbsp;non-exhaustive';
20462062
} else if (hasClass(e.childNodes[0], "impl-items")) {
20472063
extraClass = "marg-left";
20482064
}
2049-
e.parentNode.insertBefore(createToggle(otherMessage, extraClass), e);
2065+
2066+
e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass), e);
20502067
if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") {
20512068
collapseDocs(e.previousSibling.childNodes[0], "toggle");
20522069
}

src/librustdoc/html/static/rustdoc.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -1358,4 +1358,8 @@ kbd {
13581358
}
13591359
#all-types > p {
13601360
margin: 5px 0;
1361-
}
1361+
}
1362+
1363+
.non-exhaustive {
1364+
margin-bottom: 1em;
1365+
}

src/librustdoc/html/static/themes/dark.css

-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ pre {
148148
.content .fnname{ color: #2BAB63; }
149149
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; }
150150

151-
.non-exhaustive { color: #DDD; margin-bottom: 1em; }
152-
153151
pre.rust .comment { color: #8d8d8b; }
154152
pre.rust .doccomment { color: #8ca375; }
155153

src/librustdoc/html/static/themes/light.css

-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ pre {
148148
.content .fnname { color: #9a6e31; }
149149
.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; }
150150

151-
.non-exhaustive { color: #222; margin-bottom: 1em; }
152-
153151
pre.rust .comment { color: #8E908C; }
154152
pre.rust .doccomment { color: #4D4D4C; }
155153

0 commit comments

Comments
 (0)