@@ -745,6 +745,26 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
745
745
use_kind, lp_base) ;
746
746
}
747
747
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
+
748
768
// assigning to `P.f` is ok if assigning to `P` is ok
749
769
self . check_if_assigned_path_is_moved ( id, span,
750
770
use_kind, lp_base) ;
@@ -775,10 +795,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
775
795
mark_variable_as_used_mut ( self , assignee_cmt) ;
776
796
}
777
797
}
798
+
778
799
return ;
779
800
}
780
801
781
- // Initializations are OK.
802
+ // Initializations are OK if and only if they aren't partial
803
+ // reinitialization of a partially-uninitialized structure.
782
804
if mode == euv:: Init {
783
805
return
784
806
}
0 commit comments