@@ -252,6 +252,7 @@ pub(crate) fn rewrite_with_parens<'a, T: 'a + IntoOverflowableItem<'a>>(
252252 span : Span ,
253253 item_max_width : usize ,
254254 force_separator_tactic : Option < SeparatorTactic > ,
255+ force_list_tactic : Option < ListTactic > ,
255256) -> Option < String > {
256257 Context :: new (
257258 context,
@@ -263,6 +264,7 @@ pub(crate) fn rewrite_with_parens<'a, T: 'a + IntoOverflowableItem<'a>>(
263264 ")" ,
264265 item_max_width,
265266 force_separator_tactic,
267+ force_list_tactic,
266268 None ,
267269 )
268270 . rewrite ( shape)
@@ -286,6 +288,7 @@ pub(crate) fn rewrite_with_angle_brackets<'a, T: 'a + IntoOverflowableItem<'a>>(
286288 context. config . max_width ( ) ,
287289 None ,
288290 None ,
291+ None ,
289292 )
290293 . rewrite ( shape)
291294}
@@ -314,6 +317,7 @@ pub(crate) fn rewrite_with_square_brackets<'a, T: 'a + IntoOverflowableItem<'a>>
314317 rhs,
315318 context. config . array_width ( ) ,
316319 force_separator_tactic,
320+ None ,
317321 Some ( ( "[" , "]" ) ) ,
318322 )
319323 . rewrite ( shape)
@@ -331,6 +335,7 @@ struct Context<'a> {
331335 item_max_width : usize ,
332336 one_line_width : usize ,
333337 force_separator_tactic : Option < SeparatorTactic > ,
338+ force_list_tactic : Option < ListTactic > ,
334339 custom_delims : Option < ( & ' a str , & ' a str ) > ,
335340}
336341
@@ -345,6 +350,7 @@ impl<'a> Context<'a> {
345350 suffix : & ' static str ,
346351 item_max_width : usize ,
347352 force_separator_tactic : Option < SeparatorTactic > ,
353+ force_list_tactic : Option < ListTactic > ,
348354 custom_delims : Option < ( & ' a str , & ' a str ) > ,
349355 ) -> Context < ' a > {
350356 let used_width = extra_offset ( ident, shape) ;
@@ -369,6 +375,7 @@ impl<'a> Context<'a> {
369375 item_max_width,
370376 one_line_width,
371377 force_separator_tactic,
378+ force_list_tactic,
372379 custom_delims,
373380 }
374381 }
@@ -493,6 +500,8 @@ impl<'a> Context<'a> {
493500 None
494501 } ;
495502
503+ let simple_expr = is_every_expr_simple ( & self . items ) ;
504+
496505 let mut tactic = definitive_tactic (
497506 & * list_items,
498507 ListTactic :: LimitedHorizontalVertical ( self . item_max_width ) ,
@@ -570,7 +579,7 @@ impl<'a> Context<'a> {
570579 if one_line {
571580 tactic = DefinitiveListTactic :: SpecialMacro ( num_args_before) ;
572581 } ;
573- } else if is_every_expr_simple ( & self . items )
582+ } else if simple_expr
574583 && no_long_items (
575584 list_items,
576585 self . context . config . short_array_element_width_threshold ( ) ,
@@ -584,6 +593,23 @@ impl<'a> Context<'a> {
584593 _ => ( ) ,
585594 }
586595
596+ match self . force_list_tactic {
597+ Some ( list_tactic) if list_tactic == ListTactic :: Mixed && simple_expr => {
598+ if tactic != DefinitiveListTactic :: Horizontal {
599+ tactic = DefinitiveListTactic :: Mixed
600+ }
601+ }
602+ Some ( list_tactic) if list_tactic != ListTactic :: Mixed => {
603+ tactic = definitive_tactic (
604+ & * list_items,
605+ list_tactic,
606+ Separator :: Comma ,
607+ self . one_line_width ,
608+ )
609+ }
610+ _ => { }
611+ } ;
612+
587613 tactic
588614 }
589615
0 commit comments