@@ -16,7 +16,7 @@ use rustc::mir::repr as mir;
16
16
use trans:: asm;
17
17
use trans:: base;
18
18
use trans:: callee:: Callee ;
19
- use trans:: common:: { self , BlockAndBuilder , Result } ;
19
+ use trans:: common:: { self , C_uint , BlockAndBuilder , Result } ;
20
20
use trans:: debuginfo:: DebugLoc ;
21
21
use trans:: declare;
22
22
use trans:: adt;
@@ -173,13 +173,17 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
173
173
mir:: Rvalue :: Slice { ref input, from_start, from_end } => {
174
174
let ccx = bcx. ccx ( ) ;
175
175
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) ;
183
187
let lllen1 = bcx. sub ( lllen, adj) ;
184
188
bcx. store ( llbase1, get_dataptr ( & bcx, dest. llval ) ) ;
185
189
bcx. store ( lllen1, get_meta ( & bcx, dest. llval ) ) ;
@@ -440,7 +444,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
440
444
let llty = type_of:: type_of ( bcx. ccx ( ) , content_ty) ;
441
445
let llsize = machine:: llsize_of ( bcx. ccx ( ) , llty) ;
442
446
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) ;
444
448
let llty_ptr = llty. ptr_to ( ) ;
445
449
let box_ty = bcx. tcx ( ) . mk_box ( content_ty) ;
446
450
let mut llval = None ;
0 commit comments