@@ -570,17 +570,29 @@ where
570570 match & stmt. kind {
571571 StatementKind :: Assign ( assign) => {
572572 let lhs_place = assign. 0 ;
573+ let projection = lhs_place. projection ;
573574 let lhs_place_ty = lhs_place. ty ( self . body . local_decls ( ) , self . tcx ) . ty ;
574575 debug ! ( ?lhs_place, ?lhs_place_ty) ;
575576
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+ }
582592 }
583593 _ => {
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`.
584596 self . super_assign ( & assign. 0 , & assign. 1 , location) ;
585597 }
586598 }
@@ -599,12 +611,13 @@ where
599611 context : PlaceContext ,
600612 location : mir:: Location ,
601613 ) {
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) ;
604617
605- match place_ty . ty . kind ( ) {
618+ match local_ty . kind ( ) {
606619 ty:: Ref ( ..) | ty:: RawPtr ( ..) => {
607- debug ! ( "gen {:?}" , place . local) ;
620+ debug ! ( "gen {:?}" , local) ;
608621 self . _trans . gen ( place. local ) ;
609622 }
610623 _ => { }
0 commit comments