@@ -319,20 +319,11 @@ where
319
319
320
320
let list_lo = context. snippet_provider . span_after ( span, "(" ) ;
321
321
let ( list_str, tactic) = if inputs. len ( ) == 0 {
322
- let tactic = if output. contains ( '\n' ) {
323
- DefinitiveListTactic :: Vertical
324
- } else {
325
- definitive_tactic (
326
- & Vec :: < ListItem > :: new ( ) ,
327
- ListTactic :: HorizontalVertical ,
328
- Separator :: Comma ,
329
- shape. width . saturating_sub ( 2 + output. len ( ) ) ,
330
- )
331
- } ;
332
- let list_hi = context. snippet_provider . span_after_last ( span, ")" ) ;
322
+ let tactic = get_tactics ( & Vec :: < ListItem > :: new ( ) , & output, & shape) ;
323
+ let list_hi = context. snippet_provider . span_before_last ( span, ")" ) ;
333
324
let comment = context
334
325
. snippet_provider
335
- . span_to_snippet ( mk_sp ( list_lo, list_hi - BytePos ( 1 ) ) ) ?
326
+ . span_to_snippet ( mk_sp ( list_lo, list_hi) ) ?
336
327
. trim ( ) ;
337
328
let comment = if comment. starts_with ( "//" ) {
338
329
format ! (
@@ -360,19 +351,7 @@ where
360
351
) ;
361
352
362
353
let item_vec: Vec < _ > = items. collect ( ) ;
363
-
364
- // If the return type is multi-lined, then force to use multiple lines for
365
- // arguments as well.
366
- let tactic = if output. contains ( '\n' ) {
367
- DefinitiveListTactic :: Vertical
368
- } else {
369
- definitive_tactic (
370
- & * item_vec,
371
- ListTactic :: HorizontalVertical ,
372
- Separator :: Comma ,
373
- shape. width . saturating_sub ( 2 + output. len ( ) ) ,
374
- )
375
- } ;
354
+ let tactic = get_tactics ( & item_vec, & output, & shape) ;
376
355
let trailing_separator = if !context. use_block_indent ( ) || variadic {
377
356
SeparatorTactic :: Never
378
357
} else {
@@ -413,6 +392,22 @@ fn type_bound_colon(context: &RewriteContext<'_>) -> &'static str {
413
392
colon_spaces ( context. config )
414
393
}
415
394
395
+ // If the return type is multi-lined, then force to use multiple lines for
396
+ // arguments as well.
397
+ fn get_tactics ( item_vec : & Vec < ListItem > , output : & str , shape : & Shape ) -> DefinitiveListTactic {
398
+ if output. contains ( '\n' ) {
399
+ DefinitiveListTactic :: Vertical
400
+ } else {
401
+ definitive_tactic (
402
+ & * item_vec,
403
+ ListTactic :: HorizontalVertical ,
404
+ Separator :: Comma ,
405
+ // 2 is for the case of ',\n'
406
+ shape. width . saturating_sub ( 2 + output. len ( ) ) ,
407
+ )
408
+ }
409
+ }
410
+
416
411
impl Rewrite for ast:: WherePredicate {
417
412
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
418
413
// FIXME: dead spans?
0 commit comments