rustfmt
rustfmt copied to clipboard
Fix generic default type assignment panic
Fixes https://github.com/rust-lang/rustfmt/issues/6052
The cause of the issue is when there's an = type assignment with the generics that overflows a line.
The budget given to def.rewrite is too low, this causes a cascading Option::None which eventually is unwrapped and causes the panic.
One more interaction caused another Option::None, the first was the formatting mentioned above, the second is that overflow.rs hardcodes to leave the last entry, which causes nothing to be written on a single entry, as was my test-case. I changed that logic to leave_last if greater than 1 length. I'm not familiar enough with the codebase to tell whether that could cause problems that aren't covered by tests.
I tried out two solutions to the formatting issue:
- Just give a budget of
usize::MAX, then the user gets aline too longinstead of a panic. - Split the
eq_strlhs and rhs into separate lines if it's too long, if it's still too long after that the user gets aline too long. Still usingeusize::MAXas budget.
Ending up going with the second one, since that seems nicer, it's very easy to change to the first one though.
E: Added the reported example as is as a test.
Also ran it on tokio, cause it has a bunch of code, to check for unintended consequences, not the best way to check for those apart from the tests, but it's something