@@ -484,6 +484,34 @@ enum WriteKind {
484
484
Move ,
485
485
}
486
486
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
+
487
515
impl < ' cx , ' gcx , ' tcx > MirBorrowckCtxt < ' cx , ' gcx , ' tcx > {
488
516
/// Checks an access to the given lvalue to see if it is allowed. Examines the set of borrows
489
517
/// 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> {
574
602
// Write of P[i] or *P, or WriteAndRead of any P, requires P init'd.
575
603
match mode {
576
604
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) ;
578
607
}
579
608
MutateMode :: JustWrite => {
580
609
self . check_if_assigned_path_is_moved ( context, lvalue_span, flow_state) ;
@@ -600,7 +629,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
600
629
BorrowKind :: Mut => ( Deep , Write ( WriteKind :: MutableBorrow ( bk) ) ) ,
601
630
} ;
602
631
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) ;
604
634
}
605
635
606
636
Rvalue :: Use ( ref operand) |
@@ -619,7 +649,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
619
649
} ;
620
650
self . access_lvalue (
621
651
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) ;
623
654
}
624
655
625
656
Rvalue :: BinaryOp ( _bin_op, ref operand1, ref operand2) |
@@ -720,7 +751,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
720
751
// skip this check in that case).
721
752
}
722
753
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) ;
724
756
}
725
757
}
726
758
}
@@ -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