@@ -20,6 +20,7 @@ use rustc_span::{DUMMY_SP, Span, Symbol, sym};
2020use rustc_trait_selection:: infer:: InferCtxtExt ;
2121use tracing:: { debug, instrument} ;
2222
23+ use crate :: builder:: matches:: util:: Range ;
2324use crate :: builder:: matches:: { Candidate , MatchPairTree , Test , TestBranch , TestCase , TestKind } ;
2425use crate :: builder:: { Builder , PlaceBuilder } ;
2526
@@ -182,8 +183,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
182183 ) ;
183184 } else if !ty. is_scalar ( ) {
184185 let ( place, block) = if let Some ( range) = range {
185- // TODO: range handling
186- assert_eq ! ( range. start, 0 ) ;
187186 let target_block = self . cfg . start_new_block ( ) ;
188187 let subslice = self . subslice (
189188 block,
@@ -192,7 +191,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
192191 place_ty. ty ,
193192 test. span ,
194193 ty. sequence_element_type ( tcx) ,
195- range. end ,
194+ range,
196195 ) ;
197196
198197 ( subslice, target_block)
@@ -319,11 +318,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
319318 input_ty : Ty < ' tcx > ,
320319 span : Span ,
321320 elem_ty : Ty < ' tcx > ,
322- new_len : u64 ,
321+ range : Range ,
323322 ) -> Place < ' tcx > {
324323 let tcx = self . tcx ;
325324 let source_info = self . source_info ( span) ;
326325
326+ // TODO: handle range.from_end == true
327+
327328 let temp_source_ptr = self . temp ( Ty :: new_ptr ( tcx, input_ty, Mutability :: Not ) , span) ;
328329 self . cfg . push_assign (
329330 block,
@@ -335,15 +336,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
335336 let elem_ptr_ty = Ty :: new_ptr ( tcx, elem_ty, Mutability :: Not ) ;
336337 let slice_ptr_ty = Ty :: new_ptr ( tcx, Ty :: new_slice ( tcx, elem_ty) , Mutability :: Not ) ;
337338
338- let temp_elem_ptr = self . temp ( elem_ptr_ty, span) ;
339+ let mut temp_elem_ptr = self . temp ( elem_ptr_ty, span) ;
339340 self . cfg . push_assign (
340341 block,
341342 source_info,
342343 temp_elem_ptr,
343344 Rvalue :: Cast ( CastKind :: PtrToPtr , Operand :: Copy ( temp_source_ptr) , elem_ptr_ty) ,
344345 ) ;
345346
346- let temp_len = self . push_usize ( block, source_info, new_len) ;
347+ if range. start != 0 {
348+ let offset = self . temp ( elem_ptr_ty, span) ;
349+ let offset_by = self . push_usize ( block, source_info, range. start ) ;
350+ self . cfg . push_assign (
351+ block,
352+ source_info,
353+ offset,
354+ Rvalue :: BinaryOp (
355+ BinOp :: Offset ,
356+ Box :: new ( ( Operand :: Copy ( temp_elem_ptr) , Operand :: Move ( offset_by) ) ) ,
357+ ) ,
358+ ) ;
359+
360+ temp_elem_ptr = offset;
361+ }
362+
363+ let temp_len = self . push_usize ( block, source_info, range. len ( ) ) ;
347364
348365 let aggregate_raw_ptr = Operand :: function_handle (
349366 tcx,
0 commit comments