Lower and handle trait aliases in HIR

This commit is contained in:
Ryo Yoshida 2023-03-04 00:24:07 +09:00
parent e2ec3a6561
commit 29c957f973
No known key found for this signature in database
GPG key ID: E25698A930586171
47 changed files with 334 additions and 75 deletions

View file

@ -11,7 +11,7 @@ use syntax::ast;
use crate::{
db::HirDatabase, Adt, Const, Enum, Field, FieldSource, Function, Impl, LifetimeParam, Macro,
Module, Static, Struct, Trait, TypeAlias, TypeOrConstParam, Union, Variant,
Module, Static, Struct, Trait, TraitAlias, TypeAlias, TypeOrConstParam, Union, Variant,
};
pub trait HasSource {
@ -122,6 +122,12 @@ impl HasSource for Trait {
Some(self.id.lookup(db.upcast()).source(db.upcast()))
}
}
impl HasSource for TraitAlias {
type Ast = ast::TraitAlias;
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
Some(self.id.lookup(db.upcast()).source(db.upcast()))
}
}
impl HasSource for TypeAlias {
type Ast = ast::TypeAlias;
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
@ -158,7 +164,7 @@ impl HasSource for Impl {
}
impl HasSource for TypeOrConstParam {
type Ast = Either<ast::TypeOrConstParam, ast::Trait>;
type Ast = Either<ast::TypeOrConstParam, ast::TraitOrAlias>;
fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>> {
let child_source = self.id.parent.child_source(db.upcast());
Some(child_source.map(|it| it[self.id.local_id].clone()))