File tree 1 file changed +17
-4
lines changed
1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -2359,11 +2359,24 @@ pub fn wrap_args_with_parens(
2359
2359
}
2360
2360
}
2361
2361
2362
+ /// Return true if a function call or a method call represented by the given span ends with a
2363
+ /// trailing comma. This function is used when rewriting macro, as adding or removing a trailing
2364
+ /// comma from macro can potentially break the code.
2362
2365
fn span_ends_with_comma ( context : & RewriteContext , span : Span ) -> bool {
2363
- let snippet = context. snippet ( span) ;
2364
- snippet
2365
- . trim_right_matches ( |c : char | c == ')' || c. is_whitespace ( ) )
2366
- . ends_with ( ',' )
2366
+ let mut encountered_closing_paren = false ;
2367
+ for c in context. snippet ( span) . chars ( ) . rev ( ) {
2368
+ match c {
2369
+ ',' => return true ,
2370
+ ')' => if encountered_closing_paren {
2371
+ return false ;
2372
+ } else {
2373
+ encountered_closing_paren = true ;
2374
+ } ,
2375
+ _ if c. is_whitespace ( ) => continue ,
2376
+ _ => return false ,
2377
+ }
2378
+ }
2379
+ false
2367
2380
}
2368
2381
2369
2382
fn rewrite_paren ( context : & RewriteContext , subexpr : & ast:: Expr , shape : Shape ) -> Option < String > {
You can’t perform that action at this time.
0 commit comments