-
Notifications
You must be signed in to change notification settings - Fork 926
Inline if .. else
expression
#452
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
It is intended, but it's a style that's often requested, so we should probably have an option for it. (I thought there was an issue for this already, but I couldn't find one). |
+1 on this. There are some libraries in rust-lang in which this change is made all-over the place, even for very short lines (e.g. libfmt_macros, although in many cases I prefer rustfmt style). |
This is already possible by setting |
https://github.com/nrc/rustfmt/blob/master/tests/target/single-line-if-else.rs has some example output. |
Ha! That is why I couldn't find an issue :-) |
Ah cool! Thanks!! |
@marcusklaas Was option $ rustfmt --version
rustfmt 1.4.11-nightly (1838235 2019-12-03)
$ rustfmt main.rs
Warning: Unknown configuration option `single_line_if_else` |
I do not know. I haven't been involved with this project for a long time. |
even with |
if .. else
is sometimes used in lieu of the ternary operator in C, so it might be a good idea to preserve the original intention if the programmer wrote a shortif .. else
expression in a single line.A wild case found in rust-lang/rust#28988:
was converted into:
which looks a bit more verbose. Is this an intended behavior?
Hmm, well, looking at the code again, the latter also seems OK to me... Now I'm not sure which side I'm in. Maybe this should be exposed as a configuration option?
The text was updated successfully, but these errors were encountered: