From 7980a7e19a679e0bc128f2c142609f7f4a197bf6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 18:04:57 +0200 Subject: [PATCH] Minor --- .../handlers/change_return_type_to_result.rs | 1 - crates/ra_hir_def/src/body/lower.rs | 3 - crates/ra_syntax/src/ast/generated/nodes.rs | 130 +++++++++--------- xtask/src/codegen/rust.ungram | 13 +- 4 files changed, 68 insertions(+), 79 deletions(-) diff --git a/crates/ra_assists/src/handlers/change_return_type_to_result.rs b/crates/ra_assists/src/handlers/change_return_type_to_result.rs index 4b73c41dacb..b83c944049c 100644 --- a/crates/ra_assists/src/handlers/change_return_type_to_result.rs +++ b/crates/ra_assists/src/handlers/change_return_type_to_result.rs @@ -241,7 +241,6 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option> { Expr::ArrayExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::ParenExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::PathExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), - Expr::Label(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::RecordExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::IndexExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::MethodCallExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 99d72340259..0cacc63efb9 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -569,9 +569,6 @@ fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { } } } - - // FIXME implement HIR for these: - ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), } } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 158544fa216..e049548c993 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -624,6 +624,19 @@ pub fn as_token(&self) -> Option { support::token(&self.syntax, T![ pub fn ty(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ClosureExpr { + pub(crate) syntax: SyntaxNode, +} +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]) } + pub fn param_list(&self) -> Option { support::child(&self.syntax) } + pub fn ret_type(&self) -> Option { support::child(&self.syntax) } + pub fn body(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ContinueExpr { pub(crate) syntax: SyntaxNode, } @@ -690,28 +703,6 @@ pub fn l_brack_token(&self) -> Option { support::token(&self.syntax pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Label { - pub(crate) syntax: SyntaxNode, -} -impl Label { - pub fn lifetime_token(&self) -> Option { - support::token(&self.syntax, T![lifetime]) - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ClosureExpr { - pub(crate) syntax: SyntaxNode, -} -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]) } - pub fn param_list(&self) -> Option { support::child(&self.syntax) } - pub fn ret_type(&self) -> Option { support::child(&self.syntax) } - pub fn body(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct LoopExpr { pub(crate) syntax: SyntaxNode, } @@ -835,6 +826,15 @@ pub fn while_token(&self) -> Option { support::token(&self.syntax, pub fn condition(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Label { + pub(crate) syntax: SyntaxNode, +} +impl Label { + pub fn lifetime_token(&self) -> Option { + support::token(&self.syntax, T![lifetime]) + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordExprFieldList { pub(crate) syntax: SyntaxNode, } @@ -1337,14 +1337,13 @@ pub enum Expr { BreakExpr(BreakExpr), CallExpr(CallExpr), CastExpr(CastExpr), + ClosureExpr(ClosureExpr), ContinueExpr(ContinueExpr), EffectExpr(EffectExpr), FieldExpr(FieldExpr), ForExpr(ForExpr), IfExpr(IfExpr), IndexExpr(IndexExpr), - Label(Label), - ClosureExpr(ClosureExpr), Literal(Literal), LoopExpr(LoopExpr), MacroCall(MacroCall), @@ -2017,6 +2016,17 @@ fn cast(syntax: SyntaxNode) -> Option { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +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 }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for ContinueExpr { fn can_cast(kind: SyntaxKind) -> bool { kind == CONTINUE_EXPR } fn cast(syntax: SyntaxNode) -> Option { @@ -2083,28 +2093,6 @@ fn cast(syntax: SyntaxNode) -> Option { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Label { - fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -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 }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for LoopExpr { fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } fn cast(syntax: SyntaxNode) -> Option { @@ -2248,6 +2236,17 @@ fn cast(syntax: SyntaxNode) -> Option { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for Label { + fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for RecordExprFieldList { fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD_LIST } fn cast(syntax: SyntaxNode) -> Option { @@ -3086,6 +3085,9 @@ fn from(node: CallExpr) -> Expr { Expr::CallExpr(node) } impl From for Expr { fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } } +impl From for Expr { + fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) } +} impl From for Expr { fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) } } @@ -3104,12 +3106,6 @@ fn from(node: IfExpr) -> Expr { Expr::IfExpr(node) } impl From for Expr { fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) } } -impl From