@@ -35,7 +35,7 @@ use rustc_middle::mir::{InlineAsmOperand, Terminator, TerminatorKind};
35
35
use rustc_middle:: ty:: query:: Providers ;
36
36
use rustc_middle:: ty:: { self , CapturedPlace , ParamEnv , RegionVid , TyCtxt } ;
37
37
use rustc_session:: lint:: builtin:: UNUSED_MUT ;
38
- use rustc_span:: { Span , Symbol } ;
38
+ use rustc_span:: { DesugaringKind , Span , Symbol } ;
39
39
40
40
use either:: Either ;
41
41
use smallvec:: SmallVec ;
@@ -340,7 +340,6 @@ fn do_mir_borrowck<'tcx>(
340
340
next_region_name : RefCell :: new ( 1 ) ,
341
341
polonius_output : None ,
342
342
errors,
343
- replaces : Default :: default ( ) ,
344
343
} ;
345
344
promoted_mbcx. report_move_errors ( move_errors) ;
346
345
errors = promoted_mbcx. errors ;
@@ -372,7 +371,6 @@ fn do_mir_borrowck<'tcx>(
372
371
next_region_name : RefCell :: new ( 1 ) ,
373
372
polonius_output,
374
373
errors,
375
- replaces : Default :: default ( ) ,
376
374
} ;
377
375
378
376
// Compute and report region errors, if any.
@@ -555,10 +553,6 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
555
553
polonius_output : Option < Rc < PoloniusOutput > > ,
556
554
557
555
errors : error:: BorrowckErrors < ' tcx > ,
558
-
559
- /// Record the places were a replace happens so that we can use the
560
- /// correct access depth in the assignment for better diagnostic
561
- replaces : FxHashSet < Location > ,
562
556
}
563
557
564
558
// Check that:
@@ -583,10 +577,8 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
583
577
match & stmt. kind {
584
578
StatementKind :: Assign ( box ( lhs, rhs) ) => {
585
579
self . consume_rvalue ( location, ( rhs, span) , flow_state) ;
586
- // In case of a replace the drop access check is skipped for better diagnostic but we need
587
- // to use a stricter access depth here
588
- let access_depth = if self . replaces . contains ( & location) { AccessDepth :: Drop } else { Shallow ( None ) } ;
589
- self . mutate_place ( location, ( * lhs, span) , access_depth, flow_state) ;
580
+
581
+ self . mutate_place ( location, ( * lhs, span) , AccessDepth :: Shallow ( None ) , flow_state) ;
590
582
}
591
583
StatementKind :: FakeRead ( box ( _, place) ) => {
592
584
// Read for match doesn't access any memory and is used to
@@ -652,28 +644,13 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
652
644
TerminatorKind :: SwitchInt { discr, targets : _ } => {
653
645
self . consume_operand ( loc, ( discr, span) , flow_state) ;
654
646
}
655
- TerminatorKind :: Drop { place, target, unwind, is_replace } => {
647
+ TerminatorKind :: Drop { place, target : _ , unwind : _ , is_replace : _ } => {
656
648
debug ! (
657
649
"visit_terminator_drop \
658
650
loc: {:?} term: {:?} place: {:?} span: {:?}",
659
651
loc, term, place, span
660
652
) ;
661
653
662
- // In case of a replace, it's more user friendly to report a problem with the explicit
663
- // assignment than the implicit drop.
664
- // Simply skip this access and rely on the assignment to report any error.
665
- if * is_replace {
666
- // An assignment `x = ...` is usually a shallow access, but in the case of a replace
667
- // the drop could access internal references depending on the drop implementation.
668
- // Since we're skipping the drop access, we need to mark the access depth
669
- // of the assignment as AccessDepth::Drop.
670
- self . replaces . insert ( Location { block : * target, statement_index : 0 } ) ;
671
- if let Some ( unwind) = unwind {
672
- self . replaces . insert ( Location { block : * unwind, statement_index : 0 } ) ;
673
- }
674
- return ;
675
- }
676
-
677
654
self . access_place (
678
655
loc,
679
656
( * place, span) ,
@@ -1112,13 +1089,22 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1112
1089
this. report_conflicting_borrow ( location, place_span, bk, borrow) ;
1113
1090
this. buffer_error ( err) ;
1114
1091
}
1115
- WriteKind :: StorageDeadOrDrop => this
1116
- . report_borrowed_value_does_not_live_long_enough (
1117
- location,
1118
- borrow,
1119
- place_span,
1120
- Some ( kind) ,
1121
- ) ,
1092
+ WriteKind :: StorageDeadOrDrop => {
1093
+ if let Some ( DesugaringKind :: Replace ) = place_span. 1 . desugaring_kind ( ) {
1094
+ // If this is a drop triggered by a reassignment, it's more user friendly
1095
+ // to report a problem with the explicit assignment than the implicit drop.
1096
+ this. report_illegal_mutation_of_borrowed (
1097
+ location, place_span, borrow,
1098
+ )
1099
+ } else {
1100
+ this. report_borrowed_value_does_not_live_long_enough (
1101
+ location,
1102
+ borrow,
1103
+ place_span,
1104
+ Some ( kind) ,
1105
+ )
1106
+ }
1107
+ }
1122
1108
WriteKind :: Mutate => {
1123
1109
this. report_illegal_mutation_of_borrowed ( location, place_span, borrow)
1124
1110
}
0 commit comments