display: newline-indent bare function bodies(?)

This commit is contained in:
2025-12-23 05:01:25 -05:00
parent a836de32c7
commit 41b8688438

View File

@@ -41,7 +41,7 @@ impl<A: Annotation> Display for Expr<A> {
Self::Op(Op::Tuple, exprs) => f.delimit("(", ")").list(exprs, ", "), Self::Op(Op::Tuple, exprs) => f.delimit("(", ")").list(exprs, ", "),
Self::Op(Op::Group, exprs) => f.list(exprs, ", "), Self::Op(Op::Group, exprs) => f.list(exprs, ", "),
Self::Op(Op::Meta, exprs) => match exprs.as_slice() { Self::Op(Op::Meta, exprs) => match exprs.as_slice() {
[meta, expr @ ..] => f.delimit(fmt!("#[{meta}]\n"), "").list(expr, ","), [meta, expr @ ..] => f.delimit(fmt!("#[{meta}] "), "").list(expr, ","),
[] => write!(f, "#[]"), [] => write!(f, "#[]"),
}, },
@@ -182,7 +182,13 @@ impl<A: Annotation> Display for Bind<A> {
match op { match op {
BindOp::Match => f.delimit(fmt!("{pat} => "), "").list(exprs, ",!? "), BindOp::Match => f.delimit(fmt!("{pat} => "), "").list(exprs, ",!? "),
BindOp::Fn | BindOp::Mod | BindOp::Impl => { BindOp::Fn | BindOp::Mod | BindOp::Impl => {
if let [Anno(Expr::Op(Op::Block, _), _)] = exprs.as_slice() {
f.delimit(fmt!("{pat} "), "").list(exprs, ",!? ") f.delimit(fmt!("{pat} "), "").list(exprs, ",!? ")
} else {
// wrap bare function bodies to new line
f.delimit_indented(pat, "")
.list_wrap("\n", exprs, ",!?", "")
}
} }
BindOp::Struct | BindOp::Enum => match pat { BindOp::Struct | BindOp::Enum => match pat {
Pat::NamedRecord(name, bind) => match bind.as_ref() { Pat::NamedRecord(name, bind) => match bind.as_ref() {