/// Check a cast, and report an error if one exists. In some cases, this
/// can return Ok and create type errors in the fcx rather than returning
/// directly. coercion-cast is handled in check instead of here.
Check a cast, and report an error if one exists. In some cases, this
can return Ok and create type errors in the fcx rather than returning
directly. coercion-cast is handled in check instead of here.
Check a cast and report an error if one exists . In some cases this can return Ok and create type errors in the fcx rather than returning directly . coercion - cast is handled in check instead of here .
fn do_check<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<CastKind, CastError> {
        use middle::cast::IntTy::*;
        use middle::cast::CastTy::*;
        let (t_from, t_cast) = match (CastTy::from_ty(self.expr_ty),
                                      CastTy::from_ty(self.cast_ty)) {
            (Some(t_from), Some(t_cast)) => (t_from, t_cast),
            _ => {
                return Err(CastError::NonScalar)
            }
        };
        match (t_from, t_cast) {
            // These types have invariants! can't cast into them.
            (_, RPtr(_)) | (_, Int(CEnum)) | (_, FnPtr) => Err(CastError::NonScalar),
            // * -> Bool
            (_, Int(Bool)) => Err(CastError::CastToBool),
            // * -> Char
            (Int(U(hir::TyU8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast
            (_, Int(Char)) => Err(CastError::CastToChar),
            // prim -> float,ptr
            (Int(Bool), Float) | (Int(CEnum), Float) | (Int(Char), Float)
                => Err(CastError::NeedViaInt),
            (Int(Bool), Ptr(_)) | (Int(CEnum), Ptr(_)) | (Int(Char), Ptr(_))
                => Err(CastError::NeedViaUsize),
            // ptr -> *
            (Ptr(m_e), Ptr(m_c)) => self.check_ptr_ptr_cast(fcx, m_e, m_c), // ptr-ptr-cast
            (Ptr(m_expr), Int(_)) => self.check_ptr_addr_cast(fcx, m_expr), // ptr-addr-cast
            (Ptr(_), Float) | (FnPtr, Float) => Err(CastError::NeedViaUsize),
            (FnPtr, Int(_)) => Ok(CastKind::FnPtrAddrCast),
            (RPtr(_), Int(_)) | (RPtr(_), Float) => Err(CastError::NeedViaPtr),
            // * -> ptr
            (Int(_), Ptr(mt)) => self.check_addr_ptr_cast(fcx, mt), // addr-ptr-cast
            (FnPtr, Ptr(mt)) => self.check_fptr_ptr_cast(fcx, mt),
            (Float, Ptr(_)) => Err(CastError::NeedViaUsize),
            (RPtr(rmt), Ptr(mt)) => self.check_ref_cast(fcx, rmt, mt), // array-ptr-cast
            // prim -> prim
            (Int(CEnum), Int(_)) => Ok(CastKind::EnumCast),
            (Int(Char), Int(_)) | (Int(Bool), Int(_)) => Ok(CastKind::PrimIntCast),
            (Int(_), Int(_)) |
            (Int(_), Float) |
            (Float, Int(_)) |
            (Float, Float) => Ok(CastKind::NumericCast),
        }
    }
fn do_check < ' a > ( & self , fcx : & FnCtxt < ' a , ' tcx > ) -> Result < CastKind , CastError > { use middle :: cast :: IntTy :: * ; use middle :: cast :: CastTy :: * ; let ( t_from , t_cast ) = match ( CastTy :: from_ty ( self . expr_ty ) , CastTy :: from_ty ( self . cast_ty ) ) { ( Some ( t_from ) , Some ( t_cast ) ) => ( t_from , t_cast ) , _ => { return Err ( CastError :: NonScalar ) } } ; match ( t_from , t_cast ) { // These types have invariants! can't cast into them. ( _ , RPtr ( _ ) ) | ( _ , Int ( CEnum ) ) | ( _ , FnPtr ) => Err ( CastError :: NonScalar ) , // * -> Bool ( _ , Int ( Bool ) ) => Err ( CastError :: CastToBool ) , // * -> Char ( Int ( U ( hir :: TyU8 ) ) , Int ( Char ) ) => Ok ( CastKind :: U8CharCast ) , // u8-char-cast ( _ , Int ( Char ) ) => Err ( CastError :: CastToChar ) , // prim -> float,ptr ( Int ( Bool ) , Float ) | ( Int ( CEnum ) , Float ) | ( Int ( Char ) , Float ) => Err ( CastError :: NeedViaInt ) , ( Int ( Bool ) , Ptr ( _ ) ) | ( Int ( CEnum ) , Ptr ( _ ) ) | ( Int ( Char ) , Ptr ( _ ) ) => Err ( CastError :: NeedViaUsize ) , // ptr -> * ( Ptr ( m_e ) , Ptr ( m_c ) ) => self . check_ptr_ptr_cast ( fcx , m_e , m_c ) , // ptr-ptr-cast ( Ptr ( m_expr ) , Int ( _ ) ) => self . check_ptr_addr_cast ( fcx , m_expr ) , // ptr-addr-cast ( Ptr ( _ ) , Float ) | ( FnPtr , Float ) => Err ( CastError :: NeedViaUsize ) , ( FnPtr , Int ( _ ) ) => Ok ( CastKind :: FnPtrAddrCast ) , ( RPtr ( _ ) , Int ( _ ) ) | ( RPtr ( _ ) , Float ) => Err ( CastError :: NeedViaPtr ) , // * -> ptr ( Int ( _ ) , Ptr ( mt ) ) => self . check_addr_ptr_cast ( fcx , mt ) , // addr-ptr-cast ( FnPtr , Ptr ( mt ) ) => self . check_fptr_ptr_cast ( fcx , mt ) , ( Float , Ptr ( _ ) ) => Err ( CastError :: NeedViaUsize ) , ( RPtr ( rmt ) , Ptr ( mt ) ) => self . check_ref_cast ( fcx , rmt , mt ) , // array-ptr-cast // prim -> prim ( Int ( CEnum ) , Int ( _ ) ) => Ok ( CastKind :: EnumCast ) , ( Int ( Char ) , Int ( _ ) ) | ( Int ( Bool ) , Int ( _ ) ) => Ok ( CastKind :: PrimIntCast ) , ( Int ( _ ) , Int ( _ ) ) | ( Int ( _ ) , Float ) | ( Float , Int ( _ ) ) | ( Float , Float ) => Ok ( CastKind :: NumericCast ) , } }
Check a cast, and report an error if one exists.
Check a cast and report an error if one exists .
&self
fcx
&FnCtxt<'a, 'tcx>