diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 817c27410..63c85ca34 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -13,6 +13,7 @@ use hir_def::{ | |||
13 | AdtId, ConstId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId, | 13 | AdtId, ConstId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId, |
14 | LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, | 14 | LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, |
15 | TypeParamId, UnionId, | 15 | TypeParamId, UnionId, |
16 | GenericDefId | ||
16 | }; | 17 | }; |
17 | use hir_expand::{ | 18 | use hir_expand::{ |
18 | diagnostics::DiagnosticSink, | 19 | diagnostics::DiagnosticSink, |
@@ -21,7 +22,8 @@ use hir_expand::{ | |||
21 | }; | 22 | }; |
22 | use hir_ty::{ | 23 | use hir_ty::{ |
23 | autoderef, display::HirFormatter, expr::ExprValidator, method_resolution, ApplicationTy, | 24 | autoderef, display::HirFormatter, expr::ExprValidator, method_resolution, ApplicationTy, |
24 | Canonical, InEnvironment, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk, | 25 | Canonical, InEnvironment, TraitEnvironment, Ty, TyDefId, TypeCtor, |
26 | Substs | ||
25 | }; | 27 | }; |
26 | use ra_db::{CrateId, Edition, FileId}; | 28 | use ra_db::{CrateId, Edition, FileId}; |
27 | use ra_prof::profile; | 29 | use ra_prof::profile; |
@@ -270,7 +272,13 @@ impl StructField { | |||
270 | 272 | ||
271 | pub fn ty(&self, db: &impl HirDatabase) -> Type { | 273 | pub fn ty(&self, db: &impl HirDatabase) -> Type { |
272 | let var_id = self.parent.into(); | 274 | let var_id = self.parent.into(); |
273 | let ty = db.field_types(var_id)[self.id].clone(); | 275 | let generic_def_id: GenericDefId = match self.parent { |
276 | VariantDef::Struct(it) => it.id.into(), | ||
277 | VariantDef::Union(it) => it.id.into(), | ||
278 | VariantDef::EnumVariant(it) => it.parent.id.into(), | ||
279 | }; | ||
280 | let substs = Substs::type_params(db, generic_def_id); | ||
281 | let ty = db.field_types(var_id)[self.id].clone().subst(&substs); | ||
274 | Type::new(db, self.parent.module(db).id.krate.into(), var_id, ty) | 282 | Type::new(db, self.parent.module(db).id.krate.into(), var_id, ty) |
275 | } | 283 | } |
276 | 284 | ||
@@ -789,11 +797,7 @@ impl ImplBlock { | |||
789 | pub fn target_ty(&self, db: &impl HirDatabase) -> Type { | 797 | pub fn target_ty(&self, db: &impl HirDatabase) -> Type { |
790 | let impl_data = db.impl_data(self.id); | 798 | let impl_data = db.impl_data(self.id); |
791 | let resolver = self.id.resolver(db); | 799 | let resolver = self.id.resolver(db); |
792 | let ctx = hir_ty::TyLoweringContext { | 800 | let ctx = hir_ty::TyLoweringContext::new(db, &resolver); |
793 | db, | ||
794 | resolver: &resolver, | ||
795 | impl_trait_mode: hir_ty::ImplTraitLoweringMode::Disallowed, | ||
796 | }; | ||
797 | let environment = TraitEnvironment::lower(db, &resolver); | 801 | let environment = TraitEnvironment::lower(db, &resolver); |
798 | let ty = Ty::from_hir(&ctx, &impl_data.target_type); | 802 | let ty = Ty::from_hir(&ctx, &impl_data.target_type); |
799 | Type { | 803 | Type { |
@@ -856,9 +860,10 @@ impl Type { | |||
856 | fn from_def( | 860 | fn from_def( |
857 | db: &impl HirDatabase, | 861 | db: &impl HirDatabase, |
858 | krate: CrateId, | 862 | krate: CrateId, |
859 | def: impl HasResolver + Into<TyDefId>, | 863 | def: impl HasResolver + Into<TyDefId> + Into<GenericDefId>, |
860 | ) -> Type { | 864 | ) -> Type { |
861 | let ty = db.ty(def.into()); | 865 | let substs = Substs::type_params(db, def); |
866 | let ty = db.ty(def.into()).subst(&substs); | ||
862 | Type::new(db, krate, def, ty) | 867 | Type::new(db, krate, def, ty) |
863 | } | 868 | } |
864 | 869 | ||
@@ -955,7 +960,7 @@ impl Type { | |||
955 | match a_ty.ctor { | 960 | match a_ty.ctor { |
956 | TypeCtor::Tuple { .. } => { | 961 | TypeCtor::Tuple { .. } => { |
957 | for ty in a_ty.parameters.iter() { | 962 | for ty in a_ty.parameters.iter() { |
958 | let ty = ty.clone().subst(&a_ty.parameters); | 963 | let ty = ty.clone(); |
959 | res.push(self.derived(ty)); | 964 | res.push(self.derived(ty)); |
960 | } | 965 | } |
961 | } | 966 | } |