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