BinOpKind

This commit is contained in:
csmoe 2018-07-11 18:44:53 +08:00 committed by Oliver Schneider
parent 3d5753fda1
commit fe8955bd58
14 changed files with 292 additions and 288 deletions

View File

@ -3314,24 +3314,24 @@ impl<'a> LoweringContext<'a> {
fn lower_binop(&mut self, b: BinOp) -> hir::BinOp { fn lower_binop(&mut self, b: BinOp) -> hir::BinOp {
Spanned { Spanned {
node: match b.node { node: match b.node {
BinOpKind::Add => hir::BiAdd, BinOpKind::Add => hir::BinOpKind::Add,
BinOpKind::Sub => hir::BiSub, BinOpKind::Sub => hir::BinOpKind::Sub,
BinOpKind::Mul => hir::BiMul, BinOpKind::Mul => hir::BinOpKind::Mul,
BinOpKind::Div => hir::BiDiv, BinOpKind::Div => hir::BinOpKind::Div,
BinOpKind::Rem => hir::BiRem, BinOpKind::Rem => hir::BinOpKind::Rem,
BinOpKind::And => hir::BiAnd, BinOpKind::And => hir::BinOpKind::And,
BinOpKind::Or => hir::BiOr, BinOpKind::Or => hir::BinOpKind::Or,
BinOpKind::BitXor => hir::BiBitXor, BinOpKind::BitXor => hir::BinOpKind::BitXor,
BinOpKind::BitAnd => hir::BiBitAnd, BinOpKind::BitAnd => hir::BinOpKind::BitAnd,
BinOpKind::BitOr => hir::BiBitOr, BinOpKind::BitOr => hir::BinOpKind::BitOr,
BinOpKind::Shl => hir::BiShl, BinOpKind::Shl => hir::BinOpKind::Shl,
BinOpKind::Shr => hir::BiShr, BinOpKind::Shr => hir::BinOpKind::Shr,
BinOpKind::Eq => hir::BiEq, BinOpKind::Eq => hir::BinOpKind::Eq,
BinOpKind::Lt => hir::BiLt, BinOpKind::Lt => hir::BinOpKind::Lt,
BinOpKind::Le => hir::BiLe, BinOpKind::Le => hir::BinOpKind::Le,
BinOpKind::Ne => hir::BiNe, BinOpKind::Ne => hir::BinOpKind::Ne,
BinOpKind::Ge => hir::BiGe, BinOpKind::Ge => hir::BinOpKind::Ge,
BinOpKind::Gt => hir::BiGt, BinOpKind::Gt => hir::BinOpKind::Gt,
}, },
span: b.span, span: b.span,
} }

View File

@ -10,7 +10,6 @@
// The Rust HIR. // The Rust HIR.
pub use self::BinOp_::*;
pub use self::BlockCheckMode::*; pub use self::BlockCheckMode::*;
pub use self::CaptureClause::*; pub use self::CaptureClause::*;
pub use self::Decl_::*; pub use self::Decl_::*;
@ -941,98 +940,103 @@ impl Mutability {
} }
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)] #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)]
pub enum BinOp_ { pub enum BinOpKind {
/// The `+` operator (addition) /// The `+` operator (addition)
BiAdd, Add,
/// The `-` operator (subtraction) /// The `-` operator (subtraction)
BiSub, Sub,
/// The `*` operator (multiplication) /// The `*` operator (multiplication)
BiMul, Mul,
/// The `/` operator (division) /// The `/` operator (division)
BiDiv, Div,
/// The `%` operator (modulus) /// The `%` operator (modulus)
BiRem, Rem,
/// The `&&` operator (logical and) /// The `&&` operator (logical and)
BiAnd, And,
/// The `||` operator (logical or) /// The `||` operator (logical or)
BiOr, Or,
/// The `^` operator (bitwise xor) /// The `^` operator (bitwise xor)
BiBitXor, BitXor,
/// The `&` operator (bitwise and) /// The `&` operator (bitwise and)
BiBitAnd, BitAnd,
/// The `|` operator (bitwise or) /// The `|` operator (bitwise or)
BiBitOr, BitOr,
/// The `<<` operator (shift left) /// The `<<` operator (shift left)
BiShl, Shl,
/// The `>>` operator (shift right) /// The `>>` operator (shift right)
BiShr, Shr,
/// The `==` operator (equality) /// The `==` operator (equality)
BiEq, Eq,
/// The `<` operator (less than) /// The `<` operator (less than)
BiLt, Lt,
/// The `<=` operator (less than or equal to) /// The `<=` operator (less than or equal to)
BiLe, Le,
/// The `!=` operator (not equal to) /// The `!=` operator (not equal to)
BiNe, Ne,
/// The `>=` operator (greater than or equal to) /// The `>=` operator (greater than or equal to)
BiGe, Ge,
/// The `>` operator (greater than) /// The `>` operator (greater than)
BiGt, Gt,
} }
impl BinOp_ { impl BinOpKind {
pub fn as_str(self) -> &'static str { pub fn as_str(self) -> &'static str {
match self { match self {
BiAdd => "+", BinOpKind::Add => "+",
BiSub => "-", BinOpKind::Sub => "-",
BiMul => "*", BinOpKind::Mul => "*",
BiDiv => "/", BinOpKind::Div => "/",
BiRem => "%", BinOpKind::Rem => "%",
BiAnd => "&&", BinOpKind::And => "&&",
BiOr => "||", BinOpKind::Or => "||",
BiBitXor => "^", BinOpKind::BitXor => "^",
BiBitAnd => "&", BinOpKind::BitAnd => "&",
BiBitOr => "|", BinOpKind::BitOr => "|",
BiShl => "<<", BinOpKind::Shl => "<<",
BiShr => ">>", BinOpKind::Shr => ">>",
BiEq => "==", BinOpKind::Eq => "==",
BiLt => "<", BinOpKind::Lt => "<",
BiLe => "<=", BinOpKind::Le => "<=",
BiNe => "!=", BinOpKind::Ne => "!=",
BiGe => ">=", BinOpKind::Ge => ">=",
BiGt => ">", BinOpKind::Gt => ">",
} }
} }
pub fn is_lazy(self) -> bool { pub fn is_lazy(self) -> bool {
match self { match self {
BiAnd | BiOr => true, BinOpKind::And | BinOpKind::Or => true,
_ => false, _ => false,
} }
} }
pub fn is_shift(self) -> bool { pub fn is_shift(self) -> bool {
match self { match self {
BiShl | BiShr => true, BinOpKind::Shl | BinOpKind::Shr => true,
_ => false, _ => false,
} }
} }
pub fn is_comparison(self) -> bool { pub fn is_comparison(self) -> bool {
match self { match self {
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true, BinOpKind::Eq |
BiAnd | BinOpKind::Lt |
BiOr | BinOpKind::Le |
BiAdd | BinOpKind::Ne |
BiSub | BinOpKind::Gt |
BiMul | BinOpKind::Ge => true,
BiDiv | BinOpKind::And |
BiRem | BinOpKind::Or |
BiBitXor | BinOpKind::Add |
BiBitAnd | BinOpKind::Sub |
BiBitOr | BinOpKind::Mul |
BiShl | BinOpKind::Div |
BiShr => false, BinOpKind::Rem |
BinOpKind::BitXor |
BinOpKind::BitAnd |
BinOpKind::BitOr |
BinOpKind::Shl |
BinOpKind::Shr => false,
} }
} }
@ -1042,32 +1046,32 @@ impl BinOp_ {
} }
} }
impl Into<ast::BinOpKind> for BinOp_ { impl Into<ast::BinOpKind> for BinOpKind {
fn into(self) -> ast::BinOpKind { fn into(self) -> ast::BinOpKind {
match self { match self {
BiAdd => ast::BinOpKind::Add, BinOpKind::Add => ast::BinOpKind::Add,
BiSub => ast::BinOpKind::Sub, BinOpKind::Sub => ast::BinOpKind::Sub,
BiMul => ast::BinOpKind::Mul, BinOpKind::Mul => ast::BinOpKind::Mul,
BiDiv => ast::BinOpKind::Div, BinOpKind::Div => ast::BinOpKind::Div,
BiRem => ast::BinOpKind::Rem, BinOpKind::Rem => ast::BinOpKind::Rem,
BiAnd => ast::BinOpKind::And, BinOpKind::And => ast::BinOpKind::And,
BiOr => ast::BinOpKind::Or, BinOpKind::Or => ast::BinOpKind::Or,
BiBitXor => ast::BinOpKind::BitXor, BinOpKind::BitXor => ast::BinOpKind::BitXor,
BiBitAnd => ast::BinOpKind::BitAnd, BinOpKind::BitAnd => ast::BinOpKind::BitAnd,
BiBitOr => ast::BinOpKind::BitOr, BinOpKind::BitOr => ast::BinOpKind::BitOr,
BiShl => ast::BinOpKind::Shl, BinOpKind::Shl => ast::BinOpKind::Shl,
BiShr => ast::BinOpKind::Shr, BinOpKind::Shr => ast::BinOpKind::Shr,
BiEq => ast::BinOpKind::Eq, BinOpKind::Eq => ast::BinOpKind::Eq,
BiLt => ast::BinOpKind::Lt, BinOpKind::Lt => ast::BinOpKind::Lt,
BiLe => ast::BinOpKind::Le, BinOpKind::Le => ast::BinOpKind::Le,
BiNe => ast::BinOpKind::Ne, BinOpKind::Ne => ast::BinOpKind::Ne,
BiGe => ast::BinOpKind::Ge, BinOpKind::Ge => ast::BinOpKind::Ge,
BiGt => ast::BinOpKind::Gt, BinOpKind::Gt => ast::BinOpKind::Gt,
} }
} }
} }
pub type BinOp = Spanned<BinOp_>; pub type BinOp = Spanned<BinOpKind>;
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)] #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)]
pub enum UnOp { pub enum UnOp {

View File

@ -1292,8 +1292,8 @@ impl<'a> State<'a> {
// These cases need parens: `x as i32 < y` has the parser thinking that `i32 < y` is // 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 // 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. // of `(x as i32) < ...`. We need to convince it _not_ to do that.
(&hir::ExprCast { .. }, hir::BinOp_::BiLt) | (&hir::ExprCast { .. }, hir::BinOpKind::Lt) |
(&hir::ExprCast { .. }, hir::BinOp_::BiShl) => parser::PREC_FORCE_PAREN, (&hir::ExprCast { .. }, hir::BinOpKind::Shl) => parser::PREC_FORCE_PAREN,
_ => left_prec, _ => left_prec,
}; };
@ -2413,30 +2413,30 @@ fn stmt_ends_with_semi(stmt: &hir::Stmt_) -> bool {
} }
} }
fn bin_op_to_assoc_op(op: hir::BinOp_) -> AssocOp { fn bin_op_to_assoc_op(op: hir::BinOpKind) -> AssocOp {
use hir::BinOp_::*; use hir::BinOpKind::*;
match op { match op {
BiAdd => AssocOp::Add, Add => AssocOp::Add,
BiSub => AssocOp::Subtract, Sub => AssocOp::Subtract,
BiMul => AssocOp::Multiply, Mul => AssocOp::Multiply,
BiDiv => AssocOp::Divide, Div => AssocOp::Divide,
BiRem => AssocOp::Modulus, Rem => AssocOp::Modulus,
BiAnd => AssocOp::LAnd, And => AssocOp::LAnd,
BiOr => AssocOp::LOr, Or => AssocOp::LOr,
BiBitXor => AssocOp::BitXor, BitXor => AssocOp::BitXor,
BiBitAnd => AssocOp::BitAnd, BitAnd => AssocOp::BitAnd,
BiBitOr => AssocOp::BitOr, BitOr => AssocOp::BitOr,
BiShl => AssocOp::ShiftLeft, Shl => AssocOp::ShiftLeft,
BiShr => AssocOp::ShiftRight, Shr => AssocOp::ShiftRight,
BiEq => AssocOp::Equal, Eq => AssocOp::Equal,
BiLt => AssocOp::Less, Lt => AssocOp::Less,
BiLe => AssocOp::LessEqual, Le => AssocOp::LessEqual,
BiNe => AssocOp::NotEqual, Ne => AssocOp::NotEqual,
BiGe => AssocOp::GreaterEqual, Ge => AssocOp::GreaterEqual,
BiGt => AssocOp::Greater, Gt => AssocOp::Greater,
} }
} }

View File

@ -437,28 +437,28 @@ impl_stable_hash_for!(enum hir::PatKind {
Slice(one, two, three) Slice(one, two, three)
}); });
impl_stable_hash_for!(enum hir::BinOp_ { impl_stable_hash_for!(enum hir::BinOpKind {
BiAdd, Add,
BiSub, Sub,
BiMul, Mul,
BiDiv, Div,
BiRem, Rem,
BiAnd, And,
BiOr, Or,
BiBitXor, BitXor,
BiBitAnd, BitAnd,
BiBitOr, BitOr,
BiShl, Shl,
BiShr, Shr,
BiEq, Eq,
BiLt, Lt,
BiLe, Le,
BiNe, Ne,
BiGe, Ge,
BiGt Gt
}); });
impl_stable_hash_for_spanned!(hir::BinOp_); impl_stable_hash_for_spanned!(hir::BinOpKind);
impl_stable_hash_for!(enum hir::UnOp { impl_stable_hash_for!(enum hir::UnOp {
UnDeref, UnDeref,

View File

@ -943,8 +943,8 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
// scopes, meaning that temporaries cannot outlive them. // scopes, meaning that temporaries cannot outlive them.
// This ensures fixed size stacks. // This ensures fixed size stacks.
hir::ExprBinary(codemap::Spanned { node: hir::BiAnd, .. }, _, ref r) | hir::ExprKind::Binary(codemap::Spanned { node: hir::BinOpKind::And, .. }, _, ref r) |
hir::ExprBinary(codemap::Spanned { node: hir::BiOr, .. }, _, ref r) => { hir::ExprKind::Binary(codemap::Spanned { node: hir::BinOpKind::Or, .. }, _, ref r) => {
// For shortcircuiting operators, mark the RHS as a terminating // For shortcircuiting operators, mark the RHS as a terminating
// scope since it only executes conditionally. // scope since it only executes conditionally.
terminating(r.hir_id.local_id); terminating(r.hir_id.local_id);

View File

@ -256,24 +256,24 @@ impl BorrowKind {
} }
impl BinOp { impl BinOp {
pub fn to_hir_binop(self) -> hir::BinOp_ { pub fn to_hir_binop(self) -> hir::BinOpKind {
match self { match self {
BinOp::Add => hir::BinOp_::BiAdd, BinOp::Add => hir::BinOpKind::Add,
BinOp::Sub => hir::BinOp_::BiSub, BinOp::Sub => hir::BinOpKind::Sub,
BinOp::Mul => hir::BinOp_::BiMul, BinOp::Mul => hir::BinOpKind::Mul,
BinOp::Div => hir::BinOp_::BiDiv, BinOp::Div => hir::BinOpKind::Div,
BinOp::Rem => hir::BinOp_::BiRem, BinOp::Rem => hir::BinOpKind::Rem,
BinOp::BitXor => hir::BinOp_::BiBitXor, BinOp::BitXor => hir::BinOpKind::BitXor,
BinOp::BitAnd => hir::BinOp_::BiBitAnd, BinOp::BitAnd => hir::BinOpKind::BitAnd,
BinOp::BitOr => hir::BinOp_::BiBitOr, BinOp::BitOr => hir::BinOpKind::BitOr,
BinOp::Shl => hir::BinOp_::BiShl, BinOp::Shl => hir::BinOpKind::Shl,
BinOp::Shr => hir::BinOp_::BiShr, BinOp::Shr => hir::BinOpKind::Shr,
BinOp::Eq => hir::BinOp_::BiEq, BinOp::Eq => hir::BinOpKind::Eq,
BinOp::Ne => hir::BinOp_::BiNe, BinOp::Ne => hir::BinOpKind::Ne,
BinOp::Lt => hir::BinOp_::BiLt, BinOp::Lt => hir::BinOpKind::Lt,
BinOp::Gt => hir::BinOp_::BiGt, BinOp::Gt => hir::BinOpKind::Gt,
BinOp::Le => hir::BinOp_::BiLe, BinOp::Le => hir::BinOpKind::Le,
BinOp::Ge => hir::BinOp_::BiGe, BinOp::Ge => hir::BinOpKind::Ge,
BinOp::Offset => unreachable!() BinOp::Offset => unreachable!()
} }
} }

View File

@ -124,16 +124,16 @@ impl<'a, 'tcx> Drop for StatRecorder<'a, 'tcx> {
} }
} }
pub fn bin_op_to_icmp_predicate(op: hir::BinOp_, pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind,
signed: bool) signed: bool)
-> llvm::IntPredicate { -> llvm::IntPredicate {
match op { match op {
hir::BiEq => llvm::IntEQ, hir::BinOpKind::Eq => llvm::IntEQ,
hir::BiNe => llvm::IntNE, hir::BinOpKind::Ne => llvm::IntNE,
hir::BiLt => if signed { llvm::IntSLT } else { llvm::IntULT }, hir::BinOpKind::Lt => if signed { llvm::IntSLT } else { llvm::IntULT },
hir::BiLe => if signed { llvm::IntSLE } else { llvm::IntULE }, hir::BinOpKind::Le => if signed { llvm::IntSLE } else { llvm::IntULE },
hir::BiGt => if signed { llvm::IntSGT } else { llvm::IntUGT }, hir::BinOpKind::Gt => if signed { llvm::IntSGT } else { llvm::IntUGT },
hir::BiGe => if signed { llvm::IntSGE } else { llvm::IntUGE }, hir::BinOpKind::Ge => if signed { llvm::IntSGE } else { llvm::IntUGE },
op => { op => {
bug!("comparison_op_to_icmp_predicate: expected comparison operator, \ bug!("comparison_op_to_icmp_predicate: expected comparison operator, \
found {:?}", found {:?}",
@ -142,14 +142,14 @@ pub fn bin_op_to_icmp_predicate(op: hir::BinOp_,
} }
} }
pub fn bin_op_to_fcmp_predicate(op: hir::BinOp_) -> llvm::RealPredicate { pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> llvm::RealPredicate {
match op { match op {
hir::BiEq => llvm::RealOEQ, hir::BinOpKind::Eq => llvm::RealOEQ,
hir::BiNe => llvm::RealUNE, hir::BinOpKind::Ne => llvm::RealUNE,
hir::BiLt => llvm::RealOLT, hir::BinOpKind::Lt => llvm::RealOLT,
hir::BiLe => llvm::RealOLE, hir::BinOpKind::Le => llvm::RealOLE,
hir::BiGt => llvm::RealOGT, hir::BinOpKind::Gt => llvm::RealOGT,
hir::BiGe => llvm::RealOGE, hir::BinOpKind::Ge => llvm::RealOGE,
op => { op => {
bug!("comparison_op_to_fcmp_predicate: expected comparison operator, \ bug!("comparison_op_to_fcmp_predicate: expected comparison operator, \
found {:?}", found {:?}",
@ -164,7 +164,7 @@ pub fn compare_simd_types<'a, 'tcx>(
rhs: ValueRef, rhs: ValueRef,
t: Ty<'tcx>, t: Ty<'tcx>,
ret_ty: Type, ret_ty: Type,
op: hir::BinOp_ op: hir::BinOpKind
) -> ValueRef { ) -> ValueRef {
let signed = match t.sty { let signed = match t.sty {
ty::TyFloat(_) => { ty::TyFloat(_) => {
@ -332,12 +332,12 @@ pub fn coerce_unsized_into<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
} }
pub fn cast_shift_expr_rhs( pub fn cast_shift_expr_rhs(
cx: &Builder, op: hir::BinOp_, lhs: ValueRef, rhs: ValueRef cx: &Builder, op: hir::BinOpKind, lhs: ValueRef, rhs: ValueRef
) -> ValueRef { ) -> ValueRef {
cast_shift_rhs(op, lhs, rhs, |a, b| cx.trunc(a, b), |a, b| cx.zext(a, b)) cast_shift_rhs(op, lhs, rhs, |a, b| cx.trunc(a, b), |a, b| cx.zext(a, b))
} }
fn cast_shift_rhs<F, G>(op: hir::BinOp_, fn cast_shift_rhs<F, G>(op: hir::BinOpKind,
lhs: ValueRef, lhs: ValueRef,
rhs: ValueRef, rhs: ValueRef,
trunc: F, trunc: F,

View File

@ -350,7 +350,7 @@ pub fn build_unchecked_lshift<'a, 'tcx>(
lhs: ValueRef, lhs: ValueRef,
rhs: ValueRef rhs: ValueRef
) -> ValueRef { ) -> ValueRef {
let rhs = base::cast_shift_expr_rhs(bx, hir::BinOp_::BiShl, lhs, rhs); let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shl, lhs, rhs);
// #1877, #10183: Ensure that input is always valid // #1877, #10183: Ensure that input is always valid
let rhs = shift_mask_rhs(bx, rhs); let rhs = shift_mask_rhs(bx, rhs);
bx.shl(lhs, rhs) bx.shl(lhs, rhs)
@ -359,7 +359,7 @@ pub fn build_unchecked_lshift<'a, 'tcx>(
pub fn build_unchecked_rshift<'a, 'tcx>( pub fn build_unchecked_rshift<'a, 'tcx>(
bx: &Builder<'a, 'tcx>, lhs_t: Ty<'tcx>, lhs: ValueRef, rhs: ValueRef bx: &Builder<'a, 'tcx>, lhs_t: Ty<'tcx>, lhs: ValueRef, rhs: ValueRef
) -> ValueRef { ) -> ValueRef {
let rhs = base::cast_shift_expr_rhs(bx, hir::BinOp_::BiShr, lhs, rhs); let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shr, lhs, rhs);
// #1877, #10183: Ensure that input is always valid // #1877, #10183: Ensure that input is always valid
let rhs = shift_mask_rhs(bx, rhs); let rhs = shift_mask_rhs(bx, rhs);
let is_signed = lhs_t.is_signed(); let is_signed = lhs_t.is_signed();

View File

@ -1022,12 +1022,12 @@ fn generic_simd_intrinsic<'a, 'tcx>(
let in_len = arg_tys[0].simd_size(tcx); let in_len = arg_tys[0].simd_size(tcx);
let comparison = match name { let comparison = match name {
"simd_eq" => Some(hir::BiEq), "simd_eq" => Some(hir::BinOpKind::Eq),
"simd_ne" => Some(hir::BiNe), "simd_ne" => Some(hir::BinOpKind::Ne),
"simd_lt" => Some(hir::BiLt), "simd_lt" => Some(hir::BinOpKind::Lt),
"simd_le" => Some(hir::BiLe), "simd_le" => Some(hir::BinOpKind::Le),
"simd_gt" => Some(hir::BiGt), "simd_gt" => Some(hir::BinOpKind::Gt),
"simd_ge" => Some(hir::BiGe), "simd_ge" => Some(hir::BinOpKind::Ge),
_ => None _ => None
}; };

View File

@ -194,11 +194,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
fn is_valid<T: cmp::PartialOrd>(binop: hir::BinOp, v: T, min: T, max: T) -> bool { fn is_valid<T: cmp::PartialOrd>(binop: hir::BinOp, v: T, min: T, max: T) -> bool {
match binop.node { match binop.node {
hir::BiLt => v > min && v <= max, hir::BinOpKind::Lt => v > min && v <= max,
hir::BiLe => v >= min && v < max, hir::BinOpKind::Le => v >= min && v < max,
hir::BiGt => v >= min && v < max, hir::BinOpKind::Gt => v >= min && v < max,
hir::BiGe => v > min && v <= max, hir::BinOpKind::Ge => v > min && v <= max,
hir::BiEq | hir::BiNe => v >= min && v <= max, hir::BinOpKind::Eq | hir::BinOpKind::Ne => v >= min && v <= max,
_ => bug!(), _ => bug!(),
} }
} }
@ -206,10 +206,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
fn rev_binop(binop: hir::BinOp) -> hir::BinOp { fn rev_binop(binop: hir::BinOp) -> hir::BinOp {
codemap::respan(binop.span, codemap::respan(binop.span,
match binop.node { match binop.node {
hir::BiLt => hir::BiGt, hir::BinOpKind::Lt => hir::BinOpKind::Gt,
hir::BiLe => hir::BiGe, hir::BinOpKind::Le => hir::BinOpKind::Ge,
hir::BiGt => hir::BiLt, hir::BinOpKind::Gt => hir::BinOpKind::Lt,
hir::BiGe => hir::BiLe, hir::BinOpKind::Ge => hir::BinOpKind::Le,
_ => return binop, _ => return binop,
}) })
} }
@ -285,7 +285,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
fn is_comparison(binop: hir::BinOp) -> bool { fn is_comparison(binop: hir::BinOp) -> bool {
match binop.node { match binop.node {
hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe | hir::BiGt => true, hir::BinOpKind::Eq | hir::BinOpKind::Lt | hir::BinOpKind::Le | hir::BinOpKind::Ne | hir::BinOpKind::Ge | hir::BinOpKind::Gt => true,
_ => false, _ => false,
} }
} }

View File

@ -102,16 +102,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
// attribute which does exist on the comparison trait methods // attribute which does exist on the comparison trait methods
hir::ExprBinary(bin_op, ..) => { hir::ExprBinary(bin_op, ..) => {
match bin_op.node { match bin_op.node {
hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe | hir::BiGt => { hir::BinOpKind::Eq | hir::BinOpKind::Lt | hir::BinOpKind::Le | hir::BinOpKind::Ne | hir::BinOpKind::Ge | hir::BinOpKind::Gt => {
Some("comparison") Some("comparison")
}, },
hir::BiAdd | hir::BiSub | hir::BiDiv | hir::BiMul | hir::BiRem => { hir::BinOpKind::Add | hir::BinOpKind::Sub | hir::BinOpKind::Div | hir::BinOpKind::Mul | hir::BinOpKind::Rem => {
Some("arithmetic operation") Some("arithmetic operation")
}, },
hir::BiAnd | hir::BiOr => { hir::BinOpKind::And | hir::BinOpKind::Or => {
Some("logical operation") Some("logical operation")
}, },
hir::BiBitXor | hir::BiBitAnd | hir::BiBitOr | hir::BiShl | hir::BiShr => { hir::BinOpKind::BitXor | hir::BinOpKind::BitAnd | hir::BinOpKind::BitOr | hir::BinOpKind::Shl | hir::BinOpKind::Shr => {
Some("bitwise operation") Some("bitwise operation")
}, },
} }

View File

@ -325,14 +325,14 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
match (op.node, cx.constness) { match (op.node, cx.constness) {
// FIXME(eddyb) use logical ops in constants when // FIXME(eddyb) use logical ops in constants when
// they can handle that kind of control-flow. // they can handle that kind of control-flow.
(hir::BinOp_::BiAnd, hir::Constness::Const) => { (hir::BinOpKind::And, hir::Constness::Const) => {
ExprKind::Binary { ExprKind::Binary {
op: BinOp::BitAnd, op: BinOp::BitAnd,
lhs: lhs.to_ref(), lhs: lhs.to_ref(),
rhs: rhs.to_ref(), rhs: rhs.to_ref(),
} }
} }
(hir::BinOp_::BiOr, hir::Constness::Const) => { (hir::BinOpKind::Or, hir::Constness::Const) => {
ExprKind::Binary { ExprKind::Binary {
op: BinOp::BitOr, op: BinOp::BitOr,
lhs: lhs.to_ref(), lhs: lhs.to_ref(),
@ -340,14 +340,14 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
} }
} }
(hir::BinOp_::BiAnd, hir::Constness::NotConst) => { (hir::BinOpKind::And, hir::Constness::NotConst) => {
ExprKind::LogicalOp { ExprKind::LogicalOp {
op: LogicalOp::And, op: LogicalOp::And,
lhs: lhs.to_ref(), lhs: lhs.to_ref(),
rhs: rhs.to_ref(), rhs: rhs.to_ref(),
} }
} }
(hir::BinOp_::BiOr, hir::Constness::NotConst) => { (hir::BinOpKind::Or, hir::Constness::NotConst) => {
ExprKind::LogicalOp { ExprKind::LogicalOp {
op: LogicalOp::Or, op: LogicalOp::Or,
lhs: lhs.to_ref(), lhs: lhs.to_ref(),
@ -930,24 +930,24 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
} }
fn bin_op(op: hir::BinOp_) -> BinOp { fn bin_op(op: hir::BinOpKind) -> BinOp {
match op { match op {
hir::BinOp_::BiAdd => BinOp::Add, hir::BinOpKind::Add => BinOp::Add,
hir::BinOp_::BiSub => BinOp::Sub, hir::BinOpKind::Sub => BinOp::Sub,
hir::BinOp_::BiMul => BinOp::Mul, hir::BinOpKind::Mul => BinOp::Mul,
hir::BinOp_::BiDiv => BinOp::Div, hir::BinOpKind::Div => BinOp::Div,
hir::BinOp_::BiRem => BinOp::Rem, hir::BinOpKind::Rem => BinOp::Rem,
hir::BinOp_::BiBitXor => BinOp::BitXor, hir::BinOpKind::BitXor => BinOp::BitXor,
hir::BinOp_::BiBitAnd => BinOp::BitAnd, hir::BinOpKind::BitAnd => BinOp::BitAnd,
hir::BinOp_::BiBitOr => BinOp::BitOr, hir::BinOpKind::BitOr => BinOp::BitOr,
hir::BinOp_::BiShl => BinOp::Shl, hir::BinOpKind::Shl => BinOp::Shl,
hir::BinOp_::BiShr => BinOp::Shr, hir::BinOpKind::Shr => BinOp::Shr,
hir::BinOp_::BiEq => BinOp::Eq, hir::BinOpKind::Eq => BinOp::Eq,
hir::BinOp_::BiLt => BinOp::Lt, hir::BinOpKind::Lt => BinOp::Lt,
hir::BinOp_::BiLe => BinOp::Le, hir::BinOpKind::Le => BinOp::Le,
hir::BinOp_::BiNe => BinOp::Ne, hir::BinOpKind::Ne => BinOp::Ne,
hir::BinOp_::BiGe => BinOp::Ge, hir::BinOpKind::Ge => BinOp::Ge,
hir::BinOp_::BiGt => BinOp::Gt, hir::BinOpKind::Gt => BinOp::Gt,
_ => bug!("no equivalent for ast binop {:?}", op), _ => bug!("no equivalent for ast binop {:?}", op),
} }
} }

View File

@ -356,9 +356,9 @@ fn check_expr_kind<'a, 'tcx>(
} }
match v.tables.node_id_to_type(lhs.hir_id).sty { match v.tables.node_id_to_type(lhs.hir_id).sty {
ty::TyRawPtr(_) => { ty::TyRawPtr(_) => {
assert!(op.node == hir::BiEq || op.node == hir::BiNe || assert!(op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne ||
op.node == hir::BiLe || op.node == hir::BiLt || op.node == hir::BinOpKind::Le || op.node == hir::BinOpKind::Lt ||
op.node == hir::BiGe || op.node == hir::BiGt); op.node == hir::BinOpKind::Ge || op.node == hir::BinOpKind::Gt);
NotPromotable NotPromotable
} }

View File

@ -285,20 +285,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} }
} }
let missing_trait = match op.node { let missing_trait = match op.node {
hir::BiAdd => Some("std::ops::AddAssign"), hir::BinOpKind::Add => Some("std::ops::AddAssign"),
hir::BiSub => Some("std::ops::SubAssign"), hir::BinOpKind::Sub => Some("std::ops::SubAssign"),
hir::BiMul => Some("std::ops::MulAssign"), hir::BinOpKind::Mul => Some("std::ops::MulAssign"),
hir::BiDiv => Some("std::ops::DivAssign"), hir::BinOpKind::Div => Some("std::ops::DivAssign"),
hir::BiRem => Some("std::ops::RemAssign"), hir::BinOpKind::Rem => Some("std::ops::RemAssign"),
hir::BiBitAnd => Some("std::ops::BitAndAssign"), hir::BinOpKind::BitAnd => Some("std::ops::BitAndAssign"),
hir::BiBitXor => Some("std::ops::BitXorAssign"), hir::BinOpKind::BitXor => Some("std::ops::BitXorAssign"),
hir::BiBitOr => Some("std::ops::BitOrAssign"), hir::BinOpKind::BitOr => Some("std::ops::BitOrAssign"),
hir::BiShl => Some("std::ops::ShlAssign"), hir::BinOpKind::Shl => Some("std::ops::ShlAssign"),
hir::BiShr => Some("std::ops::ShrAssign"), hir::BinOpKind::Shr => Some("std::ops::ShrAssign"),
_ => None _ => None
}; };
if let Some(missing_trait) = missing_trait { if let Some(missing_trait) = missing_trait {
if op.node == hir::BiAdd && if op.node == hir::BinOpKind::Add &&
self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty, self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty,
rhs_ty, &mut err) { rhs_ty, &mut err) {
// This has nothing here because it means we did string // This has nothing here because it means we did string
@ -353,23 +353,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} }
} }
let missing_trait = match op.node { let missing_trait = match op.node {
hir::BiAdd => Some("std::ops::Add"), hir::BinOpKind::Add => Some("std::ops::Add"),
hir::BiSub => Some("std::ops::Sub"), hir::BinOpKind::Sub => Some("std::ops::Sub"),
hir::BiMul => Some("std::ops::Mul"), hir::BinOpKind::Mul => Some("std::ops::Mul"),
hir::BiDiv => Some("std::ops::Div"), hir::BinOpKind::Div => Some("std::ops::Div"),
hir::BiRem => Some("std::ops::Rem"), hir::BinOpKind::Rem => Some("std::ops::Rem"),
hir::BiBitAnd => Some("std::ops::BitAnd"), hir::BinOpKind::BitAnd => Some("std::ops::BitAnd"),
hir::BiBitXor => Some("std::ops::BitXor"), hir::BinOpKind::BitXor => Some("std::ops::BitXor"),
hir::BiBitOr => Some("std::ops::BitOr"), hir::BinOpKind::BitOr => Some("std::ops::BitOr"),
hir::BiShl => Some("std::ops::Shl"), hir::BinOpKind::Shl => Some("std::ops::Shl"),
hir::BiShr => Some("std::ops::Shr"), hir::BinOpKind::Shr => Some("std::ops::Shr"),
hir::BiEq | hir::BiNe => Some("std::cmp::PartialEq"), hir::BinOpKind::Eq | hir::BinOpKind::Ne => Some("std::cmp::PartialEq"),
hir::BiLt | hir::BiLe | hir::BiGt | hir::BiGe => hir::BinOpKind::Lt | hir::BinOpKind::Le | hir::BinOpKind::Gt | hir::BinOpKind::Ge =>
Some("std::cmp::PartialOrd"), Some("std::cmp::PartialOrd"),
_ => None _ => None
}; };
if let Some(missing_trait) = missing_trait { if let Some(missing_trait) = missing_trait {
if op.node == hir::BiAdd && if op.node == hir::BinOpKind::Add &&
self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty, self.check_str_addition(expr, lhs_expr, rhs_expr, lhs_ty,
rhs_ty, &mut err) { rhs_ty, &mut err) {
// This has nothing here because it means we did string // This has nothing here because it means we did string
@ -508,20 +508,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}; };
let (opname, trait_did) = if let Op::Binary(op, IsAssign::Yes) = op { let (opname, trait_did) = if let Op::Binary(op, IsAssign::Yes) = op {
match op.node { match op.node {
hir::BiAdd => ("add_assign", lang.add_assign_trait()), hir::BinOpKind::Add => ("add_assign", lang.add_assign_trait()),
hir::BiSub => ("sub_assign", lang.sub_assign_trait()), hir::BinOpKind::Sub => ("sub_assign", lang.sub_assign_trait()),
hir::BiMul => ("mul_assign", lang.mul_assign_trait()), hir::BinOpKind::Mul => ("mul_assign", lang.mul_assign_trait()),
hir::BiDiv => ("div_assign", lang.div_assign_trait()), hir::BinOpKind::Div => ("div_assign", lang.div_assign_trait()),
hir::BiRem => ("rem_assign", lang.rem_assign_trait()), hir::BinOpKind::Rem => ("rem_assign", lang.rem_assign_trait()),
hir::BiBitXor => ("bitxor_assign", lang.bitxor_assign_trait()), hir::BinOpKind::BitXor => ("bitxor_assign", lang.bitxor_assign_trait()),
hir::BiBitAnd => ("bitand_assign", lang.bitand_assign_trait()), hir::BinOpKind::BitAnd => ("bitand_assign", lang.bitand_assign_trait()),
hir::BiBitOr => ("bitor_assign", lang.bitor_assign_trait()), hir::BinOpKind::BitOr => ("bitor_assign", lang.bitor_assign_trait()),
hir::BiShl => ("shl_assign", lang.shl_assign_trait()), hir::BinOpKind::Shl => ("shl_assign", lang.shl_assign_trait()),
hir::BiShr => ("shr_assign", lang.shr_assign_trait()), hir::BinOpKind::Shr => ("shr_assign", lang.shr_assign_trait()),
hir::BiLt | hir::BiLe | hir::BinOpKind::Lt | hir::BinOpKind::Le |
hir::BiGe | hir::BiGt | hir::BinOpKind::Ge | hir::BinOpKind::Gt |
hir::BiEq | hir::BiNe | hir::BinOpKind::Eq | hir::BinOpKind::Ne |
hir::BiAnd | hir::BiOr => { hir::BinOpKind::And | hir::BinOpKind::Or => {
span_bug!(span, span_bug!(span,
"impossible assignment operation: {}=", "impossible assignment operation: {}=",
op.node.as_str()) op.node.as_str())
@ -529,23 +529,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} }
} else if let Op::Binary(op, IsAssign::No) = op { } else if let Op::Binary(op, IsAssign::No) = op {
match op.node { match op.node {
hir::BiAdd => ("add", lang.add_trait()), hir::BinOpKind::Add => ("add", lang.add_trait()),
hir::BiSub => ("sub", lang.sub_trait()), hir::BinOpKind::Sub => ("sub", lang.sub_trait()),
hir::BiMul => ("mul", lang.mul_trait()), hir::BinOpKind::Mul => ("mul", lang.mul_trait()),
hir::BiDiv => ("div", lang.div_trait()), hir::BinOpKind::Div => ("div", lang.div_trait()),
hir::BiRem => ("rem", lang.rem_trait()), hir::BinOpKind::Rem => ("rem", lang.rem_trait()),
hir::BiBitXor => ("bitxor", lang.bitxor_trait()), hir::BinOpKind::BitXor => ("bitxor", lang.bitxor_trait()),
hir::BiBitAnd => ("bitand", lang.bitand_trait()), hir::BinOpKind::BitAnd => ("bitand", lang.bitand_trait()),
hir::BiBitOr => ("bitor", lang.bitor_trait()), hir::BinOpKind::BitOr => ("bitor", lang.bitor_trait()),
hir::BiShl => ("shl", lang.shl_trait()), hir::BinOpKind::Shl => ("shl", lang.shl_trait()),
hir::BiShr => ("shr", lang.shr_trait()), hir::BinOpKind::Shr => ("shr", lang.shr_trait()),
hir::BiLt => ("lt", lang.partial_ord_trait()), hir::BinOpKind::Lt => ("lt", lang.partial_ord_trait()),
hir::BiLe => ("le", lang.partial_ord_trait()), hir::BinOpKind::Le => ("le", lang.partial_ord_trait()),
hir::BiGe => ("ge", lang.partial_ord_trait()), hir::BinOpKind::Ge => ("ge", lang.partial_ord_trait()),
hir::BiGt => ("gt", lang.partial_ord_trait()), hir::BinOpKind::Gt => ("gt", lang.partial_ord_trait()),
hir::BiEq => ("eq", lang.eq_trait()), hir::BinOpKind::Eq => ("eq", lang.eq_trait()),
hir::BiNe => ("ne", lang.eq_trait()), hir::BinOpKind::Ne => ("ne", lang.eq_trait()),
hir::BiAnd | hir::BiOr => { hir::BinOpKind::And | hir::BinOpKind::Or => {
span_bug!(span, "&& and || are not overloadable") span_bug!(span, "&& and || are not overloadable")
} }
} }
@ -608,31 +608,31 @@ enum BinOpCategory {
impl BinOpCategory { impl BinOpCategory {
fn from(op: hir::BinOp) -> BinOpCategory { fn from(op: hir::BinOp) -> BinOpCategory {
match op.node { match op.node {
hir::BiShl | hir::BiShr => hir::BinOpKind::Shl | hir::BinOpKind::Shr =>
BinOpCategory::Shift, BinOpCategory::Shift,
hir::BiAdd | hir::BinOpKind::Add |
hir::BiSub | hir::BinOpKind::Sub |
hir::BiMul | hir::BinOpKind::Mul |
hir::BiDiv | hir::BinOpKind::Div |
hir::BiRem => hir::BinOpKind::Rem =>
BinOpCategory::Math, BinOpCategory::Math,
hir::BiBitXor | hir::BinOpKind::BitXor |
hir::BiBitAnd | hir::BinOpKind::BitAnd |
hir::BiBitOr => hir::BinOpKind::BitOr =>
BinOpCategory::Bitwise, BinOpCategory::Bitwise,
hir::BiEq | hir::BinOpKind::Eq |
hir::BiNe | hir::BinOpKind::Ne |
hir::BiLt | hir::BinOpKind::Lt |
hir::BiLe | hir::BinOpKind::Le |
hir::BiGe | hir::BinOpKind::Ge |
hir::BiGt => hir::BinOpKind::Gt =>
BinOpCategory::Comparison, BinOpCategory::Comparison,
hir::BiAnd | hir::BinOpKind::And |
hir::BiOr => hir::BinOpKind::Or =>
BinOpCategory::Shortcircuit, BinOpCategory::Shortcircuit,
} }
} }