rustc_const_eval/util/
mod.rs

1use rustc_middle::mir;
2
3mod alignment;
4pub(crate) mod caller_location;
5mod check_validity_requirement;
6mod compare_types;
7mod type_name;
8
9pub use self::alignment::{is_disaligned, is_within_packed};
10pub use self::check_validity_requirement::check_validity_requirement;
11pub(crate) use self::check_validity_requirement::validate_scalar_in_layout;
12pub use self::compare_types::{relate_types, sub_types};
13pub use self::type_name::type_name;
14
15/// Classify whether an operator is "left-homogeneous", i.e., the LHS has the
16/// same type as the result.
17#[inline]
18pub fn binop_left_homogeneous(op: mir::BinOp) -> bool {
19    use rustc_middle::mir::BinOp::*;
20    match op {
21        Add | AddUnchecked | Sub | SubUnchecked | Mul | MulUnchecked | Div | Rem | BitXor
22        | BitAnd | BitOr | Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => true,
23        AddWithOverflow | SubWithOverflow | MulWithOverflow | Eq | Ne | Lt | Le | Gt | Ge | Cmp => {
24            false
25        }
26    }
27}
28
29/// Classify whether an operator is "right-homogeneous", i.e., the RHS has the
30/// same type as the LHS.
31#[inline]
32pub fn binop_right_homogeneous(op: mir::BinOp) -> bool {
33    use rustc_middle::mir::BinOp::*;
34    match op {
35        Add | AddUnchecked | AddWithOverflow | Sub | SubUnchecked | SubWithOverflow | Mul
36        | MulUnchecked | MulWithOverflow | Div | Rem | BitXor | BitAnd | BitOr | Eq | Ne | Lt
37        | Le | Gt | Ge | Cmp => true,
38        Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => false,
39    }
40}