Skip to content

Commit

Permalink
Fix FileMap::line_begin_pos().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelwoerister committed Jun 28, 2018
1 parent ba30c1d commit a1f8a6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/libsyntax/parse/lexer/comments.rs
Expand Up @@ -240,9 +240,11 @@ fn read_block_comment(rdr: &mut StringReader,
let mut lines: Vec<String> = Vec::new();

// 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 mut src_index = rdr.src_index(rdr.filemap.line_begin_pos(rdr.pos));
let end_src_index = rdr.src_index(rdr.pos);
assert!(src_index <= end_src_index);
assert!(src_index <= end_src_index,
"src_index={}, end_src_index={}, line_begin_pos={}",
src_index, end_src_index, rdr.filemap.line_begin_pos(rdr.pos).to_u32());
let mut n = 0;
while src_index < end_src_index {
let c = char_at(&rdr.src, src_index);
Expand Down
8 changes: 3 additions & 5 deletions src/libsyntax_pos/lib.rs
Expand Up @@ -976,11 +976,9 @@ impl FileMap {
}

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

/// Add externally loaded source.
Expand Down

0 comments on commit a1f8a6c

Please sign in to comment.