@@ -63,6 +63,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
63
63
if !lines. is_empty ( ) && lines[ 0 ] . chars ( ) . all ( |c| c == '*' ) {
64
64
i += 1 ;
65
65
}
66
+
66
67
while i < j && lines[ i] . trim ( ) . is_empty ( ) {
67
68
i += 1 ;
68
69
}
@@ -74,9 +75,11 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
74
75
. all ( |c| c == '*' ) {
75
76
j -= 1 ;
76
77
}
78
+
77
79
while j > i && lines[ j - 1 ] . trim ( ) . is_empty ( ) {
78
80
j -= 1 ;
79
81
}
82
+
80
83
lines[ i..j] . to_vec ( )
81
84
}
82
85
@@ -85,6 +88,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
85
88
let mut i = usize:: MAX ;
86
89
let mut can_trim = true ;
87
90
let mut first = true ;
91
+
88
92
for line in & lines {
89
93
for ( j, c) in line. chars ( ) . enumerate ( ) {
90
94
if j > i || !"* \t " . contains ( c) {
@@ -119,7 +123,8 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
119
123
}
120
124
121
125
// one-line comments lose their prefix
122
- const ONELINERS : & ' static [ & ' static str ] = & [ "///!" , "///" , "//!" , "//" ] ;
126
+ const ONELINERS : & [ & str ] = & [ "///!" , "///" , "//!" , "//" ] ;
127
+
123
128
for prefix in ONELINERS {
124
129
if comment. starts_with ( * prefix) {
125
130
return ( & comment[ prefix. len ( ) ..] ) . to_string ( ) ;
@@ -205,6 +210,7 @@ fn all_whitespace(s: &str, col: CharPos) -> Option<usize> {
205
210
let len = s. len ( ) ;
206
211
let mut col = col. to_usize ( ) ;
207
212
let mut cursor: usize = 0 ;
213
+
208
214
while col > 0 && cursor < len {
209
215
let ch = char_at ( s, cursor) ;
210
216
if !ch. is_whitespace ( ) {
@@ -213,7 +219,8 @@ fn all_whitespace(s: &str, col: CharPos) -> Option<usize> {
213
219
cursor += ch. len_utf8 ( ) ;
214
220
col -= 1 ;
215
221
}
216
- return Some ( cursor) ;
222
+
223
+ Some ( cursor)
217
224
}
218
225
219
226
fn trim_whitespace_prefix_and_push_line ( lines : & mut Vec < String > , s : String , col : CharPos ) {
@@ -246,11 +253,13 @@ fn read_block_comment(rdr: &mut StringReader,
246
253
"src_index={}, end_src_index={}, line_begin_pos={}" ,
247
254
src_index, end_src_index, rdr. filemap. line_begin_pos( rdr. pos) . to_u32( ) ) ;
248
255
let mut n = 0 ;
256
+
249
257
while src_index < end_src_index {
250
258
let c = char_at ( & rdr. src , src_index) ;
251
259
src_index += c. len_utf8 ( ) ;
252
260
n += 1 ;
253
261
}
262
+
254
263
let col = CharPos ( n) ;
255
264
256
265
rdr. bump ( ) ;
@@ -358,10 +367,10 @@ pub struct Literal {
358
367
// it appears this function is called only from pprust... that's
359
368
// probably not a good thing.
360
369
pub fn gather_comments_and_literals ( sess : & ParseSess , path : FileName , srdr : & mut dyn Read )
361
- -> ( Vec < Comment > , Vec < Literal > ) {
362
- let mut src = Vec :: new ( ) ;
363
- srdr . read_to_end ( & mut src) . unwrap ( ) ;
364
- let src = String :: from_utf8 ( src) . unwrap ( ) ;
370
+ -> ( Vec < Comment > , Vec < Literal > )
371
+ {
372
+ let mut src = String :: new ( ) ;
373
+ srdr . read_to_string ( & mut src) . unwrap ( ) ;
365
374
let cm = CodeMap :: new ( sess. codemap ( ) . path_mapping ( ) . clone ( ) ) ;
366
375
let filemap = cm. new_filemap ( path, src) ;
367
376
let mut rdr = lexer:: StringReader :: new_raw ( sess, filemap, None ) ;
@@ -370,6 +379,7 @@ pub fn gather_comments_and_literals(sess: &ParseSess, path: FileName, srdr: &mut
370
379
let mut literals: Vec < Literal > = Vec :: new ( ) ;
371
380
let mut code_to_the_left = false ; // Only code
372
381
let mut anything_to_the_left = false ; // Code or comments
382
+
373
383
while !rdr. is_eof ( ) {
374
384
loop {
375
385
// Eat all the whitespace and count blank lines.
0 commit comments