@@ -18,7 +18,7 @@ use rustc::mir::repr as mir;
18
18
use trans:: asm;
19
19
use trans:: base;
20
20
use trans:: callee:: Callee ;
21
- use trans:: common:: { self , BlockAndBuilder , Result } ;
21
+ use trans:: common:: { self , C_uint , BlockAndBuilder , Result } ;
22
22
use trans:: debuginfo:: DebugLoc ;
23
23
use trans:: declare;
24
24
use trans:: adt;
@@ -176,13 +176,17 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
176
176
mir:: Rvalue :: Slice { ref input, from_start, from_end } => {
177
177
let ccx = bcx. ccx ( ) ;
178
178
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) ;
186
190
let lllen1 = bcx. sub ( lllen, adj) ;
187
191
bcx. store ( llbase1, get_dataptr ( & bcx, dest. llval ) ) ;
188
192
bcx. store ( lllen1, get_meta ( & bcx, dest. llval ) ) ;
@@ -443,7 +447,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
443
447
let llty = type_of:: type_of ( bcx. ccx ( ) , content_ty) ;
444
448
let llsize = machine:: llsize_of ( bcx. ccx ( ) , llty) ;
445
449
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) ;
447
451
let llty_ptr = llty. ptr_to ( ) ;
448
452
let box_ty = bcx. tcx ( ) . mk_box ( content_ty) ;
449
453
let mut llval = None ;
0 commit comments