Skip to content
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

Empty match arms #4065

Closed
pickfire opened this issue Feb 26, 2020 · 4 comments
Closed

Empty match arms #4065

pickfire opened this issue Feb 26, 2020 · 4 comments
Labels
a-matches match arms, patterns, blocks, etc good first issue Issues up for grabs, also good candidates for new rustfmt contributors

Comments

@pickfire
Copy link

=> () should be => {} rust-lang/style-team#146

@pickfire
Copy link
Author

I took my time trying to write this but I looked at the wrong line instead (is_empty_block). T_T

@topecongiro topecongiro added the good first issue Issues up for grabs, also good candidates for new rustfmt contributors label May 10, 2020
@laysauchoa
Copy link

@pickfire are you working on this? I would like to contribute. What should be done mainly here?

@pickfire
Copy link
Author

@laysauchoa No, I tried checking this but I didn't spend much time on this issue. My guess is somewhere around https://github.com/rust-lang/rustfmt/blob/master/rustfmt-core/rustfmt-lib/src/matches.rs#L219 but I don't quite grasp the workflow of rustfmt yet, I don't quite know how to debug stuff here.

@ayazhafiz
Copy link
Contributor

@laysauchoa take a look at matches#rewrite_match_body. It should be enough to check if the arm body is an empty block, which is resolved here:

);
let (is_block, is_empty_block) = if let ast::ExprKind::Block(ref block, _) = body.kind {
(true, is_empty_block(context, block, Some(&body.attrs)))

And if so, rewrite the original arm body with (), maybe in the combine_orig_body closure which is one method responsible for formatting the rewritten arm body:

let combine_orig_body = |body_str: &str| {
let block_sep = match context.config.control_brace_style() {
ControlBraceStyle::AlwaysNextLine if is_block => alt_block_sep,
_ => " ",
};
Some(format!("{} =>{}{}{}", pats_str, block_sep, body_str, comma))
};

Or something like that..

This was referenced May 31, 2020
@calebcartwright calebcartwright added the a-matches match arms, patterns, blocks, etc label Jun 20, 2020
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 good first issue Issues up for grabs, also good candidates for new rustfmt contributors
Projects
None yet
Development

No branches or pull requests

5 participants