Skip to content

Commit 7493150

Browse files
committed
Properly handle unicode whitespace chars when rewriting missing spans
Fixes 5739
1 parent a3b2bfc commit 7493150

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/missed_spans.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ impl<'a> FmtVisitor<'a> {
205205
// 2: blank lines.
206206
self.push_vertical_spaces(newline_count);
207207
status.cur_line += newline_count;
208-
status.line_start = offset + lf_count + crlf_count * 2;
208+
// To avoid any issues with whitespace unicode chars just add the len of the slice
209+
status.line_start = offset + subslice.len()
209210
} else {
210211
// 3: code which we failed to format or which is not within file-lines range.
211212
self.process_missing_code(&mut status, snippet, subslice, offset, file_name);

tests/source/issue_5739.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Note the input snippet is: `compile-flags: -Z dump-mir-spanview=block\n\n\n\u{2029}\n`
2+
// compile-flags: -Z dump-mir-spanview=block
3+
4+
5+
6+

tests/target/issue_5739.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Note the input snippet is: `compile-flags: -Z dump-mir-spanview=block\n\n\n\u{2029}\n`
2+
// compile-flags: -Z dump-mir-spanview=block

0 commit comments

Comments
 (0)