diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 906716dfc..3d956afa7 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -23,14 +23,15 @@ use hir_expand::{ | |||
23 | name::{self, AsName}, | 23 | name::{self, AsName}, |
24 | MacroDefId, | 24 | MacroDefId, |
25 | }; | 25 | }; |
26 | use hir_ty::expr::ExprValidator; | 26 | use hir_ty::{ |
27 | autoderef, display::HirFormatter, expr::ExprValidator, ApplicationTy, Canonical, InEnvironment, | ||
28 | TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk, | ||
29 | }; | ||
27 | use ra_db::{CrateId, Edition, FileId}; | 30 | use ra_db::{CrateId, Edition, FileId}; |
28 | use ra_syntax::ast; | 31 | use ra_syntax::ast; |
29 | 32 | ||
30 | use crate::{ | 33 | use crate::{ |
31 | db::{DefDatabase, HirDatabase}, | 34 | db::{DefDatabase, HirDatabase}, |
32 | ty::display::HirFormatter, | ||
33 | ty::{self, InEnvironment, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, | ||
34 | CallableDef, HirDisplay, InFile, Name, | 35 | CallableDef, HirDisplay, InFile, Name, |
35 | }; | 36 | }; |
36 | 37 | ||
@@ -87,10 +88,6 @@ impl Crate { | |||
87 | pub fn all(db: &impl DefDatabase) -> Vec<Crate> { | 88 | pub fn all(db: &impl DefDatabase) -> Vec<Crate> { |
88 | db.crate_graph().iter().map(|id| Crate { id }).collect() | 89 | db.crate_graph().iter().map(|id| Crate { id }).collect() |
89 | } | 90 | } |
90 | |||
91 | pub fn crate_id(self) -> CrateId { | ||
92 | self.id | ||
93 | } | ||
94 | } | 91 | } |
95 | 92 | ||
96 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 93 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -937,7 +934,7 @@ impl Type { | |||
937 | pub fn fields(&self, db: &impl HirDatabase) -> Vec<(StructField, Type)> { | 934 | pub fn fields(&self, db: &impl HirDatabase) -> Vec<(StructField, Type)> { |
938 | if let Ty::Apply(a_ty) = &self.ty.value { | 935 | if let Ty::Apply(a_ty) = &self.ty.value { |
939 | match a_ty.ctor { | 936 | match a_ty.ctor { |
940 | ty::TypeCtor::Adt(AdtId::StructId(s)) => { | 937 | TypeCtor::Adt(AdtId::StructId(s)) => { |
941 | let var_def = s.into(); | 938 | let var_def = s.into(); |
942 | return db | 939 | return db |
943 | .field_types(var_def) | 940 | .field_types(var_def) |
@@ -959,7 +956,7 @@ impl Type { | |||
959 | let mut res = Vec::new(); | 956 | let mut res = Vec::new(); |
960 | if let Ty::Apply(a_ty) = &self.ty.value { | 957 | if let Ty::Apply(a_ty) = &self.ty.value { |
961 | match a_ty.ctor { | 958 | match a_ty.ctor { |
962 | ty::TypeCtor::Tuple { .. } => { | 959 | TypeCtor::Tuple { .. } => { |
963 | for ty in a_ty.parameters.iter() { | 960 | for ty in a_ty.parameters.iter() { |
964 | let ty = ty.clone().subst(&a_ty.parameters); | 961 | let ty = ty.clone().subst(&a_ty.parameters); |
965 | res.push(self.derived(ty)); | 962 | res.push(self.derived(ty)); |
@@ -995,10 +992,10 @@ impl Type { | |||
995 | pub fn autoderef<'a>(&'a self, db: &'a impl HirDatabase) -> impl Iterator<Item = Type> + 'a { | 992 | pub fn autoderef<'a>(&'a self, db: &'a impl HirDatabase) -> impl Iterator<Item = Type> + 'a { |
996 | // There should be no inference vars in types passed here | 993 | // There should be no inference vars in types passed here |
997 | // FIXME check that? | 994 | // FIXME check that? |
998 | let canonical = crate::ty::Canonical { value: self.ty.value.clone(), num_vars: 0 }; | 995 | let canonical = Canonical { value: self.ty.value.clone(), num_vars: 0 }; |
999 | let environment = self.ty.environment.clone(); | 996 | let environment = self.ty.environment.clone(); |
1000 | let ty = InEnvironment { value: canonical, environment: environment.clone() }; | 997 | let ty = InEnvironment { value: canonical, environment: environment.clone() }; |
1001 | ty::autoderef(db, Some(self.krate), ty) | 998 | autoderef(db, Some(self.krate), ty) |
1002 | .map(|canonical| canonical.value) | 999 | .map(|canonical| canonical.value) |
1003 | .map(move |ty| self.derived(ty)) | 1000 | .map(move |ty| self.derived(ty)) |
1004 | } | 1001 | } |
@@ -1038,15 +1035,14 @@ impl Type { | |||
1038 | // FIXME: provide required accessors such that it becomes implementable from outside. | 1035 | // FIXME: provide required accessors such that it becomes implementable from outside. |
1039 | pub fn is_equal_for_find_impls(&self, other: &Type) -> bool { | 1036 | pub fn is_equal_for_find_impls(&self, other: &Type) -> bool { |
1040 | match (&self.ty.value, &other.ty.value) { | 1037 | match (&self.ty.value, &other.ty.value) { |
1041 | (Ty::Apply(a_original_ty), Ty::Apply(ty::ApplicationTy { ctor, parameters })) => { | 1038 | (Ty::Apply(a_original_ty), Ty::Apply(ApplicationTy { ctor, parameters })) => match ctor |
1042 | match ctor { | 1039 | { |
1043 | TypeCtor::Ref(..) => match parameters.as_single() { | 1040 | TypeCtor::Ref(..) => match parameters.as_single() { |
1044 | Ty::Apply(a_ty) => a_original_ty.ctor == a_ty.ctor, | 1041 | Ty::Apply(a_ty) => a_original_ty.ctor == a_ty.ctor, |
1045 | _ => false, | 1042 | _ => false, |
1046 | }, | 1043 | }, |
1047 | _ => a_original_ty.ctor == *ctor, | 1044 | _ => a_original_ty.ctor == *ctor, |
1048 | } | 1045 | }, |
1049 | } | ||
1050 | _ => false, | 1046 | _ => false, |
1051 | } | 1047 | } |
1052 | } | 1048 | } |