Auto merge of #14823 - Veykril:discriminant-inlays, r=Veykril

fix: Discriminant hints only render for datacarrying enums with primitive repr
This commit is contained in:
bors 2023-05-18 05:50:41 +00:00
commit c06f088968
3 changed files with 49 additions and 46 deletions

View file

@ -1075,6 +1075,10 @@ impl Enum {
db.enum_data(self.id).variants.iter().map(|(id, _)| Variant { parent: self, id }).collect()
}
pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprOptions> {
db.enum_data(self.id).repr
}
pub fn ty(self, db: &dyn HirDatabase) -> Type {
Type::from_def(db, self.id)
}
@ -1112,6 +1116,7 @@ impl Enum {
)
}
/// Returns true if at least one variant of this enum is a non-unit variant.
pub fn is_data_carrying(self, db: &dyn HirDatabase) -> bool {
self.variants(db).iter().any(|v| !matches!(v.kind(db), StructKind::Unit))
}