@@ -5,8 +5,8 @@ use rustc_ast::ptr;
5
5
use rustc_span:: { BytePos , Span } ;
6
6
7
7
use crate :: comment:: { combine_strs_with_missing_comments, FindUncommented } ;
8
- use crate :: config:: lists:: * ;
9
8
use crate :: config:: Version ;
9
+ use crate :: config:: { lists:: * , IndentStyle } ;
10
10
use crate :: expr:: { can_be_overflowed_expr, rewrite_unary_prefix, wrap_struct_field} ;
11
11
use crate :: lists:: {
12
12
definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
@@ -365,9 +365,25 @@ fn rewrite_struct_pat(
365
365
// code ignored it and directly uses the tactic for the fields.
366
366
let tactic = if ellipsis {
367
367
let field_item_vec = & item_vec[ ..item_vec. len ( ) - 1 ] ;
368
- let field_tactic = struct_lit_tactic ( h_shape, context, field_item_vec) ;
369
- let rest_item_vec = & item_vec[ item_vec. len ( ) - 1 ..] ;
370
- let rest_tactic = struct_lit_tactic ( h_shape, context, rest_item_vec) ;
368
+ let mut field_tactic = struct_lit_tactic ( h_shape, context, field_item_vec) ;
369
+ let rest_item_vec = & item_vec[ item_vec. len ( ) - 1 ..] ;
370
+ let mut rest_tactic = struct_lit_tactic ( h_shape, context, rest_item_vec) ;
371
+
372
+ if !( context. config . struct_lit_single_line ( )
373
+ || context. config . indent_style ( ) == IndentStyle :: Visual && field_item_vec. len ( ) == 1 )
374
+ {
375
+ // FIXME: Figure out the exact behavior of mixed tactic. The old
376
+ // produces mixed tactic by ignoring the `..` when determining the
377
+ // tactic. See #5066 for an example.
378
+ let nested_shape = shape_for_tactic ( field_tactic, h_shape, v_shape) ;
379
+ let fmt = struct_lit_formatting ( nested_shape, field_tactic, context, false ) ;
380
+ let fields_str = write_list ( field_item_vec, & fmt) ?;
381
+ if !( fields_str. contains ( '\n' ) || fields_str. len ( ) > one_line_width) {
382
+ field_tactic = DefinitiveListTactic :: Horizontal ;
383
+ rest_tactic = DefinitiveListTactic :: Horizontal ;
384
+ }
385
+ }
386
+
371
387
match ( field_tactic, rest_tactic) {
372
388
( DefinitiveListTactic :: Vertical , _) | ( _, DefinitiveListTactic :: Vertical ) => {
373
389
DefinitiveListTactic :: Vertical
0 commit comments