@@ -324,21 +324,68 @@ impl<'a> fmt::Display for Html<'a> {
324
324
325
325
Cfg :: Any ( ref sub_cfgs) => {
326
326
let separator = if sub_cfgs. iter ( ) . all ( Cfg :: is_simple) { " or " } else { ", or " } ;
327
+
328
+ let short_longhand = !self . 1 && {
329
+ let all_crate_features = sub_cfgs
330
+ . iter ( )
331
+ . all ( |sub_cfg| matches ! ( sub_cfg, Cfg :: Cfg ( sym:: feature, Some ( _) ) ) ) ;
332
+ let all_target_features = sub_cfgs
333
+ . iter ( )
334
+ . all ( |sub_cfg| matches ! ( sub_cfg, Cfg :: Cfg ( sym:: target_feature, Some ( _) ) ) ) ;
335
+
336
+ if all_crate_features {
337
+ fmt. write_str ( "crate features " ) ?;
338
+ true
339
+ } else if all_target_features {
340
+ fmt. write_str ( "target features " ) ?;
341
+ true
342
+ } else {
343
+ false
344
+ }
345
+ } ;
346
+
327
347
for ( i, sub_cfg) in sub_cfgs. iter ( ) . enumerate ( ) {
328
348
if i != 0 {
329
349
fmt. write_str ( separator) ?;
330
350
}
331
- write_with_opt_paren ( fmt, !sub_cfg. is_all ( ) , Html ( sub_cfg, self . 1 ) ) ?;
351
+ if let ( true , Cfg :: Cfg ( _, Some ( feat) ) ) = ( short_longhand, sub_cfg) {
352
+ write ! ( fmt, "<code>{}</code>" , feat) ?;
353
+ } else {
354
+ write_with_opt_paren ( fmt, !sub_cfg. is_all ( ) , Html ( sub_cfg, self . 1 ) ) ?;
355
+ }
332
356
}
333
357
Ok ( ( ) )
334
358
}
335
359
336
360
Cfg :: All ( ref sub_cfgs) => {
361
+ let short_longhand = !self . 1 && {
362
+ let all_crate_features = sub_cfgs
363
+ . iter ( )
364
+ . all ( |sub_cfg| matches ! ( sub_cfg, Cfg :: Cfg ( sym:: feature, Some ( _) ) ) ) ;
365
+ let all_target_features = sub_cfgs
366
+ . iter ( )
367
+ . all ( |sub_cfg| matches ! ( sub_cfg, Cfg :: Cfg ( sym:: target_feature, Some ( _) ) ) ) ;
368
+
369
+ if all_crate_features {
370
+ fmt. write_str ( "crate features " ) ?;
371
+ true
372
+ } else if all_target_features {
373
+ fmt. write_str ( "target features " ) ?;
374
+ true
375
+ } else {
376
+ false
377
+ }
378
+ } ;
379
+
337
380
for ( i, sub_cfg) in sub_cfgs. iter ( ) . enumerate ( ) {
338
381
if i != 0 {
339
382
fmt. write_str ( " and " ) ?;
340
383
}
341
- write_with_opt_paren ( fmt, !sub_cfg. is_simple ( ) , Html ( sub_cfg, self . 1 ) ) ?;
384
+ if let ( true , Cfg :: Cfg ( _, Some ( feat) ) ) = ( short_longhand, sub_cfg) {
385
+ write ! ( fmt, "<code>{}</code>" , feat) ?;
386
+ } else {
387
+ write_with_opt_paren ( fmt, !sub_cfg. is_simple ( ) , Html ( sub_cfg, self . 1 ) ) ?;
388
+ }
342
389
}
343
390
Ok ( ( ) )
344
391
}
0 commit comments