Skip to content

Commit 7325283

Browse files
bors[bot]matklad
andauthored
Merge #5624
5624: Finalize expressions grammar r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents ad239f6 + 633aace commit 7325283

File tree

19 files changed

+894
-848
lines changed

19 files changed

+894
-848
lines changed

crates/ra_assists/src/handlers/extract_variable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ra_syntax::{
22
ast::{self, AstNode},
33
SyntaxKind::{
4-
BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
4+
BLOCK_EXPR, BREAK_EXPR, CLOSURE_EXPR, COMMENT, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
55
},
66
SyntaxNode,
77
};
@@ -148,7 +148,7 @@ impl Anchor {
148148
}
149149

150150
if let Some(parent) = node.parent() {
151-
if parent.kind() == MATCH_ARM || parent.kind() == LAMBDA_EXPR {
151+
if parent.kind() == MATCH_ARM || parent.kind() == CLOSURE_EXPR {
152152
return Some(Anchor::WrapInBlock(node));
153153
}
154154
}

crates/ra_hir_def/src/body/lower.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,22 @@ impl ExprCollector<'_> {
224224
self.alloc_expr(Expr::Unsafe { body }, syntax_ptr)
225225
}
226226
// FIXME: we need to record these effects somewhere...
227-
ast::Effect::Async(_) | ast::Effect::Label(_) => {
228-
self.collect_block_opt(e.block_expr())
229-
}
227+
ast::Effect::Label(label) => match e.block_expr() {
228+
Some(block) => {
229+
let res = self.collect_block(block);
230+
match &mut self.body.exprs[res] {
231+
Expr::Block { label: block_label, .. } => {
232+
*block_label =
233+
label.lifetime_token().map(|t| Name::new_lifetime(&t))
234+
}
235+
_ => unreachable!(),
236+
}
237+
res
238+
}
239+
None => self.missing_expr(),
240+
},
241+
// FIXME: we need to record these effects somewhere...
242+
ast::Effect::Async(_) => self.collect_block_opt(e.block_expr()),
230243
},
231244
ast::Expr::BlockExpr(e) => self.collect_block(e),
232245
ast::Expr::LoopExpr(e) => {
@@ -460,7 +473,7 @@ impl ExprCollector<'_> {
460473
self.alloc_expr(Expr::Missing, syntax_ptr)
461474
}
462475
}
463-
ast::Expr::LambdaExpr(e) => {
476+
ast::Expr::ClosureExpr(e) => {
464477
let mut args = Vec::new();
465478
let mut arg_types = Vec::new();
466479
if let Some(pl) = e.param_list() {
@@ -618,8 +631,7 @@ impl ExprCollector<'_> {
618631
})
619632
.collect();
620633
let tail = block.expr().map(|e| self.collect_expr(e));
621-
let label = block.label().and_then(|l| l.lifetime_token()).map(|t| Name::new_lifetime(&t));
622-
self.alloc_expr(Expr::Block { statements, tail, label }, syntax_node_ptr)
634+
self.alloc_expr(Expr::Block { statements, tail, label: None }, syntax_node_ptr)
623635
}
624636

625637
fn collect_block_items(&mut self, block: &ast::BlockExpr) {

crates/ra_hir_expand/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ fn to_fragment_kind(db: &dyn AstDatabase, id: MacroCallId) -> FragmentKind {
379379

380380
FOR_EXPR => FragmentKind::Expr,
381381
PATH_EXPR => FragmentKind::Expr,
382-
LAMBDA_EXPR => FragmentKind::Expr,
382+
CLOSURE_EXPR => FragmentKind::Expr,
383383
CONDITION => FragmentKind::Expr,
384384
BREAK_EXPR => FragmentKind::Expr,
385385
RETURN_EXPR => FragmentKind::Expr,

crates/ra_ide/src/completion/patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool {
134134
NodeOrToken::Token(token) => token.parent(),
135135
};
136136
for node in leaf.ancestors() {
137-
if node.kind() == FN || node.kind() == LAMBDA_EXPR {
137+
if node.kind() == FN || node.kind() == CLOSURE_EXPR {
138138
break;
139139
}
140140
let loop_body = match_ast! {

crates/ra_parser/src/grammar/expressions/atom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
250250
p.error("expected expression");
251251
}
252252
}
253-
m.complete(p, LAMBDA_EXPR)
253+
m.complete(p, CLOSURE_EXPR)
254254
}
255255

256256
// test if_expr

crates/ra_parser/src/syntax_kind/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub enum SyntaxKind {
173173
ARRAY_EXPR,
174174
PAREN_EXPR,
175175
PATH_EXPR,
176-
LAMBDA_EXPR,
176+
CLOSURE_EXPR,
177177
IF_EXPR,
178178
WHILE_EXPR,
179179
CONDITION,

0 commit comments

Comments
 (0)