mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
normalize ordering ops
This commit is contained in:
parent
7e5a186c1f
commit
b082cd679a
@ -273,12 +273,14 @@ pub enum LogicOp {
|
|||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum CmpOp {
|
pub enum CmpOp {
|
||||||
Equal,
|
Eq { negated: bool },
|
||||||
NotEqual,
|
Ord { ordering: Ordering, strict: bool },
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub enum Ordering {
|
||||||
Less,
|
Less,
|
||||||
LessOrEqual,
|
|
||||||
Greater,
|
Greater,
|
||||||
GreaterOrEqual,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
@ -1080,12 +1082,20 @@ impl From<ast::BinOp> for BinaryOp {
|
|||||||
match ast_op {
|
match ast_op {
|
||||||
ast::BinOp::BooleanOr => BinaryOp::LogicOp(LogicOp::Or),
|
ast::BinOp::BooleanOr => BinaryOp::LogicOp(LogicOp::Or),
|
||||||
ast::BinOp::BooleanAnd => BinaryOp::LogicOp(LogicOp::And),
|
ast::BinOp::BooleanAnd => BinaryOp::LogicOp(LogicOp::And),
|
||||||
ast::BinOp::EqualityTest => BinaryOp::CmpOp(CmpOp::Equal),
|
ast::BinOp::EqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: false }),
|
||||||
ast::BinOp::NegatedEqualityTest => BinaryOp::CmpOp(CmpOp::NotEqual),
|
ast::BinOp::NegatedEqualityTest => BinaryOp::CmpOp(CmpOp::Eq { negated: true }),
|
||||||
ast::BinOp::LesserEqualTest => BinaryOp::CmpOp(CmpOp::LessOrEqual),
|
ast::BinOp::LesserEqualTest => {
|
||||||
ast::BinOp::GreaterEqualTest => BinaryOp::CmpOp(CmpOp::GreaterOrEqual),
|
BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: false })
|
||||||
ast::BinOp::LesserTest => BinaryOp::CmpOp(CmpOp::Less),
|
}
|
||||||
ast::BinOp::GreaterTest => BinaryOp::CmpOp(CmpOp::Greater),
|
ast::BinOp::GreaterEqualTest => {
|
||||||
|
BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: false })
|
||||||
|
}
|
||||||
|
ast::BinOp::LesserTest => {
|
||||||
|
BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Less, strict: true })
|
||||||
|
}
|
||||||
|
ast::BinOp::GreaterTest => {
|
||||||
|
BinaryOp::CmpOp(CmpOp::Ord { ordering: Ordering::Greater, strict: true })
|
||||||
|
}
|
||||||
ast::BinOp::Addition => BinaryOp::ArithOp(ArithOp::Add),
|
ast::BinOp::Addition => BinaryOp::ArithOp(ArithOp::Add),
|
||||||
ast::BinOp::Multiplication => BinaryOp::ArithOp(ArithOp::Mul),
|
ast::BinOp::Multiplication => BinaryOp::ArithOp(ArithOp::Mul),
|
||||||
ast::BinOp::Subtraction => BinaryOp::ArithOp(ArithOp::Sub),
|
ast::BinOp::Subtraction => BinaryOp::ArithOp(ArithOp::Sub),
|
||||||
|
@ -22,9 +22,8 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty {
|
|||||||
pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
|
pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
|
||||||
match op {
|
match op {
|
||||||
BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool),
|
BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool),
|
||||||
BinaryOp::Assignment { op: None }
|
BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { negated: _ }) => {
|
||||||
| BinaryOp::CmpOp(CmpOp::Equal)
|
match lhs_ty {
|
||||||
| BinaryOp::CmpOp(CmpOp::NotEqual) => match lhs_ty {
|
|
||||||
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
||||||
TypeCtor::Int(..)
|
TypeCtor::Int(..)
|
||||||
| TypeCtor::Float(..)
|
| TypeCtor::Float(..)
|
||||||
@ -35,16 +34,17 @@ pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
|
|||||||
},
|
},
|
||||||
Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
|
Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
|
||||||
_ => Ty::Unknown,
|
_ => Ty::Unknown,
|
||||||
},
|
}
|
||||||
BinaryOp::CmpOp(_) | BinaryOp::Assignment { op: Some(_) } | BinaryOp::ArithOp(_) => {
|
}
|
||||||
match lhs_ty {
|
BinaryOp::CmpOp(CmpOp::Ord { .. })
|
||||||
|
| BinaryOp::Assignment { op: Some(_) }
|
||||||
|
| BinaryOp::ArithOp(_) => match lhs_ty {
|
||||||
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
|
||||||
TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty,
|
TypeCtor::Int(..) | TypeCtor::Float(..) => lhs_ty,
|
||||||
_ => Ty::Unknown,
|
_ => Ty::Unknown,
|
||||||
},
|
},
|
||||||
Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
|
Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
|
||||||
_ => Ty::Unknown,
|
_ => Ty::Unknown,
|
||||||
}
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user