diff options
author | Aleksey Kladov <[email protected]> | 2019-06-11 15:13:20 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-06-11 16:28:51 +0100 |
commit | 46bc8675edd403ffcd8963e4f26447b283e9d09e (patch) | |
tree | a233cc8fe98da533444f90edf929c6ae1e343b22 /crates/ra_hir | |
parent | 4f94af3c4aaa57ebb4cb01f7e4edfb3a0821b09b (diff) |
use Source for statics and consts
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 34 | ||||
-rw-r--r-- | crates/ra_hir/src/docs.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/expr.rs | 12 |
3 files changed, 30 insertions, 20 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index aa6eb741b..a8a0875e0 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -761,12 +761,17 @@ pub struct Const { | |||
761 | pub(crate) id: ConstId, | 761 | pub(crate) id: ConstId, |
762 | } | 762 | } |
763 | 763 | ||
764 | impl HasSource for Const { | ||
765 | type Ast = TreeArc<ast::ConstDef>; | ||
766 | |||
767 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> { | ||
768 | self.id.source(db).into() | ||
769 | } | ||
770 | } | ||
771 | |||
764 | impl Const { | 772 | impl Const { |
765 | pub fn source( | 773 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> { |
766 | self, | 774 | self.id.source(db).into() |
767 | db: &(impl DefDatabase + AstDatabase), | ||
768 | ) -> (HirFileId, TreeArc<ast::ConstDef>) { | ||
769 | self.id.source(db) | ||
770 | } | 775 | } |
771 | 776 | ||
772 | pub fn module(self, db: &impl DefDatabase) -> Module { | 777 | pub fn module(self, db: &impl DefDatabase) -> Module { |
@@ -819,7 +824,7 @@ impl ConstSignature { | |||
819 | db: &(impl DefDatabase + AstDatabase), | 824 | db: &(impl DefDatabase + AstDatabase), |
820 | konst: Const, | 825 | konst: Const, |
821 | ) -> Arc<ConstSignature> { | 826 | ) -> Arc<ConstSignature> { |
822 | let (_, node) = konst.source(db); | 827 | let node = konst.source(db).ast; |
823 | const_signature_for(&*node) | 828 | const_signature_for(&*node) |
824 | } | 829 | } |
825 | 830 | ||
@@ -827,7 +832,7 @@ impl ConstSignature { | |||
827 | db: &(impl DefDatabase + AstDatabase), | 832 | db: &(impl DefDatabase + AstDatabase), |
828 | konst: Static, | 833 | konst: Static, |
829 | ) -> Arc<ConstSignature> { | 834 | ) -> Arc<ConstSignature> { |
830 | let (_, node) = konst.source(db); | 835 | let node = konst.source(db).ast; |
831 | const_signature_for(&*node) | 836 | const_signature_for(&*node) |
832 | } | 837 | } |
833 | } | 838 | } |
@@ -844,12 +849,17 @@ pub struct Static { | |||
844 | pub(crate) id: StaticId, | 849 | pub(crate) id: StaticId, |
845 | } | 850 | } |
846 | 851 | ||
852 | impl HasSource for Static { | ||
853 | type Ast = TreeArc<ast::StaticDef>; | ||
854 | |||
855 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> { | ||
856 | self.id.source(db).into() | ||
857 | } | ||
858 | } | ||
859 | |||
847 | impl Static { | 860 | impl Static { |
848 | pub fn source( | 861 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> { |
849 | self, | 862 | self.id.source(db).into() |
850 | db: &(impl DefDatabase + AstDatabase), | ||
851 | ) -> (HirFileId, TreeArc<ast::StaticDef>) { | ||
852 | self.id.source(db) | ||
853 | } | 863 | } |
854 | 864 | ||
855 | pub fn module(self, db: &impl DefDatabase) -> Module { | 865 | pub fn module(self, db: &impl DefDatabase) -> Module { |
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index 8d7a5255f..86ca981f4 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs | |||
@@ -79,8 +79,8 @@ pub(crate) fn documentation_query( | |||
79 | DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast), | 79 | DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast), |
80 | DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast), | 80 | DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast), |
81 | DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast), | 81 | DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast), |
82 | DocDef::Static(it) => docs_from_ast(&*it.source(db).1), | 82 | DocDef::Static(it) => docs_from_ast(&*it.source(db).ast), |
83 | DocDef::Const(it) => docs_from_ast(&*it.source(db).1), | 83 | DocDef::Const(it) => docs_from_ast(&*it.source(db).ast), |
84 | DocDef::Function(it) => docs_from_ast(&*it.source(db).ast), | 84 | DocDef::Function(it) => docs_from_ast(&*it.source(db).ast), |
85 | DocDef::Union(it) => docs_from_ast(&*it.source(db).1), | 85 | DocDef::Union(it) => docs_from_ast(&*it.source(db).1), |
86 | DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), | 86 | DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 46d51e0db..48e597519 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -1018,9 +1018,9 @@ pub(crate) fn body_with_source_map_query( | |||
1018 | 1018 | ||
1019 | match def { | 1019 | match def { |
1020 | DefWithBody::Const(ref c) => { | 1020 | DefWithBody::Const(ref c) => { |
1021 | let (file_id, src) = c.source(db); | 1021 | let src = c.source(db); |
1022 | collector = ExprCollector::new(def, file_id, def.resolver(db), db); | 1022 | collector = ExprCollector::new(def, src.file_id, def.resolver(db), db); |
1023 | collector.collect_const_body(&src) | 1023 | collector.collect_const_body(&src.ast) |
1024 | } | 1024 | } |
1025 | DefWithBody::Function(ref f) => { | 1025 | DefWithBody::Function(ref f) => { |
1026 | let src = f.source(db); | 1026 | let src = f.source(db); |
@@ -1028,9 +1028,9 @@ pub(crate) fn body_with_source_map_query( | |||
1028 | collector.collect_fn_body(&src.ast) | 1028 | collector.collect_fn_body(&src.ast) |
1029 | } | 1029 | } |
1030 | DefWithBody::Static(ref s) => { | 1030 | DefWithBody::Static(ref s) => { |
1031 | let (file_id, src) = s.source(db); | 1031 | let src = s.source(db); |
1032 | collector = ExprCollector::new(def, file_id, def.resolver(db), db); | 1032 | collector = ExprCollector::new(def, src.file_id, def.resolver(db), db); |
1033 | collector.collect_static_body(&src) | 1033 | collector.collect_static_body(&src.ast) |
1034 | } | 1034 | } |
1035 | } | 1035 | } |
1036 | 1036 | ||