Skip to content

Commit 22ed2e7

Browse files
committed
Fix panic in annotated_snippet dependency (#4968).
* This change is based on the code review by camsteffen on PR #5039 by karyon: have rustfmt internally replace tabs with the corresponding number of spaces, so that columns/indices in the buffer passed to annotated_snippet are counted unambiguously.
1 parent 90d3140 commit 22ed2e7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/formatting.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,14 @@ impl<'a> FormatLines<'a> {
589589
fn char(&mut self, c: char, kind: FullCodeCharKind) {
590590
self.newline_count = 0;
591591
self.line_len += if c == '\t' {
592+
self.line_buffer
593+
.push_str(&" ".repeat(self.config.tab_spaces()));
592594
self.config.tab_spaces()
593595
} else {
594-
1
596+
self.line_buffer.push(c);
597+
c.len_utf8()
595598
};
596599
self.last_was_space = c.is_whitespace();
597-
self.line_buffer.push(c);
598600
if kind.is_string() {
599601
self.current_line_contains_string_literal = true;
600602
}

0 commit comments

Comments
 (0)