From 7980a7e19a679e0bc128f2c142609f7f4a197bf6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 18:04:57 +0200 Subject: Minor --- .../src/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 ++++++++++----------- 3 files changed, 62 insertions(+), 72 deletions(-) (limited to 'crates') 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 4b73c41da..b83c94404 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 99d723402..0cacc63ef 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -569,9 +569,6 @@ impl ExprCollector<'_> { } } } - - // 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 158544fa2..e049548c9 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -624,6 +624,19 @@ impl CastExpr { 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 @@ impl IndexExpr { 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 @@ impl WhileExpr { 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 @@ impl AstNode for CastExpr { } 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 @@ impl AstNode for IndexExpr { } 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 @@ impl AstNode for WhileExpr { } 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 @@ impl From for Expr { 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 @@ impl From for Expr { impl From for Expr { fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) } } -impl From