1
1
use crate :: token:: { self , Token , TokenKind } ;
2
2
use crate :: sess:: ParseSess ;
3
3
use crate :: symbol:: { sym, Symbol } ;
4
+ use crate :: util:: comments;
4
5
5
6
use errors:: { FatalError , DiagnosticBuilder } ;
6
7
use syntax_pos:: { BytePos , Pos , Span } ;
@@ -15,7 +16,6 @@ use log::debug;
15
16
#[ cfg( test) ]
16
17
mod tests;
17
18
18
- pub mod comments;
19
19
mod tokentrees;
20
20
mod unicode_chars;
21
21
mod unescape_error_reporting;
@@ -179,7 +179,7 @@ impl<'a> StringReader<'a> {
179
179
rustc_lexer:: TokenKind :: LineComment => {
180
180
let string = self . str_from ( start) ;
181
181
// comments with only more "/"s are not doc comments
182
- let tok = if is_doc_comment ( string) {
182
+ let tok = if comments :: is_line_doc_comment ( string) {
183
183
self . forbid_bare_cr ( start, string, "bare CR not allowed in doc-comment" ) ;
184
184
token:: DocComment ( Symbol :: intern ( string) )
185
185
} else {
@@ -192,7 +192,7 @@ impl<'a> StringReader<'a> {
192
192
let string = self . str_from ( start) ;
193
193
// block comments starting with "/**" or "/*!" are doc-comments
194
194
// but comments with only "*"s between two "/"s are not
195
- let is_doc_comment = is_block_doc_comment ( string) ;
195
+ let is_doc_comment = comments :: is_block_doc_comment ( string) ;
196
196
197
197
if !terminated {
198
198
let msg = if is_doc_comment {
@@ -643,18 +643,3 @@ impl<'a> StringReader<'a> {
643
643
}
644
644
}
645
645
}
646
-
647
- fn is_doc_comment ( s : & str ) -> bool {
648
- let res = ( s. starts_with ( "///" ) && * s. as_bytes ( ) . get ( 3 ) . unwrap_or ( & b' ' ) != b'/' ) ||
649
- s. starts_with ( "//!" ) ;
650
- debug ! ( "is {:?} a doc comment? {}" , s, res) ;
651
- res
652
- }
653
-
654
- fn is_block_doc_comment ( s : & str ) -> bool {
655
- // Prevent `/**/` from being parsed as a doc comment
656
- let res = ( ( s. starts_with ( "/**" ) && * s. as_bytes ( ) . get ( 3 ) . unwrap_or ( & b' ' ) != b'*' ) ||
657
- s. starts_with ( "/*!" ) ) && s. len ( ) >= 5 ;
658
- debug ! ( "is {:?} a doc comment? {}" , s, res) ;
659
- res
660
- }
0 commit comments