@@ -340,6 +340,7 @@ fn do_mir_borrowck<'tcx>(
340
340
next_region_name : RefCell :: new ( 1 ) ,
341
341
polonius_output : None ,
342
342
errors,
343
+ to_skip : Default :: default ( ) ,
343
344
} ;
344
345
promoted_mbcx. report_move_errors ( move_errors) ;
345
346
errors = promoted_mbcx. errors ;
@@ -371,6 +372,7 @@ fn do_mir_borrowck<'tcx>(
371
372
next_region_name : RefCell :: new ( 1 ) ,
372
373
polonius_output,
373
374
errors,
375
+ to_skip : Default :: default ( ) ,
374
376
} ;
375
377
376
378
// Compute and report region errors, if any.
@@ -553,6 +555,8 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
553
555
polonius_output : Option < Rc < PoloniusOutput > > ,
554
556
555
557
errors : error:: BorrowckErrors < ' tcx > ,
558
+
559
+ to_skip : FxHashSet < Location > ,
556
560
}
557
561
558
562
// Check that:
@@ -577,8 +581,9 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
577
581
match & stmt. kind {
578
582
StatementKind :: Assign ( box ( lhs, rhs) ) => {
579
583
self . consume_rvalue ( location, ( rhs, span) , flow_state) ;
580
-
581
- self . mutate_place ( location, ( * lhs, span) , Shallow ( None ) , flow_state) ;
584
+ if !self . to_skip . contains ( & location) {
585
+ self . mutate_place ( location, ( * lhs, span) , Shallow ( None ) , flow_state) ;
586
+ }
582
587
}
583
588
StatementKind :: FakeRead ( box ( _, place) ) => {
584
589
// Read for match doesn't access any memory and is used to
@@ -644,29 +649,43 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
644
649
TerminatorKind :: SwitchInt { discr, targets : _ } => {
645
650
self . consume_operand ( loc, ( discr, span) , flow_state) ;
646
651
}
647
- TerminatorKind :: Drop { place, target : _ , unwind : _ } => {
652
+ TerminatorKind :: Drop { place, target, unwind, is_replace } => {
648
653
debug ! (
649
654
"visit_terminator_drop \
650
655
loc: {:?} term: {:?} place: {:?} span: {:?}",
651
656
loc, term, place, span
652
657
) ;
653
658
654
- self . access_place (
655
- loc,
656
- ( * place, span) ,
657
- ( AccessDepth :: Drop , Write ( WriteKind :: StorageDeadOrDrop ) ) ,
658
- LocalMutationIsAllowed :: Yes ,
659
- flow_state,
660
- ) ;
661
- }
662
- TerminatorKind :: DropAndReplace {
663
- place : drop_place,
664
- value : new_value,
665
- target : _,
666
- unwind : _,
667
- } => {
668
- self . mutate_place ( loc, ( * drop_place, span) , Deep , flow_state) ;
669
- self . consume_operand ( loc, ( new_value, span) , flow_state) ;
659
+ let next_statement = if * is_replace {
660
+ self . body ( )
661
+ . basic_blocks
662
+ . get ( * target)
663
+ . expect ( "MIR should be complete at this point" )
664
+ . statements
665
+ . first ( )
666
+ } else {
667
+ None
668
+ } ;
669
+
670
+ match next_statement {
671
+ Some ( Statement { kind : StatementKind :: Assign ( _) , source_info : _ } ) => {
672
+ // this is a drop from a replace operation, for better diagnostic report
673
+ // here possible conflicts and mute the assign statement errors
674
+ self . to_skip . insert ( Location { block : * target, statement_index : 0 } ) ;
675
+ self . to_skip
676
+ . insert ( Location { block : unwind. unwrap ( ) , statement_index : 0 } ) ;
677
+ self . mutate_place ( loc, ( * place, span) , AccessDepth :: Deep , flow_state) ;
678
+ }
679
+ _ => {
680
+ self . access_place (
681
+ loc,
682
+ ( * place, span) ,
683
+ ( AccessDepth :: Drop , Write ( WriteKind :: StorageDeadOrDrop ) ) ,
684
+ LocalMutationIsAllowed :: Yes ,
685
+ flow_state,
686
+ ) ;
687
+ }
688
+ }
670
689
}
671
690
TerminatorKind :: Call {
672
691
func,
@@ -782,7 +801,6 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
782
801
| TerminatorKind :: Assert { .. }
783
802
| TerminatorKind :: Call { .. }
784
803
| TerminatorKind :: Drop { .. }
785
- | TerminatorKind :: DropAndReplace { .. }
786
804
| TerminatorKind :: FalseEdge { real_target : _, imaginary_target : _ }
787
805
| TerminatorKind :: FalseUnwind { real_target : _, unwind : _ }
788
806
| TerminatorKind :: Goto { .. }
@@ -1592,7 +1610,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1592
1610
( prefix, place_span. 0 , place_span. 1 ) ,
1593
1611
mpi,
1594
1612
) ;
1595
- } // Only query longest prefix with a MovePath, not further
1613
+ }
1614
+ // Only query longest prefix with a MovePath, not further
1596
1615
// ancestors; dataflow recurs on children when parents
1597
1616
// move (to support partial (re)inits).
1598
1617
//
0 commit comments