Skip to content

Commit a1f8a6c

Browse files
Fix FileMap::line_begin_pos().
The method relied on the FileMap still being under construction in order for it to do what the name promises. It's now independent of the current state.
1 parent ba30c1d commit a1f8a6c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/libsyntax/parse/lexer/comments.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,11 @@ fn read_block_comment(rdr: &mut StringReader,
240240
let mut lines: Vec<String> = Vec::new();
241241

242242
// Count the number of chars since the start of the line by rescanning.
243-
let mut src_index = rdr.src_index(rdr.filemap.line_begin_pos());
243+
let mut src_index = rdr.src_index(rdr.filemap.line_begin_pos(rdr.pos));
244244
let end_src_index = rdr.src_index(rdr.pos);
245-
assert!(src_index <= end_src_index);
245+
assert!(src_index <= end_src_index,
246+
"src_index={}, end_src_index={}, line_begin_pos={}",
247+
src_index, end_src_index, rdr.filemap.line_begin_pos(rdr.pos).to_u32());
246248
let mut n = 0;
247249
while src_index < end_src_index {
248250
let c = char_at(&rdr.src, src_index);

src/libsyntax_pos/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -976,11 +976,9 @@ impl FileMap {
976976
}
977977

978978
/// Return the BytePos of the beginning of the current line.
979-
pub fn line_begin_pos(&self) -> BytePos {
980-
match self.lines.last() {
981-
Some(&line_pos) => line_pos,
982-
None => self.start_pos,
983-
}
979+
pub fn line_begin_pos(&self, pos: BytePos) -> BytePos {
980+
let line_index = self.lookup_line(pos).unwrap();
981+
self.lines[line_index]
984982
}
985983

986984
/// Add externally loaded source.

0 commit comments

Comments
 (0)