@@ -109,11 +109,11 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
109109 if comment. starts_with ( "/*" ) {
110110 let doc = & comment[ 3 ..comment. len ( ) - 2 ] ;
111111 let mut sizes = vec ! [ ] ;
112-
112+ let mut contains_initial_stars = false ;
113113 for line in doc. lines ( ) {
114114 let offset = line. as_ptr ( ) as usize - comment. as_ptr ( ) as usize ;
115115 debug_assert_eq ! ( offset as u32 as usize , offset) ;
116-
116+ contains_initial_stars |= line . trim_left ( ) . starts_with ( '*' ) ;
117117 // +1 for the newline
118118 sizes. push ( (
119119 line. len ( ) + 1 ,
@@ -123,8 +123,25 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
123123 } ,
124124 ) ) ;
125125 }
126-
127- return ( doc. to_string ( ) , sizes) ;
126+ if !contains_initial_stars {
127+ return ( doc. to_string ( ) , sizes) ;
128+ }
129+ // remove the initial '*'s if any
130+ let mut no_stars = String :: with_capacity ( doc. len ( ) ) ;
131+ for line in doc. lines ( ) {
132+ let mut chars = line. chars ( ) ;
133+ while let Some ( c) = chars. next ( ) {
134+ if c. is_whitespace ( ) {
135+ no_stars. push ( c) ;
136+ } else {
137+ no_stars. push ( if c == '*' { ' ' } else { c } ) ;
138+ break ;
139+ }
140+ }
141+ no_stars. push_str ( chars. as_str ( ) ) ;
142+ no_stars. push ( '\n' ) ;
143+ }
144+ return ( no_stars, sizes) ;
128145 }
129146
130147 panic ! ( "not a doc-comment: {}" , comment) ;
0 commit comments