about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2019-08-01 16:00:29 +0200
committerGitHub <noreply@github.com>2019-08-01 16:00:29 +0200
commit7a7fcad675a142d930b6d5ca6a3bf9de7805b463 (patch)
tree872db6a8bba253f3ae66581ccf20da188cc5da42 /src/libsyntax/parse
parentaaec6dfa4788df60e337bc3b4de5f31566c74066 (diff)
parent3f461f5ec674ba42c12cb000f307c98464ed5ee7 (diff)
downloadrust-7a7fcad675a142d930b6d5ca6a3bf9de7805b463.tar.gz
rust-7a7fcad675a142d930b6d5ca6a3bf9de7805b463.zip
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
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/lexer/mod.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index 3cd5464f357..263eb1ac7a4 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -29,16 +29,15 @@ pub struct UnmatchedBrace {
 }
 
 pub struct StringReader<'a> {
-    crate sess: &'a ParseSess,
-    /// The absolute offset within the source_map of the current character
-    crate pos: BytePos,
-    /// The current character (which has been read from self.pos)
-    crate source_file: Lrc<syntax_pos::SourceFile>,
+    sess: &'a ParseSess,
+    /// Initial position, read-only.
+    start_pos: BytePos,
+    /// The absolute offset within the source_map of the current character.
+    pos: BytePos,
     /// Stop reading src at this index.
-    crate end_src_index: usize,
+    end_src_index: usize,
     fatal_errs: Vec<DiagnosticBuilder<'a>>,
-    // cache a direct reference to the source text, so that we don't have to
-    // retrieve it via `self.source_file.src.as_ref().unwrap()` all the time.
+    /// Source text to tokenize.
     src: Lrc<String>,
     override_span: Option<Span>,
 }
@@ -56,8 +55,8 @@ impl<'a> StringReader<'a> {
 
         StringReader {
             sess,
+            start_pos: source_file.start_pos,
             pos: source_file.start_pos,
-            source_file,
             end_src_index: src.len(),
             src,
             fatal_errs: Vec::new(),
@@ -108,12 +107,12 @@ impl<'a> StringReader<'a> {
         let text: &str = &self.src[start_src_index..self.end_src_index];
 
         if text.is_empty() {
-            let span = self.mk_sp(self.source_file.end_pos, self.source_file.end_pos);
+            let span = self.mk_sp(self.pos, self.pos);
             return Ok(Token::new(token::Eof, span));
         }
 
         {
-            let is_beginning_of_file = self.pos == self.source_file.start_pos;
+            let is_beginning_of_file = self.pos == self.start_pos;
             if is_beginning_of_file {
                 if let Some(shebang_len) = rustc_lexer::strip_shebang(text) {
                     let start = self.pos;
@@ -533,7 +532,7 @@ impl<'a> StringReader<'a> {
 
     #[inline]
     fn src_index(&self, pos: BytePos) -> usize {
-        (pos - self.source_file.start_pos).to_usize()
+        (pos - self.start_pos).to_usize()
     }
 
     /// Slice of the source text from `start` up to but excluding `self.pos`,