@@ -343,6 +343,7 @@ fn do_mir_borrowck<'tcx>(
343
343
next_region_name : RefCell :: new ( 1 ) ,
344
344
polonius_output : None ,
345
345
errors,
346
+ to_skip : Default :: default ( ) ,
346
347
} ;
347
348
promoted_mbcx. report_move_errors ( move_errors) ;
348
349
errors = promoted_mbcx. errors ;
@@ -374,6 +375,7 @@ fn do_mir_borrowck<'tcx>(
374
375
next_region_name : RefCell :: new ( 1 ) ,
375
376
polonius_output,
376
377
errors,
378
+ to_skip : Default :: default ( ) ,
377
379
} ;
378
380
379
381
// Compute and report region errors, if any.
@@ -556,6 +558,8 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
556
558
polonius_output : Option < Rc < PoloniusOutput > > ,
557
559
558
560
errors : error:: BorrowckErrors < ' tcx > ,
561
+
562
+ to_skip : FxHashSet < Location > ,
559
563
}
560
564
561
565
// Check that:
@@ -580,8 +584,9 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
580
584
match & stmt. kind {
581
585
StatementKind :: Assign ( box ( lhs, ref rhs) ) => {
582
586
self . consume_rvalue ( location, ( rhs, span) , flow_state) ;
583
-
584
- self . mutate_place ( location, ( * lhs, span) , Shallow ( None ) , flow_state) ;
587
+ if !self . to_skip . contains ( & location) {
588
+ self . mutate_place ( location, ( * lhs, span) , Shallow ( None ) , flow_state) ;
589
+ }
585
590
}
586
591
StatementKind :: FakeRead ( box ( _, ref place) ) => {
587
592
// Read for match doesn't access any memory and is used to
@@ -647,29 +652,43 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
647
652
TerminatorKind :: SwitchInt { ref discr, switch_ty : _, targets : _ } => {
648
653
self . consume_operand ( loc, ( discr, span) , flow_state) ;
649
654
}
650
- TerminatorKind :: Drop { place, target : _ , unwind : _ } => {
655
+ TerminatorKind :: Drop { place, target, unwind, is_replace } => {
651
656
debug ! (
652
657
"visit_terminator_drop \
653
658
loc: {:?} term: {:?} place: {:?} span: {:?}",
654
659
loc, term, place, span
655
660
) ;
656
661
657
- self . access_place (
658
- loc,
659
- ( place, span) ,
660
- ( AccessDepth :: Drop , Write ( WriteKind :: StorageDeadOrDrop ) ) ,
661
- LocalMutationIsAllowed :: Yes ,
662
- flow_state,
663
- ) ;
664
- }
665
- TerminatorKind :: DropAndReplace {
666
- place : drop_place,
667
- value : ref new_value,
668
- target : _,
669
- unwind : _,
670
- } => {
671
- self . mutate_place ( loc, ( drop_place, span) , Deep , flow_state) ;
672
- self . consume_operand ( loc, ( new_value, span) , flow_state) ;
662
+ let next_statement = if is_replace {
663
+ self . body ( )
664
+ . basic_blocks
665
+ . get ( target)
666
+ . expect ( "MIR should be complete at this point" )
667
+ . statements
668
+ . first ( )
669
+ } else {
670
+ None
671
+ } ;
672
+
673
+ match next_statement {
674
+ Some ( Statement { kind : StatementKind :: Assign ( _) , source_info : _ } ) => {
675
+ // this is a drop from a replace operation, for better diagnostic report
676
+ // here possible conflicts and mute the assign statement errors
677
+ self . to_skip . insert ( Location { block : target, statement_index : 0 } ) ;
678
+ self . to_skip
679
+ . insert ( Location { block : unwind. unwrap ( ) , statement_index : 0 } ) ;
680
+ self . mutate_place ( loc, ( place, span) , AccessDepth :: Deep , flow_state) ;
681
+ }
682
+ _ => {
683
+ self . access_place (
684
+ loc,
685
+ ( place, span) ,
686
+ ( AccessDepth :: Drop , Write ( WriteKind :: StorageDeadOrDrop ) ) ,
687
+ LocalMutationIsAllowed :: Yes ,
688
+ flow_state,
689
+ ) ;
690
+ }
691
+ }
673
692
}
674
693
TerminatorKind :: Call {
675
694
ref func,
@@ -785,7 +804,6 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
785
804
| TerminatorKind :: Assert { .. }
786
805
| TerminatorKind :: Call { .. }
787
806
| TerminatorKind :: Drop { .. }
788
- | TerminatorKind :: DropAndReplace { .. }
789
807
| TerminatorKind :: FalseEdge { real_target : _, imaginary_target : _ }
790
808
| TerminatorKind :: FalseUnwind { real_target : _, unwind : _ }
791
809
| TerminatorKind :: Goto { .. }
@@ -1627,7 +1645,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1627
1645
( prefix, place_span. 0 , place_span. 1 ) ,
1628
1646
mpi,
1629
1647
) ;
1630
- } // Only query longest prefix with a MovePath, not further
1648
+ }
1649
+ // Only query longest prefix with a MovePath, not further
1631
1650
// ancestors; dataflow recurs on children when parents
1632
1651
// move (to support partial (re)inits).
1633
1652
//
0 commit comments