@@ -43,15 +43,16 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
4343 if i != 0 || j != lines. len ( ) { Some ( ( i, j) ) } else { None }
4444 }
4545
46- fn get_horizontal_trim ( lines : & [ & str ] , kind : CommentKind ) -> Option < usize > {
46+ fn get_horizontal_trim < ' a > ( lines : & ' a [ & str ] , kind : CommentKind ) -> Option < String > {
4747 let mut i = usize:: MAX ;
4848 let mut first = true ;
4949
5050 // In case we have doc comments like `/**` or `/*!`, we want to remove stars if they are
5151 // present. However, we first need to strip the empty lines so they don't get in the middle
5252 // when we try to compute the "horizontal trim".
5353 let lines = if kind == CommentKind :: Block {
54- let mut i = 0 ;
54+ // Whatever happens, we skip the first line.
55+ let mut i = if lines[ 0 ] . trim_start ( ) . starts_with ( '*' ) { 0 } else { 1 } ;
5556 let mut j = lines. len ( ) ;
5657
5758 while i < j && lines[ i] . trim ( ) . is_empty ( ) {
@@ -84,7 +85,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
8485 return None ;
8586 }
8687 }
87- Some ( i )
88+ if lines . is_empty ( ) { None } else { Some ( lines [ 0 ] [ ..i ] . into ( ) ) }
8889 }
8990
9091 let data_s = data. as_str ( ) ;
@@ -102,8 +103,13 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
102103 changes = true ;
103104 // remove a "[ \t]*\*" block from each line, if possible
104105 for line in lines. iter_mut ( ) {
105- if horizontal + 1 < line. len ( ) {
106- * line = & line[ horizontal + 1 ..] ;
106+ if let Some ( tmp) = line. strip_prefix ( & horizontal) {
107+ * line = tmp;
108+ if kind == CommentKind :: Block
109+ && ( * line == "*" || line. starts_with ( "* " ) || line. starts_with ( "**" ) )
110+ {
111+ * line = & line[ 1 ..] ;
112+ }
107113 }
108114 }
109115 }
0 commit comments