@@ -102,6 +102,7 @@ pub(crate) fn format_expr(
102
102
path,
103
103
fields,
104
104
base. as_ref ( ) . map ( |e| & * * e) ,
105
+ & expr. attrs ,
105
106
expr. span ,
106
107
shape,
107
108
) ,
@@ -1570,6 +1571,7 @@ fn rewrite_struct_lit<'a>(
1570
1571
path : & ast:: Path ,
1571
1572
fields : & ' a [ ast:: Field ] ,
1572
1573
base : Option < & ' a ast:: Expr > ,
1574
+ attrs : & [ ast:: Attribute ] ,
1573
1575
span : Span ,
1574
1576
shape : Shape ,
1575
1577
) -> Option < String > {
@@ -1664,7 +1666,8 @@ fn rewrite_struct_lit<'a>(
1664
1666
write_list ( & item_vec, & fmt) ?
1665
1667
} ;
1666
1668
1667
- let fields_str = wrap_struct_field ( context, & fields_str, shape, v_shape, one_line_width) ;
1669
+ let fields_str =
1670
+ wrap_struct_field ( context, & attrs, & fields_str, shape, v_shape, one_line_width) ?;
1668
1671
Some ( format ! ( "{} {{{}}}" , path_str, fields_str) )
1669
1672
1670
1673
// FIXME if context.config.indent_style() == Visual, but we run out
@@ -1673,25 +1676,39 @@ fn rewrite_struct_lit<'a>(
1673
1676
1674
1677
pub ( crate ) fn wrap_struct_field (
1675
1678
context : & RewriteContext < ' _ > ,
1679
+ attrs : & [ ast:: Attribute ] ,
1676
1680
fields_str : & str ,
1677
1681
shape : Shape ,
1678
1682
nested_shape : Shape ,
1679
1683
one_line_width : usize ,
1680
- ) -> String {
1681
- if context. config . indent_style ( ) == IndentStyle :: Block
1684
+ ) -> Option < String > {
1685
+ let should_vertical = context. config . indent_style ( ) == IndentStyle :: Block
1682
1686
&& ( fields_str. contains ( '\n' )
1683
1687
|| !context. config . struct_lit_single_line ( )
1684
- || fields_str. len ( ) > one_line_width)
1685
- {
1686
- format ! (
1687
- "{}{}{}" ,
1688
+ || fields_str. len ( ) > one_line_width) ;
1689
+
1690
+ let inner_attrs = & inner_attributes ( attrs) ;
1691
+ if inner_attrs. is_empty ( ) {
1692
+ if should_vertical {
1693
+ Some ( format ! (
1694
+ "{}{}{}" ,
1695
+ nested_shape. indent. to_string_with_newline( context. config) ,
1696
+ fields_str,
1697
+ shape. indent. to_string_with_newline( context. config)
1698
+ ) )
1699
+ } else {
1700
+ // One liner or visual indent.
1701
+ Some ( format ! ( " {} " , fields_str) )
1702
+ }
1703
+ } else {
1704
+ Some ( format ! (
1705
+ "{}{}{}{}{}" ,
1706
+ nested_shape. indent. to_string_with_newline( context. config) ,
1707
+ inner_attrs. rewrite( context, shape) ?,
1688
1708
nested_shape. indent. to_string_with_newline( context. config) ,
1689
1709
fields_str,
1690
1710
shape. indent. to_string_with_newline( context. config)
1691
- )
1692
- } else {
1693
- // One liner or visual indent.
1694
- format ! ( " {} " , fields_str)
1711
+ ) )
1695
1712
}
1696
1713
}
1697
1714
0 commit comments