cl-ast: Remove variantkind, as it was redundant
This commit is contained in:
@@ -39,10 +39,6 @@ impl_from! {
|
||||
Vec<Ty> => StructKind::Tuple,
|
||||
// TODO: Struct members in struct
|
||||
}
|
||||
impl From for VariantKind {
|
||||
Ty => VariantKind::Tuple,
|
||||
// TODO: enum struct variants
|
||||
}
|
||||
impl From for TyKind {
|
||||
Path => TyKind::Path,
|
||||
TyTuple => TyKind::Tuple,
|
||||
|
||||
@@ -227,29 +227,19 @@ impl Display for StructMember {
|
||||
|
||||
impl Display for Enum {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { name, gens, variants: kind } = self;
|
||||
let Self { name, gens, variants } = self;
|
||||
write!(f, "enum {name}{gens}")?;
|
||||
match kind {
|
||||
Some(v) => separate(v, ",\n")(f.delimit(SPACED_BRACES)),
|
||||
None => ";".fmt(f),
|
||||
}
|
||||
separate(variants, ",\n")(f.delimit(SPACED_BRACES))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Variant {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { name, kind } = self;
|
||||
write!(f, "{name}{kind}")
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for VariantKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
VariantKind::Plain => Ok(()),
|
||||
VariantKind::CLike(n) => write!(f, " = {n}"),
|
||||
VariantKind::Tuple(v) => v.fmt(f),
|
||||
VariantKind::Struct(v) => separate(v, ", ")(f.delimit(INLINE_BRACES)),
|
||||
let Self { name, kind, body } = self;
|
||||
write!(f, "{name}{kind}")?;
|
||||
match body {
|
||||
Some(body) => write!(f, " {body}"),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,29 +134,14 @@ impl WeightOf for StructMember {
|
||||
impl WeightOf for Enum {
|
||||
fn weight_of(&self) -> usize {
|
||||
let Self { name, gens, variants } = self;
|
||||
name.weight_of()
|
||||
+ gens.weight_of()
|
||||
+ variants
|
||||
.as_ref()
|
||||
.map_or(size_of_val(variants), |v| v.weight_of())
|
||||
name.weight_of() + gens.weight_of() + variants.weight_of()
|
||||
}
|
||||
}
|
||||
|
||||
impl WeightOf for Variant {
|
||||
fn weight_of(&self) -> usize {
|
||||
let Self { name, kind } = self;
|
||||
name.weight_of() + kind.weight_of()
|
||||
}
|
||||
}
|
||||
|
||||
impl WeightOf for VariantKind {
|
||||
fn weight_of(&self) -> usize {
|
||||
match self {
|
||||
VariantKind::Plain => size_of_val(self),
|
||||
VariantKind::CLike(v) => v.weight_of(),
|
||||
VariantKind::Tuple(ty) => ty.weight_of(),
|
||||
VariantKind::Struct(m) => m.weight_of(),
|
||||
}
|
||||
let Self { name, kind, body } = self;
|
||||
name.weight_of() + kind.weight_of() + body.weight_of()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,7 +544,7 @@ impl WeightOf for Return {
|
||||
impl<T: WeightOf> WeightOf for Option<T> {
|
||||
fn weight_of(&self) -> usize {
|
||||
match self {
|
||||
Some(t) => t.weight_of(),
|
||||
Some(t) => t.weight_of().max(size_of_val(t)),
|
||||
None => size_of_val(self),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user