Fix formatting of function expressions with traces

Fixes #471
This commit is contained in:
KtorZ 2023-03-30 09:21:46 +02:00
parent efa31e3df7
commit cc18e7cff2
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 26 additions and 1 deletions

View File

@ -569,7 +569,7 @@ impl<'comments> Formatter<'comments> {
) -> Document<'a> {
let args = wrap_args(args.iter().map(|e| (self.fn_arg(e), false))).group();
let body = match body {
UntypedExpr::When { .. } => self.expr(body).force_break(),
UntypedExpr::Trace { .. } | UntypedExpr::When { .. } => self.expr(body).force_break(),
_ => self.expr(body),
};

View File

@ -698,3 +698,28 @@ fn weird_comments() {
assert_fmt(src, expected);
}
#[test]
fn format_trace_callback() {
let src = indoc! { r#"
fn foo() {
list.any([], fn (e) { trace @"foo"
e
})
}
"#};
let expected = indoc! { r#"
fn foo() {
list.any(
[],
fn(e) {
trace @"foo"
e
},
)
}
"#};
assert_fmt(src, expected);
}