Skip to content

Commit 6aeb54f

Browse files
committed
mir: Translate Rvalue::Slice without relying on tvec.
1 parent 396c6e4 commit 6aeb54f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/librustc_trans/trans/mir/rvalue.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::mir::repr as mir;
1616
use trans::asm;
1717
use trans::base;
1818
use trans::callee::Callee;
19-
use trans::common::{self, BlockAndBuilder, Result};
19+
use trans::common::{self, C_uint, BlockAndBuilder, Result};
2020
use trans::debuginfo::DebugLoc;
2121
use trans::declare;
2222
use trans::adt;
@@ -173,13 +173,17 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
173173
mir::Rvalue::Slice { ref input, from_start, from_end } => {
174174
let ccx = bcx.ccx();
175175
let input = self.trans_lvalue(&bcx, input);
176-
let (llbase, lllen) = bcx.with_block(|bcx| {
177-
tvec::get_base_and_len(bcx,
178-
input.llval,
179-
input.ty.to_ty(bcx.tcx()))
180-
});
181-
let llbase1 = bcx.gepi(llbase, &[from_start]);
182-
let adj = common::C_uint(ccx, from_start + from_end);
176+
let ty = input.ty.to_ty(bcx.tcx());
177+
let (llbase1, lllen) = match ty.sty {
178+
ty::TyArray(_, n) => {
179+
(bcx.gepi(input.llval, &[0, from_start]), C_uint(ccx, n))
180+
}
181+
ty::TySlice(_) | ty::TyStr => {
182+
(bcx.gepi(input.llval, &[from_start]), input.llextra)
183+
}
184+
_ => unreachable!("cannot slice {}", ty)
185+
};
186+
let adj = C_uint(ccx, from_start + from_end);
183187
let lllen1 = bcx.sub(lllen, adj);
184188
bcx.store(llbase1, get_dataptr(&bcx, dest.llval));
185189
bcx.store(lllen1, get_meta(&bcx, dest.llval));
@@ -440,7 +444,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
440444
let llty = type_of::type_of(bcx.ccx(), content_ty);
441445
let llsize = machine::llsize_of(bcx.ccx(), llty);
442446
let align = type_of::align_of(bcx.ccx(), content_ty);
443-
let llalign = common::C_uint(bcx.ccx(), align);
447+
let llalign = C_uint(bcx.ccx(), align);
444448
let llty_ptr = llty.ptr_to();
445449
let box_ty = bcx.tcx().mk_box(content_ty);
446450
let mut llval = None;

0 commit comments

Comments
 (0)