Get rid of field_type again

This commit is contained in:
Florian Diebold 2021-05-23 23:54:35 +02:00
parent e65803748d
commit b8262099cc
6 changed files with 16 additions and 24 deletions

View file

@ -514,8 +514,7 @@ impl Field {
/// Returns the type as in the signature of the struct (i.e., with
/// placeholder types for type parameters). Only use this in the context of
/// the field *definition*; if you've already got a variable of the struct
/// type, use `Type::field_type` to get to the field type.
/// the field definition.
pub fn ty(&self, db: &dyn HirDatabase) -> Type {
let var_id = self.parent.into();
let generic_def_id: GenericDefId = match self.parent {
@ -1944,18 +1943,6 @@ impl Type {
}
}
pub fn field_type(&self, db: &dyn HirDatabase, field: Field) -> Option<Type> {
let (adt_id, substs) = self.ty.as_adt()?;
let variant_id: hir_def::VariantId = field.parent.into();
if variant_id.adt_id() != adt_id {
return None;
}
let ty = db.field_types(variant_id).get(field.id)?.clone();
let ty = ty.substitute(&Interner, substs);
Some(self.derived(ty))
}
pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
let (variant_id, substs) = match self.ty.kind(&Interner) {
&TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs),