@@ -83,7 +83,9 @@ fn compute_dbg_replacement(
8383 let input_expressions = input_expressions
8484 . into_iter ( )
8585 . 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 ) )
8789 . collect :: < Option < Vec < ast:: Expr > > > ( ) ?;
8890
8991 let parent = macro_expr. syntax ( ) . parent ( ) ?;
@@ -268,6 +270,8 @@ fn foo() {
268270 dbg!('x');
269271 dbg!(&n);
270272 dbg!(n);
273+ dbg!(n,);
274+ dbg!(n, );
271275 // needless comment
272276 dbg!("foo");$0
273277}
@@ -281,6 +285,17 @@ fn foo() {
281285 ) ;
282286 }
283287
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+
284299 #[ test]
285300 fn test_remove_dbg_not_applicable ( ) {
286301 check_assist_not_applicable ( remove_dbg, "fn main() {$0vec![1, 2, 3]}" ) ;
0 commit comments