@@ -484,6 +484,34 @@ enum WriteKind {
484484 Move ,
485485}
486486
487+ #[ derive( Copy , Clone ) ]
488+ enum InitializationRequiringAction {
489+ Update ,
490+ Borrow ,
491+ Use ,
492+ Assignment ,
493+ }
494+
495+ impl InitializationRequiringAction {
496+ fn as_noun ( self ) -> & ' static str {
497+ match self {
498+ InitializationRequiringAction :: Update => "update" ,
499+ InitializationRequiringAction :: Borrow => "borrow" ,
500+ InitializationRequiringAction :: Use => "use" ,
501+ InitializationRequiringAction :: Assignment => "assign"
502+ }
503+ }
504+
505+ fn as_verb_in_past_tense ( self ) -> & ' static str {
506+ match self {
507+ InitializationRequiringAction :: Update => "updated" ,
508+ InitializationRequiringAction :: Borrow => "borrowed" ,
509+ InitializationRequiringAction :: Use => "used" ,
510+ InitializationRequiringAction :: Assignment => "assigned"
511+ }
512+ }
513+ }
514+
487515impl < ' cx , ' gcx , ' tcx > MirBorrowckCtxt < ' cx , ' gcx , ' tcx > {
488516 /// Checks an access to the given lvalue to see if it is allowed. Examines the set of borrows
489517 /// that are in scope, as well as which paths have been initialized, to ensure that (a) the
@@ -574,7 +602,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
574602 // Write of P[i] or *P, or WriteAndRead of any P, requires P init'd.
575603 match mode {
576604 MutateMode :: WriteAndRead => {
577- self . check_if_path_is_moved ( context, "update" , lvalue_span, flow_state) ;
605+ self . check_if_path_is_moved ( context, InitializationRequiringAction :: Update ,
606+ lvalue_span, flow_state) ;
578607 }
579608 MutateMode :: JustWrite => {
580609 self . check_if_assigned_path_is_moved ( context, lvalue_span, flow_state) ;
@@ -600,7 +629,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
600629 BorrowKind :: Mut => ( Deep , Write ( WriteKind :: MutableBorrow ( bk) ) ) ,
601630 } ;
602631 self . access_lvalue ( context, ( lvalue, span) , access_kind, flow_state) ;
603- self . check_if_path_is_moved ( context, "borrow" , ( lvalue, span) , flow_state) ;
632+ self . check_if_path_is_moved ( context, InitializationRequiringAction :: Borrow ,
633+ ( lvalue, span) , flow_state) ;
604634 }
605635
606636 Rvalue :: Use ( ref operand) |
@@ -619,7 +649,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
619649 } ;
620650 self . access_lvalue (
621651 context, ( lvalue, span) , ( Shallow ( Some ( af) ) , Read ( ReadKind :: Copy ) ) , flow_state) ;
622- self . check_if_path_is_moved ( context, "use" , ( lvalue, span) , flow_state) ;
652+ self . check_if_path_is_moved ( context, InitializationRequiringAction :: Use ,
653+ ( lvalue, span) , flow_state) ;
623654 }
624655
625656 Rvalue :: BinaryOp ( _bin_op, ref operand1, ref operand2) |
@@ -720,7 +751,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
720751 // skip this check in that case).
721752 }
722753 ConsumeKind :: Consume => {
723- self . check_if_path_is_moved ( context, "use" , lvalue_span, flow_state) ;
754+ self . check_if_path_is_moved ( context, InitializationRequiringAction :: Use ,
755+ lvalue_span, flow_state) ;
724756 }
725757 }
726758 }
@@ -772,7 +804,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
772804
773805 fn check_if_path_is_moved ( & mut self ,
774806 context : Context ,
775- desired_action : & str ,
807+ desired_action : InitializationRequiringAction ,
776808 lvalue_span : ( & Lvalue < ' tcx > , Span ) ,
777809 flow_state : & InProgress < ' cx , ' gcx , ' tcx > ) {
778810 // FIXME: analogous code in check_loans first maps `lvalue` to
@@ -943,7 +975,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
943975 // `base` to its base_path.
944976
945977 self . check_if_path_is_moved (
946- context, "assignment" , ( base, span) , flow_state) ;
978+ context, InitializationRequiringAction :: Assignment ,
979+ ( base, span) , flow_state) ;
947980
948981 // (base initialized; no need to
949982 // recur further)
@@ -1347,7 +1380,7 @@ mod prefixes {
13471380impl < ' cx , ' gcx , ' tcx > MirBorrowckCtxt < ' cx , ' gcx , ' tcx > {
13481381 fn report_use_of_moved_or_uninitialized ( & mut self ,
13491382 _context : Context ,
1350- desired_action : & str ,
1383+ desired_action : InitializationRequiringAction ,
13511384 ( lvalue, span) : ( & Lvalue < ' tcx > , Span ) ,
13521385 mpi : MovePathIndex ,
13531386 curr_move_out : & IdxSetBuf < MoveOutIndex > ) {
@@ -1357,7 +1390,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13571390
13581391 if mois. is_empty ( ) {
13591392 self . tcx . cannot_act_on_uninitialized_variable ( span,
1360- desired_action,
1393+ desired_action. as_noun ( ) ,
13611394 & self . describe_lvalue ( lvalue) ,
13621395 Origin :: Mir )
13631396 . span_label ( span, format ! ( "use of possibly uninitialized `{}`" ,
@@ -1367,11 +1400,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13671400 let msg = "" ; //FIXME: add "partially " or "collaterally "
13681401
13691402 let mut err = self . tcx . cannot_act_on_moved_value ( span,
1370- desired_action,
1403+ desired_action. as_noun ( ) ,
13711404 msg,
13721405 & self . describe_lvalue ( lvalue) ,
13731406 Origin :: Mir ) ;
1374- err. span_label ( span, format ! ( "value {} here after move" , desired_action) ) ;
1407+
1408+ err. span_label ( span, format ! ( "value {} here after move" ,
1409+ desired_action. as_verb_in_past_tense( ) ) ) ;
13751410 for moi in mois {
13761411 let move_msg = "" ; //FIXME: add " (into closure)"
13771412 let move_span = self . mir . source_info ( self . move_data . moves [ * moi] . source ) . span ;
0 commit comments