aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-31 14:46:12 +0100
committerAleksey Kladov <[email protected]>2020-07-31 14:51:01 +0100
commitd4d986c7f850e1f535bb4c22e3a7f7fba5483628 (patch)
tree08477af01b6c828249c88db126b2f86e0e6899bd /crates/ra_syntax
parenta7ca6583fbce6f1bddce7b31ad5bb1fc0665b616 (diff)
Item is a Stmt
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs8
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs6
2 files changed, 10 insertions, 4 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index ba55f1c42..4a6f41ee7 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -17,14 +17,17 @@ impl AstNode for Stmt {
17 fn can_cast(kind: SyntaxKind) -> bool { 17 fn can_cast(kind: SyntaxKind) -> bool {
18 match kind { 18 match kind {
19 LET_STMT | EXPR_STMT => true, 19 LET_STMT | EXPR_STMT => true,
20 _ => false, 20 _ => Item::can_cast(kind),
21 } 21 }
22 } 22 }
23 fn cast(syntax: SyntaxNode) -> Option<Self> { 23 fn cast(syntax: SyntaxNode) -> Option<Self> {
24 let res = match syntax.kind() { 24 let res = match syntax.kind() {
25 LET_STMT => Stmt::LetStmt(LetStmt { syntax }), 25 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
26 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }), 26 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
27 _ => return None, 27 _ => {
28 let item = Item::cast(syntax)?;
29 Stmt::Item(item)
30 }
28 }; 31 };
29 Some(res) 32 Some(res)
30 } 33 }
@@ -32,6 +35,7 @@ impl AstNode for Stmt {
32 match self { 35 match self {
33 Stmt::LetStmt(it) => &it.syntax, 36 Stmt::LetStmt(it) => &it.syntax,
34 Stmt::ExprStmt(it) => &it.syntax, 37 Stmt::ExprStmt(it) => &it.syntax,
38 Stmt::Item(it) => it.syntax(),
35 } 39 }
36 } 40 }
37} 41}
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 8ef72fec7..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}
350impl ast::AttrsOwner for BlockExpr {} 350impl ast::AttrsOwner for BlockExpr {}
351impl ast::ModuleItemOwner for BlockExpr {}
352impl BlockExpr { 351impl 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 {}
1395pub enum Stmt { 1394pub enum Stmt {
1396 LetStmt(LetStmt), 1395 LetStmt(LetStmt),
1397 ExprStmt(ExprStmt), 1396 ExprStmt(ExprStmt),
1397 Item(Item),
1398} 1398}
1399impl ast::AttrsOwner for Stmt {}
1400impl AstNode for SourceFile { 1399impl 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,6 +3379,9 @@ impl From<LetStmt> for Stmt {
3380impl From<ExprStmt> for Stmt { 3379impl From<ExprStmt> for Stmt {
3381 fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } 3380 fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) }
3382} 3381}
3382impl From<Item> for Stmt {
3383 fn from(node: Item) -> Stmt { Stmt::Item(node) }
3384}
3383impl std::fmt::Display for Item { 3385impl std::fmt::Display for Item {
3384 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3386 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3385 std::fmt::Display::fmt(self.syntax(), f) 3387 std::fmt::Display::fmt(self.syntax(), f)