mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Use From::from
instead of as
where possible
This commit is contained in:
parent
4ec2831ebc
commit
a0580610b2
@ -273,7 +273,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||
let ret_vals = self.lib_call(name, input_tys, return_tys, &args);
|
||||
match *ret_vals {
|
||||
[] => CValue::by_ref(
|
||||
Pointer::const_addr(self, self.pointer_type.bytes() as i64),
|
||||
Pointer::const_addr(self, i64::from(self.pointer_type.bytes())),
|
||||
return_layout,
|
||||
),
|
||||
[val] => CValue::by_val(val, return_layout),
|
||||
|
12
src/base.rs
12
src/base.rs
@ -778,10 +778,10 @@ pub(crate) fn trans_place<'tcx>(
|
||||
from_end,
|
||||
} => {
|
||||
let index = if !from_end {
|
||||
fx.bcx.ins().iconst(fx.pointer_type, offset as i64)
|
||||
fx.bcx.ins().iconst(fx.pointer_type, i64::from(offset))
|
||||
} else {
|
||||
let len = codegen_array_len(fx, cplace);
|
||||
fx.bcx.ins().iadd_imm(len, -(offset as i64))
|
||||
fx.bcx.ins().iadd_imm(len, -i64::from(offset))
|
||||
};
|
||||
cplace = cplace.place_index(fx, index);
|
||||
}
|
||||
@ -795,8 +795,8 @@ pub(crate) fn trans_place<'tcx>(
|
||||
let elem_layout = fx.layout_of(elem_ty);
|
||||
let ptr = cplace.to_ptr();
|
||||
cplace = CPlace::for_ptr(
|
||||
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),
|
||||
fx.layout_of(fx.tcx.mk_array(elem_ty, to as u64 - from as u64)),
|
||||
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * i64::from(from)),
|
||||
fx.layout_of(fx.tcx.mk_array(elem_ty, u64::from(to) - u64::from(from))),
|
||||
);
|
||||
}
|
||||
ty::Slice(elem_ty) => {
|
||||
@ -805,8 +805,8 @@ pub(crate) fn trans_place<'tcx>(
|
||||
let (ptr, len) = cplace.to_ptr_maybe_unsized();
|
||||
let len = len.unwrap();
|
||||
cplace = CPlace::for_ptr_with_extra(
|
||||
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),
|
||||
fx.bcx.ins().iadd_imm(len, -(from as i64 + to as i64)),
|
||||
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * i64::from(from)),
|
||||
fx.bcx.ins().iadd_imm(len, -(i64::from(from) + i64::from(to))),
|
||||
cplace.layout(),
|
||||
);
|
||||
}
|
||||
|
@ -160,10 +160,10 @@ pub(crate) fn clif_int_or_float_cast(
|
||||
fx.bcx.ins().fcvt_to_uint_sat(types::I32, from)
|
||||
};
|
||||
let (min, max) = match (to_ty, to_signed) {
|
||||
(types::I8, false) => (0, u8::MAX as i64),
|
||||
(types::I16, false) => (0, u16::MAX as i64),
|
||||
(types::I8, true) => (i8::MIN as i64, i8::MAX as i64),
|
||||
(types::I16, true) => (i16::MIN as i64, i16::MAX as i64),
|
||||
(types::I8, false) => (0, i64::from(u8::MAX)),
|
||||
(types::I16, false) => (0, i64::from(u16::MAX)),
|
||||
(types::I8, true) => (i64::from(i8::MIN), i64::from(i8::MAX)),
|
||||
(types::I16, true) => (i64::from(i16::MIN), i64::from(i16::MAX)),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let min_val = fx.bcx.ins().iconst(types::I32, min);
|
||||
|
@ -172,8 +172,8 @@ fn resolve_128bit_value_imm(func: &Function, val: Value) -> Option<u128> {
|
||||
return None;
|
||||
};
|
||||
|
||||
let lsb = resolve_normal_value_imm(func, lsb)? as u64 as u128;
|
||||
let msb = resolve_normal_value_imm(func, msb)? as u64 as u128;
|
||||
let lsb = u128::from(resolve_normal_value_imm(func, lsb)? as u64);
|
||||
let msb = u128::from(resolve_normal_value_imm(func, msb)? as u64);
|
||||
|
||||
Some(msb << 64 | lsb)
|
||||
}
|
||||
@ -182,7 +182,7 @@ pub(crate) fn resolve_value_imm(func: &Function, val: Value) -> Option<u128> {
|
||||
if func.dfg.value_type(val) == types::I128 {
|
||||
resolve_128bit_value_imm(func, val)
|
||||
} else {
|
||||
resolve_normal_value_imm(func, val).map(|imm| imm as u64 as u128)
|
||||
resolve_normal_value_imm(func, val).map(|imm| u128::from(imm as u64))
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,21 +217,21 @@ pub(crate) fn type_min_max_value(bcx: &mut FunctionBuilder<'_>, ty: Type, signed
|
||||
(types::I8, false) | (types::I16, false) | (types::I32, false) | (types::I64, false) => {
|
||||
0i64
|
||||
}
|
||||
(types::I8, true) => i8::MIN as i64,
|
||||
(types::I16, true) => i16::MIN as i64,
|
||||
(types::I32, true) => i32::MIN as i64,
|
||||
(types::I8, true) => i64::from(i8::MIN),
|
||||
(types::I16, true) => i64::from(i16::MIN),
|
||||
(types::I32, true) => i64::from(i32::MIN),
|
||||
(types::I64, true) => i64::MIN,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let max = match (ty, signed) {
|
||||
(types::I8, false) => u8::MAX as i64,
|
||||
(types::I16, false) => u16::MAX as i64,
|
||||
(types::I32, false) => u32::MAX as i64,
|
||||
(types::I8, false) => i64::from(u8::MAX),
|
||||
(types::I16, false) => i64::from(u16::MAX),
|
||||
(types::I32, false) => i64::from(u32::MAX),
|
||||
(types::I64, false) => u64::MAX as i64,
|
||||
(types::I8, true) => i8::MAX as i64,
|
||||
(types::I16, true) => i16::MAX as i64,
|
||||
(types::I32, true) => i32::MAX as i64,
|
||||
(types::I8, true) => i64::from(i8::MAX),
|
||||
(types::I16, true) => i64::from(i16::MAX),
|
||||
(types::I32, true) => i64::from(i32::MAX),
|
||||
(types::I64, true) => i64::MAX,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
@ -197,7 +197,7 @@ impl<'tcx> DebugContext<'tcx> {
|
||||
|
||||
if let Some(ref mcr) = &context.mach_compile_result {
|
||||
for &MachSrcLoc { start, end, loc } in mcr.buffer.get_srclocs_sorted() {
|
||||
line_program.row().address_offset = start as u64;
|
||||
line_program.row().address_offset = u64::from(start);
|
||||
if !loc.is_default() {
|
||||
let source_info = *source_info_set.get_index(loc.bits() as usize).unwrap();
|
||||
create_row_for_span(line_program, source_info.span);
|
||||
@ -207,7 +207,7 @@ impl<'tcx> DebugContext<'tcx> {
|
||||
func_end = end;
|
||||
}
|
||||
|
||||
line_program.end_sequence(func_end as u64);
|
||||
line_program.end_sequence(u64::from(func_end));
|
||||
|
||||
func_end = mcr.buffer.total_size();
|
||||
} else {
|
||||
@ -218,7 +218,7 @@ impl<'tcx> DebugContext<'tcx> {
|
||||
for block in blocks {
|
||||
for (offset, inst, size) in func.inst_offsets(block, &encinfo) {
|
||||
let srcloc = func.srclocs[inst];
|
||||
line_program.row().address_offset = offset as u64;
|
||||
line_program.row().address_offset = u64::from(offset);
|
||||
if !srcloc.is_default() {
|
||||
let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap();
|
||||
create_row_for_span(line_program, source_info.span);
|
||||
@ -228,7 +228,7 @@ impl<'tcx> DebugContext<'tcx> {
|
||||
func_end = offset + size;
|
||||
}
|
||||
}
|
||||
line_program.end_sequence(func_end as u64);
|
||||
line_program.end_sequence(u64::from(func_end));
|
||||
}
|
||||
|
||||
assert_ne!(func_end, 0);
|
||||
@ -241,7 +241,7 @@ impl<'tcx> DebugContext<'tcx> {
|
||||
addend: 0,
|
||||
}),
|
||||
);
|
||||
entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(func_end as u64));
|
||||
entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(u64::from(func_end)));
|
||||
|
||||
self.emit_location(entry_id, function_span);
|
||||
|
||||
|
@ -433,7 +433,7 @@ fn translate_loc(isa: &dyn TargetIsa, loc: ValueLoc, stack_slots: &StackSlots) -
|
||||
ValueLoc::Stack(ss) => {
|
||||
if let Some(ss_offset) = stack_slots[ss].offset {
|
||||
let mut expr = Expression::new();
|
||||
expr.op_breg(X86_64::RBP, ss_offset as i64 + 16);
|
||||
expr.op_breg(X86_64::RBP, i64::from(ss_offset) + 16);
|
||||
Some(expr)
|
||||
} else {
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user