@@ -1822,9 +1822,17 @@ impl Rewrite for ast::FunctionRetTy {
1822
1822
match * self {
1823
1823
ast:: FunctionRetTy :: Default ( _) => Some ( String :: new ( ) ) ,
1824
1824
ast:: FunctionRetTy :: Ty ( ref ty) => {
1825
- let inner_width = shape. width . checked_sub ( 3 ) ?;
1826
- ty. rewrite ( context, Shape :: legacy ( inner_width, shape. indent + 3 ) )
1827
- . map ( |r| format ! ( "-> {}" , r) )
1825
+ if context. config . version ( ) == Version :: One
1826
+ || context. config . indent_style ( ) == IndentStyle :: Visual
1827
+ {
1828
+ let inner_width = shape. width . checked_sub ( 3 ) ?;
1829
+ return ty
1830
+ . rewrite ( context, Shape :: legacy ( inner_width, shape. indent + 3 ) )
1831
+ . map ( |r| format ! ( "-> {}" , r) ) ;
1832
+ }
1833
+
1834
+ ty. rewrite ( context, shape. offset_left ( 3 ) ?)
1835
+ . map ( |s| format ! ( "-> {}" , s) )
1828
1836
}
1829
1837
}
1830
1838
}
@@ -2147,20 +2155,39 @@ fn rewrite_fn_base(
2147
2155
sig_length > context. config . max_width ( )
2148
2156
}
2149
2157
} ;
2150
- let ret_indent = if ret_should_indent {
2151
- let indent = if arg_str. is_empty ( ) {
2152
- // Aligning with non-existent args looks silly.
2153
- force_new_line_for_brace = true ;
2154
- indent + 4
2158
+ let ret_shape = if ret_should_indent {
2159
+ if context. config . version ( ) == Version :: One
2160
+ || context. config . indent_style ( ) == IndentStyle :: Visual
2161
+ {
2162
+ let indent = if arg_str. is_empty ( ) {
2163
+ // Aligning with non-existent args looks silly.
2164
+ force_new_line_for_brace = true ;
2165
+ indent + 4
2166
+ } else {
2167
+ // FIXME: we might want to check that using the arg indent
2168
+ // doesn't blow our budget, and if it does, then fallback to
2169
+ // the where-clause indent.
2170
+ arg_indent
2171
+ } ;
2172
+
2173
+ result. push_str ( & indent. to_string_with_newline ( context. config ) ) ;
2174
+ Shape :: indented ( indent, context. config )
2155
2175
} else {
2156
- // FIXME: we might want to check that using the arg indent
2157
- // doesn't blow our budget, and if it does, then fallback to
2158
- // the where-clause indent.
2159
- arg_indent
2160
- } ;
2176
+ let mut ret_shape = Shape :: indented ( indent, context. config ) ;
2177
+ if arg_str. is_empty ( ) {
2178
+ // Aligning with non-existent args looks silly.
2179
+ force_new_line_for_brace = true ;
2180
+ ret_shape = if context. use_block_indent ( ) {
2181
+ ret_shape. offset_left ( 4 ) . unwrap_or ( ret_shape)
2182
+ } else {
2183
+ ret_shape. indent = ret_shape. indent + 4 ;
2184
+ ret_shape
2185
+ } ;
2186
+ }
2161
2187
2162
- result. push_str ( & indent. to_string_with_newline ( context. config ) ) ;
2163
- indent
2188
+ result. push_str ( & ret_shape. indent . to_string_with_newline ( context. config ) ) ;
2189
+ ret_shape
2190
+ }
2164
2191
} else {
2165
2192
if context. config . version ( ) == Version :: Two {
2166
2193
if !arg_str. is_empty ( ) || !no_args_and_over_max_width {
@@ -2170,15 +2197,16 @@ fn rewrite_fn_base(
2170
2197
result. push ( ' ' ) ;
2171
2198
}
2172
2199
2173
- Indent :: new ( indent. block_indent , last_line_width ( & result) )
2200
+ let ret_shape = Shape :: indented ( indent, context. config ) ;
2201
+ ret_shape
2202
+ . offset_left ( last_line_width ( & result) )
2203
+ . unwrap_or ( ret_shape)
2174
2204
} ;
2175
2205
2176
2206
if multi_line_ret_str || ret_should_indent {
2177
2207
// Now that we know the proper indent and width, we need to
2178
2208
// re-layout the return type.
2179
- let ret_str = fd
2180
- . output
2181
- . rewrite ( context, Shape :: indented ( ret_indent, context. config ) ) ?;
2209
+ let ret_str = fd. output . rewrite ( context, ret_shape) ?;
2182
2210
result. push_str ( & ret_str) ;
2183
2211
} else {
2184
2212
result. push_str ( & ret_str) ;
0 commit comments