rust-lang / rustfmt

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

Allow not indenting match arms #2937

Open strega-nil opened 6 years ago

strega-nil commented 6 years ago

It's a common style in C++ to see:

switch (foo) {
case Foo::Bar: {
  ...
} break;
case Foo::Baz: {
  ...
} break;
}

I would like a similar style to be possible with rustfmt:

match foo {
| Foo::Bar => {
    ...
}
| Foo::Baz => {
    ...
}
}

or

match foo {
Foo::Bar => {
    ...
}
Foo::Baz => {
    ...
}
}

This would require two configuration options, probably; | before each case, and the non-indentation.

Thanks!

myrrlyn commented 6 years ago

I strongly agree with this! Nested matches get especially painful; I have instances in my work where, with impl/fn already consuming two indents, a triple match level adds on another six and I don't get to write actual code until 32 columns in

My personal possibly bad habits about code layout aside, indenting match arm conditions and bodies feels redundant and unnecessarily wasteful to me; they don't both add meaning to rightward drift.

I think a | arm would provide a visual half-indent and be a nice blend of keeping the interior of the match body indented without costing additional space.