fn check_literal(raw_literal: &raw::Literal, expected_ty: &RcType) -> Result<Literal, TypeError> {
    match expected_ty.global_app() {
        Some((name, spine)) if spine.is_empty() => {
            match (raw_literal, name) {
                (&raw::Literal::String(_, ref val), "String") => {
                    return Ok(Literal::String(val.clone()));
                },
                (&raw::Literal::Char(_, val), "Char") => return Ok(Literal::Char(val)),

                // FIXME: overflow?
                (&raw::Literal::Int(_, val), "U8") => return Ok(Literal::U8(val as u8)),
                (&raw::Literal::Int(_, val), "U16") => return Ok(Literal::U16(val as u16)),
                (&raw::Literal::Int(_, val), "U32") => return Ok(Literal::U32(val as u32)),
                (&raw::Literal::Int(_, val), "U64") => return Ok(Literal::U64(val)),
                (&raw::Literal::Int(_, val), "I8") => return Ok(Literal::I8(val as i8)),
                (&raw::Literal::Int(_, val), "I16") => return Ok(Literal::I16(val as i16)),
                (&raw::Literal::Int(_, val), "I32") => return Ok(Literal::I32(val as i32)),
                (&raw::Literal::Int(_, val), "I64") => return Ok(Literal::I64(val as i64)),
                (&raw::Literal::Int(_, val), "F32") => return Ok(Literal::F32(val as f32)),
                (&raw::Literal::Int(_, val), "F64") => return Ok(Literal::F64(val as f64)),
                (&raw::Literal::Float(_, val), "F32") => return Ok(Literal::F32(val as f32)),
                (&raw::Literal::Float(_, val), "F64") => return Ok(Literal::F64(val)),

                _ => {},
            }
        },
        Some(_) | None => {},
    }

    Err(TypeError::LiteralMismatch {
        literal_span: raw_literal.span(),
        found: raw_literal.clone(),
        expected: Box::new(expected_ty.resugar()),
    })
}
/// Checks that a literal is compatible with the given type, returning the
/// elaborated literal if successful
Checks that a literal is compatible with the given type, returning the
elaborated literal if successful
Checks that a literal is compatible with the given type returning the elaborated literal if successful
fn check_literal(raw_literal: &raw::Literal, expected_ty: &RcType) -> Result<Literal, TypeError> {
    match expected_ty.global_app() {
        Some((name, spine)) if spine.is_empty() => {
            match (raw_literal, name) {
                (&raw::Literal::String(_, ref val), "String") => {
                    return Ok(Literal::String(val.clone()));
                },
                (&raw::Literal::Char(_, val), "Char") => return Ok(Literal::Char(val)),
                // FIXME: overflow?
                (&raw::Literal::Int(_, val), "U8") => return Ok(Literal::U8(val as u8)),
                (&raw::Literal::Int(_, val), "U16") => return Ok(Literal::U16(val as u16)),
                (&raw::Literal::Int(_, val), "U32") => return Ok(Literal::U32(val as u32)),
                (&raw::Literal::Int(_, val), "U64") => return Ok(Literal::U64(val)),
                (&raw::Literal::Int(_, val), "I8") => return Ok(Literal::I8(val as i8)),
                (&raw::Literal::Int(_, val), "I16") => return Ok(Literal::I16(val as i16)),
                (&raw::Literal::Int(_, val), "I32") => return Ok(Literal::I32(val as i32)),
                (&raw::Literal::Int(_, val), "I64") => return Ok(Literal::I64(val as i64)),
                (&raw::Literal::Int(_, val), "F32") => return Ok(Literal::F32(val as f32)),
                (&raw::Literal::Int(_, val), "F64") => return Ok(Literal::F64(val as f64)),
                (&raw::Literal::Float(_, val), "F32") => return Ok(Literal::F32(val as f32)),
                (&raw::Literal::Float(_, val), "F64") => return Ok(Literal::F64(val)),
                _ => {},
            }
        },
        Some(_) | None => {},
    }
    Err(TypeError::LiteralMismatch {
        literal_span: raw_literal.span(),
        found: raw_literal.clone(),
        expected: Box::new(expected_ty.resugar()),
    })
}
fn check_literal ( raw_literal : & raw :: Literal , expected_ty : & RcType ) -> Result < Literal , TypeError > { match expected_ty . global_app ( ) { Some ( ( name , spine ) ) if spine . is_empty ( ) => { match ( raw_literal , name ) { ( & raw :: Literal :: String ( _ , ref val ) , " " ) => { return Ok ( Literal :: String ( val . clone ( ) ) ) ; } , ( & raw :: Literal :: Char ( _ , val ) , " " ) => return Ok ( Literal :: Char ( val ) ) , // FIXME: overflow? ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: U8 ( val as u8 ) ) , ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: U16 ( val as u16 ) ) , ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: U32 ( val as u32 ) ) , ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: U64 ( val ) ) , ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: I8 ( val as i8 ) ) , ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: I16 ( val as i16 ) ) , ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: I32 ( val as i32 ) ) , ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: I64 ( val as i64 ) ) , ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: F32 ( val as f32 ) ) , ( & raw :: Literal :: Int ( _ , val ) , " " ) => return Ok ( Literal :: F64 ( val as f64 ) ) , ( & raw :: Literal :: Float ( _ , val ) , " " ) => return Ok ( Literal :: F32 ( val as f32 ) ) , ( & raw :: Literal :: Float ( _ , val ) , " " ) => return Ok ( Literal :: F64 ( val ) ) , _ => { } , } } , Some ( _ ) | None => { } , } Err ( TypeError :: LiteralMismatch { literal_span : raw_literal . span ( ) , found : raw_literal . clone ( ) , expected : Box :: new ( expected_ty . resugar ( ) ) , } ) }
Checks that a literal is compatible with the given type, returning the
elaborated literal if successful
Checks that a literal is compatible with the given type returning the elaborated literal if successful
raw_literal
&raw::Literal
expected_ty
&RcType
raw_literal
&raw::Literal
expected_ty
&RcType