-
Notifications
You must be signed in to change notification settings - Fork 925
Panic in SourceAnnotation when using hard_tabs = true
#6442
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
Comments
I tried a freshly installed nightly toolchain on Ubuntu and got the same error. Same codebase, here's the crash report: |
@lbfalvy can you please get this down to a minimal example that can be used to reproduce the error. Also, it would be good to know the exact version of rustfmt that you're using and if you're using any non-default rustfmt configs. |
@ytmimi All done, it's very similar to other SourceAnnotation bugs but I can't find the specific issue that had a really long print statement as a minimal example. For completeness' sake, here's my minimal example. repo: https://github.com/lbfalvy/orchid/tree/rustfmt-minimal-crash It's just one file: // src/main.rs
pub fn main() {
println!(
"Reeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
)
} rustfmt options: # rustfmt.toml
unstable_features = true
style_edition = "2024"
hard_tabs = true
# the following two are unstable
error_on_line_overflow = true
error_on_unformatted = true I checked, all three options are necessary to trigger the panic, any other combination results in either a successful run or an explicit formatting error. rustfmt version according to
And finally the crash file |
Thank you for the extra info! |
Because this issue involves tabs, I think this is related to #4968 (comment) |
hard_tabs = true
Just checked with main because I saw that #6391 got merged and it seems to be working fine. Thank you! |
From local testing with rustfmt 1.8.0-nightly (d97c4fb 2025-01-13) this snippet from #6442 (comment) still panics with |
@ytmimi right, then it looks like my minimal example wasn't accurate because the original full project now correctly reports an error instead of panicking. |
I see. Either way, the MCVE you provided still panics, and I think that's a good enough reason to keep the issue open |
I'm affected, too. This issue seems to be caused by rustfmt tracking line widths and positions in character width units. Normally this isn't too obvious, but if |
Just to clarify |
The type of indentation is not important for error reporting. However, keeping the indentation as tabs has two issues: 1. rustfmt keeps track of widths, not character offsets. For space indentation, these two are the same. For tab indentation, this leads to issues like [1]. 2. annotate-snippet-rs always format leading tabs as four spaces. Thus, formatter error reporting is not faithful and ranges will not be marked correctly (or need another transformation). Replacing tabs with spaces for error reporting as early as possible solves these issues. [1] rust-lang#6442
I may have a practical solution that avoids messing too much with hard_tabs in #6500. Instead of trying to do index magic, I'd suggest to just report errors with lines converted to leading space representation. See my reasoning in the PR. Thanks for the notice about byte offsets. I guess #6500 won't break (or fix) anything regarding this change.
|
Also, here's a minimum example ready to clone: https://github.com/naseschwarz/rustfmt-issue-6442 |
The type of indentation is not important for error reporting. However, keeping the indentation as tabs has two issues: 1. rustfmt keeps track of widths, not character offsets. For space indentation, these two are the same. For tab indentation, this leads to issues like [1]. 2. annotate-snippet-rs always format leading tabs as four spaces. Thus, formatter error reporting is not faithful and ranges will not be marked correctly (or need another transformation). Replacing tabs with spaces for error reporting as early as possible solves these issues. [1] rust-lang#6442
The type of indentation is not important for error reporting. However, keeping the indentation as tabs has two issues: 1. rustfmt keeps track of widths, not character offsets. For space indentation, these two are the same. For tab indentation, this leads to issues like [1]. 2. annotate-snippet-rs always format leading tabs as four spaces. Thus, formatter error reporting is not faithful and ranges will not be marked correctly (or need another transformation). Replacing tabs with spaces for error reporting as early as possible solves these issues. [1] rust-lang#6442
Here's the code it died on
https://github.com/lbfalvy/orchid/tree/e0d246fe1fa75405305ec4390ba6815049246726
Logfile the panic asked me to attach
rustc-ice-2025-01-12T01_00_58-10688.txt
The text was updated successfully, but these errors were encountered: