Skip to content

Commit fafb883

Browse files
committed
Fix tabs having a fixed width internally
Ref rust-lang#4968. Tabs were always counted to have a width of config.tab_spaces. Since they actually can have less than that depending on the line's previous contents, rustfmt would sometimes complain about the line length even if the line did actually fit.
1 parent efa8f55 commit fafb883

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/formatting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl<'a> FormatLines<'a> {
559559
fn char(&mut self, c: char, kind: FullCodeCharKind) {
560560
self.newline_count = 0;
561561
self.line_len += if c == '\t' {
562-
self.config.tab_spaces()
562+
self.config.tab_spaces() - self.line_len % self.config.tab_spaces()
563563
} else {
564564
1
565565
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-error_on_unformatted: true
2+
// rustfmt-error_on_line_overflow: true
3+
4+
// Part of #4968. This line has a width of 100, so it should be fine, but rustfmt panicked.
5+
fn panic_with_tabs() {
6+
let a = "tab here: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonu est \
7+
est, consetetur sadipscing";
8+
}

0 commit comments

Comments
 (0)