-
Notifications
You must be signed in to change notification settings - Fork 898
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
Double Commas in #derive eats entire #derive #3898
Comments
Marking this p-low as the input does not compile in the first place, though rustfmt should be able to handle this somehow as it is parsable. |
I will try to take a look at this as my very first open-source issue at RustFest impl-days.. |
That's great @lusen82! I don't know offhand specifically where the issue may be, but I'd probably start with looking at some of the below functions in Lines 60 to 66 in 7ecd467
I'm guessing that Lines 95 to 127 in 7ecd467
|
Hi Calebcartwright, sorry, it seems I came back to reality (and with that, my day-job) so I haven't seen your message. |
Thanks for digging into it @lusen82! Were you able to determine if I could see this issue being frustrating in instances where folks have automatic format-on-save enabled in their editors, and a simple extra comma typo results in that entire derive getting wiped on save. I think to address this we'd need to be able to detect this malformed derivce condition and if possible, remove the erroneous comma, or just leave the malformed derive as-is in the worst case scenario. rustfmt would also need to be able to differentiate between this scenario (a malformed derive) and an empty derive #[derive(Debug)]
#[derive()]
struct Foo {
bar: u32,
} to #[derive(Debug)]
struct Foo {
bar: u32,
} |
Thanks for your reply! To me, it really seems that meta_item_list in this case is returning None (and the derives are thus already "lost"). I tried to trace back to where the attribute was kind of created to see if the check could com in at an earlier state, but I some what ended up in the rustc and didn't really find anywhere to identify the typo.. |
rustfmt uses the rustc parser to generate the AST, and the AST is then used to generate the desired formatting. It's this piece that'll need to be updated to handle the malformed derive (rustfmt takes whatever the parser gives us). Even though the derive is malformed, the associated AST node still has everything needed to get the original derive attribute contents (via The problem is that when Lines 418 to 431 in d5b6560
For those derive attributes, the attributes that have You'll notice that if you set Lines 459 to 460 in d5b6560
Which just emits the original snippet of the derive. Perhaps one way to solve this would be to split the resulting collection of derive attributes returned from |
Thank you very much for your detailed input. I understand what you mean and also found the context's original text of derive. I have a small fix now which seems to work but it feels a little bit ugly and non-general. I will at least try to clean it up a little bit and test some more cases before proposing a first version :) |
Input:
(note the double commas after
Debug
above. The space is irrelevant in my testing)Outputs:
and a :( from me.
Thanks guys
The text was updated successfully, but these errors were encountered: