-
Notifications
You must be signed in to change notification settings - Fork 925
Trailing commas handling in macro calls #3065
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
Comments
I investigated this issue and it is indeed doing the "right thing" as designed. Looking at https://github.com./rust-lang-nursery/rustfmt/blob/master/src/macros.rs#L298-L318 we see: DelimToken::Paren => {
// Format macro invocation as function call, preserve the trailing
// comma because not all macros support them.
overflow::rewrite_with_parens(
context,
¯o_name,
arg_vec.iter(),
shape,
mac.span,
context.config.width_heuristics().fn_call_width,
if trailing_comma {
Some(SeparatorTactic::Always)
} else {
Some(SeparatorTactic::Never)
},
) so it is avoiding adding the comma at end. The default is This is required because some macros do not support the trailing comma and fail to parse, causing parsing errors. The only way to address this would be adding a "whitelist" for macros which would be good to keep the default separator tectic. What people thing? |
Note that changing commas in nested expressions can still change the semantics of the macro expansion, so changing this only is not an option
I think the proposal is that where we already special case macros, we should further special case them if we know that trailing commas do not affect semantics. This seems like a reasonable thing to do, but I am not in a rush to do it - formatting of macros is far from perfect and I think one of the big things for 2.0 will be doing better in that area in a more generic, elegant manner. As such I'd rather not add too many special cases now. |
Good, I tend to agree with this vision as well. That said, I think creating a 2.0 milestone would be a good way to mark those issues also to allow new contributors to know where to focus their effort. |
gets, as expected, formatted to:
However,
gets formatted as:
No trailing comma after the second parameter.
And even worse, function calls in one of the
assert_eq!
parameters get the same treatment:gets formatted as:
No trailing comma after the second parameter of
foo
.And if you have a trailing comma and a parameter gets shorter, the trailing comma stays.
gets formatted as:
I understand that trailings commas can change the meaning of macros, but it seems
assert_eq!
is already special cased.Even more than the trailing comma after
assert_eq!
's second parameter, the handling of trailing commas in function calls in one ofassert_eq!
's parameter seems to me pretty inconvenient.Thanks for the hard work on such a useful tool.
The text was updated successfully, but these errors were encountered: