-
Notifications
You must be signed in to change notification settings - Fork 892
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
fix panic on failure to format generics in enum #6396
base: master
Are you sure you want to change the base?
Conversation
97e8897
to
733e1ef
Compare
@ding-young thanks for picking this one up! I wonder if now would be a good time to refactor Let me know what you think? |
Can we also add this smaller reproducible case from the original issue: enum Node where P::<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S<S>>>>>>>>>>>>>>>>>>>>>>>>: {
Cons,
} |
@ding-young there were also some linked issues like #6137, #6318, #6378. Would be good to check these issues out as well. #6378 doesn't seem to have a minimal test case so feel free to ignore that one. |
- related issues: rust-lang#5738, rust-lang#6137, rust-lang#6318, rust-lang#6378 - instead of calling unwrap(), restore original snippet when we fail to format generics in enum - we need to propagate this rewrite failure later
733e1ef
to
ff6ebd3
Compare
- introduce format_enum that returns Rewrite - early return when it fails to format the generics in enum
Thank you for listing all the related issues! I included only the cases that originally lead to a rustfmt crash. |
About refactoring I still need to take a closer look to ensure the original behavior is preserved, so I’ll leave it as a draft, but it would be great if you could briefly check whether I’m refactoring in the right direction. |
@ding-young thanks for looking into this refactor. I won't have time to review this PR this weekend, but I'll try to set aside some time for a review next week. |
fixes #5738
Description
Above issue reports panic when formatting complex enum with generic parameters.
This is because rustfmt simply calls
unwrap()
onRewrite
(RewriteResult
in future), the return value fromformat_generics
.It is better not to panic on this sort of rewrite failure.
Therefore, this pr restores original snippet when we fail to formatgenerics
in enum instead of callingunwrap()
.None
early and then leave entire enum unformatted instead of callingunwrap()
.visit_enum
is refactored withformat_enum
that returnsRewrite
. Later pr will replace this rewrite withRewriteResult
TODO
visitor.rs
?