2023-06-04 18:09:20 +00:00
|
|
|
use rustc_middle::mir;
|
|
|
|
|
2017-10-03 14:01:01 +00:00
|
|
|
mod alignment;
|
2023-02-26 21:50:19 +00:00
|
|
|
mod check_validity_requirement;
|
2022-11-15 12:42:14 +00:00
|
|
|
mod compare_types;
|
2022-10-31 10:04:03 +00:00
|
|
|
mod type_name;
|
2017-03-09 18:10:05 +00:00
|
|
|
|
2017-10-03 14:01:01 +00:00
|
|
|
pub use self::alignment::is_disaligned;
|
2023-02-26 21:50:19 +00:00
|
|
|
pub use self::check_validity_requirement::check_validity_requirement;
|
2022-11-15 12:42:14 +00:00
|
|
|
pub use self::compare_types::{is_equal_up_to_subtyping, is_subtype};
|
2022-10-31 10:04:03 +00:00
|
|
|
pub use self::type_name::type_name;
|
2023-06-04 18:09:20 +00:00
|
|
|
|
|
|
|
/// Classify whether an operator is "left-homogeneous", i.e., the LHS has the
|
|
|
|
/// same type as the result.
|
|
|
|
#[inline]
|
|
|
|
pub(crate) fn binop_left_homogeneous(op: mir::BinOp) -> bool {
|
|
|
|
use rustc_middle::mir::BinOp::*;
|
|
|
|
match op {
|
|
|
|
Add | AddUnchecked | Sub | SubUnchecked | Mul | MulUnchecked | Div | Rem | BitXor
|
|
|
|
| BitAnd | BitOr | Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => true,
|
|
|
|
Eq | Ne | Lt | Le | Gt | Ge => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Classify whether an operator is "right-homogeneous", i.e., the RHS has the
|
|
|
|
/// same type as the LHS.
|
|
|
|
#[inline]
|
|
|
|
pub(crate) fn binop_right_homogeneous(op: mir::BinOp) -> bool {
|
|
|
|
use rustc_middle::mir::BinOp::*;
|
|
|
|
match op {
|
|
|
|
Add | AddUnchecked | Sub | SubUnchecked | Mul | MulUnchecked | Div | Rem | BitXor
|
|
|
|
| BitAnd | BitOr | Eq | Ne | Lt | Le | Gt | Ge => true,
|
|
|
|
Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => false,
|
|
|
|
}
|
|
|
|
}
|