Fix generic default type assignment panic #6087
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #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 cascadingOption::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 thatoverflow.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 toleave_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:
usize::MAX
, then the user gets aline too long
instead of a panic.eq_str
lhs 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::MAX
as 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