pub fn repr_discr(tcx: TyCtxt, hint: attr::ReprAttr, min: i64, max: i64)
                      -> (Integer, bool) {
        // Theoretically, negative values could be larger in unsigned representation
        // than the unsigned representation of the signed minimum. However, if there
        // are any negative values, the only valid unsigned representation is u64
        // which can fit all i64 values, so the result remains unaffected.
        let unsigned_fit = Integer::fit_unsigned(cmp::max(min as u64, max as u64));
        let signed_fit = cmp::max(Integer::fit_signed(min), Integer::fit_signed(max));

        let at_least = match hint {
            attr::ReprInt(span, ity) => {
                let discr = Integer::from_attr(&tcx.data_layout, ity);
                let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
                if discr < fit {
                    span_bug!(span, "representation hint insufficient for discriminant range")
                }
                return (discr, ity.is_signed());
            }
            attr::ReprExtern => {
                match &tcx.sess.target.target.arch[..] {
                    // WARNING: the ARM EABI has two variants; the one corresponding
                    // to `at_least == I32` appears to be used on Linux and NetBSD,
                    // but some systems may use the variant corresponding to no
                    // lower bound.  However, we don't run on those yet...?
                    "arm" => I32,
                    _ => I32,
                }
            }
            attr::ReprAny => I8,
            attr::ReprPacked => {
                bug!("Integer::repr_discr: found #[repr(packed)] on an enum");
            }
            attr::ReprSimd => {
                bug!("Integer::repr_discr: found #[repr(simd)] on an enum");
            }
        };

        // If there are no negative values, we can use the unsigned fit.
        if min >= 0 {
            (cmp::max(unsigned_fit, at_least), false)
        } else {
            (cmp::max(signed_fit, at_least), true)
        }
    }
/// Find the appropriate Integer type and signedness for the given
/// signed discriminant range and #[repr] attribute.
/// N.B.: u64 values above i64::MAX will be treated as signed, but
/// that shouldn't affect anything, other than maybe debuginfo.
Find the appropriate Integer type and signedness for the given
signed discriminant range and #[repr] attribute.
N.B.: u64 values above i64::MAX will be treated as signed, but
that shouldn't affect anything, other than maybe debuginfo.
Find the appropriate Integer type and signedness for the given signed discriminant range and # [ repr ] attribute . N . B . : u64 values above i64 :: MAX will be treated as signed but that shouldn ' t affect anything other than maybe debuginfo .
pub fn repr_discr(tcx: TyCtxt, hint: attr::ReprAttr, min: i64, max: i64)
                      -> (Integer, bool) {
        // Theoretically, negative values could be larger in unsigned representation
        // than the unsigned representation of the signed minimum. However, if there
        // are any negative values, the only valid unsigned representation is u64
        // which can fit all i64 values, so the result remains unaffected.
        let unsigned_fit = Integer::fit_unsigned(cmp::max(min as u64, max as u64));
        let signed_fit = cmp::max(Integer::fit_signed(min), Integer::fit_signed(max));
        let at_least = match hint {
            attr::ReprInt(span, ity) => {
                let discr = Integer::from_attr(&tcx.data_layout, ity);
                let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
                if discr < fit {
                    span_bug!(span, "representation hint insufficient for discriminant range")
                }
                return (discr, ity.is_signed());
            }
            attr::ReprExtern => {
                match &tcx.sess.target.target.arch[..] {
                    // WARNING: the ARM EABI has two variants; the one corresponding
                    // to `at_least == I32` appears to be used on Linux and NetBSD,
                    // but some systems may use the variant corresponding to no
                    // lower bound.  However, we don't run on those yet...?
                    "arm" => I32,
                    _ => I32,
                }
            }
            attr::ReprAny => I8,
            attr::ReprPacked => {
                bug!("Integer::repr_discr: found #[repr(packed)] on an enum");
            }
            attr::ReprSimd => {
                bug!("Integer::repr_discr: found #[repr(simd)] on an enum");
            }
        };
        // If there are no negative values, we can use the unsigned fit.
        if min >= 0 {
            (cmp::max(unsigned_fit, at_least), false)
        } else {
            (cmp::max(signed_fit, at_least), true)
        }
    }
pub fn repr_discr ( tcx : TyCtxt , hint : attr :: ReprAttr , min : i64 , max : i64 ) -> ( Integer , bool ) { // Theoretically, negative values could be larger in unsigned representation // than the unsigned representation of the signed minimum. However, if there // are any negative values, the only valid unsigned representation is u64 // which can fit all i64 values, so the result remains unaffected. let unsigned_fit = Integer :: fit_unsigned ( cmp :: max ( min as u64 , max as u64 ) ) ; let signed_fit = cmp :: max ( Integer :: fit_signed ( min ) , Integer :: fit_signed ( max ) ) ; let at_least = match hint { attr :: ReprInt ( span , ity ) => { let discr = Integer :: from_attr ( & tcx . data_layout , ity ) ; let fit = if ity . is_signed ( ) { signed_fit } else { unsigned_fit } ; if discr < fit { span_bug ! ( span " " ) } return ( discr , ity . is_signed ( ) ) ; } attr :: ReprExtern => { match & tcx . sess . target . target . arch [ .. ] { // WARNING: the ARM EABI has two variants; the one corresponding // to `at_least == I32` appears to be used on Linux and NetBSD, // but some systems may use the variant corresponding to no // lower bound.  However, we don't run on those yet...? " " => I32 , _ => I32 , } } attr :: ReprAny => I8 , attr :: ReprPacked => { bug ! ( " " ) ; } attr :: ReprSimd => { bug ! ( " " ) ; } } ; // If there are no negative values, we can use the unsigned fit. if min >= 0 { ( cmp :: max ( unsigned_fit , at_least ) , false ) } else { ( cmp :: max ( signed_fit , at_least ) , true ) } }
Find the appropriate Integer type and signedness for the given
signed discriminant range and #[repr] attribute.
Find the appropriate Integer type and signedness for the given signed discriminant range and # [ repr ] attribute .
tcx
TyCtxt
hint
attr::ReprAttr
min
i64
max
i64
tcx
TyCtxt
hint
attr::ReprAttr
min
i64
max
i64