diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-26 15:13:54 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-26 15:13:54 +0000 |
commit | ac05571dc9b01dbbb6cf97988190563f1b33ce13 (patch) | |
tree | 3ac357657b2dfa901bc28d35a7934123778dc30a /crates/ra_syntax/src/ast | |
parent | 539e597743229b4497491f325a257bef026602c7 (diff) | |
parent | db34abeb8589518896b82f52062b9fab4c2b1352 (diff) |
Merge #3734
3734: Get rid of ItemOrMacro r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/traits.rs | 31 |
2 files changed, 10 insertions, 31 deletions
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 { | |||
4135 | ConstDef(ConstDef), | 4135 | ConstDef(ConstDef), |
4136 | StaticDef(StaticDef), | 4136 | StaticDef(StaticDef), |
4137 | Module(Module), | 4137 | Module(Module), |
4138 | MacroCall(MacroCall), | ||
4138 | } | 4139 | } |
4139 | impl From<StructDef> for ModuleItem { | 4140 | impl From<StructDef> for ModuleItem { |
4140 | fn from(node: StructDef) -> ModuleItem { | 4141 | fn from(node: StructDef) -> ModuleItem { |
@@ -4196,6 +4197,11 @@ impl From<Module> for ModuleItem { | |||
4196 | ModuleItem::Module(node) | 4197 | ModuleItem::Module(node) |
4197 | } | 4198 | } |
4198 | } | 4199 | } |
4200 | impl From<MacroCall> for ModuleItem { | ||
4201 | fn from(node: MacroCall) -> ModuleItem { | ||
4202 | ModuleItem::MacroCall(node) | ||
4203 | } | ||
4204 | } | ||
4199 | impl std::fmt::Display for ModuleItem { | 4205 | impl std::fmt::Display for ModuleItem { |
4200 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | 4206 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
4201 | std::fmt::Display::fmt(self.syntax(), f) | 4207 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -4205,7 +4211,7 @@ impl AstNode for ModuleItem { | |||
4205 | fn can_cast(kind: SyntaxKind) -> bool { | 4211 | fn can_cast(kind: SyntaxKind) -> bool { |
4206 | match kind { | 4212 | match kind { |
4207 | STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF | 4213 | STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF |
4208 | | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, | 4214 | | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL => true, |
4209 | _ => false, | 4215 | _ => false, |
4210 | } | 4216 | } |
4211 | } | 4217 | } |
@@ -4223,6 +4229,7 @@ impl AstNode for ModuleItem { | |||
4223 | CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), | 4229 | CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }), |
4224 | STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), | 4230 | STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }), |
4225 | MODULE => ModuleItem::Module(Module { syntax }), | 4231 | MODULE => ModuleItem::Module(Module { syntax }), |
4232 | MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }), | ||
4226 | _ => return None, | 4233 | _ => return None, |
4227 | }; | 4234 | }; |
4228 | Some(res) | 4235 | Some(res) |
@@ -4241,6 +4248,7 @@ impl AstNode for ModuleItem { | |||
4241 | ModuleItem::ConstDef(it) => &it.syntax, | 4248 | ModuleItem::ConstDef(it) => &it.syntax, |
4242 | ModuleItem::StaticDef(it) => &it.syntax, | 4249 | ModuleItem::StaticDef(it) => &it.syntax, |
4243 | ModuleItem::Module(it) => &it.syntax, | 4250 | ModuleItem::Module(it) => &it.syntax, |
4251 | ModuleItem::MacroCall(it) => &it.syntax, | ||
4244 | } | 4252 | } |
4245 | } | 4253 | } |
4246 | } | 4254 | } |
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; | |||
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, | 8 | ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, |
9 | match_ast, | 9 | syntax_node::SyntaxElementChildren, |
10 | syntax_node::{SyntaxElementChildren, SyntaxNodeChildren}, | ||
11 | }; | 10 | }; |
12 | 11 | ||
13 | pub trait TypeAscriptionOwner: AstNode { | 12 | pub trait TypeAscriptionOwner: AstNode { |
@@ -46,38 +45,10 @@ pub trait FnDefOwner: AstNode { | |||
46 | } | 45 | } |
47 | } | 46 | } |
48 | 47 | ||
49 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
50 | pub enum ItemOrMacro { | ||
51 | Item(ast::ModuleItem), | ||
52 | Macro(ast::MacroCall), | ||
53 | } | ||
54 | |||
55 | pub trait ModuleItemOwner: AstNode { | 48 | pub trait ModuleItemOwner: AstNode { |
56 | fn items(&self) -> AstChildren<ast::ModuleItem> { | 49 | fn items(&self) -> AstChildren<ast::ModuleItem> { |
57 | children(self) | 50 | children(self) |
58 | } | 51 | } |
59 | fn items_with_macros(&self) -> ItemOrMacroIter { | ||
60 | ItemOrMacroIter(self.syntax().children()) | ||
61 | } | ||
62 | } | ||
63 | |||
64 | #[derive(Debug)] | ||
65 | pub struct ItemOrMacroIter(SyntaxNodeChildren); | ||
66 | |||
67 | impl Iterator for ItemOrMacroIter { | ||
68 | type Item = ItemOrMacro; | ||
69 | fn next(&mut self) -> Option<ItemOrMacro> { | ||
70 | loop { | ||
71 | let n = self.0.next()?; | ||
72 | match_ast! { | ||
73 | match n { | ||
74 | ast::ModuleItem(it) => { return Some(ItemOrMacro::Item(it)) }, | ||
75 | ast::MacroCall(it) => { return Some(ItemOrMacro::Macro(it)) }, | ||
76 | _ => {}, | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | } | 52 | } |
82 | 53 | ||
83 | pub trait TypeParamsOwner: AstNode { | 54 | pub trait TypeParamsOwner: AstNode { |