-
Notifications
You must be signed in to change notification settings - Fork 901
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
Compiler unexpectedly panicked when formatting code #5876
Comments
@gianzellweger when you have a moment can you please provide a minimal code snippet inline that we can run rustfmt on with your configuration to reproduce the issue. something like: fn main() {
// code that reproduces the issue
} Without an example code snippet there's very little we can do to help. |
@ytmimi Is there a way to see which code it was trying to format? The entire project has about 2000 LOC and I do not think that satisfies the "minimal code snippet" requirement. I also tried it with another project and there it worked like intended. |
@gianzellweger first, I want to say thanks for bringing this to our attention. If you can try to narrow it down that would be great. Just looking at the logs you've provided I think this might be a duplicate of #4968 |
@ytmimi I have now narrowed it down to a single file (which is still 1000 lines, so not a helpful progression) and I have tried deactivating every single configuration on its own. The panic only goes away if I remove |
Normally I'd recommend running rustfmt with Any chance you can share a link to the file? |
@ytmimi How about I instead narrow it down to the specific piece of code? There's only about 10-20 functions which I can comment out separately until the error goes away. |
Alright, I had a look at this and I think I've got it. In your case the error is happening in the |
@ytmimi That fixed it, thank you so much. Can we agree that this isn't optimal behavior from rustfmt and could be improved? Not trying to put any pressure on anybody. |
@gianzellweger this particular issue will almost certainly be resolved once we add support for Here's a bit of a deep dive explanation into what's happening in this case: fn fail() {
if let Some(x) = x && y {
format!("{:name_width$} {:temperature_width$.2}°C {:critical_width$}")
// ^
// |
// |
// trailing whitespace
}
} and here's a screenshot that highlights the whitespace at the end: The issue is that rustfmt doesn't currently support formatting At the end of the formatting process rustfmt does a pass over that output buffer to see if there are instances of trailing whitespace or lines that exceed the |
@ytmimi That makes a lot of sense, as my code uses let-chains. Is there any issue that tracks the progress of this or has this implementation not started at all? Thank you once more. |
The example input from #5888 is also really helpful at highlighting this issue: pub(crate) fn sanity_needs_ocr<T: HasWord + HasRect>(collection: &[T]) -> bool {
let needs_ocr = collection.is_empty()
// the presence of 'UNICODE REPLACEMENT CHARACTER'
|| collection.iter().any(|c| c.text().contains('�'))
// (yes, empty pages will also be OCR'd)
|| collection_is_void_of_text(collection)
|| is_gibberish(&collection.to_rendered_text());
#[cfg(debug_assertions)]
if needs_ocr {
tracing::trace!(
"sanity check failed, with text: {:?}",
collection.to_rendered_text()
);
}
needs_ocr
} and here's my explanation of the problem: #5888 (comment) |
I found a much smaller example that triggers the same error: #![allow(incomplete_features)]
#![feature(
try_blocks,
never_type,
min_specialization,
exclusive_range_pattern,
lazy_cell
)] Putting that as input into
There's no |
@danielhuang thanks! The tab characters are what's causing the panic. Similar issues have been reported before. An explanation of what's going on can be found at #4968 (comment), and there are PRs already open to resolve your case. |
I recently looked through all the features of Rustfmt and picked a few options where I preferred some option over the default. When trying this new mix, however, I got an error. I have attached both the log and my configuration.
rustc-ice-2023-08-02T21:08:46.715244Z-75321.txt
rustfmt.toml
The text was updated successfully, but these errors were encountered: