@@ -632,23 +632,28 @@ pub(crate) fn extract_post_comment(
632
632
post_snippet : & str ,
633
633
comment_end : usize ,
634
634
separator : & str ,
635
+ leave_last : bool ,
635
636
) -> Option < String > {
636
637
let white_space: & [ _ ] = & [ ' ' , '\t' ] ;
637
638
638
639
// Cleanup post-comment: strip separators and whitespace.
639
- let post_snippet = post_snippet[ ..comment_end] . trim ( ) ;
640
- let post_snippet_trimmed = if post_snippet. starts_with ( |c| c == ',' || c == ':' ) {
641
- post_snippet[ 1 ..] . trim_matches ( white_space)
642
- } else if let Some ( post_snippet) = post_snippet. strip_prefix ( separator) {
640
+ let ( post_snippet, comment_end) = post_snippet. split_at ( comment_end) ;
641
+ let post_snippet_trimmed = post_snippet. trim ( ) ;
642
+
643
+ let post_snippet_trimmed = if post_snippet_trimmed. starts_with ( |c| c == ',' || c == ':' ) {
644
+ post_snippet_trimmed[ 1 ..] . trim_matches ( white_space)
645
+ } else if let Some ( post_snippet) = post_snippet_trimmed. strip_prefix ( separator) {
643
646
post_snippet. trim_matches ( white_space)
644
647
}
645
648
// not comment or over two lines
646
- else if post_snippet . ends_with ( ',' )
647
- && ( !post_snippet . trim ( ) . starts_with ( "//" ) || post_snippet . trim ( ) . contains ( '\n' ) )
649
+ else if post_snippet_trimmed . ends_with ( ',' )
650
+ && ( !post_snippet_trimmed . starts_with ( "//" ) || post_snippet_trimmed . contains ( '\n' ) )
648
651
{
649
- post_snippet[ ..( post_snippet. len ( ) - 1 ) ] . trim_matches ( white_space)
652
+ post_snippet_trimmed[ ..( post_snippet_trimmed. len ( ) - 1 ) ] . trim_matches ( white_space)
653
+ } else if comment_end == ")" && !leave_last {
654
+ post_snippet_trimmed
650
655
} else {
651
- post_snippet
656
+ post_snippet. trim_start_matches ( white_space ) . trim_end ( )
652
657
} ;
653
658
// FIXME(#3441): post_snippet includes 'const' now
654
659
// it should not include here
@@ -776,7 +781,8 @@ where
776
781
self . inner . peek ( ) . is_none ( ) ,
777
782
) ;
778
783
let new_lines = has_extra_newline ( post_snippet, comment_end) ;
779
- let post_comment = extract_post_comment ( post_snippet, comment_end, self . separator ) ;
784
+ let post_comment =
785
+ extract_post_comment ( post_snippet, comment_end, self . separator , self . leave_last ) ;
780
786
781
787
self . prev_span_end = ( self . get_hi ) ( & item) + BytePos ( comment_end as u32 ) ;
782
788
0 commit comments