Skip to content

[not ready] Implement match_arm_forces_newline option (#2039) #2041

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

Merged
merged 3 commits into from
Oct 27, 2017
Merged

[not ready] Implement match_arm_forces_newline option (#2039) #2041

merged 3 commits into from
Oct 27, 2017

Conversation

osa1
Copy link
Contributor

@osa1 osa1 commented Oct 7, 2017

This is an attempt at implementing #2039. I don't quite understand rewrite_match_body function yet, I just played around with some parameters until it indented as I wanted.

Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I think the code change looks correct. This PR needs some tests and also needs to add to configurations.md

src/config.rs Outdated
@@ -622,6 +622,8 @@ create_config! {
merge_derives: bool, true, "Merge multiple `#[derive(...)]` into a single one";
binop_separator: SeparatorPlace, SeparatorPlace::Front,
"Where to put a binary operator when a binary expression goes multiline.";
match_arm_forces_newline: bool, false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this match_arm_force_block. The description should mention blocks rather than newlines too.

@osa1
Copy link
Contributor Author

osa1 commented Oct 15, 2017

I think this PR was previously misunderstood -- I now added examples which hopefully make the intention here more clear. This flag when combined with wrap_match_arms: false does not change block-ness of an arm, but it consistently indents all arm bodies no matter how long the arm is or whether it was a block or not.

This style may seem weird to others (especially the empty block case) but I like this a lot because I know exactly where to look for the body when I see a match expression.

I understand if we don't want to merge this (I may be the only user of this). I kinda wish that rustfmt was more customizable and allowed to have this effect via some combination of existing flags. I think that's currently not possible. If anyone know a flag that's (1) more useful than that and (2) allows indenting match arms this way when combined with some other flags I'd be more than happy to implement that.

@nrc
Copy link
Member

nrc commented Oct 27, 2017

Thanks for adding tests! Could you add documentation of the option to https://github.com/rust-lang-nursery/rustfmt/blob/master/Configurations.md please? r+ with that.

@osa1
Copy link
Contributor Author

osa1 commented Oct 27, 2017

Done! Thanks for the review. Let me know if you want me to rename the flag, it may be impossible to rename after publishing it.

@nrc nrc merged commit 6cfeb1f into rust-lang:master Oct 27, 2017
@nrc
Copy link
Member

nrc commented Oct 27, 2017

Great, thanks!

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

Successfully merging this pull request may close these issues.

2 participants