Skip to content
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

rustfmt should remove format!("hello",);'s comma #4956

Closed
wooster0 opened this issue Aug 15, 2021 · 1 comment
Closed

rustfmt should remove format!("hello",);'s comma #4956

wooster0 opened this issue Aug 15, 2021 · 1 comment

Comments

@wooster0
Copy link
Contributor

fn main() {
    format!("hello",);
}

If I format this, I expect to get this:

fn main() {
    format!("hello");
}

But instead, nothing happens. It doesn't only apply to format!. For normal functions it works but for macros it doesn't because the comma could potentially be important input for the macro and rustfmt doesn't know that in this case the comma doesn't have a meaning.
I think we should do something about that.

  1. Maybe rustfmt can be made smarter to know that the comma is useless there?
  2. Maybe the definition can be changed to make it more specific and allow rustfmt to infer that trailing commas are unnecessary? https://doc.rust-lang.org/src/alloc/macros.rs.html#112
  3. Maybe only standard library macros can be put in a special "list" that rustfmt considers and then it removes trailing commas and other unnecessary stuff only from those macros. It might be unfair for macro authors that make macros outside the std.
  4. Some kind of attribute could be added that can be applied to macros to say that this macro's parameters are to be handled similarly like a normal function? #[treat_parameters_as_function_parameters] or something like that.
  5. Macros 2.0 are coming. Can they do something about this? Maybe we should make sure that with 2.0 macros it becomes easier to define macros where rustfmt can infer that trailing commas can be removed?
@calebcartwright
Copy link
Member

Thanks for reaching out, but going to close this as a duplicate as it's been discussed in various other issues where I'd want to keep the discussion (refs #3277, #3065, #8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants