@@ -2276,6 +2276,37 @@ fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item)
2276
2276
Ok ( ( ) )
2277
2277
}
2278
2278
2279
+ fn document_non_exhaustive_header ( item : & clean:: Item ) -> & str {
2280
+ if item. is_non_exhaustive ( ) { " (Non-exhaustive)" } else { "" }
2281
+ }
2282
+
2283
+ fn document_non_exhaustive ( w : & mut fmt:: Formatter , item : & clean:: Item ) -> fmt:: Result {
2284
+ if item. is_non_exhaustive ( ) {
2285
+ write ! ( w, "<div class='docblock non-exhaustive non-exhaustive-{}'>" , {
2286
+ if item. is_struct( ) { "struct" } else if item. is_enum( ) { "enum" } else { "type" }
2287
+ } ) ?;
2288
+
2289
+ if item. is_struct ( ) {
2290
+ write ! ( w, "Non-exhaustive structs could have additional fields added in future. \
2291
+ Therefore, non-exhaustive structs cannot be constructed in external crates \
2292
+ using the traditional <code>Struct {{ .. }}</code> syntax; cannot be \
2293
+ matched against without a wildcard <code>..</code>; and \
2294
+ struct update syntax will not work.") ?;
2295
+ } else if item. is_enum ( ) {
2296
+ write ! ( w, "Non-exhaustive enums could have additional variants added in future. \
2297
+ Therefore, when matching against variants of non-exhaustive enums, an \
2298
+ extra wildcard arm must be added to account for any future variants.") ?;
2299
+ } else {
2300
+ write ! ( w, "This type will require a wildcard arm in any match statements or \
2301
+ constructors.") ?;
2302
+ }
2303
+
2304
+ write ! ( w, "</div>" ) ?;
2305
+ }
2306
+
2307
+ Ok ( ( ) )
2308
+ }
2309
+
2279
2310
fn name_key ( name : & str ) -> ( & str , u64 , usize ) {
2280
2311
// find number at end
2281
2312
let split = name. bytes ( ) . rposition ( |b| b < b'0' || b'9' < b) . map_or ( 0 , |s| s + 1 ) ;
@@ -3136,7 +3167,9 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
3136
3167
if let doctree:: Plain = s. struct_type {
3137
3168
if fields. peek ( ) . is_some ( ) {
3138
3169
write ! ( w, "<h2 id='fields' class='fields small-section-header'>
3139
- Fields<a href='#fields' class='anchor'></a></h2>" ) ?;
3170
+ Fields{}<a href='#fields' class='anchor'></a></h2>" ,
3171
+ document_non_exhaustive_header( it) ) ?;
3172
+ document_non_exhaustive ( w, it) ?;
3140
3173
for ( field, ty) in fields {
3141
3174
let id = derive_id ( format ! ( "{}.{}" ,
3142
3175
ItemType :: StructField ,
@@ -3268,7 +3301,9 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
3268
3301
document ( w, cx, it) ?;
3269
3302
if !e. variants . is_empty ( ) {
3270
3303
write ! ( w, "<h2 id='variants' class='variants small-section-header'>
3271
- Variants<a href='#variants' class='anchor'></a></h2>\n " ) ?;
3304
+ Variants{}<a href='#variants' class='anchor'></a></h2>\n " ,
3305
+ document_non_exhaustive_header( it) ) ?;
3306
+ document_non_exhaustive ( w, it) ?;
3272
3307
for variant in & e. variants {
3273
3308
let id = derive_id ( format ! ( "{}.{}" ,
3274
3309
ItemType :: Variant ,
@@ -3369,7 +3404,8 @@ const ATTRIBUTE_WHITELIST: &'static [&'static str] = &[
3369
3404
"must_use" ,
3370
3405
"no_mangle" ,
3371
3406
"repr" ,
3372
- "unsafe_destructor_blind_to_params"
3407
+ "unsafe_destructor_blind_to_params" ,
3408
+ "non_exhaustive"
3373
3409
] ;
3374
3410
3375
3411
fn render_attributes ( w : & mut fmt:: Formatter , it : & clean:: Item ) -> fmt:: Result {
0 commit comments