@@ -570,17 +570,29 @@ where
570
570
match & stmt. kind {
571
571
StatementKind :: Assign ( assign) => {
572
572
let lhs_place = assign. 0 ;
573
+ let projection = lhs_place. projection ;
573
574
let lhs_place_ty = lhs_place. ty ( self . body . local_decls ( ) , self . tcx ) . ty ;
574
575
debug ! ( ?lhs_place, ?lhs_place_ty) ;
575
576
576
- match lhs_place_ty. kind ( ) {
577
- ty:: Ref ( ..) | ty:: RawPtr ( ..) => {
578
- debug ! ( "killing {:?}" , lhs_place. local) ;
579
- self . _trans . kill ( lhs_place. local ) ;
580
-
581
- self . visit_rvalue ( & assign. 1 , location) ;
577
+ match projection. as_slice ( ) {
578
+ & [ ] | & [ ProjectionElem :: OpaqueCast ( _) ] => {
579
+ // If there aren't any projections or just an OpaqueCast we need to
580
+ // kill the local if it's a ref or a pointer.
581
+ match lhs_place_ty. kind ( ) {
582
+ ty:: Ref ( ..) | ty:: RawPtr ( ..) => {
583
+ debug ! ( "killing {:?}" , lhs_place. local) ;
584
+ self . _trans . kill ( lhs_place. local ) ;
585
+
586
+ self . visit_rvalue ( & assign. 1 , location) ;
587
+ }
588
+ _ => {
589
+ self . super_assign ( & assign. 0 , & assign. 1 , location) ;
590
+ }
591
+ }
582
592
}
583
593
_ => {
594
+ // With any other projection elements a projection of a local (of type ref/ptr)
595
+ // is actually a use-site, but we handle this in the call to `visit_place`.
584
596
self . super_assign ( & assign. 0 , & assign. 1 , location) ;
585
597
}
586
598
}
@@ -599,12 +611,13 @@ where
599
611
context : PlaceContext ,
600
612
location : mir:: Location ,
601
613
) {
602
- let place_ty = place. ty ( self . body . local_decls ( ) , self . tcx ) ;
603
- debug ! ( ?place_ty) ;
614
+ let local = place. local ;
615
+ let local_ty = self . body . local_decls ( ) [ local] . ty ;
616
+ debug ! ( ?local_ty) ;
604
617
605
- match place_ty . ty . kind ( ) {
618
+ match local_ty . kind ( ) {
606
619
ty:: Ref ( ..) | ty:: RawPtr ( ..) => {
607
- debug ! ( "gen {:?}" , place . local) ;
620
+ debug ! ( "gen {:?}" , local) ;
608
621
self . _trans . gen ( place. local ) ;
609
622
}
610
623
_ => { }
0 commit comments