Skip to content

Commit 415d95f

Browse files
committed
mir: Translate Rvalue::Slice without relying on tvec.
1 parent aca4f93 commit 415d95f

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
@@ -18,7 +18,7 @@ use rustc::mir::repr as mir;
1818
use trans::asm;
1919
use trans::base;
2020
use trans::callee::Callee;
21-
use trans::common::{self, BlockAndBuilder, Result};
21+
use trans::common::{self, C_uint, BlockAndBuilder, Result};
2222
use trans::debuginfo::DebugLoc;
2323
use trans::declare;
2424
use trans::adt;
@@ -176,13 +176,17 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
176176
mir::Rvalue::Slice { ref input, from_start, from_end } => {
177177
let ccx = bcx.ccx();
178178
let input = self.trans_lvalue(&bcx, input);
179-
let (llbase, lllen) = bcx.with_block(|bcx| {
180-
tvec::get_base_and_len(bcx,
181-
input.llval,
182-
input.ty.to_ty(bcx.tcx()))
183-
});
184-
let llbase1 = bcx.gepi(llbase, &[from_start]);
185-
let adj = common::C_uint(ccx, from_start + from_end);
179+
let ty = input.ty.to_ty(bcx.tcx());
180+
let (llbase1, lllen) = match ty.sty {
181+
ty::TyArray(_, n) => {
182+
(bcx.gepi(input.llval, &[0, from_start]), C_uint(ccx, n))
183+
}
184+
ty::TySlice(_) | ty::TyStr => {
185+
(bcx.gepi(input.llval, &[from_start]), input.llextra)
186+
}
187+
_ => unreachable!("cannot slice {}", ty)
188+
};
189+
let adj = C_uint(ccx, from_start + from_end);
186190
let lllen1 = bcx.sub(lllen, adj);
187191
bcx.store(llbase1, get_dataptr(&bcx, dest.llval));
188192
bcx.store(lllen1, get_meta(&bcx, dest.llval));
@@ -443,7 +447,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
443447
let llty = type_of::type_of(bcx.ccx(), content_ty);
444448
let llsize = machine::llsize_of(bcx.ccx(), llty);
445449
let align = type_of::align_of(bcx.ccx(), content_ty);
446-
let llalign = common::C_uint(bcx.ccx(), align);
450+
let llalign = C_uint(bcx.ccx(), align);
447451
let llty_ptr = llty.ptr_to();
448452
let box_ty = bcx.tcx().mk_box(content_ty);
449453
let mut llval = None;

0 commit comments

Comments
 (0)