Unnamed repository; edit this file 'description' to name the repository.
revert blocklike changes
jnyfah 2025-01-16
parent e3deeec · commit 2ac6cb1
-rw-r--r--crates/parser/src/grammar.rs5
-rw-r--r--crates/parser/src/grammar/expressions.rs10
-rw-r--r--crates/parser/src/grammar/expressions/atom.rs2
3 files changed, 9 insertions, 8 deletions
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs
index d3aa56c7eb..fe6b904bd8 100644
--- a/crates/parser/src/grammar.rs
+++ b/crates/parser/src/grammar.rs
@@ -204,9 +204,8 @@ impl BlockLike {
self == BlockLike::Block
}
- fn is_blocklike(expr: &CompletedMarker, p: &Parser<'_>) -> bool {
- matches!(expr.kind(), BLOCK_EXPR | IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR)
- || (expr.last_token(p) == Some(T!['}']) && !matches!(expr.kind(), CLOSURE_EXPR))
+ fn is_blocklike(kind: SyntaxKind) -> bool {
+ matches!(kind, BLOCK_EXPR | IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR)
}
}
diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs
index e7ba33bcb6..6494ce8d71 100644
--- a/crates/parser/src/grammar/expressions.rs
+++ b/crates/parser/src/grammar/expressions.rs
@@ -134,10 +134,12 @@ pub(super) fn let_stmt(p: &mut Parser<'_>, with_semi: Semicolon) {
// test_err let_else_right_curly_brace
// fn func() { let Some(_) = {Some(1)} else { panic!("h") };}
if let Some(expr) = expr_after_eq {
- if BlockLike::is_blocklike(&expr, p) {
- p.error(
- "right curly brace `}` before `else` in a `let...else` statement not allowed",
- )
+ if let Some(token) = expr.last_token(p) {
+ if token == T!['}'] {
+ p.error(
+ "right curly brace `}` before `else` in a `let...else` statement not allowed"
+ )
+ }
}
}
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs
index 40705d4a39..407320e1d0 100644
--- a/crates/parser/src/grammar/expressions/atom.rs
+++ b/crates/parser/src/grammar/expressions/atom.rs
@@ -198,7 +198,7 @@ pub(super) fn atom_expr(
}
};
let blocklike =
- if BlockLike::is_blocklike(&done, p) { BlockLike::Block } else { BlockLike::NotBlock };
+ if BlockLike::is_blocklike(done.kind()) { BlockLike::Block } else { BlockLike::NotBlock };
Some((done, blocklike))
}