Support bool constants and fix a u8 const error
This commit is contained in:
parent
75430b22e3
commit
5508d44e2b
3 changed files with 11 additions and 6 deletions
12
example.rs
12
example.rs
|
@ -18,10 +18,10 @@ trait Mul<RHS = Self> {
|
|||
fn mul(self, rhs: RHS) -> Self::Output;
|
||||
}
|
||||
|
||||
impl Mul for u32 {
|
||||
type Output = u32;
|
||||
impl Mul for u8 {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: u32) -> u32 {
|
||||
fn mul(self, rhs: Self) -> Self {
|
||||
self * rhs
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,11 @@ unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
|
|||
drop_in_place(to_drop);
|
||||
}
|
||||
|
||||
fn abc(a: u32) -> u32 {
|
||||
fn abc(a: u8) -> u8 {
|
||||
a * 2
|
||||
}
|
||||
|
||||
fn bcd(b: bool, a: u32) -> u32 {
|
||||
fn bcd(b: bool, a: u8) -> u8 {
|
||||
if b {
|
||||
a * 2
|
||||
} else {
|
||||
|
@ -73,6 +73,6 @@ fn option_unwrap_or(o: BoolOption, d: bool) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn ret_42() -> u32 {
|
||||
fn ret_42() -> u8 {
|
||||
42
|
||||
}
|
||||
|
|
|
@ -514,6 +514,10 @@ fn trans_operand<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx>, operand: &Operand<'tcx
|
|||
Literal::Value { value } => {
|
||||
let layout = fx.layout_of(const_.ty);
|
||||
match const_.ty.sty {
|
||||
TypeVariants::TyBool => {
|
||||
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
|
||||
CValue::const_val(fx, const_.ty, bits as u64 as i64)
|
||||
}
|
||||
TypeVariants::TyUint(_) => {
|
||||
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
|
||||
CValue::const_val(fx, const_.ty, bits as u64 as i64)
|
||||
|
|
|
@ -165,6 +165,7 @@ impl<'tcx> CValue<'tcx> {
|
|||
|
||||
pub fn const_val<'a>(fx: &mut FunctionCx<'a, 'tcx>, ty: Ty<'tcx>, const_val: i64) -> CValue<'tcx> where 'tcx: 'a {
|
||||
let cton_ty = fx.cton_type(ty).unwrap();
|
||||
let cton_ty = fixup_cton_ty(cton_ty);
|
||||
let layout = fx.layout_of(ty);
|
||||
CValue::ByVal(fx.bcx.ins().iconst(cton_ty, const_val), layout)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue