aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-30 17:39:40 +0100
committerGitHub <[email protected]>2020-07-30 17:39:40 +0100
commitaf8132e610d1e649e67ab797e372d1efcf106c48 (patch)
treeb08fbc93e85f25301ad84a05a3f859ed3edfeb17 /crates
parent0f5805541be90a2789b0bc34c5d829042ac3b0ad (diff)
parent917c89c103597d09e95bdee273633f79123dd19e (diff)
Merge #5607
5607: Finaize item grammar r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/item_tree/lower.rs1
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs135
2 files changed, 72 insertions, 64 deletions
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs
index b0cf94956..29f1de547 100644
--- a/crates/ra_hir_def/src/item_tree/lower.rs
+++ b/crates/ra_hir_def/src/item_tree/lower.rs
@@ -557,6 +557,7 @@ impl Ctx {
557 let statik = self.lower_static(&ast)?; 557 let statik = self.lower_static(&ast)?;
558 statik.into() 558 statik.into()
559 } 559 }
560 ast::ExternItem::MacroCall(_) => return None,
560 }; 561 };
561 self.add_attrs(id.into(), attrs); 562 self.add_attrs(id.into(), attrs);
562 Some(id) 563 Some(id)
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index ba00742f0..9345a5e8f 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -453,12 +453,23 @@ impl Variant {
453pub struct AssocItemList { 453pub struct AssocItemList {
454 pub(crate) syntax: SyntaxNode, 454 pub(crate) syntax: SyntaxNode,
455} 455}
456impl ast::AttrsOwner for AssocItemList {}
456impl AssocItemList { 457impl AssocItemList {
457 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 458 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
458 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } 459 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
459 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 460 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
460} 461}
461#[derive(Debug, Clone, PartialEq, Eq, Hash)] 462#[derive(Debug, Clone, PartialEq, Eq, Hash)]
463pub struct ExternItemList {
464 pub(crate) syntax: SyntaxNode,
465}
466impl ast::AttrsOwner for ExternItemList {}
467impl ExternItemList {
468 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
469 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
470 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
471}
472#[derive(Debug, Clone, PartialEq, Eq, Hash)]
462pub struct ParenType { 473pub struct ParenType {
463 pub(crate) syntax: SyntaxNode, 474 pub(crate) syntax: SyntaxNode,
464} 475}
@@ -1254,15 +1265,6 @@ impl ConstArg {
1254 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 1265 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
1255} 1266}
1256#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1267#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1257pub struct ExternItemList {
1258 pub(crate) syntax: SyntaxNode,
1259}
1260impl ExternItemList {
1261 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1262 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
1263 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1264}
1265#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1266pub struct MetaItem { 1268pub struct MetaItem {
1267 pub(crate) syntax: SyntaxNode, 1269 pub(crate) syntax: SyntaxNode,
1268} 1270}
@@ -1373,6 +1375,14 @@ pub enum AssocItem {
1373impl ast::AttrsOwner for AssocItem {} 1375impl ast::AttrsOwner for AssocItem {}
1374impl ast::NameOwner for AssocItem {} 1376impl ast::NameOwner for AssocItem {}
1375#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1377#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1378pub enum ExternItem {
1379 Fn(Fn),
1380 Static(Static),
1381 MacroCall(MacroCall),
1382}
1383impl ast::AttrsOwner for ExternItem {}
1384impl ast::NameOwner for ExternItem {}
1385#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1376pub enum Stmt { 1386pub enum Stmt {
1377 LetStmt(LetStmt), 1387 LetStmt(LetStmt),
1378 ExprStmt(ExprStmt), 1388 ExprStmt(ExprStmt),
@@ -1384,14 +1394,6 @@ pub enum AttrInput {
1384 TokenTree(TokenTree), 1394 TokenTree(TokenTree),
1385} 1395}
1386#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1396#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1387pub enum ExternItem {
1388 Fn(Fn),
1389 Static(Static),
1390}
1391impl ast::AttrsOwner for ExternItem {}
1392impl ast::NameOwner for ExternItem {}
1393impl ast::VisibilityOwner for ExternItem {}
1394#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1395pub enum AdtDef { 1397pub enum AdtDef {
1396 Struct(Struct), 1398 Struct(Struct),
1397 Enum(Enum), 1399 Enum(Enum),
@@ -1841,6 +1843,17 @@ impl AstNode for AssocItemList {
1841 } 1843 }
1842 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1844 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1843} 1845}
1846impl AstNode for ExternItemList {
1847 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST }
1848 fn cast(syntax: SyntaxNode) -> Option<Self> {
1849 if Self::can_cast(syntax.kind()) {
1850 Some(Self { syntax })
1851 } else {
1852 None
1853 }
1854 }
1855 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1856}
1844impl AstNode for ParenType { 1857impl AstNode for ParenType {
1845 fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE } 1858 fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE }
1846 fn cast(syntax: SyntaxNode) -> Option<Self> { 1859 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2754,17 +2767,6 @@ impl AstNode for ConstArg {
2754 } 2767 }
2755 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2768 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2756} 2769}
2757impl AstNode for ExternItemList {
2758 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST }
2759 fn cast(syntax: SyntaxNode) -> Option<Self> {
2760 if Self::can_cast(syntax.kind()) {
2761 Some(Self { syntax })
2762 } else {
2763 None
2764 }
2765 }
2766 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2767}
2768impl AstNode for MetaItem { 2770impl AstNode for MetaItem {
2769 fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM } 2771 fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM }
2770 fn cast(syntax: SyntaxNode) -> Option<Self> { 2772 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3290,6 +3292,39 @@ impl AstNode for AssocItem {
3290 } 3292 }
3291 } 3293 }
3292} 3294}
3295impl From<Fn> for ExternItem {
3296 fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
3297}
3298impl From<Static> for ExternItem {
3299 fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
3300}
3301impl From<MacroCall> for ExternItem {
3302 fn from(node: MacroCall) -> ExternItem { ExternItem::MacroCall(node) }
3303}
3304impl AstNode for ExternItem {
3305 fn can_cast(kind: SyntaxKind) -> bool {
3306 match kind {
3307 FN | STATIC | MACRO_CALL => true,
3308 _ => false,
3309 }
3310 }
3311 fn cast(syntax: SyntaxNode) -> Option<Self> {
3312 let res = match syntax.kind() {
3313 FN => ExternItem::Fn(Fn { syntax }),
3314 STATIC => ExternItem::Static(Static { syntax }),
3315 MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }),
3316 _ => return None,
3317 };
3318 Some(res)
3319 }
3320 fn syntax(&self) -> &SyntaxNode {
3321 match self {
3322 ExternItem::Fn(it) => &it.syntax,
3323 ExternItem::Static(it) => &it.syntax,
3324 ExternItem::MacroCall(it) => &it.syntax,
3325 }
3326 }
3327}
3293impl From<LetStmt> for Stmt { 3328impl From<LetStmt> for Stmt {
3294 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } 3329 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) }
3295} 3330}
@@ -3346,34 +3381,6 @@ impl AstNode for AttrInput {
3346 } 3381 }
3347 } 3382 }
3348} 3383}
3349impl From<Fn> for ExternItem {
3350 fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
3351}
3352impl From<Static> for ExternItem {
3353 fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
3354}
3355impl AstNode for ExternItem {
3356 fn can_cast(kind: SyntaxKind) -> bool {
3357 match kind {
3358 FN | STATIC => true,
3359 _ => false,
3360 }
3361 }
3362 fn cast(syntax: SyntaxNode) -> Option<Self> {
3363 let res = match syntax.kind() {
3364 FN => ExternItem::Fn(Fn { syntax }),
3365 STATIC => ExternItem::Static(Static { syntax }),
3366 _ => return None,
3367 };
3368 Some(res)
3369 }
3370 fn syntax(&self) -> &SyntaxNode {
3371 match self {
3372 ExternItem::Fn(it) => &it.syntax,
3373 ExternItem::Static(it) => &it.syntax,
3374 }
3375 }
3376}
3377impl From<Struct> for AdtDef { 3384impl From<Struct> for AdtDef {
3378 fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) } 3385 fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) }
3379} 3386}
@@ -3437,17 +3444,17 @@ impl std::fmt::Display for AssocItem {
3437 std::fmt::Display::fmt(self.syntax(), f) 3444 std::fmt::Display::fmt(self.syntax(), f)
3438 } 3445 }
3439} 3446}
3440impl std::fmt::Display for Stmt { 3447impl std::fmt::Display for ExternItem {
3441 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3448 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3442 std::fmt::Display::fmt(self.syntax(), f) 3449 std::fmt::Display::fmt(self.syntax(), f)
3443 } 3450 }
3444} 3451}
3445impl std::fmt::Display for AttrInput { 3452impl std::fmt::Display for Stmt {
3446 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3453 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3447 std::fmt::Display::fmt(self.syntax(), f) 3454 std::fmt::Display::fmt(self.syntax(), f)
3448 } 3455 }
3449} 3456}
3450impl std::fmt::Display for ExternItem { 3457impl std::fmt::Display for AttrInput {
3451 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3458 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3452 std::fmt::Display::fmt(self.syntax(), f) 3459 std::fmt::Display::fmt(self.syntax(), f)
3453 } 3460 }
@@ -3657,6 +3664,11 @@ impl std::fmt::Display for AssocItemList {
3657 std::fmt::Display::fmt(self.syntax(), f) 3664 std::fmt::Display::fmt(self.syntax(), f)
3658 } 3665 }
3659} 3666}
3667impl std::fmt::Display for ExternItemList {
3668 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3669 std::fmt::Display::fmt(self.syntax(), f)
3670 }
3671}
3660impl std::fmt::Display for ParenType { 3672impl std::fmt::Display for ParenType {
3661 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3673 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3662 std::fmt::Display::fmt(self.syntax(), f) 3674 std::fmt::Display::fmt(self.syntax(), f)
@@ -4072,11 +4084,6 @@ impl std::fmt::Display for ConstArg {
4072 std::fmt::Display::fmt(self.syntax(), f) 4084 std::fmt::Display::fmt(self.syntax(), f)
4073 } 4085 }
4074} 4086}
4075impl std::fmt::Display for ExternItemList {
4076 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4077 std::fmt::Display::fmt(self.syntax(), f)
4078 }
4079}
4080impl std::fmt::Display for MetaItem { 4087impl std::fmt::Display for MetaItem {
4081 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4088 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4082 std::fmt::Display::fmt(self.syntax(), f) 4089 std::fmt::Display::fmt(self.syntax(), f)