Finish move of StructField for pattern type inference

This commit is contained in:
Marcus Klaas de Vries 2019-01-18 15:38:11 +01:00 committed by Aleksey Kladov
parent 4277f420aa
commit bcbfa2cc11
3 changed files with 46 additions and 31 deletions

View file

@ -158,7 +158,7 @@ impl Module {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StructField {
struct_: Struct,
parent: DefId,
name: Name,
}
@ -166,8 +166,9 @@ impl StructField {
pub fn name(&self) -> &Name {
&self.name
}
pub fn ty(&self, db: &impl HirDatabase) -> Option<Ty> {
db.type_for_field(self.struct_.def_id, self.name.clone())
db.type_for_field(self.parent, self.name.clone())
}
}
@ -191,7 +192,7 @@ impl Struct {
.fields()
.iter()
.map(|it| StructField {
struct_: self.clone(),
parent: self.def_id,
name: it.name.clone(),
})
.collect()
@ -255,6 +256,17 @@ impl EnumVariant {
db.enum_variant_data(self.def_id).variant_data.clone()
}
pub fn fields(&self, db: &impl HirDatabase) -> Vec<StructField> {
self.variant_data(db)
.fields()
.iter()
.map(|it| StructField {
parent: self.def_id,
name: it.name.clone(),
})
.collect()
}
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) {
def_id_to_ast(db, self.def_id)
}