Skip to content

Fix tabs having a fixed width internally #5039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ impl<'a> FormatLines<'a> {
fn char(&mut self, c: char, kind: FullCodeCharKind) {
self.newline_count = 0;
self.line_len += if c == '\t' {
self.config.tab_spaces()
self.config.tab_spaces() - self.line_len % self.config.tab_spaces()
} else {
1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 1 can also cause issues with non-ascii idents. Could be c.len_utf8().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possible fix for tabs is to use self.line_buffer.push_str(&" ".repeat(self.config.tab_spaces())). Not sure which is correct.

};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// rustfmt-error_on_unformatted: true
// rustfmt-error_on_line_overflow: true

// Part of #4968. This line has a width of 100, so it should be fine, but rustfmt panicked.
fn panic_with_tabs() {
let a = "tab here: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonu est \
est, consetetur sadipscing";
}