@@ -745,6 +745,26 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
745745 use_kind, lp_base) ;
746746 }
747747 LpExtend ( ref lp_base, _, LpInterior ( InteriorField ( _) ) ) => {
748+ match lp_base. to_type ( ) . sty {
749+ ty:: ty_struct( def_id, _) | ty:: ty_enum( def_id, _) => {
750+ if ty:: has_dtor ( self . tcx ( ) , def_id) {
751+ // In the case where the owner implements drop, then
752+ // the path must be initialized to prevent a case of
753+ // partial reinitialization
754+ let loan_path = owned_ptr_base_path_rc ( lp_base) ;
755+ self . move_data . each_move_of ( id, & loan_path, |_, _| {
756+ self . bccx
757+ . report_partial_reinitialization_of_uninitialized_structure (
758+ span,
759+ & * loan_path) ;
760+ false
761+ } ) ;
762+ return ;
763+ }
764+ } ,
765+ _ => { } ,
766+ }
767+
748768 // assigning to `P.f` is ok if assigning to `P` is ok
749769 self . check_if_assigned_path_is_moved ( id, span,
750770 use_kind, lp_base) ;
@@ -775,10 +795,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
775795 mark_variable_as_used_mut ( self , assignee_cmt) ;
776796 }
777797 }
798+
778799 return ;
779800 }
780801
781- // Initializations are OK.
802+ // Initializations are OK if and only if they aren't partial
803+ // reinitialization of a partially-uninitialized structure.
782804 if mode == euv:: Init {
783805 return
784806 }
0 commit comments