diff --git a/src/ast.rs b/src/ast.rs index 6756c1e..b50d4ec 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -127,7 +127,6 @@ pub struct Mod(pub Ty, pub Anno, A>); #[derive(Clone, Debug, PartialEq, Eq)] pub struct Struct(pub Pat); - /// Expressions: The beating heart of Dough #[derive(Clone, Debug, PartialEq, Eq)] pub enum Expr { @@ -312,7 +311,15 @@ impl Display for Mod { impl Display for Struct { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let Self(pat) = self; - write!(f, "struct {pat}") + match pat { + Pat::Struct(name, bind) => match bind.as_ref() { + Pat::Tuple(parts) => f + .delimit_indented(fmt!("{name} {{"), "}") + .list_wrap("\n", parts, ",\n", ",\n"), + other => write!(f, "{name} {{ {other} }}"), + }, + _ => write!(f, "struct {pat}"), + } } } @@ -438,7 +445,10 @@ impl Display for Pat { Self::Lit(literal) => literal.fmt(f), Self::MetId(name) => write!(f, "`{name}"), Self::Name(name) => name.fmt(f), - Self::Struct(name, bind) => write!(f, "{name} {{{bind}}}"), + Self::Struct(name, bind) => match bind.as_ref() { + Pat::Tuple(parts) => f.delimit(fmt!("{name} {{"), "}").list(parts, ", "), + other => write!(f, "{name} {{ {other} }}"), + }, Self::TupStruct(name, bind) => write!(f, "{name} {bind}"), Self::Rest(Some(rest)) => write!(f, "..{rest}"), Self::Rest(None) => write!(f, ".."),