about summary refs log tree commit diff
path: root/src/libsyntax/codemap.rs
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2018-01-17 10:01:57 +0000
committerDavid Wood <david@davidtw.co>2018-01-27 11:46:28 +0000
commitbe465b0b85746b2f56dc4bb1842e603e8489a0f3 (patch)
tree52cde4dfcb54ad8c5795521140fa5a3346c8e6dd /src/libsyntax/codemap.rs
parent62356471b3746012df74db22479b03ad1f6ab8ab (diff)
downloadrust-be465b0b85746b2f56dc4bb1842e603e8489a0f3.tar.gz
rust-be465b0b85746b2f56dc4bb1842e603e8489a0f3.zip
next_point now handles creating spans over multibyte characters.
Diffstat (limited to 'src/libsyntax/codemap.rs')
-rw-r--r--src/libsyntax/codemap.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 76050f8dc09..cfb891f0faa 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -621,13 +621,17 @@ impl CodeMap {
 
     /// Returns a new span representing the next character after the end-point of this span
     pub fn next_point(&self, sp: Span) -> Span {
-        let pos = sp.lo().0;
+        let start_of_next_point = sp.hi().0;
 
         let width = self.find_width_of_character_at_span(sp, true);
-        let corrected_next_position = pos.checked_add(width).unwrap_or(pos);
-
-        let next_point = BytePos(cmp::max(sp.hi().0, corrected_next_position));
-        Span::new(next_point, next_point, sp.ctxt())
+        // If the width is 1, then the next span should point to the same `lo` and `hi`. However,
+        // in the case of a multibyte character, where the width != 1, the next span should
+        // span multiple bytes to include the whole character.
+        let end_of_next_point = start_of_next_point.checked_add(
+            width - 1).unwrap_or(start_of_next_point);
+
+        let end_of_next_point = BytePos(cmp::max(sp.lo().0 + 1, end_of_next_point));
+        Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt())
     }
 
     /// Finds the width of a character, either before or after the provided span.