@@ -1822,9 +1822,17 @@ impl Rewrite for ast::FunctionRetTy {
18221822 match * self {
18231823 ast:: FunctionRetTy :: Default ( _) => Some ( String :: new ( ) ) ,
18241824 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) )
18281836 }
18291837 }
18301838 }
@@ -2147,20 +2155,39 @@ fn rewrite_fn_base(
21472155 sig_length > context. config . max_width ( )
21482156 }
21492157 } ;
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 )
21552175 } 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+ }
21612187
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+ }
21642191 } else {
21652192 if context. config . version ( ) == Version :: Two {
21662193 if !arg_str. is_empty ( ) || !no_args_and_over_max_width {
@@ -2170,15 +2197,16 @@ fn rewrite_fn_base(
21702197 result. push ( ' ' ) ;
21712198 }
21722199
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)
21742204 } ;
21752205
21762206 if multi_line_ret_str || ret_should_indent {
21772207 // Now that we know the proper indent and width, we need to
21782208 // 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) ?;
21822210 result. push_str ( & ret_str) ;
21832211 } else {
21842212 result. push_str ( & ret_str) ;
0 commit comments