diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index b0cf94956e..29f1de5477 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 { let statik = self.lower_static(&ast)?; statik.into() } + ast::ExternItem::MacroCall(_) => return None, }; self.add_attrs(id.into(), attrs); Some(id) diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index ba00742f0c..9345a5e8f4 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 { pub struct AssocItemList { pub(crate) syntax: SyntaxNode, } +impl ast::AttrsOwner for AssocItemList {} impl AssocItemList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } pub fn assoc_items(&self) -> AstChildren { support::children(&self.syntax) } pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ExternItemList { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for ExternItemList {} +impl ExternItemList { + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } + pub fn extern_items(&self) -> AstChildren { support::children(&self.syntax) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ParenType { pub(crate) syntax: SyntaxNode, } @@ -1254,15 +1265,6 @@ impl ConstArg { pub fn block_expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ExternItemList { - pub(crate) syntax: SyntaxNode, -} -impl ExternItemList { - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn extern_items(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MetaItem { pub(crate) syntax: SyntaxNode, } @@ -1373,6 +1375,14 @@ pub enum AssocItem { impl ast::AttrsOwner for AssocItem {} impl ast::NameOwner for AssocItem {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum ExternItem { + Fn(Fn), + Static(Static), + MacroCall(MacroCall), +} +impl ast::AttrsOwner for ExternItem {} +impl ast::NameOwner for ExternItem {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Stmt { LetStmt(LetStmt), ExprStmt(ExprStmt), @@ -1384,14 +1394,6 @@ pub enum AttrInput { TokenTree(TokenTree), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum ExternItem { - Fn(Fn), - Static(Static), -} -impl ast::AttrsOwner for ExternItem {} -impl ast::NameOwner for ExternItem {} -impl ast::VisibilityOwner for ExternItem {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum AdtDef { Struct(Struct), Enum(Enum), @@ -1841,6 +1843,17 @@ impl AstNode for AssocItemList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for ExternItemList { + fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST } + 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 ParenType { fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE } fn cast(syntax: SyntaxNode) -> Option { @@ -2754,17 +2767,6 @@ impl AstNode for ConstArg { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for ExternItemList { - fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST } - 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 MetaItem { fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM } fn cast(syntax: SyntaxNode) -> Option { @@ -3290,6 +3292,39 @@ impl AstNode for AssocItem { } } } +impl From for ExternItem { + fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) } +} +impl From for ExternItem { + fn from(node: Static) -> ExternItem { ExternItem::Static(node) } +} +impl From for ExternItem { + fn from(node: MacroCall) -> ExternItem { ExternItem::MacroCall(node) } +} +impl AstNode for ExternItem { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + FN | STATIC | MACRO_CALL => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + let res = match syntax.kind() { + FN => ExternItem::Fn(Fn { syntax }), + STATIC => ExternItem::Static(Static { syntax }), + MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }), + _ => return None, + }; + Some(res) + } + fn syntax(&self) -> &SyntaxNode { + match self { + ExternItem::Fn(it) => &it.syntax, + ExternItem::Static(it) => &it.syntax, + ExternItem::MacroCall(it) => &it.syntax, + } + } +} impl From for Stmt { fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } } @@ -3346,34 +3381,6 @@ impl AstNode for AttrInput { } } } -impl From for ExternItem { - fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) } -} -impl From for ExternItem { - fn from(node: Static) -> ExternItem { ExternItem::Static(node) } -} -impl AstNode for ExternItem { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - FN | STATIC => true, - _ => false, - } - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - FN => ExternItem::Fn(Fn { syntax }), - STATIC => ExternItem::Static(Static { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - ExternItem::Fn(it) => &it.syntax, - ExternItem::Static(it) => &it.syntax, - } - } -} impl From for AdtDef { fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) } } @@ -3437,6 +3444,11 @@ impl std::fmt::Display for AssocItem { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for ExternItem { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for Stmt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3447,11 +3459,6 @@ impl std::fmt::Display for AttrInput { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ExternItem { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for AdtDef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3657,6 +3664,11 @@ impl std::fmt::Display for AssocItemList { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for ExternItemList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for ParenType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -4072,11 +4084,6 @@ impl std::fmt::Display for ConstArg { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ExternItemList { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for MetaItem { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index cda0e8fbb5..cdd3adf457 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -129,7 +129,13 @@ Trait = AssocItemList AssocItemList = - '{' AssocItem* '}' + '{' Attr* AssocItem* '}' + +AssocItem = + Fn +| TypeAlias +| Const +| MacroCall Impl = Attr* Visibility? @@ -139,6 +145,15 @@ Impl = ) WhereClause? AssocItemList +ExternBlock = + Attr* Abi ExternItemList + +ExternItemList = + '{' Attr* ExternItem* '}' + +ExternItem = + Fn | Static | MacroCall + ParenType = '(' TypeRef ')' @@ -449,12 +464,6 @@ LifetimeArg = ConstArg = Literal | BlockExpr BlockExpr -ExternBlock = - Attr* Abi ExternItemList - -ExternItemList = - '{' extern_items:ExternItem* '}' - MetaItem = Path '=' AttrInput nested_meta_items:MetaItem* @@ -478,15 +487,6 @@ TypeRef = | ImplTraitType | DynTraitType -AssocItem = - Fn -| TypeAlias -| Const -| MacroCall - -ExternItem = - Fn | Static - AttrInput = Literal | TokenTree