File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -402,7 +402,16 @@ fn rewrite_match_body(
402
402
let arrow_snippet = context. snippet ( arrow_span) . trim ( ) ;
403
403
// search for the arrow starting from the end of the snippet since there may be a match
404
404
// expression within the guard
405
- let arrow_index = arrow_snippet. rfind ( "=>" ) . unwrap ( ) ;
405
+ let mut arrow_index = arrow_snippet. rfind ( "=>" ) . unwrap ( ) ;
406
+ // check whether `=>` is included in the comment
407
+ if arrow_index != 0 {
408
+ let prev_arrow = arrow_snippet[ ..arrow_index] . trim ( ) ;
409
+ let single_line_comment_index = prev_arrow. rfind ( "//" ) . unwrap_or ( 0 ) ;
410
+ let new_line_index = prev_arrow. rfind ( "\n " ) . unwrap_or ( 0 ) ;
411
+ if single_line_comment_index > new_line_index {
412
+ arrow_index = 0 ;
413
+ }
414
+ }
406
415
// 2 = `=>`
407
416
let comment_str = arrow_snippet[ arrow_index + 2 ..] . trim ( ) ;
408
417
if comment_str. is_empty ( ) {
Original file line number Diff line number Diff line change
1
+ // rustfmt-wrap_comments: true
2
+ fn main ( ) {
3
+ match a {
4
+ _ =>
5
+ // comment with =>
6
+ {
7
+ println ! ( "A" )
8
+ }
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-wrap_comments: true
2
+ fn main ( ) {
3
+ match a {
4
+ _ =>
5
+ // comment with =>
6
+ {
7
+ println ! ( "A" )
8
+ }
9
+ }
10
+ }
You can’t perform that action at this time.
0 commit comments