1
Fork 0

Display #[non_exhaustive] in rustdoc on types.

This commit is contained in:
David Wood 2018-06-27 20:50:59 +01:00
parent ed0350e945
commit a074bd7334
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
8 changed files with 75 additions and 3 deletions

View file

@ -2194,6 +2194,7 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re
info!("Documenting {}", name);
}
document_stability(w, cx, item)?;
document_non_exhaustive(w, item)?;
let prefix = render_assoc_const_value(item);
document_full(w, item, cx, &prefix)?;
Ok(())
@ -2262,6 +2263,28 @@ fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item)
Ok(())
}
fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
if item.non_exhaustive {
write!(w, r##"
<div class='non-exhaustive'>
<div class='stab non-exhaustive'>
<details>
<summary>
<span class=microscope>🔬</span>
This type is marked as non exhaustive.
</summary>
<p>
This type will require a wildcard arm in any match statements or constructors.
</p>
</details>
</div>
</div>
"##)?;
}
Ok(())
}
fn name_key(name: &str) -> (&str, u64, usize) {
// find number at end
let split = name.bytes().rposition(|b| b < b'0' || b'9' < b).map_or(0, |s| s + 1);