Skip to content

Commit 9c95245

Browse files
authored
Unrolled build for rust-lang#123777
Rollup merge of rust-lang#123777 - oli-obk:operator_cleanup, r=jieyouxu Deduplicate some function implementations between the parser and AST/HIR These functions already existed on parser binops, so just convert back to them back and invoke the equivalent method.
2 parents aa6a697 + 0c8aad6 commit 9c95245

File tree

2 files changed

+3
-36
lines changed

2 files changed

+3
-36
lines changed

compiler/rustc_ast/src/ast.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,8 @@ impl BinOpKind {
920920
matches!(self, BinOpKind::And | BinOpKind::Or)
921921
}
922922

923-
pub fn is_comparison(&self) -> bool {
924-
use BinOpKind::*;
925-
// Note for developers: please keep this match exhaustive;
926-
// we want compilation to fail if another variant is added.
927-
match *self {
928-
Eq | Lt | Le | Ne | Gt | Ge => true,
929-
And | Or | Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Shl | Shr => false,
930-
}
923+
pub fn is_comparison(self) -> bool {
924+
crate::util::parser::AssocOp::from_ast_binop(self).is_comparison()
931925
}
932926

933927
/// Returns `true` if the binary operator takes its arguments by value.

compiler/rustc_hir_pretty/src/lib.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ impl<'a> State<'a> {
11421142
}
11431143

11441144
fn print_expr_binary(&mut self, op: hir::BinOp, lhs: &hir::Expr<'_>, rhs: &hir::Expr<'_>) {
1145-
let assoc_op = bin_op_to_assoc_op(op.node);
1145+
let assoc_op = AssocOp::from_ast_binop(op.node);
11461146
let prec = assoc_op.precedence() as i8;
11471147
let fixity = assoc_op.fixity();
11481148

@@ -2328,33 +2328,6 @@ fn stmt_ends_with_semi(stmt: &hir::StmtKind<'_>) -> bool {
23282328
}
23292329
}
23302330

2331-
fn bin_op_to_assoc_op(op: hir::BinOpKind) -> AssocOp {
2332-
use crate::hir::BinOpKind::*;
2333-
match op {
2334-
Add => AssocOp::Add,
2335-
Sub => AssocOp::Subtract,
2336-
Mul => AssocOp::Multiply,
2337-
Div => AssocOp::Divide,
2338-
Rem => AssocOp::Modulus,
2339-
2340-
And => AssocOp::LAnd,
2341-
Or => AssocOp::LOr,
2342-
2343-
BitXor => AssocOp::BitXor,
2344-
BitAnd => AssocOp::BitAnd,
2345-
BitOr => AssocOp::BitOr,
2346-
Shl => AssocOp::ShiftLeft,
2347-
Shr => AssocOp::ShiftRight,
2348-
2349-
Eq => AssocOp::Equal,
2350-
Lt => AssocOp::Less,
2351-
Le => AssocOp::LessEqual,
2352-
Ne => AssocOp::NotEqual,
2353-
Ge => AssocOp::GreaterEqual,
2354-
Gt => AssocOp::Greater,
2355-
}
2356-
}
2357-
23582331
/// Expressions that syntactically contain an "exterior" struct literal, i.e., not surrounded by any
23592332
/// parens or other delimiters, e.g., `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and
23602333
/// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not.

0 commit comments

Comments
 (0)