aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model.rs35
-rw-r--r--crates/ra_hir/src/code_model/src.rs10
-rw-r--r--crates/ra_hir/src/impl_block.rs52
-rw-r--r--crates/ra_hir/src/lib.rs1
4 files changed, 43 insertions, 55 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
976impl 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
977pub enum ScopeDef { 1012pub enum ScopeDef {
978 ModuleDef(ModuleDef), 1013 ModuleDef(ModuleDef),
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index a0e605603..a4e317c20 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -5,8 +5,8 @@ use hir_expand::either::Either;
5use ra_syntax::ast; 5use ra_syntax::ast;
6 6
7use crate::{ 7use crate::{
8 db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, Import, MacroDef, Module, 8 db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, Import, MacroDef,
9 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, 9 Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
10}; 10};
11 11
12pub use hir_expand::Source; 12pub use hir_expand::Source;
@@ -108,6 +108,12 @@ impl HasSource for MacroDef {
108 Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } 108 Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) }
109 } 109 }
110} 110}
111impl HasSource for ImplBlock {
112 type Ast = ast::ImplBlock;
113 fn source(self, db: &impl DefDatabase) -> Source<ast::ImplBlock> {
114 self.id.source(db)
115 }
116}
111impl HasSource for Import { 117impl HasSource for Import {
112 type Ast = Either<ast::UseTree, ast::ExternCrateItem>; 118 type Ast = Either<ast::UseTree, ast::ExternCrateItem>;
113 119
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
deleted file mode 100644
index 334eeebac..000000000
--- a/crates/ra_hir/src/impl_block.rs
+++ /dev/null
@@ -1,52 +0,0 @@
1//! FIXME: write short doc here
2
3use hir_def::{resolver::HasResolver, type_ref::TypeRef, AstItemDef};
4use ra_syntax::ast;
5
6use crate::{
7 db::{AstDatabase, DefDatabase, HirDatabase},
8 ty::Ty,
9 AssocItem, Crate, HasSource, ImplBlock, Module, Source, TraitRef,
10};
11
12impl HasSource for ImplBlock {
13 type Ast = ast::ImplBlock;
14 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::ImplBlock> {
15 self.id.source(db)
16 }
17}
18
19impl ImplBlock {
20 pub fn target_trait(&self, db: &impl DefDatabase) -> Option<TypeRef> {
21 db.impl_data(self.id).target_trait.clone()
22 }
23
24 pub fn target_type(&self, db: &impl DefDatabase) -> TypeRef {
25 db.impl_data(self.id).target_type.clone()
26 }
27
28 pub fn target_ty(&self, db: &impl HirDatabase) -> Ty {
29 Ty::from_hir(db, &self.id.resolver(db), &self.target_type(db))
30 }
31
32 pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option<TraitRef> {
33 let target_ty = self.target_ty(db);
34 TraitRef::from_hir(db, &self.id.resolver(db), &self.target_trait(db)?, Some(target_ty))
35 }
36
37 pub fn items(&self, db: &impl DefDatabase) -> Vec<AssocItem> {
38 db.impl_data(self.id).items.iter().map(|it| (*it).into()).collect()
39 }
40
41 pub fn is_negative(&self, db: &impl DefDatabase) -> bool {
42 db.impl_data(self.id).is_negative
43 }
44
45 pub fn module(&self, db: &impl DefDatabase) -> Module {
46 self.id.module(db).into()
47 }
48
49 pub fn krate(&self, db: &impl DefDatabase) -> Crate {
50 Crate { crate_id: self.module(db).id.krate }
51 }
52}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 70bba2efb..843ce6a88 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -32,7 +32,6 @@ pub mod db;
32pub mod source_binder; 32pub mod source_binder;
33 33
34mod ty; 34mod ty;
35mod impl_block;
36mod expr; 35mod expr;
37pub mod diagnostics; 36pub mod diagnostics;
38mod util; 37mod util;