@@ -15,9 +15,10 @@ use codemap::SpanUtils;
15
15
use utils:: { format_mutability, format_visibility, contains_skip, end_typaram, wrap_str,
16
16
last_line_width, format_unsafety, trim_newlines, stmt_expr, semicolon_for_expr,
17
17
trimmed_last_line_width, colon_spaces, mk_sp} ;
18
- use lists:: { write_list, itemize_list, definitive_tactic, ListItem , ListFormatting ,
19
- SeparatorTactic , DefinitiveListTactic , ListTactic } ;
20
- use expr:: { format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, ExprType } ;
18
+ use lists:: { write_list, itemize_list, ListItem , ListFormatting , SeparatorTactic ,
19
+ DefinitiveListTactic , ListTactic , definitive_tactic} ;
20
+ use expr:: { format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs,
21
+ rewrite_call_inner, ExprType } ;
21
22
use comment:: { FindUncommented , contains_comment, rewrite_comment, recover_comment_removed} ;
22
23
use visitor:: FmtVisitor ;
23
24
use rewrite:: { Rewrite , RewriteContext } ;
@@ -1216,91 +1217,19 @@ fn format_tuple_struct(
1216
1217
}
1217
1218
result. push ( ')' ) ;
1218
1219
} else {
1219
- let ( tactic, item_indent) = match context. config . fn_args_layout ( ) {
1220
- IndentStyle :: Visual => {
1221
- // 1 = `(`
1222
- (
1223
- ListTactic :: HorizontalVertical ,
1224
- offset. block_only ( ) + result. len ( ) + 1 ,
1225
- )
1226
- }
1227
- IndentStyle :: Block => {
1228
- (
1229
- if result. contains ( '\n' ) {
1230
- ListTactic :: Vertical
1231
- } else {
1232
- ListTactic :: HorizontalVertical
1233
- } ,
1234
- offset. block_only ( ) . block_indent ( & context. config ) ,
1235
- )
1236
- }
1237
- } ;
1238
1220
// 3 = `();`
1239
- let item_budget = try_opt ! (
1240
- context
1241
- . config
1242
- . max_width( )
1243
- . checked_sub( item_indent. width( ) + 3 )
1244
- ) ;
1245
-
1246
- let items = itemize_list (
1247
- context. codemap ,
1248
- fields. iter ( ) ,
1249
- ")" ,
1250
- |field| {
1251
- // Include attributes and doc comments, if present
1252
- if !field. attrs . is_empty ( ) {
1253
- field. attrs [ 0 ] . span . lo
1254
- } else {
1255
- field. span . lo
1256
- }
1257
- } ,
1258
- |field| field. ty . span . hi ,
1259
- |field| {
1260
- rewrite_struct_field ( context, field, Shape :: legacy ( item_budget, item_indent) , 0 )
1261
- } ,
1262
- context. codemap . span_after ( span, "(" ) ,
1263
- span. hi ,
1264
- ) ;
1265
- let body_budget = try_opt ! (
1266
- context
1267
- . config
1268
- . max_width( )
1269
- . checked_sub( offset. block_only( ) . width( ) + last_line_width( & result) + 3 )
1221
+ let body = try_opt ! (
1222
+ rewrite_call_inner(
1223
+ context,
1224
+ "" ,
1225
+ & fields. iter( ) . map( |field| field) . collect:: <Vec <_>>( ) [ ..] ,
1226
+ span,
1227
+ Shape :: legacy( context. budget( last_line_width( & result) + 3 ) , offset) ,
1228
+ context. config. fn_call_width( ) ,
1229
+ false ,
1230
+ ) . ok( )
1270
1231
) ;
1271
-
1272
- let item_vec: Vec < _ > = items. collect ( ) ;
1273
- let tactic = definitive_tactic ( & item_vec, tactic, body_budget) ;
1274
- let fmt = ListFormatting {
1275
- tactic : tactic,
1276
- separator : "," ,
1277
- trailing_separator : context. config . trailing_comma ( ) ,
1278
- shape : Shape :: indented ( item_indent, context. config ) ,
1279
- ends_with_newline : false ,
1280
- config : context. config ,
1281
- } ;
1282
- let body = try_opt ! ( write_list( & item_vec, & fmt) ) ;
1283
-
1284
- if context. config . fn_args_layout ( ) == IndentStyle :: Visual || !body. contains ( '\n' ) {
1285
- result. push ( '(' ) ;
1286
- if context. config . spaces_within_parens ( ) && body. len ( ) > 0 {
1287
- result. push ( ' ' ) ;
1288
- }
1289
-
1290
- result. push_str ( & body) ;
1291
-
1292
- if context. config . spaces_within_parens ( ) && body. len ( ) > 0 {
1293
- result. push ( ' ' ) ;
1294
- }
1295
- result. push ( ')' ) ;
1296
- } else {
1297
- result. push_str ( "(\n " ) ;
1298
- result. push_str ( & item_indent. to_string ( & context. config ) ) ;
1299
- result. push_str ( & body) ;
1300
- result. push ( '\n' ) ;
1301
- result. push_str ( & offset. block_only ( ) . to_string ( & context. config ) ) ;
1302
- result. push ( ')' ) ;
1303
- }
1232
+ result. push_str ( & body) ;
1304
1233
}
1305
1234
1306
1235
if !where_clause_str. is_empty ( ) && !where_clause_str. contains ( '\n' ) &&
@@ -2422,7 +2351,7 @@ fn rewrite_generics(
2422
2351
span : Span ,
2423
2352
) -> Option < String > {
2424
2353
let g_shape = try_opt ! ( generics_shape_from_config( context. config, shape, 0 ) ) ;
2425
- let one_line_width = try_opt ! ( shape. width. checked_sub( 2 ) ) ;
2354
+ let one_line_width = shape. width . checked_sub ( 2 ) . unwrap_or ( 0 ) ;
2426
2355
rewrite_generics_inner ( context, generics, g_shape, one_line_width, span) . or_else ( || {
2427
2356
rewrite_generics_inner ( context, generics, g_shape, 0 , span)
2428
2357
} )
@@ -2497,16 +2426,19 @@ where
2497
2426
{
2498
2427
let item_vec = items. collect :: < Vec < _ > > ( ) ;
2499
2428
2429
+ let tactic = definitive_tactic ( & item_vec, ListTactic :: HorizontalVertical , one_line_budget) ;
2430
+ let ends_with_newline = context. config . generics_indent ( ) == IndentStyle :: Block &&
2431
+ tactic == DefinitiveListTactic :: Vertical ;
2500
2432
let fmt = ListFormatting {
2501
- tactic : definitive_tactic ( & item_vec , ListTactic :: HorizontalVertical , one_line_budget ) ,
2433
+ tactic : tactic ,
2502
2434
separator : "," ,
2503
2435
trailing_separator : if context. config . generics_indent ( ) == IndentStyle :: Visual {
2504
2436
SeparatorTactic :: Never
2505
2437
} else {
2506
2438
context. config . trailing_comma ( )
2507
2439
} ,
2508
2440
shape : shape,
2509
- ends_with_newline : false ,
2441
+ ends_with_newline : ends_with_newline ,
2510
2442
config : context. config ,
2511
2443
} ;
2512
2444
@@ -2735,8 +2667,9 @@ fn format_generics(
2735
2667
force_same_line_brace : bool ,
2736
2668
offset : Indent ,
2737
2669
span : Span ,
2670
+ used_width : usize ,
2738
2671
) -> Option < String > {
2739
- let shape = Shape :: indented ( offset, context . config ) ;
2672
+ let shape = Shape :: legacy ( context . budget ( used_width + offset. width ( ) ) , offset ) ;
2740
2673
let mut result = try_opt ! ( rewrite_generics( context, generics, shape, span) ) ;
2741
2674
2742
2675
if !generics. where_clause . predicates . is_empty ( ) || result. contains ( '\n' ) {
0 commit comments