pub fn const_int_checked_neg<'a>(
    a: i64, e: &'a Expr, opt_ety: Option<IntTy>) -> EvalResult {

    let (min,max) = match opt_ety {
        // (-i8::MIN is itself not an i8, etc, but this is an easy way
        // to allow literals to pass the check. Of course that does
        // not work for i64::MIN.)
        Some(IntTy::I8) =>  (-(i8::MAX as i64), -(i8::MIN as i64)),
        Some(IntTy::I16) => (-(i16::MAX as i64), -(i16::MIN as i64)),
        Some(IntTy::I32) => (-(i32::MAX as i64), -(i32::MIN as i64)),
        None | Some(IntTy::I64) => (-i64::MAX, -(i64::MIN+1)),
    };

    let oflo = a < min || a > max;
    if oflo {
        signal!(e, NegateWithOverflow(a));
    } else {
        Ok(const_int(-a))
    }
}
// The const_{int,uint}_checked_{neg,add,sub,mul,div,shl,shr} family
// of functions catch and signal overflow errors during constant
// evaluation.
//
// They all take the operator's arguments (`a` and `b` if binary), the
// overall expression (`e`) and, if available, whole expression's
// concrete type (`opt_ety`).
//
// If the whole expression's concrete type is None, then this is a
// constant evaluation happening before type check (e.g. in the check
// to confirm that a pattern range's left-side is not greater than its
// right-side). We do not do arithmetic modulo the type's bitwidth in
// such a case; we just do 64-bit arithmetic and assume that later
// passes will do it again with the type information, and thus do the
// overflow checks then.
The const_{int,uint}_checked_{neg,add,sub,mul,div,shl,shr} family
of functions catch and signal overflow errors during constant
evaluation.



If the whole expression's concrete type is None, then this is a
constant evaluation happening before type check . We do not do arithmetic modulo the type's bitwidth in
such a case; we just do 64-bit arithmetic and assume that later
passes will do it again with the type information, and thus do the
overflow checks then.
The const_ { int uint } _checked_ { neg add sub mul div shl shr } family of functions catch and signal overflow errors during constant evaluation . If the whole expression ' s concrete type is None then this is a constant evaluation happening before type check . We do not do arithmetic modulo the type ' s bitwidth in such a case ; we just do 64 - bit arithmetic and assume that later passes will do it again with the type information and thus do the overflow checks then .
pub fn const_int_checked_neg<'a>(
    a: i64, e: &'a Expr, opt_ety: Option<IntTy>) -> EvalResult {
    let (min,max) = match opt_ety {
        // (-i8::MIN is itself not an i8, etc, but this is an easy way
        // to allow literals to pass the check. Of course that does
        // not work for i64::MIN.)
        Some(IntTy::I8) =>  (-(i8::MAX as i64), -(i8::MIN as i64)),
        Some(IntTy::I16) => (-(i16::MAX as i64), -(i16::MIN as i64)),
        Some(IntTy::I32) => (-(i32::MAX as i64), -(i32::MIN as i64)),
        None | Some(IntTy::I64) => (-i64::MAX, -(i64::MIN+1)),
    };
    let oflo = a < min || a > max;
    if oflo {
        signal!(e, NegateWithOverflow(a));
    } else {
        Ok(const_int(-a))
    }
}
pub fn const_int_checked_neg < ' a > ( a : i64 , e : & ' a Expr , opt_ety : Option < IntTy > ) -> EvalResult { let ( min , max ) = match opt_ety { // (-i8::MIN is itself not an i8, etc, but this is an easy way // to allow literals to pass the check. Of course that does // not work for i64::MIN.) Some ( IntTy :: I8 ) => ( - ( i8 :: MAX as i64 ) , - ( i8 :: MIN as i64 ) ) , Some ( IntTy :: I16 ) => ( - ( i16 :: MAX as i64 ) , - ( i16 :: MIN as i64 ) ) , Some ( IntTy :: I32 ) => ( - ( i32 :: MAX as i64 ) , - ( i32 :: MIN as i64 ) ) , None | Some ( IntTy :: I64 ) => ( - i64 :: MAX , - ( i64 :: MIN + 1 ) ) , } ; let oflo = a < min || a > max ; if oflo { signal ! ( e NegateWithOverflow ( a ) ) ; } else { Ok ( const_int ( - a ) ) } }
The const_{int,uint}_checked_{neg,add,sub,mul,div,shl,shr} family
of functions catch and signal overflow errors during constant
evaluation.
The const_ { int uint } _checked_ { neg add sub mul div shl shr } family of functions catch and signal overflow errors during constant evaluation .
a
i64
e
&'a Expr
opt_ety
Option<IntTy>