@@ -220,6 +220,12 @@ enum UseError<'tcx> {
220
220
UseWhileBorrowed ( /*loan*/ Rc < LoanPath < ' tcx > > , /*loan*/ Span )
221
221
}
222
222
223
+ #[ derive( Debug ) ]
224
+ enum AssignError {
225
+ Moved ,
226
+ PartialReinit
227
+ }
228
+
223
229
fn compatible_borrow_kinds ( borrow_kind1 : ty:: BorrowKind ,
224
230
borrow_kind2 : ty:: BorrowKind )
225
231
-> bool {
@@ -690,26 +696,41 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
690
696
return ret;
691
697
}
692
698
699
+ fn report_if_path_is_moved ( & self ,
700
+ id : ast:: NodeId ,
701
+ span : Span ,
702
+ use_kind : MovedValueUseKind ,
703
+ lp : & Rc < LoanPath < ' tcx > > ,
704
+ err_kind : AssignError ) {
705
+ use self :: AssignError :: * ;
706
+ debug ! ( "report_if_moved(id={}, use_kind={:?}, lp={}, err_kind={:?})" ,
707
+ id, use_kind, lp. repr( self . bccx. tcx) , err_kind) ;
708
+
709
+ let base_lp = owned_ptr_base_path_rc ( lp) ;
710
+ self . move_data . each_move_of ( id, & base_lp, |the_move, moved_lp| {
711
+ match err_kind {
712
+ Moved => self . bccx . report_use_of_moved_value (
713
+ span, use_kind, & * * lp, the_move, moved_lp, self . param_env ) ,
714
+ PartialReinit => {
715
+ self . bccx
716
+ . report_partial_reinitialization_of_uninitialized_structure (
717
+ span, & * lp)
718
+ }
719
+ } ;
720
+
721
+ false
722
+ } ) ;
723
+
724
+ }
725
+
693
726
/// Reports an error if `expr` (which should be a path)
694
727
/// is using a moved/uninitialized value
695
728
fn check_if_path_is_moved ( & self ,
696
729
id : ast:: NodeId ,
697
730
span : Span ,
698
731
use_kind : MovedValueUseKind ,
699
732
lp : & Rc < LoanPath < ' tcx > > ) {
700
- debug ! ( "check_if_path_is_moved(id={}, use_kind={:?}, lp={})" ,
701
- id, use_kind, lp. repr( self . bccx. tcx) ) ;
702
- let base_lp = owned_ptr_base_path_rc ( lp) ;
703
- self . move_data . each_move_of ( id, & base_lp, |the_move, moved_lp| {
704
- self . bccx . report_use_of_moved_value (
705
- span,
706
- use_kind,
707
- & * * lp,
708
- the_move,
709
- moved_lp,
710
- self . param_env ) ;
711
- false
712
- } ) ;
733
+ self . report_if_path_is_moved ( id, span, use_kind, lp, AssignError :: Moved ) ;
713
734
}
714
735
715
736
/// Reports an error if assigning to `lp` will use a
@@ -747,19 +768,13 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
747
768
LpExtend ( ref lp_base, _, LpInterior ( InteriorField ( _) ) ) => {
748
769
match lp_base. to_type ( ) . sty {
749
770
ty:: ty_struct( def_id, _) | ty:: ty_enum( def_id, _) => {
771
+ // In the case where the owner implements drop, then
772
+ // the path must be initialized to prevent a case of
773
+ // partial reinitialization
750
774
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 ;
775
+ return self . report_if_path_is_moved ( id, span,
776
+ use_kind, lp_base,
777
+ AssignError :: PartialReinit ) ;
763
778
}
764
779
} ,
765
780
_ => { } ,
0 commit comments