diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 263c557f3..96a5cc857 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -973,6 +973,41 @@ pub struct ImplBlock { | |||
973 | pub(crate) id: ImplId, | 973 | pub(crate) id: ImplId, |
974 | } | 974 | } |
975 | 975 | ||
976 | impl ImplBlock { | ||
977 | pub fn target_trait(&self, db: &impl DefDatabase) -> Option<TypeRef> { | ||
978 | db.impl_data(self.id).target_trait.clone() | ||
979 | } | ||
980 | |||
981 | pub fn target_type(&self, db: &impl DefDatabase) -> TypeRef { | ||
982 | db.impl_data(self.id).target_type.clone() | ||
983 | } | ||
984 | |||
985 | pub fn target_ty(&self, db: &impl HirDatabase) -> Ty { | ||
986 | Ty::from_hir(db, &self.id.resolver(db), &self.target_type(db)) | ||
987 | } | ||
988 | |||
989 | pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option<TraitRef> { | ||
990 | let target_ty = self.target_ty(db); | ||
991 | TraitRef::from_hir(db, &self.id.resolver(db), &self.target_trait(db)?, Some(target_ty)) | ||
992 | } | ||
993 | |||
994 | pub fn items(&self, db: &impl DefDatabase) -> Vec<AssocItem> { | ||
995 | db.impl_data(self.id).items.iter().map(|it| (*it).into()).collect() | ||
996 | } | ||
997 | |||
998 | pub fn is_negative(&self, db: &impl DefDatabase) -> bool { | ||
999 | db.impl_data(self.id).is_negative | ||
1000 | } | ||
1001 | |||
1002 | pub fn module(&self, db: &impl DefDatabase) -> Module { | ||
1003 | self.id.module(db).into() | ||
1004 | } | ||
1005 | |||
1006 | pub fn krate(&self, db: &impl DefDatabase) -> Crate { | ||
1007 | Crate { crate_id: self.module(db).id.krate } | ||
1008 | } | ||
1009 | } | ||
1010 | |||
976 | /// For IDE only | 1011 | /// For IDE only |
977 | pub enum ScopeDef { | 1012 | pub enum ScopeDef { |
978 | ModuleDef(ModuleDef), | 1013 | ModuleDef(ModuleDef), |