diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-31 14:54:19 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-31 14:54:19 +0100 |
commit | ad239f6197bda31f7a9b904b5ccb25c93cbc701a (patch) | |
tree | 5e4b244c62c61824dbb63246aa9943e3b2398131 /crates/ra_syntax/src/ast | |
parent | 3407d6f8a430627be333c32cb4cef02c0c8d11e3 (diff) | |
parent | d4d986c7f850e1f535bb4c22e3a7f7fba5483628 (diff) |
Merge #5623
5623: Item is a Stmt r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 41 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated/nodes.rs | 26 |
2 files changed, 41 insertions, 26 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index f5199e09f..4a6f41ee7 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -1,6 +1,41 @@ | |||
1 | //! This file is actually hand-written, but the submodules are indeed generated. | 1 | //! This file is actually hand-written, but the submodules are indeed generated. |
2 | |||
3 | #[rustfmt::skip] | 2 | #[rustfmt::skip] |
4 | pub(super) mod nodes; | 3 | mod nodes; |
5 | #[rustfmt::skip] | 4 | #[rustfmt::skip] |
6 | pub(super) mod tokens; | 5 | mod tokens; |
6 | |||
7 | use crate::{ | ||
8 | AstNode, | ||
9 | SyntaxKind::{self, *}, | ||
10 | SyntaxNode, | ||
11 | }; | ||
12 | |||
13 | pub use {nodes::*, tokens::*}; | ||
14 | |||
15 | // Stmt is the only nested enum, so it's easier to just hand-write it | ||
16 | impl AstNode for Stmt { | ||
17 | fn can_cast(kind: SyntaxKind) -> bool { | ||
18 | match kind { | ||
19 | LET_STMT | EXPR_STMT => true, | ||
20 | _ => Item::can_cast(kind), | ||
21 | } | ||
22 | } | ||
23 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
24 | let res = match syntax.kind() { | ||
25 | LET_STMT => Stmt::LetStmt(LetStmt { syntax }), | ||
26 | EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }), | ||
27 | _ => { | ||
28 | let item = Item::cast(syntax)?; | ||
29 | Stmt::Item(item) | ||
30 | } | ||
31 | }; | ||
32 | Some(res) | ||
33 | } | ||
34 | fn syntax(&self) -> &SyntaxNode { | ||
35 | match self { | ||
36 | Stmt::LetStmt(it) => &it.syntax, | ||
37 | Stmt::ExprStmt(it) => &it.syntax, | ||
38 | Stmt::Item(it) => it.syntax(), | ||
39 | } | ||
40 | } | ||
41 | } | ||
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 286be1032..763fd20f4 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs | |||
@@ -348,7 +348,6 @@ pub struct BlockExpr { | |||
348 | pub(crate) syntax: SyntaxNode, | 348 | pub(crate) syntax: SyntaxNode, |
349 | } | 349 | } |
350 | impl ast::AttrsOwner for BlockExpr {} | 350 | impl ast::AttrsOwner for BlockExpr {} |
351 | impl ast::ModuleItemOwner for BlockExpr {} | ||
352 | impl BlockExpr { | 351 | impl BlockExpr { |
353 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } | 352 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } |
354 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 353 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
@@ -1395,8 +1394,8 @@ impl ast::AttrsOwner for GenericParam {} | |||
1395 | pub enum Stmt { | 1394 | pub enum Stmt { |
1396 | LetStmt(LetStmt), | 1395 | LetStmt(LetStmt), |
1397 | ExprStmt(ExprStmt), | 1396 | ExprStmt(ExprStmt), |
1397 | Item(Item), | ||
1398 | } | 1398 | } |
1399 | impl ast::AttrsOwner for Stmt {} | ||
1400 | impl AstNode for SourceFile { | 1399 | impl AstNode for SourceFile { |
1401 | fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } | 1400 | fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } |
1402 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1401 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3380,27 +3379,8 @@ impl From<LetStmt> for Stmt { | |||
3380 | impl From<ExprStmt> for Stmt { | 3379 | impl From<ExprStmt> for Stmt { |
3381 | fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } | 3380 | fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } |
3382 | } | 3381 | } |
3383 | impl AstNode for Stmt { | 3382 | impl From<Item> for Stmt { |
3384 | fn can_cast(kind: SyntaxKind) -> bool { | 3383 | fn from(node: Item) -> Stmt { Stmt::Item(node) } |
3385 | match kind { | ||
3386 | LET_STMT | EXPR_STMT => true, | ||
3387 | _ => false, | ||
3388 | } | ||
3389 | } | ||
3390 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3391 | let res = match syntax.kind() { | ||
3392 | LET_STMT => Stmt::LetStmt(LetStmt { syntax }), | ||
3393 | EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }), | ||
3394 | _ => return None, | ||
3395 | }; | ||
3396 | Some(res) | ||
3397 | } | ||
3398 | fn syntax(&self) -> &SyntaxNode { | ||
3399 | match self { | ||
3400 | Stmt::LetStmt(it) => &it.syntax, | ||
3401 | Stmt::ExprStmt(it) => &it.syntax, | ||
3402 | } | ||
3403 | } | ||
3404 | } | 3384 | } |
3405 | impl std::fmt::Display for Item { | 3385 | impl std::fmt::Display for Item { |
3406 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 3386 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |