@@ -340,6 +340,7 @@ fn do_mir_borrowck<'tcx>(
340340 next_region_name : RefCell :: new ( 1 ) ,
341341 polonius_output : None ,
342342 errors,
343+ to_skip : Default :: default ( ) ,
343344 } ;
344345 promoted_mbcx. report_move_errors ( move_errors) ;
345346 errors = promoted_mbcx. errors ;
@@ -371,6 +372,7 @@ fn do_mir_borrowck<'tcx>(
371372 next_region_name : RefCell :: new ( 1 ) ,
372373 polonius_output,
373374 errors,
375+ to_skip : Default :: default ( ) ,
374376 } ;
375377
376378 // Compute and report region errors, if any.
@@ -553,6 +555,8 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
553555 polonius_output : Option < Rc < PoloniusOutput > > ,
554556
555557 errors : error:: BorrowckErrors < ' tcx > ,
558+
559+ to_skip : FxHashSet < Location > ,
556560}
557561
558562// Check that:
@@ -577,8 +581,9 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
577581 match & stmt. kind {
578582 StatementKind :: Assign ( box ( lhs, rhs) ) => {
579583 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+ }
582587 }
583588 StatementKind :: FakeRead ( box ( _, place) ) => {
584589 // 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
644649 TerminatorKind :: SwitchInt { discr, targets : _ } => {
645650 self . consume_operand ( loc, ( discr, span) , flow_state) ;
646651 }
647- TerminatorKind :: Drop { place, target : _ , unwind : _ } => {
652+ TerminatorKind :: Drop { place, target, unwind, is_replace } => {
648653 debug ! (
649654 "visit_terminator_drop \
650655 loc: {:?} term: {:?} place: {:?} span: {:?}",
651656 loc, term, place, span
652657 ) ;
653658
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+ }
670689 }
671690 TerminatorKind :: Call {
672691 func,
@@ -782,7 +801,6 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
782801 | TerminatorKind :: Assert { .. }
783802 | TerminatorKind :: Call { .. }
784803 | TerminatorKind :: Drop { .. }
785- | TerminatorKind :: DropAndReplace { .. }
786804 | TerminatorKind :: FalseEdge { real_target : _, imaginary_target : _ }
787805 | TerminatorKind :: FalseUnwind { real_target : _, unwind : _ }
788806 | TerminatorKind :: Goto { .. }
@@ -1625,7 +1643,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16251643 ( prefix, place_span. 0 , place_span. 1 ) ,
16261644 mpi,
16271645 ) ;
1628- } // Only query longest prefix with a MovePath, not further
1646+ }
1647+ // Only query longest prefix with a MovePath, not further
16291648 // ancestors; dataflow recurs on children when parents
16301649 // move (to support partial (re)inits).
16311650 //
0 commit comments