From 633aace41108b74fe6c93c5ab04272067db033f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 17:08:58 +0200 Subject: [PATCH] Rename LambdaExpr -> ClosureExpr --- .../src/handlers/extract_variable.rs | 4 +-- crates/ra_hir_def/src/body/lower.rs | 2 +- crates/ra_hir_expand/src/db.rs | 2 +- crates/ra_ide/src/completion/patterns.rs | 2 +- .../ra_parser/src/grammar/expressions/atom.rs | 2 +- crates/ra_parser/src/syntax_kind/generated.rs | 2 +- crates/ra_syntax/src/ast/generated/nodes.rs | 35 ++++++++----------- .../parser/err/0010_unsafe_lambda_block.rast | 2 +- .../parser/err/0012_broken_lambda.rast | 2 +- .../parser/err/0039_lambda_recovery.rast | 2 +- .../parser/inline/ok/0106_lambda_expr.rast | 14 ++++---- .../parser/inline/ok/0130_let_stmt.rast | 2 +- .../parser/inline/ok/0155_closure_params.rast | 2 +- .../inline/ok/0158_lambda_ret_block.rast | 2 +- .../test_data/parser/ok/0035_weird_exprs.rast | 4 +-- .../test_data/parser/ok/0044_let_attrs.rast | 2 +- xtask/src/ast_src.rs | 2 +- xtask/src/codegen/gen_syntax.rs | 14 +++++++- xtask/src/codegen/rust.ungram | 16 ++++----- 19 files changed, 59 insertions(+), 54 deletions(-) diff --git a/crates/ra_assists/src/handlers/extract_variable.rs b/crates/ra_assists/src/handlers/extract_variable.rs index b925a2884c..cc62db0c44 100644 --- a/crates/ra_assists/src/handlers/extract_variable.rs +++ b/crates/ra_assists/src/handlers/extract_variable.rs @@ -1,7 +1,7 @@ use ra_syntax::{ ast::{self, AstNode}, SyntaxKind::{ - BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, + BLOCK_EXPR, BREAK_EXPR, CLOSURE_EXPR, COMMENT, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, }, SyntaxNode, }; @@ -148,7 +148,7 @@ impl Anchor { } if let Some(parent) = node.parent() { - if parent.kind() == MATCH_ARM || parent.kind() == LAMBDA_EXPR { + if parent.kind() == MATCH_ARM || parent.kind() == CLOSURE_EXPR { return Some(Anchor::WrapInBlock(node)); } } diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 67d7041fc4..99d7234025 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -473,7 +473,7 @@ impl ExprCollector<'_> { self.alloc_expr(Expr::Missing, syntax_ptr) } } - ast::Expr::LambdaExpr(e) => { + ast::Expr::ClosureExpr(e) => { let mut args = Vec::new(); let mut arg_types = Vec::new(); if let Some(pl) = e.param_list() { diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs index 41df666965..f3b7cd492c 100644 --- a/crates/ra_hir_expand/src/db.rs +++ b/crates/ra_hir_expand/src/db.rs @@ -379,7 +379,7 @@ fn to_fragment_kind(db: &dyn AstDatabase, id: MacroCallId) -> FragmentKind { FOR_EXPR => FragmentKind::Expr, PATH_EXPR => FragmentKind::Expr, - LAMBDA_EXPR => FragmentKind::Expr, + CLOSURE_EXPR => FragmentKind::Expr, CONDITION => FragmentKind::Expr, BREAK_EXPR => FragmentKind::Expr, RETURN_EXPR => FragmentKind::Expr, diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index a68861e1c9..9e654b373c 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -134,7 +134,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { NodeOrToken::Token(token) => token.parent(), }; for node in leaf.ancestors() { - if node.kind() == FN || node.kind() == LAMBDA_EXPR { + if node.kind() == FN || node.kind() == CLOSURE_EXPR { break; } let loop_body = match_ast! { diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 706a2f796b..0b01d3bc64 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs @@ -250,7 +250,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { p.error("expected expression"); } } - m.complete(p, LAMBDA_EXPR) + m.complete(p, CLOSURE_EXPR) } // test if_expr diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 64ab182175..2830c0d74b 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -173,7 +173,7 @@ pub enum SyntaxKind { ARRAY_EXPR, PAREN_EXPR, PATH_EXPR, - LAMBDA_EXPR, + CLOSURE_EXPR, IF_EXPR, WHILE_EXPR, CONDITION, diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 186db538b8..158544fa21 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -582,9 +582,7 @@ pub struct BinExpr { pub(crate) syntax: SyntaxNode, } impl ast::AttrsOwner for BinExpr {} -impl BinExpr { - pub fn expr(&self) -> Option { support::child(&self.syntax) } -} +impl BinExpr {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BoxExpr { pub(crate) syntax: SyntaxNode, @@ -680,9 +678,7 @@ impl ast::AttrsOwner for IfExpr {} impl IfExpr { pub fn if_token(&self) -> Option { support::token(&self.syntax, T![if]) } pub fn condition(&self) -> Option { support::child(&self.syntax) } - pub fn block_expr(&self) -> Option { support::child(&self.syntax) } pub fn else_token(&self) -> Option { support::token(&self.syntax, T![else]) } - pub fn if_expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct IndexExpr { @@ -690,7 +686,6 @@ pub struct IndexExpr { } impl ast::AttrsOwner for IndexExpr {} impl IndexExpr { - pub fn expr(&self) -> Option { support::child(&self.syntax) } pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } @@ -704,11 +699,11 @@ impl Label { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct LambdaExpr { +pub struct ClosureExpr { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for LambdaExpr {} -impl LambdaExpr { +impl ast::AttrsOwner for ClosureExpr {} +impl ClosureExpr { pub fn static_token(&self) -> Option { support::token(&self.syntax, T![static]) } pub fn async_token(&self) -> Option { support::token(&self.syntax, T![async]) } pub fn move_token(&self) -> Option { support::token(&self.syntax, T![move]) } @@ -778,9 +773,7 @@ pub struct RangeExpr { pub(crate) syntax: SyntaxNode, } impl ast::AttrsOwner for RangeExpr {} -impl RangeExpr { - pub fn expr(&self) -> Option { support::child(&self.syntax) } -} +impl RangeExpr {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordExpr { pub(crate) syntax: SyntaxNode, @@ -1351,7 +1344,7 @@ pub enum Expr { IfExpr(IfExpr), IndexExpr(IndexExpr), Label(Label), - LambdaExpr(LambdaExpr), + ClosureExpr(ClosureExpr), Literal(Literal), LoopExpr(LoopExpr), MacroCall(MacroCall), @@ -2101,8 +2094,8 @@ impl AstNode for Label { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for LambdaExpr { - fn can_cast(kind: SyntaxKind) -> bool { kind == LAMBDA_EXPR } +impl AstNode for ClosureExpr { + fn can_cast(kind: SyntaxKind) -> bool { kind == CLOSURE_EXPR } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -3114,8 +3107,8 @@ impl From for Expr { impl From