@@ -17,7 +17,7 @@ use rustc::hir::map::definitions::DefPathData;
17
17
use rustc:: infer:: InferCtxt ;
18
18
use rustc:: ty:: { self , ParamEnv , TyCtxt } ;
19
19
use rustc:: ty:: maps:: Providers ;
20
- use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Local , Location , Place } ;
20
+ use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Location , Place } ;
21
21
use rustc:: mir:: { Mir , Mutability , Operand , Projection , ProjectionElem , Rvalue } ;
22
22
use rustc:: mir:: { Field , Statement , StatementKind , Terminator , TerminatorKind } ;
23
23
use rustc:: mir:: ClosureRegionRequirements ;
@@ -228,8 +228,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
228
228
hir:: BodyOwnerKind :: Const | hir:: BodyOwnerKind :: Static ( _) => false ,
229
229
hir:: BodyOwnerKind :: Fn => true ,
230
230
} ,
231
- storage_dead_or_drop_error_reported_l : FxHashSet ( ) ,
232
- storage_dead_or_drop_error_reported_s : FxHashSet ( ) ,
231
+ access_place_error_reported : FxHashSet ( ) ,
233
232
reservation_error_reported : FxHashSet ( ) ,
234
233
nonlexical_regioncx : opt_regioncx. clone ( ) ,
235
234
} ;
@@ -294,12 +293,12 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
294
293
/// I'm not sure this is the right approach - @eddyb could you try and
295
294
/// figure this out?
296
295
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 ) > ,
303
302
/// This field keeps track of when borrow conflict errors are reported
304
303
/// for reservations, so that we don't report seemingly duplicate
305
304
/// errors for corresponding activations
@@ -348,20 +347,20 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
348
347
349
348
match stmt. kind {
350
349
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
+
351
357
self . mutate_place (
352
358
ContextKind :: AssignLhs . new ( location) ,
353
359
( lhs, span) ,
354
360
Shallow ( None ) ,
355
361
JustWrite ,
356
362
flow_state,
357
363
) ;
358
-
359
- self . consume_rvalue (
360
- ContextKind :: AssignRhs . new ( location) ,
361
- ( rhs, span) ,
362
- location,
363
- flow_state,
364
- ) ;
365
364
}
366
365
StatementKind :: SetDiscriminant {
367
366
ref place,
@@ -726,24 +725,35 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
726
725
727
726
if let Activation ( _, borrow_index) = rw {
728
727
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) ;
735
730
return AccessErrorsReported {
736
731
mutability_error : false ,
737
732
conflict_error : true ,
738
733
} ;
739
734
}
740
735
}
741
736
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
+
742
746
let mutability_error =
743
747
self . check_access_permissions ( place_span, rw, is_local_mutation_allowed) ;
744
748
let conflict_error =
745
749
self . check_access_for_conflict ( context, place_span, sd, rw, flow_state) ;
746
750
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
+
747
757
AccessErrorsReported {
748
758
mutability_error,
749
759
conflict_error,
@@ -829,15 +839,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
829
839
place_span. 0
830
840
) ;
831
841
this. reservation_error_reported . insert ( place_span. 0 . clone ( ) ) ;
832
- }
842
+ } ,
833
843
Activation ( _, activating) => {
834
844
debug ! (
835
845
"observing check_place for activation of \
836
846
borrow_index: {:?}",
837
847
activating
838
848
) ;
839
- }
840
- Read ( ..) | Write ( ..) => { }
849
+ } ,
850
+ Read ( ..) | Write ( ..) => { } ,
841
851
}
842
852
843
853
match kind {
0 commit comments