mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Add HIR for impl blocks
Since we need to be able to go from def to containing impl block, as well as the other direction, and to find all impls for a certain type, a design similar to the one for modules, where we collect all impls for the whole crate and keep them in an arena, seemed fitting. The ImplBlock type, which provides the public interface, then consists only of an Arc to the arena containing all impls, and the index into it.
This commit is contained in:
parent
226e31dae9
commit
ae9530addc
11 changed files with 269 additions and 8 deletions
|
@ -1442,7 +1442,39 @@ impl<R: TreeRoot<RaTypes>> ImplBlockNode<R> {
|
|||
}
|
||||
|
||||
|
||||
impl<'a> ImplBlock<'a> {}
|
||||
impl<'a> ImplBlock<'a> {
|
||||
pub fn item_list(self) -> Option<ItemList<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
||||
// ImplItem
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ImplItem<'a> {
|
||||
FnDef(FnDef<'a>),
|
||||
TypeDef(TypeDef<'a>),
|
||||
ConstDef(ConstDef<'a>),
|
||||
}
|
||||
|
||||
impl<'a> AstNode<'a> for ImplItem<'a> {
|
||||
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
FN_DEF => Some(ImplItem::FnDef(FnDef { syntax })),
|
||||
TYPE_DEF => Some(ImplItem::TypeDef(TypeDef { syntax })),
|
||||
CONST_DEF => Some(ImplItem::ConstDef(ConstDef { syntax })),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(self) -> SyntaxNodeRef<'a> {
|
||||
match self {
|
||||
ImplItem::FnDef(inner) => inner.syntax(),
|
||||
ImplItem::TypeDef(inner) => inner.syntax(),
|
||||
ImplItem::ConstDef(inner) => inner.syntax(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ImplItem<'a> {}
|
||||
|
||||
// ImplTraitType
|
||||
#[derive(Debug, Clone, Copy,)]
|
||||
|
@ -1555,7 +1587,11 @@ impl<R: TreeRoot<RaTypes>> ItemListNode<R> {
|
|||
|
||||
impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {}
|
||||
impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {}
|
||||
impl<'a> ItemList<'a> {}
|
||||
impl<'a> ItemList<'a> {
|
||||
pub fn impl_items(self) -> impl Iterator<Item = ImplItem<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
}
|
||||
|
||||
// Label
|
||||
#[derive(Debug, Clone, Copy,)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue