2019-09-30 08:58:53 +00:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2019-11-15 18:28:00 +00:00
|
|
|
use hir_def::{type_ref::TypeRef, AstItemDef};
|
|
|
|
use ra_syntax::ast::{self};
|
2018-12-28 13:34:00 +00:00
|
|
|
|
|
|
|
use crate::{
|
2019-09-08 06:53:49 +00:00
|
|
|
db::{AstDatabase, DefDatabase, HirDatabase},
|
2019-11-20 18:55:33 +00:00
|
|
|
resolve::HasResolver,
|
2019-04-14 11:07:45 +00:00
|
|
|
ty::Ty,
|
2019-11-15 18:28:00 +00:00
|
|
|
AssocItem, Crate, HasSource, ImplBlock, Module, Source, TraitRef,
|
2018-12-28 13:34:00 +00:00
|
|
|
};
|
|
|
|
|
2019-06-11 14:36:52 +00:00
|
|
|
impl HasSource for ImplBlock {
|
2019-07-19 07:43:01 +00:00
|
|
|
type Ast = ast::ImplBlock;
|
|
|
|
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::ImplBlock> {
|
2019-11-15 18:28:00 +00:00
|
|
|
self.id.source(db)
|
2019-06-11 14:36:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 13:34:00 +00:00
|
|
|
impl ImplBlock {
|
2019-03-26 22:07:26 +00:00
|
|
|
pub fn target_trait(&self, db: &impl DefDatabase) -> Option<TypeRef> {
|
2019-11-15 18:28:00 +00:00
|
|
|
db.impl_data(self.id).target_trait().cloned()
|
2018-12-30 18:59:49 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 12:37:04 +00:00
|
|
|
pub fn target_type(&self, db: &impl DefDatabase) -> TypeRef {
|
2019-11-15 18:28:00 +00:00
|
|
|
db.impl_data(self.id).target_type().clone()
|
2018-12-28 13:34:00 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 21:52:04 +00:00
|
|
|
pub fn target_ty(&self, db: &impl HirDatabase) -> Ty {
|
2019-02-16 20:09:58 +00:00
|
|
|
Ty::from_hir(db, &self.resolver(db), &self.target_type(db))
|
2019-01-26 21:52:04 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 22:07:26 +00:00
|
|
|
pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option<TraitRef> {
|
2019-03-31 18:02:16 +00:00
|
|
|
let target_ty = self.target_ty(db);
|
|
|
|
TraitRef::from_hir(db, &self.resolver(db), &self.target_trait(db)?, Some(target_ty))
|
2019-01-26 21:52:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:01:13 +00:00
|
|
|
pub fn items(&self, db: &impl DefDatabase) -> Vec<AssocItem> {
|
2019-11-15 18:28:00 +00:00
|
|
|
db.impl_data(self.id).items().iter().map(|it| (*it).into()).collect()
|
2018-12-28 13:34:00 +00:00
|
|
|
}
|
2019-01-23 22:08:41 +00:00
|
|
|
|
2019-05-07 16:53:16 +00:00
|
|
|
pub fn is_negative(&self, db: &impl DefDatabase) -> bool {
|
2019-11-15 18:28:00 +00:00
|
|
|
db.impl_data(self.id).is_negative()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn module(&self, db: &impl DefDatabase) -> Module {
|
|
|
|
self.id.module(db).into()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn krate(&self, db: &impl DefDatabase) -> Crate {
|
|
|
|
Crate { crate_id: self.module(db).id.krate }
|
2019-05-07 16:53:16 +00:00
|
|
|
}
|
2018-12-28 13:34:00 +00:00
|
|
|
}
|