Skip to content

Commit cb4c25b

Browse files
authored
Rollup merge of #63170 - matklad:cleanup-fields, r=petrochenkov
cleanup StringReader fields reduce visibility and replace `Lrc<SourceFile>` with `start_pos`: the single bit we actually *need* from the file. r? @petrochenkov
2 parents 28461b6 + 3f461f5 commit cb4c25b

File tree

1 file changed

+11
-12
lines changed
  • src/libsyntax/parse/lexer

1 file changed

+11
-12
lines changed

src/libsyntax/parse/lexer/mod.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ pub struct UnmatchedBrace {
2929
}
3030

3131
pub struct StringReader<'a> {
32-
crate sess: &'a ParseSess,
33-
/// The absolute offset within the source_map of the current character
34-
crate pos: BytePos,
35-
/// The current character (which has been read from self.pos)
36-
crate source_file: Lrc<syntax_pos::SourceFile>,
32+
sess: &'a ParseSess,
33+
/// Initial position, read-only.
34+
start_pos: BytePos,
35+
/// The absolute offset within the source_map of the current character.
36+
pos: BytePos,
3737
/// Stop reading src at this index.
38-
crate end_src_index: usize,
38+
end_src_index: usize,
3939
fatal_errs: Vec<DiagnosticBuilder<'a>>,
40-
// cache a direct reference to the source text, so that we don't have to
41-
// retrieve it via `self.source_file.src.as_ref().unwrap()` all the time.
40+
/// Source text to tokenize.
4241
src: Lrc<String>,
4342
override_span: Option<Span>,
4443
}
@@ -56,8 +55,8 @@ impl<'a> StringReader<'a> {
5655

5756
StringReader {
5857
sess,
58+
start_pos: source_file.start_pos,
5959
pos: source_file.start_pos,
60-
source_file,
6160
end_src_index: src.len(),
6261
src,
6362
fatal_errs: Vec::new(),
@@ -108,12 +107,12 @@ impl<'a> StringReader<'a> {
108107
let text: &str = &self.src[start_src_index..self.end_src_index];
109108

110109
if text.is_empty() {
111-
let span = self.mk_sp(self.source_file.end_pos, self.source_file.end_pos);
110+
let span = self.mk_sp(self.pos, self.pos);
112111
return Ok(Token::new(token::Eof, span));
113112
}
114113

115114
{
116-
let is_beginning_of_file = self.pos == self.source_file.start_pos;
115+
let is_beginning_of_file = self.pos == self.start_pos;
117116
if is_beginning_of_file {
118117
if let Some(shebang_len) = rustc_lexer::strip_shebang(text) {
119118
let start = self.pos;
@@ -534,7 +533,7 @@ impl<'a> StringReader<'a> {
534533

535534
#[inline]
536535
fn src_index(&self, pos: BytePos) -> usize {
537-
(pos - self.source_file.start_pos).to_usize()
536+
(pos - self.start_pos).to_usize()
538537
}
539538

540539
/// Slice of the source text from `start` up to but excluding `self.pos`,

0 commit comments

Comments
 (0)