diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2018-05-08 19:58:54 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2018-05-14 14:41:34 +1000 |
| commit | e913d692117e57ea2908461865aa08037f0bd2b9 (patch) | |
| tree | b756de98b23cedccbf0fd731d3c7e71876960f5c /src/libsyntax/parse/lexer/comments.rs | |
| parent | 444b770f4cd8d817e7b7fec683ea301620034d13 (diff) | |
| download | rust-e913d692117e57ea2908461865aa08037f0bd2b9.tar.gz rust-e913d692117e57ea2908461865aa08037f0bd2b9.zip | |
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.
Diffstat (limited to 'src/libsyntax/parse/lexer/comments.rs')
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 63aa5d28ce8..672b0b9bbd1 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -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(); |
