@@ -403,45 +403,47 @@ impl<'a> StringReader<'a> {
403
403
Some ( '/' ) => {
404
404
self . bump ( ) ;
405
405
self . bump ( ) ;
406
+
406
407
// line comments starting with "///" or "//!" are doc-comments
407
- if self . curr_is ( '/' ) || self . curr_is ( '!' ) {
408
- let start_bpos = self . pos - BytePos ( 3 ) ;
409
- while ! self . is_eof ( ) {
410
- match self . curr . unwrap ( ) {
411
- '\n' => break ,
412
- '\r ' => {
413
- if self . nextch_is ( '\n' ) {
414
- // CRLF
415
- break
416
- } else {
417
- self . err_span_ ( self . last_pos , self . pos ,
418
- "bare CR not allowed in doc-comment" ) ;
419
- }
408
+ let doc_comment = self . curr_is ( '/' ) || self . curr_is ( '!' ) ;
409
+ let start_bpos = self . pos - BytePos ( 3 ) ;
410
+
411
+ while ! self . is_eof ( ) {
412
+ match self . curr . unwrap ( ) {
413
+ '\n ' => break ,
414
+ '\r' => {
415
+ if self . nextch_is ( '\n' ) {
416
+ // CRLF
417
+ break
418
+ } else {
419
+ self . err_span_ ( self . last_pos , self . pos ,
420
+ "bare CR not allowed in comment" ) ;
420
421
}
421
- _ => ( )
422
422
}
423
- self . bump ( ) ;
423
+ _ => ( )
424
424
}
425
- return self . with_str_from ( start_bpos, |string| {
426
- // but comments with only more "/"s are not
425
+ self . bump ( ) ;
426
+ }
427
+
428
+ return if doc_comment {
429
+ self . with_str_from ( start_bpos, |string| {
430
+ // comments with only more "/"s are not doc comments
427
431
let tok = if is_doc_comment ( string) {
428
432
token:: DocComment ( token:: intern ( string) )
429
433
} else {
430
434
token:: Comment
431
435
} ;
432
436
433
- return Some ( TokenAndSpan {
437
+ Some ( TokenAndSpan {
434
438
tok : tok,
435
439
sp : codemap:: mk_sp ( start_bpos, self . last_pos )
436
- } ) ;
437
- } ) ;
440
+ } )
441
+ } )
438
442
} else {
439
- let start_bpos = self . last_pos - BytePos ( 2 ) ;
440
- while !self . curr_is ( '\n' ) && !self . is_eof ( ) { self . bump ( ) ; }
441
- return Some ( TokenAndSpan {
443
+ Some ( TokenAndSpan {
442
444
tok : token:: Comment ,
443
445
sp : codemap:: mk_sp ( start_bpos, self . last_pos )
444
- } ) ;
446
+ } )
445
447
}
446
448
}
447
449
Some ( '*' ) => {
0 commit comments