@@ -3,7 +3,7 @@ use rustc_span::Span;
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 } ;
@@ -253,9 +253,16 @@ fn rewrite_closure_fn_decl(
253253 . shrink_left ( immovable. len ( ) + is_async. len ( ) + mover. len ( ) ) ?
254254 . sub_width ( 4 ) ?;
255255
256+ let indent_style = context. config . indent_style ( ) ;
257+
256258 // 1 = |
257259 let param_offset = nested_shape. indent + 1 ;
258- let param_shape = nested_shape. offset_left ( 1 ) ?. visual_indent ( 0 ) ;
260+ let param_shape = match indent_style {
261+ IndentStyle :: Block => {
262+ Shape :: indented ( shape. indent . block_indent ( context. config ) , context. config )
263+ }
264+ IndentStyle :: Visual => nested_shape. offset_left ( 1 ) ?. visual_indent ( 0 ) ,
265+ } ;
259266 let ret_str = fn_decl. output . rewrite ( context, param_shape) ?;
260267
261268 let param_items = itemize_list (
@@ -288,10 +295,31 @@ fn rewrite_closure_fn_decl(
288295 . tactic ( tactic)
289296 . preserve_newline ( true ) ;
290297 let list_str = write_list ( & item_vec, & fmt) ?;
291- let mut prefix = format ! ( "{}{}{}|{}|" , immovable, is_async, mover, list_str) ;
298+ let one_line_budget = context. budget ( param_shape. indent . width ( ) ) ;
299+ let multi_line_params = match indent_style {
300+ IndentStyle :: Block => list_str. contains ( '\n' ) || list_str. len ( ) > one_line_budget,
301+ _ => false ,
302+ } ;
303+ let put_params_in_block = multi_line_params && !item_vec. is_empty ( ) ;
304+ let param_str = if put_params_in_block {
305+ let trailing_comma = match context. config . trailing_comma ( ) {
306+ SeparatorTactic :: Never => "" ,
307+ _ => "," ,
308+ } ;
309+ format ! (
310+ "{}{}{}{}" ,
311+ param_shape. indent. to_string_with_newline( context. config) ,
312+ & list_str,
313+ trailing_comma,
314+ shape. indent. to_string_with_newline( context. config)
315+ )
316+ } else {
317+ list_str
318+ } ;
319+ let mut prefix = format ! ( "{}{}{}|{}|" , immovable, is_async, mover, param_str) ;
292320
293321 if !ret_str. is_empty ( ) {
294- if prefix. contains ( '\n' ) {
322+ if prefix. contains ( '\n' ) && !put_params_in_block {
295323 prefix. push ( '\n' ) ;
296324 prefix. push_str ( & param_offset. to_string ( context. config ) ) ;
297325 } else {
0 commit comments