2023-06-04 18:09:20 +00:00
|
|
|
use rustc_middle::mir;
|
|
|
|
|
2017-10-03 14:01:01 +00:00
|
|
|
mod alignment;
|
2023-10-28 13:39:54 +00:00
|
|
|
pub(crate) mod caller_location;
|
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
|
|
|
|
2023-08-24 15:42:55 +00:00
|
|
|
pub use self::alignment::{is_disaligned, is_within_packed};
|
2023-02-26 21:50:19 +00:00
|
|
|
pub use self::check_validity_requirement::check_validity_requirement;
|
2024-10-31 11:41:50 +00:00
|
|
|
pub use self::compare_types::{relate_types, sub_types};
|
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]
|
2024-01-04 16:27:05 +00:00
|
|
|
pub fn binop_left_homogeneous(op: mir::BinOp) -> bool {
|
2023-06-04 18:09:20 +00:00
|
|
|
use rustc_middle::mir::BinOp::*;
|
|
|
|
match op {
|
|
|
|
Add | AddUnchecked | Sub | SubUnchecked | Mul | MulUnchecked | Div | Rem | BitXor
|
|
|
|
| BitAnd | BitOr | Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => true,
|
2024-05-16 09:07:31 +00:00
|
|
|
AddWithOverflow | SubWithOverflow | MulWithOverflow | Eq | Ne | Lt | Le | Gt | Ge | Cmp => {
|
|
|
|
false
|
|
|
|
}
|
2023-06-04 18:09:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Classify whether an operator is "right-homogeneous", i.e., the RHS has the
|
|
|
|
/// same type as the LHS.
|
|
|
|
#[inline]
|
2024-01-04 16:27:05 +00:00
|
|
|
pub fn binop_right_homogeneous(op: mir::BinOp) -> bool {
|
2023-06-04 18:09:20 +00:00
|
|
|
use rustc_middle::mir::BinOp::*;
|
|
|
|
match op {
|
2024-05-16 09:07:31 +00:00
|
|
|
Add | AddUnchecked | AddWithOverflow | Sub | SubUnchecked | SubWithOverflow | Mul
|
|
|
|
| MulUnchecked | MulWithOverflow | Div | Rem | BitXor | BitAnd | BitOr | Eq | Ne | Lt
|
|
|
|
| Le | Gt | Ge | Cmp => true,
|
2023-06-04 18:09:20 +00:00
|
|
|
Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => false,
|
|
|
|
}
|
|
|
|
}
|