Rollup merge of #118394 - nnethercote:rm-hir-Ops, r=cjgillot
Remove HIR opkinds `hir::BinOp`, `hir::BinOpKind`, and `hir::UnOp` are identical to `ast::BinOp`, `ast::BinOpKind`, and `ast::UnOp`, respectively. This seems silly, so this PR removes the HIR ones. (A re-export lets the AST ones be referred to using a `hir::` qualifier, which avoids renaming churn.) r? `@cjgillot`
This commit is contained in:
commit
20473eba0b
12 changed files with 42 additions and 202 deletions
|
@ -817,7 +817,7 @@ pub enum BorrowKind {
|
|||
Raw,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
|
||||
pub enum BinOpKind {
|
||||
/// The `+` operator (addition)
|
||||
Add,
|
||||
|
@ -858,9 +858,9 @@ pub enum BinOpKind {
|
|||
}
|
||||
|
||||
impl BinOpKind {
|
||||
pub fn to_string(&self) -> &'static str {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
use BinOpKind::*;
|
||||
match *self {
|
||||
match self {
|
||||
Add => "+",
|
||||
Sub => "-",
|
||||
Mul => "*",
|
||||
|
@ -881,19 +881,25 @@ impl BinOpKind {
|
|||
Gt => ">",
|
||||
}
|
||||
}
|
||||
pub fn lazy(&self) -> bool {
|
||||
|
||||
pub fn is_lazy(&self) -> bool {
|
||||
matches!(self, BinOpKind::And | BinOpKind::Or)
|
||||
}
|
||||
|
||||
pub fn is_comparison(&self) -> bool {
|
||||
use BinOpKind::*;
|
||||
// Note for developers: please keep this as is;
|
||||
// Note for developers: please keep this match exhaustive;
|
||||
// we want compilation to fail if another variant is added.
|
||||
match *self {
|
||||
Eq | Lt | Le | Ne | Gt | Ge => true,
|
||||
And | Or | Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Shl | Shr => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the binary operator takes its arguments by value.
|
||||
pub fn is_by_value(self) -> bool {
|
||||
!self.is_comparison()
|
||||
}
|
||||
}
|
||||
|
||||
pub type BinOp = Spanned<BinOpKind>;
|
||||
|
@ -901,7 +907,7 @@ pub type BinOp = Spanned<BinOpKind>;
|
|||
/// Unary operator.
|
||||
///
|
||||
/// Note that `&data` is not an operator, it's an `AddrOf` expression.
|
||||
#[derive(Clone, Encodable, Decodable, Debug, Copy)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
|
||||
pub enum UnOp {
|
||||
/// The `*` operator for dereferencing
|
||||
Deref,
|
||||
|
@ -912,13 +918,18 @@ pub enum UnOp {
|
|||
}
|
||||
|
||||
impl UnOp {
|
||||
pub fn to_string(op: UnOp) -> &'static str {
|
||||
match op {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
UnOp::Deref => "*",
|
||||
UnOp::Not => "!",
|
||||
UnOp::Neg => "-",
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the unary operator takes its argument by value.
|
||||
pub fn is_by_value(self) -> bool {
|
||||
matches!(self, Self::Neg | Self::Not)
|
||||
}
|
||||
}
|
||||
|
||||
/// A statement
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue