diff options
| author | David Wood <david@davidtw.co> | 2019-03-23 02:36:30 +0100 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2019-03-29 11:03:35 +0100 |
| commit | 49a6da2cda1a208838911e296fc72a6791e68406 (patch) | |
| tree | ddccdb032fd71f600e948b9082cf9734f6f473be /src/librustdoc/html | |
| parent | 18938416e4d34d7f7d64d11decd87ce47036bb75 (diff) | |
| download | rust-49a6da2cda1a208838911e296fc72a6791e68406.tar.gz rust-49a6da2cda1a208838911e296fc72a6791e68406.zip | |
Support non-exhaustive enum variants in rustdoc.
This commit adds support for non-exhaustive enum variants in rustdoc, extending the existing support for non-exhaustive enums and structs.
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/render.rs | 15 | ||||
| -rw-r--r-- | src/librustdoc/html/static/main.js | 5 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 445ce063766..982c033be99 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2596,7 +2596,15 @@ fn document_non_exhaustive_header(item: &clean::Item) -> &str { fn document_non_exhaustive(w: &mut fmt::Formatter<'_>, item: &clean::Item) -> fmt::Result { if item.is_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() { + "struct" + } else if item.is_enum() { + "enum" + } else if item.is_variant() { + "variant" + } else { + "type" + } })?; if item.is_struct() { @@ -2609,6 +2617,10 @@ fn document_non_exhaustive(w: &mut fmt::Formatter<'_>, item: &clean::Item) -> fm write!(w, "Non-exhaustive enums could have additional variants added in future. \ Therefore, when matching against variants of non-exhaustive enums, an \ extra wildcard arm must be added to account for any future variants.")?; + } else if item.is_variant() { + write!(w, "Non-exhaustive enum variants could have additional fields added in future. \ + Therefore, non-exhaustive enum variants cannot be constructed in external \ + crates and cannot be matched against.")?; } else { write!(w, "This type will require a wildcard arm in any match statements or \ constructors.")?; @@ -3671,6 +3683,7 @@ fn item_enum(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item, } write!(w, "</code></span>")?; document(w, cx, variant)?; + document_non_exhaustive(w, variant)?; use crate::clean::{Variant, VariantKind}; if let clean::VariantItem(Variant { diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index fef6910f40a..85dc4d57337 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -2247,6 +2247,8 @@ if (!DOMTokenList.prototype.remove) { otherMessage += "struct"; } else if (hasClass(e, "non-exhaustive-enum")) { otherMessage += "enum"; + } else if (hasClass(e, "non-exhaustive-variant")) { + otherMessage += "enum variant"; } else if (hasClass(e, "non-exhaustive-type")) { otherMessage += "type"; } @@ -2264,6 +2266,9 @@ if (!DOMTokenList.prototype.remove) { if (hasClass(e, "type-decl") === true && showItemDeclarations === true) { collapseDocs(e.previousSibling.childNodes[0], "toggle"); } + if (hasClass(e, "non-exhaustive") === true) { + collapseDocs(e.previousSibling.childNodes[0], "toggle"); + } } } |
