diff options
| author | yukang <moorekang@gmail.com> | 2022-10-18 02:00:06 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2022-10-18 02:59:38 +0800 |
| commit | 0af255a5aa448efe6ab7e3252e85081128beaa9e (patch) | |
| tree | 0146f27c9650f7d955e506f323c1e71b48a7d741 /compiler/rustc_span/src | |
| parent | 11432fe952cdc531785bd1bf7dc4e8a15da6daab (diff) | |
| download | rust-0af255a5aa448efe6ab7e3252e85081128beaa9e.tar.gz rust-0af255a5aa448efe6ab7e3252e85081128beaa9e.zip | |
Fix the bug of next_point in span
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 4d94c92d3f2..d3c2550aa2a 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -859,14 +859,15 @@ impl SourceMap { } let start_of_next_point = sp.hi().0; - let width = self.find_width_of_character_at_span(sp.shrink_to_hi(), true); + let width = self.find_width_of_character_at_span(sp, true); + debug_assert!(width > 0); // 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); + start_of_next_point.checked_add(width).unwrap_or(start_of_next_point); - let end_of_next_point = BytePos(cmp::max(sp.lo().0 + 1, end_of_next_point)); + let end_of_next_point = BytePos(cmp::max(start_of_next_point + 1, end_of_next_point)); Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt(), None) } |
