diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3695115e4..e854b22bf 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -265,8 +265,10 @@ impl StructField { | |||
265 | self.parent.variant_data(db).fields()[self.id].name.clone() | 265 | self.parent.variant_data(db).fields()[self.id].name.clone() |
266 | } | 266 | } |
267 | 267 | ||
268 | pub fn ty(&self, db: &impl HirDatabase) -> Ty { | 268 | pub fn ty(&self, db: &impl HirDatabase) -> Type { |
269 | db.field_types(self.parent.into())[self.id].clone() | 269 | let var_id = self.parent.into(); |
270 | let ty = db.field_types(var_id)[self.id].clone(); | ||
271 | Type::new(db, self.parent.module(db).id.krate.into(), var_id, ty) | ||
270 | } | 272 | } |
271 | 273 | ||
272 | pub fn parent_def(&self, _db: &impl HirDatabase) -> VariantDef { | 274 | pub fn parent_def(&self, _db: &impl HirDatabase) -> VariantDef { |
@@ -940,15 +942,19 @@ pub struct Type { | |||
940 | } | 942 | } |
941 | 943 | ||
942 | impl Type { | 944 | impl Type { |
945 | fn new(db: &impl HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type { | ||
946 | let resolver = lexical_env.resolver(db); | ||
947 | let environment = TraitEnvironment::lower(db, &resolver); | ||
948 | Type { krate, ty: InEnvironment { value: ty, environment } } | ||
949 | } | ||
950 | |||
943 | fn from_def( | 951 | fn from_def( |
944 | db: &impl HirDatabase, | 952 | db: &impl HirDatabase, |
945 | krate: CrateId, | 953 | krate: CrateId, |
946 | def: impl HasResolver + Into<TyDefId>, | 954 | def: impl HasResolver + Into<TyDefId>, |
947 | ) -> Type { | 955 | ) -> Type { |
948 | let resolver = def.resolver(db); | ||
949 | let environment = TraitEnvironment::lower(db, &resolver); | ||
950 | let ty = db.ty(def.into()); | 956 | let ty = db.ty(def.into()); |
951 | Type { krate, ty: InEnvironment { value: ty, environment } } | 957 | Type::new(db, krate, def, ty) |
952 | } | 958 | } |
953 | 959 | ||
954 | pub fn is_bool(&self) -> bool { | 960 | pub fn is_bool(&self) -> bool { |
@@ -1039,11 +1045,16 @@ impl Type { | |||
1039 | ) -> Vec<(StructField, Type)> { | 1045 | ) -> Vec<(StructField, Type)> { |
1040 | // FIXME: check that ty and def match | 1046 | // FIXME: check that ty and def match |
1041 | match &self.ty.value { | 1047 | match &self.ty.value { |
1042 | Ty::Apply(a_ty) => def | 1048 | Ty::Apply(a_ty) => { |
1043 | .fields(db) | 1049 | let field_types = db.field_types(def.into()); |
1044 | .into_iter() | 1050 | def.fields(db) |
1045 | .map(|it| (it, self.derived(it.ty(db).subst(&a_ty.parameters)))) | 1051 | .into_iter() |
1046 | .collect(), | 1052 | .map(|it| { |
1053 | let ty = field_types[it.id].clone().subst(&a_ty.parameters); | ||
1054 | (it, self.derived(ty)) | ||
1055 | }) | ||
1056 | .collect() | ||
1057 | } | ||
1047 | _ => Vec::new(), | 1058 | _ => Vec::new(), |
1048 | } | 1059 | } |
1049 | } | 1060 | } |