diff options
author | Aleksey Kladov <[email protected]> | 2019-11-22 15:46:39 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-22 15:46:39 +0000 |
commit | d4f4ae0dd88f0baf0065d612f41fea3d54af79fd (patch) | |
tree | a08c33528a8a1579c9017e43ad3b28042e77f8fe /crates/ra_hir/src/code_model.rs | |
parent | b841c53a0c93cdca3f08b1c917c9fa8a63d31604 (diff) |
Move const&static date to hir_def
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 51 |
1 files changed, 6 insertions, 45 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3daf7488e..1b65eefe5 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -10,7 +10,7 @@ use hir_def::{ | |||
10 | adt::VariantData, | 10 | adt::VariantData, |
11 | body::scope::ExprScopes, | 11 | body::scope::ExprScopes, |
12 | builtin_type::BuiltinType, | 12 | builtin_type::BuiltinType, |
13 | data::TraitData, | 13 | data::{ConstData, TraitData}, |
14 | nameres::per_ns::PerNs, | 14 | nameres::per_ns::PerNs, |
15 | resolver::{HasResolver, TypeNs}, | 15 | resolver::{HasResolver, TypeNs}, |
16 | type_ref::TypeRef, | 16 | type_ref::TypeRef, |
@@ -22,10 +22,10 @@ use hir_expand::{ | |||
22 | name::{self, AsName}, | 22 | name::{self, AsName}, |
23 | }; | 23 | }; |
24 | use ra_db::{CrateId, Edition}; | 24 | use ra_db::{CrateId, Edition}; |
25 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 25 | use ra_syntax::ast; |
26 | 26 | ||
27 | use crate::{ | 27 | use crate::{ |
28 | db::{AstDatabase, DefDatabase, HirDatabase}, | 28 | db::{DefDatabase, HirDatabase}, |
29 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, | 29 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, |
30 | ids::{ | 30 | ids::{ |
31 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, | 31 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, |
@@ -645,11 +645,11 @@ impl Const { | |||
645 | } | 645 | } |
646 | 646 | ||
647 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { | 647 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { |
648 | db.const_data(self) | 648 | db.const_data(self.id) |
649 | } | 649 | } |
650 | 650 | ||
651 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { | 651 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { |
652 | self.data(db).name().cloned() | 652 | self.data(db).name.clone() |
653 | } | 653 | } |
654 | 654 | ||
655 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 655 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
@@ -681,45 +681,6 @@ impl Const { | |||
681 | } | 681 | } |
682 | } | 682 | } |
683 | 683 | ||
684 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
685 | pub struct ConstData { | ||
686 | pub(crate) name: Option<Name>, | ||
687 | pub(crate) type_ref: TypeRef, | ||
688 | } | ||
689 | |||
690 | impl ConstData { | ||
691 | pub fn name(&self) -> Option<&Name> { | ||
692 | self.name.as_ref() | ||
693 | } | ||
694 | |||
695 | pub fn type_ref(&self) -> &TypeRef { | ||
696 | &self.type_ref | ||
697 | } | ||
698 | |||
699 | pub(crate) fn const_data_query( | ||
700 | db: &(impl DefDatabase + AstDatabase), | ||
701 | konst: Const, | ||
702 | ) -> Arc<ConstData> { | ||
703 | let node = konst.source(db).value; | ||
704 | const_data_for(&node) | ||
705 | } | ||
706 | |||
707 | pub(crate) fn static_data_query( | ||
708 | db: &(impl DefDatabase + AstDatabase), | ||
709 | konst: Static, | ||
710 | ) -> Arc<ConstData> { | ||
711 | let node = konst.source(db).value; | ||
712 | const_data_for(&node) | ||
713 | } | ||
714 | } | ||
715 | |||
716 | fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> { | ||
717 | let name = node.name().map(|n| n.as_name()); | ||
718 | let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); | ||
719 | let sig = ConstData { name, type_ref }; | ||
720 | Arc::new(sig) | ||
721 | } | ||
722 | |||
723 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 684 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
724 | pub struct Static { | 685 | pub struct Static { |
725 | pub(crate) id: StaticId, | 686 | pub(crate) id: StaticId, |
@@ -735,7 +696,7 @@ impl Static { | |||
735 | } | 696 | } |
736 | 697 | ||
737 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { | 698 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { |
738 | db.static_data(self) | 699 | db.static_data(self.id) |
739 | } | 700 | } |
740 | 701 | ||
741 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 702 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |