From db34abeb8589518896b82f52062b9fab4c2b1352 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 26 Mar 2020 16:10:01 +0100 Subject: Get rid of ItemOrMacro --- crates/ra_syntax/src/ast/generated.rs | 10 +++++++++- crates/ra_syntax/src/ast/traits.rs | 31 +------------------------------ 2 files changed, 10 insertions(+), 31 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 002f453cd..7204ca5b1 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -4135,6 +4135,7 @@ pub enum ModuleItem { ConstDef(ConstDef), StaticDef(StaticDef), Module(Module), + MacroCall(MacroCall), } impl From for ModuleItem { fn from(node: StructDef) -> ModuleItem { @@ -4196,6 +4197,11 @@ impl From for ModuleItem { ModuleItem::Module(node) } } +impl From for ModuleItem { + fn from(node: MacroCall) -> ModuleItem { + ModuleItem::MacroCall(node) + } +} impl std::fmt::Display for ModuleItem { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -4205,7 +4211,7 @@ impl AstNode for ModuleItem { fn can_cast(kind: SyntaxKind) -> bool { match kind { STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF - | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, + | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL => true, _ => false, } } @@ -4223,6 +4229,7 @@ impl AstNode for ModuleItem { CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), MODULE => ModuleItem::Module(Module { syntax }), + MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }), _ => return None, }; Some(res) @@ -4241,6 +4248,7 @@ impl AstNode for ModuleItem { ModuleItem::ConstDef(it) => &it.syntax, ModuleItem::StaticDef(it) => &it.syntax, ModuleItem::Module(it) => &it.syntax, + ModuleItem::MacroCall(it) => &it.syntax, } } } diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index f8cf1e3eb..576378306 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -6,8 +6,7 @@ use itertools::Itertools; use crate::{ ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, - match_ast, - syntax_node::{SyntaxElementChildren, SyntaxNodeChildren}, + syntax_node::SyntaxElementChildren, }; pub trait TypeAscriptionOwner: AstNode { @@ -46,38 +45,10 @@ pub trait FnDefOwner: AstNode { } } -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum ItemOrMacro { - Item(ast::ModuleItem), - Macro(ast::MacroCall), -} - pub trait ModuleItemOwner: AstNode { fn items(&self) -> AstChildren { children(self) } - fn items_with_macros(&self) -> ItemOrMacroIter { - ItemOrMacroIter(self.syntax().children()) - } -} - -#[derive(Debug)] -pub struct ItemOrMacroIter(SyntaxNodeChildren); - -impl Iterator for ItemOrMacroIter { - type Item = ItemOrMacro; - fn next(&mut self) -> Option { - loop { - let n = self.0.next()?; - match_ast! { - match n { - ast::ModuleItem(it) => { return Some(ItemOrMacro::Item(it)) }, - ast::MacroCall(it) => { return Some(ItemOrMacro::Macro(it)) }, - _ => {}, - } - } - } - } } pub trait TypeParamsOwner: AstNode { -- cgit v1.2.3