@@ -475,6 +475,34 @@ enum WriteKind {
475
475
Move ,
476
476
}
477
477
478
+ #[ derive( Copy , Clone ) ]
479
+ enum InitializationRequiringAction {
480
+ Update ,
481
+ Borrow ,
482
+ Use ,
483
+ Assignment ,
484
+ }
485
+
486
+ impl InitializationRequiringAction {
487
+ fn as_noun ( self ) -> & ' static str {
488
+ match self {
489
+ InitializationRequiringAction :: Update => "update" ,
490
+ InitializationRequiringAction :: Borrow => "borrow" ,
491
+ InitializationRequiringAction :: Use => "use" ,
492
+ InitializationRequiringAction :: Assignment => "assign"
493
+ }
494
+ }
495
+
496
+ fn as_verb_in_past_tense ( self ) -> & ' static str {
497
+ match self {
498
+ InitializationRequiringAction :: Update => "updated" ,
499
+ InitializationRequiringAction :: Borrow => "borrowed" ,
500
+ InitializationRequiringAction :: Use => "used" ,
501
+ InitializationRequiringAction :: Assignment => "assigned"
502
+ }
503
+ }
504
+ }
505
+
478
506
impl < ' cx , ' gcx , ' tcx > MirBorrowckCtxt < ' cx , ' gcx , ' tcx > {
479
507
/// Checks an access to the given lvalue to see if it is allowed. Examines the set of borrows
480
508
/// that are in scope, as well as which paths have been initialized, to ensure that (a) the
@@ -565,7 +593,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
565
593
// Write of P[i] or *P, or WriteAndRead of any P, requires P init'd.
566
594
match mode {
567
595
MutateMode :: WriteAndRead => {
568
- self . check_if_path_is_moved ( context, "update" , lvalue_span, flow_state) ;
596
+ self . check_if_path_is_moved ( context, InitializationRequiringAction :: Update ,
597
+ lvalue_span, flow_state) ;
569
598
}
570
599
MutateMode :: JustWrite => {
571
600
self . check_if_assigned_path_is_moved ( context, lvalue_span, flow_state) ;
@@ -591,7 +620,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
591
620
BorrowKind :: Mut => ( Deep , Write ( WriteKind :: MutableBorrow ( bk) ) ) ,
592
621
} ;
593
622
self . access_lvalue ( context, ( lvalue, span) , access_kind, flow_state) ;
594
- self . check_if_path_is_moved ( context, "borrow" , ( lvalue, span) , flow_state) ;
623
+ self . check_if_path_is_moved ( context, InitializationRequiringAction :: Borrow ,
624
+ ( lvalue, span) , flow_state) ;
595
625
}
596
626
597
627
Rvalue :: Use ( ref operand) |
@@ -610,7 +640,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
610
640
} ;
611
641
self . access_lvalue (
612
642
context, ( lvalue, span) , ( Shallow ( Some ( af) ) , Read ( ReadKind :: Copy ) ) , flow_state) ;
613
- self . check_if_path_is_moved ( context, "use" , ( lvalue, span) , flow_state) ;
643
+ self . check_if_path_is_moved ( context, InitializationRequiringAction :: Use ,
644
+ ( lvalue, span) , flow_state) ;
614
645
}
615
646
616
647
Rvalue :: BinaryOp ( _bin_op, ref operand1, ref operand2) |
@@ -711,7 +742,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
711
742
// skip this check in that case).
712
743
}
713
744
ConsumeKind :: Consume => {
714
- self . check_if_path_is_moved ( context, "use" , lvalue_span, flow_state) ;
745
+ self . check_if_path_is_moved ( context, InitializationRequiringAction :: Use ,
746
+ lvalue_span, flow_state) ;
715
747
}
716
748
}
717
749
}
@@ -772,7 +804,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
772
804
773
805
fn check_if_path_is_moved ( & mut self ,
774
806
context : Context ,
775
- desired_action : & str ,
807
+ desired_action : InitializationRequiringAction ,
776
808
lvalue_span : ( & Lvalue < ' tcx > , Span ) ,
777
809
flow_state : & InProgress < ' cx , ' gcx , ' tcx > ) {
778
810
// FIXME: analogous code in check_loans first maps `lvalue` to
@@ -943,7 +975,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
943
975
// `base` to its base_path.
944
976
945
977
self . check_if_path_is_moved (
946
- context, "assignment" , ( base, span) , flow_state) ;
978
+ context, InitializationRequiringAction :: Assignment ,
979
+ ( base, span) , flow_state) ;
947
980
948
981
// (base initialized; no need to
949
982
// recur further)
@@ -1347,7 +1380,7 @@ mod prefixes {
1347
1380
impl < ' cx , ' gcx , ' tcx > MirBorrowckCtxt < ' cx , ' gcx , ' tcx > {
1348
1381
fn report_use_of_moved_or_uninitialized ( & mut self ,
1349
1382
_context : Context ,
1350
- desired_action : & str ,
1383
+ desired_action : InitializationRequiringAction ,
1351
1384
( lvalue, span) : ( & Lvalue < ' tcx > , Span ) ,
1352
1385
mpi : MovePathIndex ,
1353
1386
curr_move_out : & IdxSetBuf < MoveOutIndex > ) {
@@ -1357,7 +1390,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1357
1390
1358
1391
if mois. is_empty ( ) {
1359
1392
self . tcx . cannot_act_on_uninitialized_variable ( span,
1360
- desired_action,
1393
+ desired_action. as_noun ( ) ,
1361
1394
& self . describe_lvalue ( lvalue) ,
1362
1395
Origin :: Mir )
1363
1396
. span_label ( span, format ! ( "use of possibly uninitialized `{}`" ,
@@ -1367,11 +1400,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1367
1400
let msg = "" ; //FIXME: add "partially " or "collaterally "
1368
1401
1369
1402
let mut err = self . tcx . cannot_act_on_moved_value ( span,
1370
- desired_action,
1403
+ desired_action. as_noun ( ) ,
1371
1404
msg,
1372
1405
& self . describe_lvalue ( lvalue) ,
1373
1406
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( ) ) ) ;
1375
1410
for moi in mois {
1376
1411
let move_msg = "" ; //FIXME: add " (into closure)"
1377
1412
let move_span = self . mir . source_info ( self . move_data . moves [ * moi] . source ) . span ;
0 commit comments