@@ -20,6 +20,7 @@ use rustc_span::{DUMMY_SP, Span, Symbol, sym};
20
20
use rustc_trait_selection:: infer:: InferCtxtExt ;
21
21
use tracing:: { debug, instrument} ;
22
22
23
+ use crate :: builder:: matches:: util:: Range ;
23
24
use crate :: builder:: matches:: { Candidate , MatchPairTree , Test , TestBranch , TestCase , TestKind } ;
24
25
use crate :: builder:: { Builder , PlaceBuilder } ;
25
26
@@ -182,8 +183,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
182
183
) ;
183
184
} else if !ty. is_scalar ( ) {
184
185
let ( place, block) = if let Some ( range) = range {
185
- // TODO: range handling
186
- assert_eq ! ( range. start, 0 ) ;
187
186
let target_block = self . cfg . start_new_block ( ) ;
188
187
let subslice = self . subslice (
189
188
block,
@@ -192,7 +191,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
192
191
place_ty. ty ,
193
192
test. span ,
194
193
ty. sequence_element_type ( tcx) ,
195
- range. end ,
194
+ range,
196
195
) ;
197
196
198
197
( subslice, target_block)
@@ -319,11 +318,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
319
318
input_ty : Ty < ' tcx > ,
320
319
span : Span ,
321
320
elem_ty : Ty < ' tcx > ,
322
- new_len : u64 ,
321
+ range : Range ,
323
322
) -> Place < ' tcx > {
324
323
let tcx = self . tcx ;
325
324
let source_info = self . source_info ( span) ;
326
325
326
+ // TODO: handle range.from_end == true
327
+
327
328
let temp_source_ptr = self . temp ( Ty :: new_ptr ( tcx, input_ty, Mutability :: Not ) , span) ;
328
329
self . cfg . push_assign (
329
330
block,
@@ -335,15 +336,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
335
336
let elem_ptr_ty = Ty :: new_ptr ( tcx, elem_ty, Mutability :: Not ) ;
336
337
let slice_ptr_ty = Ty :: new_ptr ( tcx, Ty :: new_slice ( tcx, elem_ty) , Mutability :: Not ) ;
337
338
338
- let temp_elem_ptr = self . temp ( elem_ptr_ty, span) ;
339
+ let mut temp_elem_ptr = self . temp ( elem_ptr_ty, span) ;
339
340
self . cfg . push_assign (
340
341
block,
341
342
source_info,
342
343
temp_elem_ptr,
343
344
Rvalue :: Cast ( CastKind :: PtrToPtr , Operand :: Copy ( temp_source_ptr) , elem_ptr_ty) ,
344
345
) ;
345
346
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 ( ) ) ;
347
364
348
365
let aggregate_raw_ptr = Operand :: function_handle (
349
366
tcx,
0 commit comments