@@ -3,7 +3,7 @@ use syntax::{ast, ptr};
33
44use crate :: attr:: get_attrs_from_stmt;
55use crate :: config:: lists:: * ;
6- use crate :: config:: Version ;
6+ use crate :: config:: { IndentStyle , SeparatorTactic , Version } ;
77use crate :: expr:: { block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond} ;
88use crate :: items:: { span_hi_for_param, span_lo_for_param} ;
99use crate :: lists:: { definitive_tactic, itemize_list, write_list, ListFormatting , Separator } ;
@@ -238,9 +238,16 @@ fn rewrite_closure_fn_decl(
238238 . shrink_left ( is_async. len ( ) + mover. len ( ) + immovable. len ( ) ) ?
239239 . sub_width ( 4 ) ?;
240240
241+ let indent_style = context. config . indent_style ( ) ;
242+
241243 // 1 = |
242244 let param_offset = nested_shape. indent + 1 ;
243- let param_shape = nested_shape. offset_left ( 1 ) ?. visual_indent ( 0 ) ;
245+ let param_shape = match indent_style {
246+ IndentStyle :: Block => {
247+ Shape :: indented ( shape. indent . block_indent ( context. config ) , context. config )
248+ }
249+ IndentStyle :: Visual => nested_shape. offset_left ( 1 ) ?. visual_indent ( 0 ) ,
250+ } ;
244251 let ret_str = fn_decl. output . rewrite ( context, param_shape) ?;
245252
246253 let param_items = itemize_list (
@@ -273,10 +280,31 @@ fn rewrite_closure_fn_decl(
273280 . tactic ( tactic)
274281 . preserve_newline ( true ) ;
275282 let list_str = write_list ( & item_vec, & fmt) ?;
276- let mut prefix = format ! ( "{}{}{}|{}|" , is_async, immovable, mover, list_str) ;
283+ let one_line_budget = context. budget ( param_shape. indent . width ( ) ) ;
284+ let multi_line_params = match indent_style {
285+ IndentStyle :: Block => list_str. contains ( '\n' ) || list_str. len ( ) > one_line_budget,
286+ _ => false ,
287+ } ;
288+ let put_params_in_block = multi_line_params && !item_vec. is_empty ( ) ;
289+ let param_str = if put_params_in_block {
290+ let trailing_comma = match context. config . trailing_comma ( ) {
291+ SeparatorTactic :: Never => "" ,
292+ _ => "," ,
293+ } ;
294+ format ! (
295+ "{}{}{}{}" ,
296+ param_shape. indent. to_string_with_newline( context. config) ,
297+ & list_str,
298+ trailing_comma,
299+ shape. indent. to_string_with_newline( context. config)
300+ )
301+ } else {
302+ list_str
303+ } ;
304+ let mut prefix = format ! ( "{}{}{}|{}|" , is_async, immovable, mover, param_str) ;
277305
278306 if !ret_str. is_empty ( ) {
279- if prefix. contains ( '\n' ) {
307+ if prefix. contains ( '\n' ) && !put_params_in_block {
280308 prefix. push ( '\n' ) ;
281309 prefix. push_str ( & param_offset. to_string ( context. config ) ) ;
282310 } else {
0 commit comments