@@ -109,11 +109,11 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
109
109
if comment. starts_with ( "/*" ) {
110
110
let doc = & comment[ 3 ..comment. len ( ) - 2 ] ;
111
111
let mut sizes = vec ! [ ] ;
112
-
112
+ let mut contains_initial_stars = false ;
113
113
for line in doc. lines ( ) {
114
114
let offset = line. as_ptr ( ) as usize - comment. as_ptr ( ) as usize ;
115
115
debug_assert_eq ! ( offset as u32 as usize , offset) ;
116
-
116
+ contains_initial_stars |= line . trim_left ( ) . starts_with ( '*' ) ;
117
117
// +1 for the newline
118
118
sizes. push ( (
119
119
line. len ( ) + 1 ,
@@ -123,8 +123,25 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
123
123
} ,
124
124
) ) ;
125
125
}
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) ;
128
145
}
129
146
130
147
panic ! ( "not a doc-comment: {}" , comment) ;
0 commit comments