mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Implement char to uint cast
This commit is contained in:
parent
1138d38d87
commit
bf2c35f05d
@ -135,6 +135,10 @@ fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize) {
|
||||
)
|
||||
}
|
||||
|
||||
fn char_cast(c: char) -> u8 {
|
||||
c as u8
|
||||
}
|
||||
|
||||
struct DebugTuple(());
|
||||
|
||||
fn debug_tuple() -> DebugTuple {
|
||||
|
@ -298,6 +298,7 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, stmt: &Statement<'tcx
|
||||
(TypeVariants::TyRawPtr(..), TypeVariants::TyRawPtr(..)) => {
|
||||
lval.write_cvalue(fx, operand.unchecked_cast_to(dest_layout));
|
||||
}
|
||||
(TypeVariants::TyChar, TypeVariants::TyUint(_)) |
|
||||
(TypeVariants::TyUint(_), TypeVariants::TyInt(_)) |
|
||||
(TypeVariants::TyUint(_), TypeVariants::TyUint(_)) => {
|
||||
let from = operand.load_value(fx);
|
||||
|
@ -48,6 +48,7 @@ pub fn cton_type_from_ty<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>
|
||||
IntTy::Isize => types::I64,
|
||||
}
|
||||
}
|
||||
TypeVariants::TyChar => types::I32,
|
||||
TypeVariants::TyFnPtr(_) => types::I64,
|
||||
TypeVariants::TyRawPtr(TypeAndMut { ty, mutbl: _ }) | TypeVariants::TyRef(_, ty, _) => {
|
||||
if ty.is_sized(tcx.at(DUMMY_SP), ParamEnv::reveal_all()) {
|
||||
@ -100,7 +101,7 @@ impl<'tcx> CValue<'tcx> {
|
||||
pub fn load_value<'a>(self, fx: &mut FunctionCx<'a, 'tcx>) -> Value where 'tcx: 'a{
|
||||
match self {
|
||||
CValue::ByRef(addr, layout) => {
|
||||
let cton_ty = fx.cton_type(layout.ty).expect(&format!("{:?}", layout.ty));
|
||||
let cton_ty = fx.cton_type(layout.ty).expect(&format!("load_value of type {:?}", layout.ty));
|
||||
fx.bcx.ins().load(cton_ty, MemFlags::new(), addr, 0)
|
||||
}
|
||||
CValue::ByVal(value, _layout) => value,
|
||||
|
Loading…
Reference in New Issue
Block a user