diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-12-02 12:50:28 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-02 12:50:28 +0000 |
| commit | 54a1a96b5786148d96a3918be7dcb058e0115a42 (patch) | |
| tree | 244d9682f19c4301558b932d647257ca08c06beb | |
| parent | 0946570e646f1c57969499cd289ac5672f651cfb (diff) | |
| parent | 03ae70dcacf96e50c52b0df20a99d655d33255d4 (diff) | |
| download | rust-54a1a96b5786148d96a3918be7dcb058e0115a42.tar.gz rust-54a1a96b5786148d96a3918be7dcb058e0115a42.zip | |
Merge pull request #18587 from Veykril/push-urrlrursyrws
fix: Fix syntax fixup inserting unnecessary semicolons
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs b/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs index b6d5828da96..0af29681a13 100644 --- a/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs +++ b/src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs @@ -110,7 +110,8 @@ pub(crate) fn fixup_syntax( } }, ast::ExprStmt(it) => { - if it.semicolon_token().is_none() { + let needs_semi = it.semicolon_token().is_none() && it.expr().map_or(false, |e| e.syntax().kind() != SyntaxKind::BLOCK_EXPR); + if needs_semi { append.insert(node.clone().into(), vec![ Leaf::Punct(Punct { char: ';', @@ -908,4 +909,19 @@ fn foo () {|| __ra_fixup} "#]], ); } + + #[test] + fn fixup_regression_() { + check( + r#" +fn foo() { + {} + {} +} +"#, + expect![[r#" +fn foo () {{} {}} +"#]], + ); + } } |
