diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-24 18:18:47 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-24 18:18:47 +0000 |
commit | 09389ed1d43c244352cecbd78c8685480d60157d (patch) | |
tree | 047d256c33567aa3dfb59e7986f7059bf99ffb6b /crates/ra_hir/src | |
parent | 64fc9ac9650afb04a353ba8a18381f0db83cbc82 (diff) | |
parent | 191b1d238fd1594ab74b1ab6a17dbe0430fc6b1a (diff) |
Merge #2391
2391: Simplify r=matklad a=matklad
bors r+
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 35 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 52 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 1 |
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 | ||
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), |
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; | |||
5 | use ra_syntax::ast; | 5 | use ra_syntax::ast; |
6 | 6 | ||
7 | use crate::{ | 7 | use 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 | ||
12 | pub use hir_expand::Source; | 12 | pub 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 | } |
111 | impl 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 | } | ||
111 | impl HasSource for Import { | 117 | impl 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 | |||
3 | use hir_def::{resolver::HasResolver, type_ref::TypeRef, AstItemDef}; | ||
4 | use ra_syntax::ast; | ||
5 | |||
6 | use crate::{ | ||
7 | db::{AstDatabase, DefDatabase, HirDatabase}, | ||
8 | ty::Ty, | ||
9 | AssocItem, Crate, HasSource, ImplBlock, Module, Source, TraitRef, | ||
10 | }; | ||
11 | |||
12 | impl 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 | |||
19 | impl 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; | |||
32 | pub mod source_binder; | 32 | pub mod source_binder; |
33 | 33 | ||
34 | mod ty; | 34 | mod ty; |
35 | mod impl_block; | ||
36 | mod expr; | 35 | mod expr; |
37 | pub mod diagnostics; | 36 | pub mod diagnostics; |
38 | mod util; | 37 | mod util; |