mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-05 21:24:12 +00:00
add make::expr_op
This commit is contained in:
parent
c943057038
commit
20c3b20db3
@ -350,6 +350,42 @@ impl ast::BinExpr {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BinOp {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
BinOp::BooleanOr => write!(f, "||"),
|
||||
BinOp::BooleanAnd => write!(f, "&&"),
|
||||
BinOp::EqualityTest => write!(f, "=="),
|
||||
BinOp::NegatedEqualityTest => write!(f, "!="),
|
||||
BinOp::LesserEqualTest => write!(f, "<="),
|
||||
BinOp::GreaterEqualTest => write!(f, ">="),
|
||||
BinOp::LesserTest => write!(f, "<"),
|
||||
BinOp::GreaterTest => write!(f, ">"),
|
||||
BinOp::Addition => write!(f, "+"),
|
||||
BinOp::Multiplication => write!(f, "*"),
|
||||
BinOp::Subtraction => write!(f, "-"),
|
||||
BinOp::Division => write!(f, "/"),
|
||||
BinOp::Remainder => write!(f, "%"),
|
||||
BinOp::LeftShift => write!(f, "<<"),
|
||||
BinOp::RightShift => write!(f, ">>"),
|
||||
BinOp::BitwiseXor => write!(f, "^"),
|
||||
BinOp::BitwiseOr => write!(f, "|"),
|
||||
BinOp::BitwiseAnd => write!(f, "&"),
|
||||
BinOp::Assignment => write!(f, "="),
|
||||
BinOp::AddAssign => write!(f, "+="),
|
||||
BinOp::DivAssign => write!(f, "/="),
|
||||
BinOp::MulAssign => write!(f, "*="),
|
||||
BinOp::RemAssign => write!(f, "%="),
|
||||
BinOp::ShrAssign => write!(f, ">>="),
|
||||
BinOp::ShlAssign => write!(f, "<<="),
|
||||
BinOp::SubAssign => write!(f, "-"),
|
||||
BinOp::BitOrAssign => write!(f, "|="),
|
||||
BinOp::BitAndAssign => write!(f, "&="),
|
||||
BinOp::BitXorAssign => write!(f, "^="),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum RangeOp {
|
||||
/// `..`
|
||||
|
@ -264,6 +264,9 @@ pub fn expr_path(path: ast::Path) -> ast::Expr {
|
||||
pub fn expr_continue() -> ast::Expr {
|
||||
expr_from_text("continue")
|
||||
}
|
||||
pub fn expr_op(op: ast::BinOp, lhs: ast::Expr, rhs: ast::Expr) -> ast::Expr {
|
||||
expr_from_text(&format!("{} {} {}", lhs, op, rhs))
|
||||
}
|
||||
pub fn expr_break(expr: Option<ast::Expr>) -> ast::Expr {
|
||||
match expr {
|
||||
Some(expr) => expr_from_text(&format!("break {}", expr)),
|
||||
|
Loading…
Reference in New Issue
Block a user