Implement Rvalue::Len for arrays
This commit is contained in:
parent
2cf7a64021
commit
f4e544894a
3 changed files with 15 additions and 6 deletions
|
@ -168,4 +168,6 @@ fn main() {
|
|||
Ordering::Less => {},
|
||||
_ => assert!(false),
|
||||
}
|
||||
|
||||
[NoisyDropInner, NoisyDropInner];
|
||||
}
|
||||
|
|
17
src/base.rs
17
src/base.rs
|
@ -589,12 +589,19 @@ fn trans_stmt<'a, 'tcx: 'a>(
|
|||
}
|
||||
Rvalue::Len(place) => {
|
||||
let place = trans_place(fx, place);
|
||||
let size = match place {
|
||||
CPlace::Addr(_, size, _) => size.unwrap(),
|
||||
CPlace::Var(_, _) => unreachable!(),
|
||||
};
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
lval.write_cvalue(fx, CValue::ByVal(size, usize_layout));
|
||||
let len = match place.layout().ty.sty {
|
||||
ty::Array(_elem_ty, len) => {
|
||||
let len = crate::constant::force_eval_const(fx, len).unwrap_usize(fx.tcx) as i64;
|
||||
fx.bcx.ins().iconst(fx.module.pointer_type(), len)
|
||||
},
|
||||
ty::Slice(_elem_ty) => match place {
|
||||
CPlace::Addr(_, size, _) => size.unwrap(),
|
||||
CPlace::Var(_, _) => unreachable!(),
|
||||
}
|
||||
_ => bug!("Rvalue::Len({:?})", place),
|
||||
};
|
||||
lval.write_cvalue(fx, CValue::ByVal(len, usize_layout));
|
||||
}
|
||||
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
|
||||
use crate::rustc::middle::lang_items::ExchangeMallocFnLangItem;
|
||||
|
|
|
@ -67,7 +67,7 @@ pub fn trans_constant<'a, 'tcx: 'a>(
|
|||
trans_const_value(fx, const_)
|
||||
}
|
||||
|
||||
fn force_eval_const<'a, 'tcx: 'a>(
|
||||
pub fn force_eval_const<'a, 'tcx: 'a>(
|
||||
fx: &FunctionCx<'a, 'tcx, impl Backend>,
|
||||
const_: &'tcx Const<'tcx>,
|
||||
) -> &'tcx Const<'tcx> {
|
||||
|
|
Loading…
Add table
Reference in a new issue