Skip to content

Commit

Permalink
Fix panic in annotated_snippet dependency (#4968).
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Raekye committed Dec 30, 2023
1 parent 90d3140 commit 22ed2e7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,14 @@ impl<'a> FormatLines<'a> {
fn char(&mut self, c: char, kind: FullCodeCharKind) {
self.newline_count = 0;
self.line_len += if c == '\t' {
self.line_buffer
.push_str(&" ".repeat(self.config.tab_spaces()));
self.config.tab_spaces()
} else {
1
self.line_buffer.push(c);
c.len_utf8()
};
self.last_was_space = c.is_whitespace();
self.line_buffer.push(c);
if kind.is_string() {
self.current_line_contains_string_literal = true;
}
Expand Down

0 comments on commit 22ed2e7

Please sign in to comment.