Skip to content

Commit fb50767

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 2d049af commit fb50767

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/formatting.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,14 @@ impl<'a> FormatLines<'a> {
582582
fn char(&mut self, c: char, kind: FullCodeCharKind) {
583583
self.newline_count = 0;
584584
self.line_len += if c == '\t' {
585+
self.line_buffer
586+
.push_str(&" ".repeat(self.config.tab_spaces()));
585587
self.config.tab_spaces()
586588
} else {
587-
1
589+
self.line_buffer.push(c);
590+
c.len_utf8()
588591
};
589592
self.last_was_space = c.is_whitespace();
590-
self.line_buffer.push(c);
591593
if kind.is_string() {
592594
self.current_line_contains_string_literal = true;
593595
}

0 commit comments

Comments
 (0)