@@ -343,6 +343,7 @@ fn do_mir_borrowck<'tcx>(
343343 next_region_name : RefCell :: new ( 1 ) ,
344344 polonius_output : None ,
345345 errors,
346+ to_skip : Default :: default ( ) ,
346347 } ;
347348 promoted_mbcx. report_move_errors ( move_errors) ;
348349 errors = promoted_mbcx. errors ;
@@ -374,6 +375,7 @@ fn do_mir_borrowck<'tcx>(
374375 next_region_name : RefCell :: new ( 1 ) ,
375376 polonius_output,
376377 errors,
378+ to_skip : Default :: default ( ) ,
377379 } ;
378380
379381 // Compute and report region errors, if any.
@@ -556,6 +558,8 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
556558 polonius_output : Option < Rc < PoloniusOutput > > ,
557559
558560 errors : error:: BorrowckErrors < ' tcx > ,
561+
562+ to_skip : FxHashSet < Location > ,
559563}
560564
561565// Check that:
@@ -580,8 +584,9 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
580584 match & stmt. kind {
581585 StatementKind :: Assign ( box ( lhs, ref rhs) ) => {
582586 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+ }
585590 }
586591 StatementKind :: FakeRead ( box ( _, ref place) ) => {
587592 // 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
647652 TerminatorKind :: SwitchInt { ref discr, switch_ty : _, targets : _ } => {
648653 self . consume_operand ( loc, ( discr, span) , flow_state) ;
649654 }
650- TerminatorKind :: Drop { place, target : _ , unwind : _ } => {
655+ TerminatorKind :: Drop { place, target, unwind, is_replace } => {
651656 debug ! (
652657 "visit_terminator_drop \
653658 loc: {:?} term: {:?} place: {:?} span: {:?}",
654659 loc, term, place, span
655660 ) ;
656661
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+ }
673692 }
674693 TerminatorKind :: Call {
675694 ref func,
@@ -785,7 +804,6 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
785804 | TerminatorKind :: Assert { .. }
786805 | TerminatorKind :: Call { .. }
787806 | TerminatorKind :: Drop { .. }
788- | TerminatorKind :: DropAndReplace { .. }
789807 | TerminatorKind :: FalseEdge { real_target : _, imaginary_target : _ }
790808 | TerminatorKind :: FalseUnwind { real_target : _, unwind : _ }
791809 | TerminatorKind :: Goto { .. }
@@ -1627,7 +1645,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16271645 ( prefix, place_span. 0 , place_span. 1 ) ,
16281646 mpi,
16291647 ) ;
1630- } // Only query longest prefix with a MovePath, not further
1648+ }
1649+ // Only query longest prefix with a MovePath, not further
16311650 // ancestors; dataflow recurs on children when parents
16321651 // move (to support partial (re)inits).
16331652 //
0 commit comments