mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 05:25:37 +03:00
Remove StringReader::col.
It only has a single use, within code handling indented block comments. We can replace that with the new `FileMap::col_pos()`, which computes the col position (BytePos instead of CharPos) based on the record of the last newline char (which we already record). This is actually an improvement, because `trim_whitespace_prefix_and_push_line()` was using `col`, which is a `CharPos`, as a slice index, which is a byte/char confusion.
This commit is contained in:
@@ -238,7 +238,19 @@ fn read_block_comment(rdr: &mut StringReader,
|
||||
debug!(">>> block comment");
|
||||
let p = rdr.pos;
|
||||
let mut lines: Vec<String> = Vec::new();
|
||||
let col = rdr.col;
|
||||
|
||||
// Count the number of chars since the start of the line by rescanning.
|
||||
let mut src_index = rdr.src_index(rdr.filemap.line_begin_pos());
|
||||
let end_src_index = rdr.src_index(rdr.pos);
|
||||
assert!(src_index <= end_src_index);
|
||||
let mut n = 0;
|
||||
while src_index < end_src_index {
|
||||
let c = char_at(&rdr.src, src_index);
|
||||
src_index += c.len_utf8();
|
||||
n += 1;
|
||||
}
|
||||
let col = CharPos(n);
|
||||
|
||||
rdr.bump();
|
||||
rdr.bump();
|
||||
|
||||
|
||||
@@ -44,8 +44,6 @@ pub struct StringReader<'a> {
|
||||
pub next_pos: BytePos,
|
||||
/// The absolute offset within the codemap of the current character
|
||||
pub pos: BytePos,
|
||||
/// The column of the next character to read
|
||||
pub col: CharPos,
|
||||
/// The current character (which has been read from self.pos)
|
||||
pub ch: Option<char>,
|
||||
pub filemap: Lrc<syntax_pos::FileMap>,
|
||||
@@ -175,7 +173,6 @@ fn new_raw_internal(sess: &'a ParseSess, filemap: Lrc<syntax_pos::FileMap>) -> S
|
||||
sess,
|
||||
next_pos: filemap.start_pos,
|
||||
pos: filemap.start_pos,
|
||||
col: CharPos(0),
|
||||
ch: Some('\n'),
|
||||
filemap,
|
||||
end_src_index: src.len(),
|
||||
@@ -442,9 +439,6 @@ pub fn bump(&mut self) {
|
||||
if self.save_new_lines_and_multibyte {
|
||||
self.filemap.next_line(self.next_pos);
|
||||
}
|
||||
self.col = CharPos(0);
|
||||
} else {
|
||||
self.col = self.col + CharPos(1);
|
||||
}
|
||||
if next_ch_len > 1 {
|
||||
if self.save_new_lines_and_multibyte {
|
||||
|
||||
@@ -971,6 +971,15 @@ pub fn next_line(&self, pos: BytePos) {
|
||||
lines.push(pos);
|
||||
}
|
||||
|
||||
/// Return the BytePos of the beginning of the current line.
|
||||
pub fn line_begin_pos(&self) -> BytePos {
|
||||
let lines = self.lines.borrow();
|
||||
match lines.last() {
|
||||
Some(&line_pos) => line_pos,
|
||||
None => self.start_pos,
|
||||
}
|
||||
}
|
||||
|
||||
/// Add externally loaded source.
|
||||
/// If the hash of the input doesn't match or no input is supplied via None,
|
||||
/// it is interpreted as an error and the corresponding enum variant is set.
|
||||
|
||||
Reference in New Issue
Block a user