mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 10:17:15 +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")
|
||||
});
|
||||
|
|
|
|||
|
|
@ -435,7 +435,7 @@ mod tests {
|
|||
_ => {
|
||||
let var_name = 2 + 2;
|
||||
(var_name, true)
|
||||
}"#]];
|
||||
},"#]];
|
||||
expect.assert_eq(&edit.new_root.to_string());
|
||||
|
||||
assert_eq!(edit.find_annotation(placeholder_snippet).len(), 2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue