diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 53 |
1 files changed, 3 insertions, 50 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3daf7488e..af07b2c4d 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -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, |
@@ -644,12 +644,8 @@ impl Const { | |||
644 | Some(self.module(db).krate()) | 644 | Some(self.module(db).krate()) |
645 | } | 645 | } |
646 | 646 | ||
647 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { | ||
648 | db.const_data(self) | ||
649 | } | ||
650 | |||
651 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { | 647 | pub fn name(self, db: &impl HirDatabase) -> Option<Name> { |
652 | self.data(db).name().cloned() | 648 | db.const_data(self.id).name.clone() |
653 | } | 649 | } |
654 | 650 | ||
655 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 651 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
@@ -681,45 +677,6 @@ impl Const { | |||
681 | } | 677 | } |
682 | } | 678 | } |
683 | 679 | ||
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)] | 680 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
724 | pub struct Static { | 681 | pub struct Static { |
725 | pub(crate) id: StaticId, | 682 | pub(crate) id: StaticId, |
@@ -734,10 +691,6 @@ impl Static { | |||
734 | Some(self.module(db).krate()) | 691 | Some(self.module(db).krate()) |
735 | } | 692 | } |
736 | 693 | ||
737 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { | ||
738 | db.static_data(self) | ||
739 | } | ||
740 | |||
741 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | 694 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { |
742 | db.infer(self.into()) | 695 | db.infer(self.into()) |
743 | } | 696 | } |