@@ -267,10 +267,10 @@ fn trans_stmt<'tcx>(
267
267
let place = trans_place ( fx, place) ;
268
268
crate :: discriminant:: codegen_set_discriminant ( fx, place, * variant_index) ;
269
269
}
270
- StatementKind :: Assign ( to_place , rval ) => {
271
- let lval = trans_place ( fx, to_place ) ;
270
+ StatementKind :: Assign ( to_place_and_rval ) => {
271
+ let lval = trans_place ( fx, & to_place_and_rval . 0 ) ;
272
272
let dest_layout = lval. layout ( ) ;
273
- match & * * rval {
273
+ match & to_place_and_rval . 1 {
274
274
Rvalue :: Use ( operand) => {
275
275
let val = trans_operand ( fx, operand) ;
276
276
lval. write_cvalue ( fx, val) ;
@@ -506,7 +506,7 @@ fn trans_stmt<'tcx>(
506
506
to. write_cvalue ( fx, operand) ;
507
507
}
508
508
}
509
- _ => unimpl ! ( "shouldn't exist at trans {:?}" , rval ) ,
509
+ _ => unimpl ! ( "shouldn't exist at trans {:?}" , to_place_and_rval . 1 ) ,
510
510
} ,
511
511
}
512
512
}
@@ -606,7 +606,7 @@ pub fn trans_place<'tcx>(
606
606
fx : & mut FunctionCx < ' _ , ' tcx , impl Backend > ,
607
607
place : & Place < ' tcx > ,
608
608
) -> CPlace < ' tcx > {
609
- let base = match & place. base {
609
+ let mut cplace = match & place. base {
610
610
PlaceBase :: Local ( local) => fx. get_local_place ( * local) ,
611
611
PlaceBase :: Static ( static_) => match static_. kind {
612
612
StaticKind :: Static => {
@@ -619,76 +619,70 @@ pub fn trans_place<'tcx>(
619
619
} ,
620
620
} ;
621
621
622
- trans_place_projection ( fx, base, & place. projection )
623
- }
624
-
625
- pub fn trans_place_projection < ' tcx > (
626
- fx : & mut FunctionCx < ' _ , ' tcx , impl Backend > ,
627
- base : CPlace < ' tcx > ,
628
- projection : & Option < Box < Projection < ' tcx > > > ,
629
- ) -> CPlace < ' tcx > {
630
- let projection = if let Some ( projection) = projection {
631
- projection
632
- } else {
633
- return base;
634
- } ;
635
-
636
- let base = trans_place_projection ( fx, base, & projection. base ) ;
637
-
638
- match projection. elem {
639
- ProjectionElem :: Deref => base. place_deref ( fx) ,
640
- ProjectionElem :: Field ( field, _ty) => base. place_field ( fx, field) ,
641
- ProjectionElem :: Index ( local) => {
642
- let index = fx. get_local_place ( local) . to_cvalue ( fx) . load_scalar ( fx) ;
643
- base. place_index ( fx, index)
644
- }
645
- ProjectionElem :: ConstantIndex {
646
- offset,
647
- min_length : _,
648
- from_end,
649
- } => {
650
- let index = if !from_end {
651
- fx. bcx . ins ( ) . iconst ( fx. pointer_type , offset as i64 )
652
- } else {
653
- let len = codegen_array_len ( fx, base) ;
654
- fx. bcx . ins ( ) . iadd_imm ( len, -( offset as i64 ) )
655
- } ;
656
- base. place_index ( fx, index)
657
- }
658
- ProjectionElem :: Subslice { from, to } => {
659
- // These indices are generated by slice patterns.
660
- // slice[from:-to] in Python terms.
661
-
662
- match base. layout ( ) . ty . sty {
663
- ty:: Array ( elem_ty, len) => {
664
- let elem_layout = fx. layout_of ( elem_ty) ;
665
- let ptr = base. to_addr ( fx) ;
666
- let len = crate :: constant:: force_eval_const ( fx, len)
667
- . eval_usize ( fx. tcx , ParamEnv :: reveal_all ( ) ) ;
668
- CPlace :: for_addr (
669
- fx. bcx
670
- . ins ( )
671
- . iadd_imm ( ptr, elem_layout. size . bytes ( ) as i64 * from as i64 ) ,
672
- fx. layout_of ( fx. tcx . mk_array ( elem_ty, len - from as u64 - to as u64 ) ) ,
673
- )
674
- }
675
- ty:: Slice ( elem_ty) => {
676
- let elem_layout = fx. layout_of ( elem_ty) ;
677
- let ( ptr, len) = base. to_addr_maybe_unsized ( fx) ;
678
- let len = len. unwrap ( ) ;
679
- CPlace :: for_addr_with_extra (
680
- fx. bcx
681
- . ins ( )
682
- . iadd_imm ( ptr, elem_layout. size . bytes ( ) as i64 * from as i64 ) ,
683
- fx. bcx . ins ( ) . iadd_imm ( len, -( from as i64 + to as i64 ) ) ,
684
- base. layout ( ) ,
685
- )
622
+ for elem in & * place. projection {
623
+ match * elem {
624
+ PlaceElem :: Deref => {
625
+ cplace = cplace. place_deref ( fx) ;
626
+ }
627
+ PlaceElem :: Field ( field, _ty) => {
628
+ cplace = cplace. place_field ( fx, field) ;
629
+ }
630
+ PlaceElem :: Index ( local) => {
631
+ let index = fx. get_local_place ( local) . to_cvalue ( fx) . load_scalar ( fx) ;
632
+ cplace = cplace. place_index ( fx, index) ;
633
+ }
634
+ PlaceElem :: ConstantIndex {
635
+ offset,
636
+ min_length : _,
637
+ from_end,
638
+ } => {
639
+ let index = if !from_end {
640
+ fx. bcx . ins ( ) . iconst ( fx. pointer_type , offset as i64 )
641
+ } else {
642
+ let len = codegen_array_len ( fx, cplace) ;
643
+ fx. bcx . ins ( ) . iadd_imm ( len, -( offset as i64 ) )
644
+ } ;
645
+ cplace = cplace. place_index ( fx, index) ;
646
+ }
647
+ PlaceElem :: Subslice { from, to } => {
648
+ // These indices are generated by slice patterns.
649
+ // slice[from:-to] in Python terms.
650
+
651
+ match cplace. layout ( ) . ty . sty {
652
+ ty:: Array ( elem_ty, len) => {
653
+ let elem_layout = fx. layout_of ( elem_ty) ;
654
+ let ptr = cplace. to_addr ( fx) ;
655
+ let len = crate :: constant:: force_eval_const ( fx, len)
656
+ . eval_usize ( fx. tcx , ParamEnv :: reveal_all ( ) ) ;
657
+ cplace = CPlace :: for_addr (
658
+ fx. bcx
659
+ . ins ( )
660
+ . iadd_imm ( ptr, elem_layout. size . bytes ( ) as i64 * from as i64 ) ,
661
+ fx. layout_of ( fx. tcx . mk_array ( elem_ty, len - from as u64 - to as u64 ) ) ,
662
+ ) ;
663
+ }
664
+ ty:: Slice ( elem_ty) => {
665
+ let elem_layout = fx. layout_of ( elem_ty) ;
666
+ let ( ptr, len) = cplace. to_addr_maybe_unsized ( fx) ;
667
+ let len = len. unwrap ( ) ;
668
+ cplace = CPlace :: for_addr_with_extra (
669
+ fx. bcx
670
+ . ins ( )
671
+ . iadd_imm ( ptr, elem_layout. size . bytes ( ) as i64 * from as i64 ) ,
672
+ fx. bcx . ins ( ) . iadd_imm ( len, -( from as i64 + to as i64 ) ) ,
673
+ cplace. layout ( ) ,
674
+ ) ;
675
+ }
676
+ _ => unreachable ! ( ) ,
686
677
}
687
- _ => unreachable ! ( ) ,
678
+ }
679
+ PlaceElem :: Downcast ( _adt_def, variant) => {
680
+ cplace = cplace. downcast_variant ( fx, variant) ;
688
681
}
689
682
}
690
- ProjectionElem :: Downcast ( _adt_def, variant) => base. downcast_variant ( fx, variant) ,
691
683
}
684
+
685
+ cplace
692
686
}
693
687
694
688
pub fn trans_operand < ' tcx > (
0 commit comments