Skip to content

fix: prevent panic when reporting line overflow with hard_tabs (6442) - #7009

Open
willbuckner wants to merge 1 commit into
rust-lang:mainfrom
willbuckner:will/rustfmt-6442
Open

fix: prevent panic when reporting line overflow with hard_tabs (6442)#7009
willbuckner wants to merge 1 commit into
rust-lang:mainfrom
willbuckner:will/rustfmt-6442

Conversation

@willbuckner

@willbuckner willbuckner commented Aug 3, 2026

Copy link
Copy Markdown

The LineOverflow struct stores line widths in visual columns (a tab counts as tab_spaces), but the error report was using them as byte offsets into the line buffer when building the annotation. When an overflowing line was indented with hard tabs, the range overran the end of the buffer, and annotate-snippets panicked.

Instead, compute the annotation range in bytes from the line buffer. This also fixes misplaced annotations on overflowing lines containing multi-byte characters.

Fixes: #6442

The `LineOverflow` struct stores line widths in visual columns (a tab
counts as `tab_spaces`), but the error report was using them as byte
offsets into the line buffer when building the annotation. When an
overflowing line was indented with hard tabs, the range overran the
end of the buffer, and `annotate-snippets` panicked.

Instead, compute the annotation range in bytes from the line buffer.
This also fixes misplaced annotations on overflowing lines containing
multi-byte characters.
@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Aug 3, 2026
@ytmimi

ytmimi commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This is meant to fix #6442? If so, can you update the PR description with Fixes #6442 so that GitHub properly links this PR to the issue.

@willbuckner

Copy link
Copy Markdown
Author

This is meant to fix #6442? If so, can you update the PR description with Fixes #6442 so that GitHub properly links this PR to the issue.

Yes, sorry about that, added! I was too focused on the rest of my commit message and forgot to tag the issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic in SourceAnnotation when using hard_tabs = true

3 participants