Remove hir::BinOp
, hir::BinOpKind
, and hir::UnOp
.
They're identical to the same-named types from `ast`. I find it silly (and inefficient) to have all this boilerplate code to convert one type to an identical type. There is already a small amount of type sharing between the AST and HIR, e.g. `Attribute`, `MacroDef`. The commit adds a `pub use` to `rustc_hir` so that, for example, `ast::BinOp` can also be referred to as `hir::BinOp`. This is so the many existing `hir`-qualified mentions of these types don't need to change. The commit also moves a couple of operations from the (removed) HIR types to the AST types, e.g. `is_by_value`.
This commit is contained in:
parent
705b484922
commit
d9fef774e3
3 changed files with 17 additions and 178 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,
|
||||
|
@ -888,13 +888,18 @@ impl BinOpKind {
|
|||
|
||||
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>;
|
||||
|
@ -902,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,
|
||||
|
@ -920,6 +925,11 @@ impl UnOp {
|
|||
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