Skip to content

Commit 27f97aa

Browse files
committed
move syntax::parse::lexer::comments -> syntax::util::comments
1 parent a1571b6 commit 27f97aa

File tree

11 files changed

+31
-29
lines changed

11 files changed

+31
-29
lines changed

src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::path::{Path, PathBuf};
2929

3030
use syntax::ast::{self, Attribute, DUMMY_NODE_ID, NodeId, PatKind};
3131
use syntax::source_map::Spanned;
32-
use syntax::parse::lexer::comments::strip_doc_comment_decoration;
32+
use syntax::util::comments::strip_doc_comment_decoration;
3333
use syntax::print::pprust;
3434
use syntax::visit::{self, Visitor};
3535
use syntax::print::pprust::{param_to_string, ty_to_string};

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc::ty::layout::VariantIdx;
2828
use rustc::util::nodemap::{FxHashMap, FxHashSet};
2929
use syntax::ast::{self, Attribute, AttrStyle, AttrKind, Ident};
3030
use syntax::attr;
31-
use syntax::parse::lexer::comments;
31+
use syntax::util::comments;
3232
use syntax::source_map::DUMMY_SP;
3333
use syntax_pos::symbol::{Symbol, kw, sym};
3434
use syntax_pos::hygiene::MacroKind;

src/libsyntax/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub mod error_codes;
8686

8787
pub mod util {
8888
crate mod classify;
89+
pub mod comments;
8990
pub mod lev_distance;
9091
pub mod node_count;
9192
pub mod parser;

src/libsyntax/parse/lexer/mod.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::token::{self, Token, TokenKind};
22
use crate::sess::ParseSess;
33
use crate::symbol::{sym, Symbol};
4+
use crate::util::comments;
45

56
use errors::{FatalError, DiagnosticBuilder};
67
use syntax_pos::{BytePos, Pos, Span};
@@ -15,7 +16,6 @@ use log::debug;
1516
#[cfg(test)]
1617
mod tests;
1718

18-
pub mod comments;
1919
mod tokentrees;
2020
mod unicode_chars;
2121
mod unescape_error_reporting;
@@ -179,7 +179,7 @@ impl<'a> StringReader<'a> {
179179
rustc_lexer::TokenKind::LineComment => {
180180
let string = self.str_from(start);
181181
// 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) {
183183
self.forbid_bare_cr(start, string, "bare CR not allowed in doc-comment");
184184
token::DocComment(Symbol::intern(string))
185185
} else {
@@ -192,7 +192,7 @@ impl<'a> StringReader<'a> {
192192
let string = self.str_from(start);
193193
// block comments starting with "/**" or "/*!" are doc-comments
194194
// 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);
196196

197197
if !terminated {
198198
let msg = if is_doc_comment {
@@ -643,18 +643,3 @@ impl<'a> StringReader<'a> {
643643
}
644644
}
645645
}
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-
}

src/libsyntax/parse/lexer/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::*;
33
use crate::symbol::Symbol;
44
use crate::source_map::{SourceMap, FilePathMapping};
55
use crate::token;
6+
use crate::util::comments::is_doc_comment;
67
use crate::with_default_globals;
78

89
use errors::{Handler, emitter::EmitterWriter};

src/libsyntax/parse/parser/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{SeqSep, Parser, TokenType, PathStyle};
22
use crate::attr;
33
use crate::ast;
4-
use crate::parse::lexer::comments;
4+
use crate::util::comments;
55
use crate::token::{self, Nonterminal, DelimToken};
66
use crate::tokenstream::{TokenStream, TokenTree};
77
use crate::source_map::Span;

src/libsyntax/parse/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::ast::{
1717
};
1818
use crate::parse::{Directory, DirectoryOwnership};
1919
use crate::parse::lexer::UnmatchedBrace;
20-
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
20+
use crate::util::comments::{doc_comment_style, strip_doc_comment_decoration};
2121
use crate::token::{self, Token, TokenKind, DelimToken};
2222
use crate::print::pprust;
2323
use crate::ptr::P;

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use crate::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
22
use crate::ast::{SelfKind, GenericBound, TraitBoundModifier};
33
use crate::ast::{Attribute, MacDelimiter, GenericArg};
44
use crate::util::parser::{self, AssocOp, Fixity};
5+
use crate::util::comments;
56
use crate::attr;
67
use crate::source_map::{self, SourceMap, Spanned};
78
use crate::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
8-
use crate::parse::lexer::comments;
99
use crate::print::pp::{self, Breaks};
1010
use crate::print::pp::Breaks::{Consistent, Inconsistent};
1111
use crate::ptr::P;

src/libsyntax/parse/lexer/comments.rs renamed to src/libsyntax/util/comments.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
pub use CommentStyle::*;
22

3-
use super::is_block_doc_comment;
4-
53
use crate::ast;
64
use crate::source_map::SourceMap;
75
use crate::sess::ParseSess;
@@ -10,6 +8,8 @@ use syntax_pos::{BytePos, CharPos, Pos, FileName};
108

119
use std::usize;
1210

11+
use log::debug;
12+
1313
#[cfg(test)]
1414
mod tests;
1515

@@ -32,8 +32,23 @@ pub struct Comment {
3232
pub pos: BytePos,
3333
}
3434

35-
fn is_doc_comment(s: &str) -> bool {
36-
(s.starts_with("///") && super::is_doc_comment(s)) || s.starts_with("//!") ||
35+
crate fn is_line_doc_comment(s: &str) -> bool {
36+
let res = (s.starts_with("///") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'/') ||
37+
s.starts_with("//!");
38+
debug!("is {:?} a doc comment? {}", s, res);
39+
res
40+
}
41+
42+
crate fn is_block_doc_comment(s: &str) -> bool {
43+
// Prevent `/**/` from being parsed as a doc comment
44+
let res = ((s.starts_with("/**") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'*') ||
45+
s.starts_with("/*!")) && s.len() >= 5;
46+
debug!("is {:?} a doc comment? {}", s, res);
47+
res
48+
}
49+
50+
crate fn is_doc_comment(s: &str) -> bool {
51+
(s.starts_with("///") && is_line_doc_comment(s)) || s.starts_with("//!") ||
3752
(s.starts_with("/**") && is_block_doc_comment(s)) || s.starts_with("/*!")
3853
}
3954

src/libsyntax_expand/proc_macro_server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::base::ExtCtxt;
22

33
use syntax::ast;
4-
use syntax::parse::{self};
5-
use syntax::parse::lexer::comments;
4+
use syntax::parse;
5+
use syntax::util::comments;
66
use syntax::print::pprust;
77
use syntax::sess::ParseSess;
88
use syntax::token;

0 commit comments

Comments
 (0)