Implement formatter for anon binop.

This commit is contained in:
KtorZ 2023-06-17 08:44:59 +02:00
parent 91f03abb7b
commit 4252ee6373
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 39 additions and 17 deletions

View File

@ -775,11 +775,8 @@ impl<'comments> Formatter<'comments> {
UntypedExpr::Fn { UntypedExpr::Fn {
fn_style: FnStyle::BinOp(op), fn_style: FnStyle::BinOp(op),
body,
.. ..
} => { } => op.to_doc(),
unimplemented!()
}
UntypedExpr::Fn { UntypedExpr::Fn {
fn_style: FnStyle::Plain, fn_style: FnStyle::Plain,
@ -1070,7 +1067,9 @@ impl<'comments> Formatter<'comments> {
let right = self.expr(right); let right = self.expr(right);
self.operator_side(left, precedence, left_precedence) self.operator_side(left, precedence, left_precedence)
.append(" ")
.append(name) .append(name)
.append(" ")
.append(self.operator_side(right, precedence, right_precedence - 1)) .append(self.operator_side(right, precedence, right_precedence - 1))
} }

View File

@ -864,3 +864,26 @@ fn hex_and_numeric_underscore() {
assert_fmt(src, src); assert_fmt(src, src);
} }
#[test]
fn first_class_binop() {
let src = indoc! { r#"
fn foo() {
compare_with(a, >, b)
compare_with(a, >=, b)
compare_with(a, <, b)
compare_with(a, <=, b)
compare_with(a, ==, b)
compare_with(a, !=, b)
combine_with(a, &&, b)
combine_with(a, ||, b)
compute_with(a, +, b)
compute_with(a, -, b)
compute_with(a, /, b)
compute_with(a, *, b)
compute_with(a, %, b)
}
"#};
assert_fmt(src, src);
}