Skip to content

Allow not indenting match arms #2937

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

Open
strega-nil opened this issue Aug 19, 2018 · 1 comment
Open

Allow not indenting match arms #2937

strega-nil opened this issue Aug 19, 2018 · 1 comment
Labels
a-matches match arms, patterns, blocks, etc feature-request only-with-option requires a non-default option value to reproduce p-low

Comments

@strega-nil
Copy link

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
Copy link

myrrlyn commented Aug 19, 2018

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.

@nrc nrc added the only-with-option requires a non-default option value to reproduce label Aug 21, 2018
@ytmimi ytmimi added a-matches match arms, patterns, blocks, etc p-low labels Jul 20, 2022
KAAtheWiseGit added a commit to KAAtheWiseGit/rustfmt that referenced this issue Mar 29, 2025
Allows to disable the indentation of match arms.

Related issue: rust-lang#2937
KAAtheWiseGit added a commit to KAAtheWiseGit/rustfmt that referenced this issue Mar 30, 2025
Allows to disable the indentation of match arms.

Related issue: rust-lang#2937

Co-authored-by: Yacin Tmimi <[email protected]>
KAAtheWiseGit added a commit to KAAtheWiseGit/rustfmt that referenced this issue Mar 30, 2025
Allows to disable the indentation of match arms.

Related issue: rust-lang#2937

Co-authored-by: Yacin Tmimi <[email protected]>
KAAtheWiseGit added a commit to KAAtheWiseGit/rustfmt that referenced this issue Mar 30, 2025
Allows to disable the indentation of match arms.

Related issue: rust-lang#2937

Co-authored-by: Yacin Tmimi <[email protected]>
KAAtheWiseGit added a commit to KAAtheWiseGit/rustfmt that referenced this issue Apr 2, 2025
Allows to disable the indentation of match arms.

Related issue: rust-lang#2937

Co-authored-by: Yacin Tmimi <[email protected]>
ytmimi added a commit to KAAtheWiseGit/rustfmt that referenced this issue Apr 3, 2025
Allows to disable the indentation of match arms.

Related issue: rust-lang#2937

Co-authored-by: Yacin Tmimi <[email protected]>
ytmimi added a commit that referenced this issue Apr 3, 2025
Allows to disable the indentation of match arms.

Related issue: #2937

Co-authored-by: Yacin Tmimi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-matches match arms, patterns, blocks, etc feature-request only-with-option requires a non-default option value to reproduce p-low
Projects
None yet
Development

No branches or pull requests

5 participants