@@ -83,7 +83,9 @@ fn compute_dbg_replacement(
83
83
let input_expressions = input_expressions
84
84
. into_iter ( )
85
85
. filter_map ( |( is_sep, group) | ( !is_sep) . then_some ( group) )
86
- . map ( |mut tokens| syntax:: hacks:: parse_expr_from_str ( & tokens. join ( "" ) , Edition :: CURRENT ) )
86
+ . map ( |tokens| tokens. collect :: < Vec < _ > > ( ) )
87
+ . filter ( |tokens| !tokens. iter ( ) . all ( |it| it. kind ( ) . is_trivia ( ) ) )
88
+ . map ( |tokens| syntax:: hacks:: parse_expr_from_str ( & tokens. iter ( ) . join ( "" ) , Edition :: CURRENT ) )
87
89
. collect :: < Option < Vec < ast:: Expr > > > ( ) ?;
88
90
89
91
let parent = macro_expr. syntax ( ) . parent ( ) ?;
@@ -268,6 +270,8 @@ fn foo() {
268
270
dbg!('x');
269
271
dbg!(&n);
270
272
dbg!(n);
273
+ dbg!(n,);
274
+ dbg!(n, );
271
275
// needless comment
272
276
dbg!("foo");$0
273
277
}
@@ -281,6 +285,17 @@ fn foo() {
281
285
) ;
282
286
}
283
287
288
+ #[ test]
289
+ fn test_remove_trailing_comma_dbg ( ) {
290
+ check ( "$0dbg!(1 + 1,)" , "1 + 1" ) ;
291
+ check ( "$0dbg!(1 + 1, )" , "1 + 1" ) ;
292
+ check ( "$0dbg!(1 + 1,\n )" , "1 + 1" ) ;
293
+ check ( "$0dbg!(1 + 1, 2 + 3)" , "(1 + 1, 2 + 3)" ) ;
294
+ check ( "$0dbg!(1 + 1, 2 + 3 )" , "(1 + 1, 2 + 3)" ) ;
295
+ check ( "$0dbg!(1 + 1, 2 + 3, )" , "(1 + 1, 2 + 3)" ) ;
296
+ check ( "$0dbg!(1 + 1, 2 + 3 ,)" , "(1 + 1, 2 + 3)" ) ;
297
+ }
298
+
284
299
#[ test]
285
300
fn test_remove_dbg_not_applicable ( ) {
286
301
check_assist_not_applicable ( remove_dbg, "fn main() {$0vec![1, 2, 3]}" ) ;
0 commit comments