diff options
| author | David Wood <david@davidtw.co> | 2018-06-30 20:03:51 +0100 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2018-06-30 20:03:51 +0100 |
| commit | 3e59aef385ef6a418f77560458012adc179ee64a (patch) | |
| tree | 28de6835062b4d730016d8cd89bfdd6a2cc18b06 | |
| parent | 039709d34f40b6602853f1627a1bc22048e1b5d3 (diff) | |
| download | rust-3e59aef385ef6a418f77560458012adc179ee64a.tar.gz rust-3e59aef385ef6a418f77560458012adc179ee64a.zip | |
Improved non_exhaustive message.
| -rw-r--r-- | src/librustdoc/html/render.rs | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 432aaac15aa..a79dad0f820 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2265,22 +2265,35 @@ fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result { if item.non_exhaustive { - let name = item.type_(); - write!(w, r##" - <div class='non-exhaustive'> - <div class='stab non-exhaustive'> - <details> - <summary> - <span class=microscope>🔬</span> - This {} is marked as non exhaustive. - </summary> - <p> - This {} will require a wildcard arm in any match statements or constructors. - </p> - </details> - </div> - </div> - "##, name, name)?; + write!(w, "<div class='non-exhaustive'><div class='stab non-exhaustive'>")?; + write!(w, "<details><summary><span class=microscope>🔬</span>")?; + + if item.is_struct() { + write!(w, "This struct is marked as non exhaustive.")?; + } else if item.is_enum() { + write!(w, "This enum is marked as non exhaustive.")?; + } else { + write!(w, "This type is marked as non exhaustive.")?; + } + + write!(w, "</summary><p>")?; + + if item.is_struct() { + write!(w, "This struct is marked as non-exhaustive as additional fields may be \ + added in the future. This means that this struct cannot be constructed in \ + external crates using the traditional <code>Struct {{ .. }}</code> syntax; + cannot be matched against without a wildcard <code>..</code>; and \ + functional-record-updates do not work on this struct.")?; + } else if item.is_enum() { + write!(w, "This enum is marked as non-exhaustive, and additional variants may be \ + added in the future. When matching over values of this type, an extra \ + <code>_</code> arm must be added to account for future extensions.")?; + } else { + write!(w, "This type will require a wildcard arm in any match statements or \ + constructors.")?; + } + + write!(w, "</p></details></div></div>")?; } Ok(()) |
