@@ -20,6 +20,7 @@ use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Symbol};
2020use  tracing:: debug; 
2121
2222use  crate :: Config ; 
23+ use  crate :: attr:: rewrite_meta_item_inner_result; 
2324use  crate :: comment:: { 
2425    CharClasses ,  FindUncommented ,  FullCodeCharKind ,  LineClasses ,  contains_comment, 
2526} ; 
@@ -1513,6 +1514,39 @@ fn format_lazy_static(
15131514    Ok ( result) 
15141515} 
15151516
1517+ fn  format_cfg_select_rule ( 
1518+     rule :  & ast:: MetaItemInner , 
1519+     context :  & RewriteContext < ' _ > , 
1520+     shape :  Shape , 
1521+     span :  Span , 
1522+ )  -> RewriteResult  { 
1523+     let  mut  result = String :: with_capacity ( 128 ) ; 
1524+ 
1525+     // The cfg plus ` => {` should stay within the line length. 
1526+     let  rule_shape = shape
1527+         . sub_width ( " => {" . len ( ) ) 
1528+         . max_width_error ( shape. width ,  span) ?; 
1529+ 
1530+     let  formatted = rewrite_meta_item_inner_result ( rule,  context,  rule_shape,  true ) ?; 
1531+     result. push_str ( & formatted) ; 
1532+ 
1533+     let  is_key_value = match  rule { 
1534+         ast:: MetaItemInner :: MetaItem ( ref  meta_item)  => { 
1535+             matches ! ( meta_item. kind,  ast:: MetaItemKind :: NameValue ( _) ) 
1536+         } 
1537+         _ => false , 
1538+     } ; 
1539+ 
1540+     if  is_key_value && formatted. contains ( '\n' )  { 
1541+         result. push_str ( & shape. indent . to_string_with_newline ( context. config ) ) ; 
1542+         result. push_str ( "=>" ) ; 
1543+     }  else  { 
1544+         result. push_str ( " =>" ) ; 
1545+     } 
1546+ 
1547+     Ok ( result) 
1548+ } 
1549+ 
15161550fn  format_cfg_select ( 
15171551    context :  & RewriteContext < ' _ > , 
15181552    shape :  Shape , 
@@ -1529,16 +1563,10 @@ fn format_cfg_select(
15291563        . block_indent ( context. config . tab_spaces ( ) ) 
15301564        . with_max_width ( context. config ) ; 
15311565
1532-     // The cfg plus ` => {` should stay within the line length. 
1533-     let  rule_shape = shape
1534-         . sub_width ( " => {" . len ( ) ) 
1535-         . max_width_error ( shape. width ,  span) ?; 
1536- 
15371566    result. push_str ( & shape. indent . to_string_with_newline ( context. config ) ) ; 
15381567
15391568    for  ( rule,  rhs,  _)  in  branches. reachable  { 
1540-         result. push_str ( & rule. rewrite_result ( context,  rule_shape) ?) ; 
1541-         result. push_str ( " =>" ) ; 
1569+         result. push_str ( & format_cfg_select_rule ( & rule,  context,  shape,  span) ?) ; 
15421570        result. push_str ( & format_cfg_select_rhs ( context,  shape,  rhs) ?) ; 
15431571    } 
15441572
@@ -1552,14 +1580,13 @@ fn format_cfg_select(
15521580
15531581        match  lhs { 
15541582            CfgSelectPredicate :: Cfg ( rule)  => { 
1555-                 result. push_str ( & rule . rewrite_result ( context,  rule_shape ) ?) ; 
1583+                 result. push_str ( & format_cfg_select_rule ( & rule ,   context,  shape ,  span ) ?) ; 
15561584            } 
15571585            CfgSelectPredicate :: Wildcard ( _)  => { 
1558-                 result. push ( '_' ) ; 
1586+                 result. push_str ( "_ =>" ) ; 
15591587            } 
15601588        } 
15611589
1562-         result. push_str ( " =>" ) ; 
15631590        result. push_str ( & format_cfg_select_rhs ( context,  shape,  rhs) ?) ; 
15641591    } 
15651592
0 commit comments