@@ -17,7 +17,7 @@ use rustc::hir::map::definitions::DefPathData;
1717use rustc:: infer:: InferCtxt ;
1818use rustc:: ty:: { self , ParamEnv , TyCtxt } ;
1919use rustc:: ty:: maps:: Providers ;
20- use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Local , Location , Place } ;
20+ use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Location , Place } ;
2121use rustc:: mir:: { Mir , Mutability , Operand , Projection , ProjectionElem , Rvalue } ;
2222use rustc:: mir:: { Field , Statement , StatementKind , Terminator , TerminatorKind } ;
2323use rustc:: mir:: ClosureRegionRequirements ;
@@ -228,8 +228,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
228228 hir:: BodyOwnerKind :: Const | hir:: BodyOwnerKind :: Static ( _) => false ,
229229 hir:: BodyOwnerKind :: Fn => true ,
230230 } ,
231- storage_dead_or_drop_error_reported_l : FxHashSet ( ) ,
232- storage_dead_or_drop_error_reported_s : FxHashSet ( ) ,
231+ access_place_error_reported : FxHashSet ( ) ,
233232 reservation_error_reported : FxHashSet ( ) ,
234233 nonlexical_regioncx : opt_regioncx. clone ( ) ,
235234 } ;
@@ -294,12 +293,12 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
294293 /// I'm not sure this is the right approach - @eddyb could you try and
295294 /// figure this out?
296295 locals_are_invalidated_at_exit : bool ,
297- /// This field keeps track of when storage dead or drop errors are reported
298- /// in order to stop duplicate error reporting and identify the conditions required
299- /// for a "temporary value dropped here while still borrowed" error. See #45360.
300- storage_dead_or_drop_error_reported_l : FxHashSet < Local > ,
301- /// Same as the above, but for statics (thread-locals)
302- storage_dead_or_drop_error_reported_s : FxHashSet < DefId > ,
296+ /// This field keeps track of when borrow errors are reported in the access_place function
297+ /// so that there is no duplicate reporting. This field cannot also be used for the conflicting
298+ /// borrow errors that is handled by the `reservation_error_reported` field as the inclusion
299+ /// of the `Span` type (while required to mute some errors) stops the muting of the reservation
300+ /// errors.
301+ access_place_error_reported : FxHashSet < ( Place < ' tcx > , Span ) > ,
303302 /// This field keeps track of when borrow conflict errors are reported
304303 /// for reservations, so that we don't report seemingly duplicate
305304 /// errors for corresponding activations
@@ -348,20 +347,20 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
348347
349348 match stmt. kind {
350349 StatementKind :: Assign ( ref lhs, ref rhs) => {
350+ self . consume_rvalue (
351+ ContextKind :: AssignRhs . new ( location) ,
352+ ( rhs, span) ,
353+ location,
354+ flow_state,
355+ ) ;
356+
351357 self . mutate_place (
352358 ContextKind :: AssignLhs . new ( location) ,
353359 ( lhs, span) ,
354360 Shallow ( None ) ,
355361 JustWrite ,
356362 flow_state,
357363 ) ;
358-
359- self . consume_rvalue (
360- ContextKind :: AssignRhs . new ( location) ,
361- ( rhs, span) ,
362- location,
363- flow_state,
364- ) ;
365364 }
366365 StatementKind :: SetDiscriminant {
367366 ref place,
@@ -726,24 +725,35 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
726725
727726 if let Activation ( _, borrow_index) = rw {
728727 if self . reservation_error_reported . contains ( & place_span. 0 ) {
729- debug ! (
730- "skipping access_place for activation of invalid reservation \
731- place: {:?} borrow_index: {:?}",
732- place_span. 0 ,
733- borrow_index
734- ) ;
728+ debug ! ( "skipping access_place for activation of invalid reservation \
729+ place: {:?} borrow_index: {:?}", place_span. 0 , borrow_index) ;
735730 return AccessErrorsReported {
736731 mutability_error : false ,
737732 conflict_error : true ,
738733 } ;
739734 }
740735 }
741736
737+ if self . access_place_error_reported . contains ( & ( place_span. 0 . clone ( ) , place_span. 1 ) ) {
738+ debug ! ( "access_place: suppressing error place_span=`{:?}` kind=`{:?}`" ,
739+ place_span, kind) ;
740+ return AccessErrorsReported {
741+ mutability_error : false ,
742+ conflict_error : true ,
743+ } ;
744+ }
745+
742746 let mutability_error =
743747 self . check_access_permissions ( place_span, rw, is_local_mutation_allowed) ;
744748 let conflict_error =
745749 self . check_access_for_conflict ( context, place_span, sd, rw, flow_state) ;
746750
751+ if conflict_error || mutability_error {
752+ debug ! ( "access_place: logging error place_span=`{:?}` kind=`{:?}`" ,
753+ place_span, kind) ;
754+ self . access_place_error_reported . insert ( ( place_span. 0 . clone ( ) , place_span. 1 ) ) ;
755+ }
756+
747757 AccessErrorsReported {
748758 mutability_error,
749759 conflict_error,
@@ -829,15 +839,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
829839 place_span. 0
830840 ) ;
831841 this. reservation_error_reported . insert ( place_span. 0 . clone ( ) ) ;
832- }
842+ } ,
833843 Activation ( _, activating) => {
834844 debug ! (
835845 "observing check_place for activation of \
836846 borrow_index: {:?}",
837847 activating
838848 ) ;
839- }
840- Read ( ..) | Write ( ..) => { }
849+ } ,
850+ Read ( ..) | Write ( ..) => { } ,
841851 }
842852
843853 match kind {
0 commit comments