diff --git a/crates/ide_assists/src/handlers/merge_match_arms.rs b/crates/ide_assists/src/handlers/merge_match_arms.rs index 5c6bb986b9..0ebc5d267c 100644 --- a/crates/ide_assists/src/handlers/merge_match_arms.rs +++ b/crates/ide_assists/src/handlers/merge_match_arms.rs @@ -72,7 +72,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option .join(" | ") }; - let arm = format!("{} => {}", pats, current_expr.syntax().text()); + let arm = format!("{} => {},", pats, current_expr.syntax().text()); if let [first, .., last] = &*arms_to_merge { let start = first.syntax().text_range().start(); @@ -118,7 +118,7 @@ enum X { A, B, C } fn main() { let x = X::A; let y = match x { - X::A | X::B => { 1i32 } + X::A | X::B => { 1i32 }, X::C => { 2i32 } } } @@ -183,7 +183,7 @@ fn main() { let x = X::A; let y = match x { X::A => { 1i32 }, - _ => { 2i32 } + _ => { 2i32 }, } } "#, diff --git a/crates/ide_diagnostics/src/handlers/inactive_code.rs b/crates/ide_diagnostics/src/handlers/inactive_code.rs index dfd0e33519..b6a7aee59e 100644 --- a/crates/ide_diagnostics/src/handlers/inactive_code.rs +++ b/crates/ide_diagnostics/src/handlers/inactive_code.rs @@ -64,7 +64,7 @@ fn f() { match () { () => (), #[cfg(a)] () => (), - //^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled + //^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled } #[cfg(a)] 0 // Trailing expression of block diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs index 30af469bc7..e9280ab45c 100644 --- a/crates/syntax/src/ast/edit_in_place.rs +++ b/crates/syntax/src/ast/edit_in_place.rs @@ -359,14 +359,10 @@ impl ast::MatchArmList { let mut elements = Vec::new(); let position = match self.arms().last() { Some(last_arm) => { - let comma = last_arm - .syntax() - .siblings_with_tokens(Direction::Next) - .find(|it| it.kind() == T![,]); - if needs_comma(&last_arm) && comma.is_none() { - elements.push(make::token(SyntaxKind::COMMA).into()); + if needs_comma(&last_arm) { + ted::append_child(last_arm.syntax(), make::token(SyntaxKind::COMMA)); } - Position::after(comma.unwrap_or_else(|| last_arm.syntax().clone().into())) + Position::after(last_arm.syntax().clone()) } None => match self.l_curly_token() { Some(it) => Position::after(it), @@ -377,12 +373,12 @@ impl ast::MatchArmList { elements.push(make::tokens::whitespace(&format!("\n{}", indent)).into()); elements.push(arm.syntax().clone().into()); if needs_comma(&arm) { - elements.push(make::token(SyntaxKind::COMMA).into()); + ted::append_child(arm.syntax(), make::token(SyntaxKind::COMMA)); } ted::insert_all(position, elements); fn needs_comma(arm: &ast::MatchArm) -> bool { - arm.expr().map_or(false, |e| !e.is_block_like()) + arm.expr().map_or(false, |e| !e.is_block_like()) && arm.comma_token().is_none() } } }