mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 02:52:11 +00:00
minor: Handle match arm commas in make::match_arm
Co-authored-by: Giga Bowser <45986823+Giga-Bowser@users.noreply.github.com>
This commit is contained in:
parent
4183bcdcde
commit
2c01609d6d
3 changed files with 11 additions and 21 deletions
|
|
@ -842,9 +842,10 @@ pub fn ref_pat(pat: ast::Pat) -> ast::RefPat {
|
|||
}
|
||||
|
||||
pub fn match_arm(pat: ast::Pat, guard: Option<ast::MatchGuard>, expr: ast::Expr) -> ast::MatchArm {
|
||||
let comma_str = if expr.is_block_like() { "" } else { "," };
|
||||
return match guard {
|
||||
Some(guard) => from_text(&format!("{pat} {guard} => {expr}")),
|
||||
None => from_text(&format!("{pat} => {expr}")),
|
||||
Some(guard) => from_text(&format!("{pat} {guard} => {expr}{comma_str}")),
|
||||
None => from_text(&format!("{pat} => {expr}{comma_str}")),
|
||||
};
|
||||
|
||||
fn from_text(text: &str) -> ast::MatchArm {
|
||||
|
|
@ -877,7 +878,7 @@ pub fn match_arm_list(arms: impl IntoIterator<Item = ast::MatchArm>) -> ast::Mat
|
|||
let arms_str = arms.into_iter().fold(String::new(), |mut acc, arm| {
|
||||
let needs_comma =
|
||||
arm.comma_token().is_none() && arm.expr().is_none_or(|it| !it.is_block_like());
|
||||
let comma = if needs_comma { "," } else { "" };
|
||||
let comma = if needs_comma && arm.comma_token().is_none() { "," } else { "" };
|
||||
let arm = arm.syntax();
|
||||
format_to_acc!(acc, " {arm}{comma}\n")
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue