@@ -324,21 +324,68 @@ impl<'a> fmt::Display for Html<'a> {
324324
325325 Cfg :: Any ( ref sub_cfgs) => {
326326 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+
327347 for ( i, sub_cfg) in sub_cfgs. iter ( ) . enumerate ( ) {
328348 if i != 0 {
329349 fmt. write_str ( separator) ?;
330350 }
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+ }
332356 }
333357 Ok ( ( ) )
334358 }
335359
336360 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+
337380 for ( i, sub_cfg) in sub_cfgs. iter ( ) . enumerate ( ) {
338381 if i != 0 {
339382 fmt. write_str ( " and " ) ?;
340383 }
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+ }
342389 }
343390 Ok ( ( ) )
344391 }
0 commit comments