/// Find the appropriate Integer type and signedness for the given
/// signed discriminant range and #[repr] attribute.
/// N.B.: u128 values above i128::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.: u128 values above i128::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 . : u128 values above i128 :: MAX will be treated as signed but that shouldn ' t affect anything other than maybe debuginfo .
fn repr_discr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                  ty: Ty<'tcx>,
                  repr: &ReprOptions,
                  min: i128,
                  max: i128)
                  -> (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 u128
        // which can fit all i128 values, so the result remains unaffected.
        let unsigned_fit = Integer::fit_unsigned(cmp::max(min as u128, max as u128));
        let signed_fit = cmp::max(Integer::fit_signed(min), Integer::fit_signed(max));
        let mut min_from_extern = None;
        let min_default = I8;
        if let Some(ity) = repr.int {
            let discr = Integer::from_attr(tcx, ity);
            let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
            if discr < fit {
                bug!("Integer::repr_discr: `#[repr]` hint too small for \
                  discriminant range of enum `{}", ty)
            }
            return (discr, ity.is_signed());
        }
        if repr.c() {
            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" => min_from_extern = Some(I32),
                _ => min_from_extern = Some(I32),
            }
        }
        let at_least = min_from_extern.unwrap_or(min_default);
        // 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)
        }
    }
fn repr_discr < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , ty : Ty < ' tcx > , repr : & ReprOptions , min : i128 , max : i128 ) -> ( 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 u128 // which can fit all i128 values, so the result remains unaffected. let unsigned_fit = Integer :: fit_unsigned ( cmp :: max ( min as u128 , max as u128 ) ) ; let signed_fit = cmp :: max ( Integer :: fit_signed ( min ) , Integer :: fit_signed ( max ) ) ; let mut min_from_extern = None ; let min_default = I8 ; if let Some ( ity ) = repr . int { let discr = Integer :: from_attr ( tcx , ity ) ; let fit = if ity . is_signed ( ) { signed_fit } else { unsigned_fit } ; if discr < fit { bug ! ( " \
 " ty ) } return ( discr , ity . is_signed ( ) ) ; } if repr . c ( ) { 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...? " " => min_from_extern = Some ( I32 ) , _ => min_from_extern = Some ( I32 ) , } } let at_least = min_from_extern . unwrap_or ( min_default ) ; // 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<'a, 'tcx, 'tcx>
ty
Ty<'tcx>
repr
&ReprOptions
min
i128
max
i128