-
Notifications
You must be signed in to change notification settings - Fork 928
Not removing commas from end of multiple attributes list #5394
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
base: master
Are you sure you want to change the base?
Not removing commas from end of multiple attributes list #5394
Conversation
I think the trailing comma should still be removed if it isn't followed by a line break, same as for function calls. edit: with less negatives: I think the trailing comma should only be kept if it's followed by a line break. |
@jplatte I appreciate that you'd prefer different behavior around commas in macro calls, but we're not going to rehash the same, settled posture again on this PR. The current behavior is a bug which this PR is intended to address, so please refrain from attempts to modify or increase scope. |
Whoa okay, sorry! I thought this was simply a case that wasn't considered properly, rather than an intentional design decision. I didn't see it discussed in #3277 at all. |
So, to clarify: the behaviour after this PR is that commas at the end of multi-item metalists will not be added/removed at all. If the attribute is converted between multi-line/single-line the user will have to add/remove the final comma to have it consistent with function arguments, but then running |
No worries. It was implicit vs explicit, but yes it's intentional. If there's a comma in the input source we need to maintain it regardless of leading/trailing whitespace characters. |
yup |
Overall these changes look good to me. I was curious why the |
I don't know. This is beyond my understanding of caro ... It seems that at least the first
Adding such commas seem to cause parsing/compilation errors. Are there cases where such commas are valid? |
Ah I see. I don't think you need to use
Maybe not in the case of all attribute macros, but you could conceivably write a macro that requires them and removing those commas would then lead to compilation errors. Ultimately I think our goal for macro rewriting is to not add or remove any tokens so if the developer wrote |
Switched to
This PR changes should not affect such macro case. However, I was not able to write code example that will prove that. |
1 similar comment
Switched to
This PR changes should not affect such macro case. However, I was not able to write code example that will prove that. |
Fantastic! I assume with the switch you wont see any other changes with the Cargo.lock
Taking an existing test case, could we just add trailing commas and make sure that those commas aren't removed. For example:
|
6bca615
to
45f81b6
Compare
This is a good example! I found that my initial fix was wrong, and did not properly handle the commas between the parenthesis ... (Note that the last comma before the I re-implemented the fix and added test cases. The root cause of the issue is that for a list in an attribute, the last AST item includes both the list closing ')' and the attribute closing ']'. Therefore, the check in |
@davidBar-On I've been doing some backlog triage and came across #3228, which this PR solves. If you don't mind could you add a test case for the |
Added |
Thank you!! |
What's the status of this PR? Would be nice to get this merged. |
Came here from #6439. PR looks reviewed. I rebased locally (small easy conflict) and it passes tests. Can it be merged in that case? Thanks. |
Fix for #3277 - not removing commas from end of multiple attributes list.
The comma was originally removed since otherwise redundant commas would have been added after consecutive closing delimiters. E.g.
.... attr,)])
would have been formatted as.... attr,),],)
. To prevent that, a logic was added to prevent the comma removal after the last attribute, but without adding the redundant commas.UPDATE: per this comment, also resolves issue #3228.