Merge pull request #18587 from Veykril/push-urrlrursyrws

fix: Fix syntax fixup inserting unnecessary semicolons
This commit is contained in:
Lukas Wirth 2024-12-02 12:50:28 +00:00 committed by GitHub
commit 8762a4f9be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: ';',
@ -905,6 +906,21 @@ fn foo() {
"#,
expect![[r#"
fn foo () {|| __ra_fixup}
"#]],
);
}
#[test]
fn fixup_regression_() {
check(
r#"
fn foo() {
{}
{}
}
"#,
expect![[r#"
fn foo () {{} {}}
"#]],
);
}