Skip to content

Commit 2fedbd3

Browse files
committed
Improve PlaceElem::Subslice handling
1 parent 084a1be commit 2fedbd3

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/base.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,10 @@ pub fn trans_place<'tcx>(
678678
// slice[from:-to] in Python terms.
679679

680680
match cplace.layout().ty.kind {
681-
ty::Array(elem_ty, len) => {
681+
ty::Array(elem_ty, _len) => {
682+
assert!(!from_end, "array subslices are never `from_end`");
682683
let elem_layout = fx.layout_of(elem_ty);
683684
let ptr = cplace.to_ptr(fx);
684-
let len = crate::constant::force_eval_const(fx, len)
685-
.eval_usize(fx.tcx, ParamEnv::reveal_all());
686685
cplace = CPlace::for_ptr(
687686
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),
688687
fx.layout_of(fx.tcx.mk_array(elem_ty, to as u64 - from as u64)),
@@ -691,11 +690,10 @@ pub fn trans_place<'tcx>(
691690
ty::Slice(elem_ty) => {
692691
assert!(from_end, "slice subslices should be `from_end`");
693692
let elem_layout = fx.layout_of(elem_ty);
694-
let (ptr, len) = cplace.to_ptr_maybe_unsized(fx);
695-
let len = len.unwrap();
693+
let (ptr, _len) = cplace.to_ptr_maybe_unsized(fx);
696694
cplace = CPlace::for_ptr_with_extra(
697695
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * from as i64),
698-
fx.bcx.ins().iadd_imm(len, -(from as i64 + to as i64)),
696+
fx.bcx.ins().iconst(pointer_ty(fx.tcx), (to as u64 - from as u64) as i64),
699697
cplace.layout(),
700698
);
701699
}

0 commit comments

Comments
 (0)