diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 3e6d2aa992ad..4d9021ce04ed 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -168,4 +168,6 @@ fn main() { Ordering::Less => {}, _ => assert!(false), } + + [NoisyDropInner, NoisyDropInner]; } diff --git a/src/base.rs b/src/base.rs index 1cb5f51fcf72..7b81481fb466 100644 --- a/src/base.rs +++ b/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; diff --git a/src/constant.rs b/src/constant.rs index 30dab10495f9..f962511c7000 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -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> {