@@ -70,7 +70,7 @@ pub fn format_expr(
70
70
expr. span ,
71
71
context,
72
72
shape,
73
- None ,
73
+ choose_separator_tactic ( context , expr . span ) ,
74
74
None ,
75
75
) ,
76
76
ast:: ExprKind :: Lit ( ref l) => rewrite_literal ( context, l, shape) ,
@@ -1336,6 +1336,18 @@ const SPECIAL_MACRO_WHITELIST: &[(&str, usize)] = &[
1336
1336
( "debug_assert_ne!" , 2 ) ,
1337
1337
] ;
1338
1338
1339
+ fn choose_separator_tactic ( context : & RewriteContext , span : Span ) -> Option < SeparatorTactic > {
1340
+ if context. inside_macro ( ) {
1341
+ if span_ends_with_comma ( context, span) {
1342
+ Some ( SeparatorTactic :: Always )
1343
+ } else {
1344
+ Some ( SeparatorTactic :: Never )
1345
+ }
1346
+ } else {
1347
+ None
1348
+ }
1349
+ }
1350
+
1339
1351
pub fn rewrite_call (
1340
1352
context : & RewriteContext ,
1341
1353
callee : & str ,
@@ -1350,15 +1362,7 @@ pub fn rewrite_call(
1350
1362
shape,
1351
1363
span,
1352
1364
context. config . width_heuristics ( ) . fn_call_width ,
1353
- if context. inside_macro ( ) {
1354
- if span_ends_with_comma ( context, span) {
1355
- Some ( SeparatorTactic :: Always )
1356
- } else {
1357
- Some ( SeparatorTactic :: Never )
1358
- }
1359
- } else {
1360
- None
1361
- } ,
1365
+ choose_separator_tactic ( context, span) ,
1362
1366
)
1363
1367
}
1364
1368
@@ -1436,11 +1440,14 @@ pub fn is_nested_call(expr: &ast::Expr) -> bool {
1436
1440
pub fn span_ends_with_comma ( context : & RewriteContext , span : Span ) -> bool {
1437
1441
let mut result: bool = Default :: default ( ) ;
1438
1442
let mut prev_char: char = Default :: default ( ) ;
1443
+ let closing_delimiters = & [ ')' , '}' , ']' ] ;
1439
1444
1440
1445
for ( kind, c) in CharClasses :: new ( context. snippet ( span) . chars ( ) ) {
1441
1446
match c {
1442
1447
_ if kind. is_comment ( ) || c. is_whitespace ( ) => continue ,
1443
- ')' | '}' => result = result && prev_char != ')' && prev_char != '}' ,
1448
+ c if closing_delimiters. contains ( & c) => {
1449
+ result &= !closing_delimiters. contains ( & prev_char) ;
1450
+ }
1444
1451
',' => result = true ,
1445
1452
_ => result = false ,
1446
1453
}
0 commit comments