fix: Discriminant hints only render for datacarrying enums with primitive repr

This commit is contained in:
Lukas Wirth 2023-05-16 22:15:39 +02:00
parent 2f8cd66fb4
commit c12ede8c34
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))
}