Use BinOpKind
instead of BinOp
for function args where possible.
Because it's nice to avoid passing in unnecessary data.
This commit is contained in:
parent
076cccd412
commit
ac8ccf09b4
7 changed files with 77 additions and 78 deletions
|
@ -1271,18 +1271,18 @@ impl<'a> State<'a> {
|
|||
self.print_call_post(base_args)
|
||||
}
|
||||
|
||||
fn print_expr_binary(&mut self, op: hir::BinOp, lhs: &hir::Expr<'_>, rhs: &hir::Expr<'_>) {
|
||||
let binop_prec = op.node.precedence();
|
||||
fn print_expr_binary(&mut self, op: hir::BinOpKind, lhs: &hir::Expr<'_>, rhs: &hir::Expr<'_>) {
|
||||
let binop_prec = op.precedence();
|
||||
let left_prec = lhs.precedence();
|
||||
let right_prec = rhs.precedence();
|
||||
|
||||
let (mut left_needs_paren, right_needs_paren) = match op.node.fixity() {
|
||||
let (mut left_needs_paren, right_needs_paren) = match op.fixity() {
|
||||
Fixity::Left => (left_prec < binop_prec, right_prec <= binop_prec),
|
||||
Fixity::Right => (left_prec <= binop_prec, right_prec < binop_prec),
|
||||
Fixity::None => (left_prec <= binop_prec, right_prec <= binop_prec),
|
||||
};
|
||||
|
||||
match (&lhs.kind, op.node) {
|
||||
match (&lhs.kind, op) {
|
||||
// These cases need parens: `x as i32 < y` has the parser thinking that `i32 < y` is
|
||||
// the beginning of a path type. It starts trying to parse `x as (i32 < y ...` instead
|
||||
// of `(x as i32) < ...`. We need to convince it _not_ to do that.
|
||||
|
@ -1297,7 +1297,7 @@ impl<'a> State<'a> {
|
|||
|
||||
self.print_expr_cond_paren(lhs, left_needs_paren);
|
||||
self.space();
|
||||
self.word_space(op.node.as_str());
|
||||
self.word_space(op.as_str());
|
||||
self.print_expr_cond_paren(rhs, right_needs_paren);
|
||||
}
|
||||
|
||||
|
@ -1451,7 +1451,7 @@ impl<'a> State<'a> {
|
|||
self.word(".use");
|
||||
}
|
||||
hir::ExprKind::Binary(op, lhs, rhs) => {
|
||||
self.print_expr_binary(op, lhs, rhs);
|
||||
self.print_expr_binary(op.node, lhs, rhs);
|
||||
}
|
||||
hir::ExprKind::Unary(op, expr) => {
|
||||
self.print_expr_unary(op, expr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue