@@ -574,9 +574,17 @@ where
574
574
575
575
pub ( crate ) fn extract_pre_comment ( pre_snippet : & str ) -> ( Option < String > , ListItemCommentStyle ) {
576
576
let trimmed_pre_snippet = pre_snippet. trim ( ) ;
577
- let has_block_comment = trimmed_pre_snippet. ends_with ( "*/" ) ;
578
- let has_single_line_comment = trimmed_pre_snippet. starts_with ( "//" ) ;
579
- if has_block_comment {
577
+ // Both start and end are checked to support keeping a block comment inline with
578
+ // the item, even if there are preceeding line comments, while still supporting
579
+ // a snippet that starts with a block comment but also contains one or more
580
+ // trailing single line comments.
581
+ // https://github.com/rust-lang/rustfmt/issues/3025
582
+ // https://github.com/rust-lang/rustfmt/pull/3048
583
+ // https://github.com/rust-lang/rustfmt/issues/3839
584
+ let starts_with_block_comment = trimmed_pre_snippet. starts_with ( "/*" ) ;
585
+ let ends_with_block_comment = trimmed_pre_snippet. ends_with ( "*/" ) ;
586
+ let starts_with_single_line_comment = trimmed_pre_snippet. starts_with ( "//" ) ;
587
+ if ends_with_block_comment {
580
588
let comment_end = pre_snippet. rfind ( |c| c == '/' ) . unwrap ( ) ;
581
589
if pre_snippet[ comment_end..] . contains ( '\n' ) {
582
590
(
@@ -589,7 +597,7 @@ pub(crate) fn extract_pre_comment(pre_snippet: &str) -> (Option<String>, ListIte
589
597
ListItemCommentStyle :: SameLine ,
590
598
)
591
599
}
592
- } else if has_single_line_comment {
600
+ } else if starts_with_single_line_comment || starts_with_block_comment {
593
601
(
594
602
Some ( trimmed_pre_snippet. to_owned ( ) ) ,
595
603
ListItemCommentStyle :: DifferentLine ,
0 commit comments