rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.03k stars 889 forks source link

Feature Request: Add spaces_within_parenthesized_items Option #5435

Open henriquemelicias opened 2 years ago

henriquemelicias commented 2 years ago

Discussion for spaces_within_parenthesized_items configuration option. Implemented by #5434.

This option enforces consistent spacing directly inside of parentheses, by putting one space to the right of '(' and to the left of ')' in parenthesized items, such as function calls:

fn ipsum_lorem(arg1: usize, arg2: usize, arg3: usize) to fn ipsum_lorem( arg1: usize, arg2: usize, arg3: usize )

I do believe there are cases where having these spaces do improve readability, for example on calls:

ipsum_lorem<T>(dolor_amet<T>(string)); to ipsum_lorem<T>( dolor_amet<T>( string ) );

Although I do understand that at the end of the day it is very subjective.

This option goes against some behaviours of the Rust Style Guide: Single line calls and tuple literals.

Discussion topics:

to

( a, b, c )
Foo( a, b )

Cheers!

ytmimi commented 2 years ago

@henriquemelicias I appreciate you opening this issue. I made a few tweaks to the title and description to better reflect that this is feature request. I think if we decide to move forward with the option we can add a separate issue to track stabilization.

calebcartwright commented 2 years ago

I think this falls in a similar theme as requests like #3564.

Though not an entirely uncommon style in certain other programming languages, it's not common at all for Rust code in my experience. I could see this being something folks coming from other languages may want to reach for at first due to subjective preference and/or familiarity as compared to non-Rust languages. However, like the author of #3564, I would also envision many of those same folks abandoning this style after becoming more used to Rust and not wanting to go against the grain.

As such I have some reservations, however, and again similar to #3564, it is a small and non-intrusive code change so I think we can certainly consider supporting it.

wcravens commented 3 months ago

In my team, this isn't a style issue, it's an accessibility issue. Space immediately inside opening and closing parens is easier to read for some of our older team members. This currently stops us from integrating rustfmt into our project.