mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Get rid of ItemOrMacro
This commit is contained in:
parent
539e597743
commit
db34abeb85
7 changed files with 21 additions and 41 deletions
|
@ -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<ast::ModuleItem> {
|
||||
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<ItemOrMacro> {
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue