diff options
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index fb788736d..af59aa1b6 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -953,6 +953,16 @@ impl TypeParam { | |||
953 | pub fn module(self, db: &dyn HirDatabase) -> Module { | 953 | pub fn module(self, db: &dyn HirDatabase) -> Module { |
954 | self.id.parent.module(db.upcast()).into() | 954 | self.id.parent.module(db.upcast()).into() |
955 | } | 955 | } |
956 | |||
957 | pub fn ty(self, db: &dyn HirDatabase) -> Type { | ||
958 | let resolver = self.id.parent.resolver(db.upcast()); | ||
959 | let environment = TraitEnvironment::lower(db, &resolver); | ||
960 | let ty = Ty::Placeholder(self.id); | ||
961 | Type { | ||
962 | krate: self.id.parent.module(db.upcast()).krate, | ||
963 | ty: InEnvironment { value: ty, environment }, | ||
964 | } | ||
965 | } | ||
956 | } | 966 | } |
957 | 967 | ||
958 | // FIXME: rename from `ImplDef` to `Impl` | 968 | // FIXME: rename from `ImplDef` to `Impl` |
@@ -1157,18 +1167,21 @@ impl Type { | |||
1157 | 1167 | ||
1158 | pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> { | 1168 | pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> { |
1159 | if let Ty::Apply(a_ty) = &self.ty.value { | 1169 | if let Ty::Apply(a_ty) = &self.ty.value { |
1160 | if let TypeCtor::Adt(AdtId::StructId(s)) = a_ty.ctor { | 1170 | let variant_id = match a_ty.ctor { |
1161 | let var_def = s.into(); | 1171 | TypeCtor::Adt(AdtId::StructId(s)) => s.into(), |
1162 | return db | 1172 | TypeCtor::Adt(AdtId::UnionId(u)) => u.into(), |
1163 | .field_types(var_def) | 1173 | _ => return Vec::new(), |
1164 | .iter() | 1174 | }; |
1165 | .map(|(local_id, ty)| { | 1175 | |
1166 | let def = Field { parent: var_def.into(), id: local_id }; | 1176 | return db |
1167 | let ty = ty.clone().subst(&a_ty.parameters); | 1177 | .field_types(variant_id) |
1168 | (def, self.derived(ty)) | 1178 | .iter() |
1169 | }) | 1179 | .map(|(local_id, ty)| { |
1170 | .collect(); | 1180 | let def = Field { parent: variant_id.into(), id: local_id }; |
1171 | } | 1181 | let ty = ty.clone().subst(&a_ty.parameters); |
1182 | (def, self.derived(ty)) | ||
1183 | }) | ||
1184 | .collect(); | ||
1172 | }; | 1185 | }; |
1173 | Vec::new() | 1186 | Vec::new() |
1174 | } | 1187 | } |