Skip to content

Commit 9d4ca01

Browse files
committed
next_point now handles creating spans over multibyte characters.
1 parent e1c927b commit 9d4ca01

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/libsyntax/codemap.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,17 @@ impl CodeMap {
621621

622622
/// Returns a new span representing the next character after the end-point of this span
623623
pub fn next_point(&self, sp: Span) -> Span {
624-
let pos = sp.lo().0;
624+
let start_of_next_point = sp.hi().0;
625625

626626
let width = self.find_width_of_character_at_span(sp, true);
627-
let corrected_next_position = pos.checked_add(width).unwrap_or(pos);
628-
629-
let next_point = BytePos(cmp::max(sp.hi().0, corrected_next_position));
630-
Span::new(next_point, next_point, sp.ctxt())
627+
// If the width is 1, then the next span should point to the same `lo` and `hi`. However,
628+
// in the case of a multibyte character, where the width != 1, the next span should
629+
// span multiple bytes to include the whole character.
630+
let end_of_next_point = start_of_next_point.checked_add(
631+
width - 1).unwrap_or(start_of_next_point);
632+
633+
let end_of_next_point = BytePos(cmp::max(sp.lo().0 + 1, end_of_next_point));
634+
Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt())
631635
}
632636

633637
/// Finds the width of a character, either before or after the provided span.

0 commit comments

Comments
 (0)