@@ -230,6 +230,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
230
230
} ,
231
231
storage_dead_or_drop_error_reported_l : FxHashSet ( ) ,
232
232
storage_dead_or_drop_error_reported_s : FxHashSet ( ) ,
233
+ read_or_write_error_reported : FxHashSet ( ) ,
233
234
reservation_error_reported : FxHashSet ( ) ,
234
235
nonlexical_regioncx : opt_regioncx. clone ( ) ,
235
236
} ;
@@ -300,6 +301,9 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
300
301
storage_dead_or_drop_error_reported_l : FxHashSet < Local > ,
301
302
/// Same as the above, but for statics (thread-locals)
302
303
storage_dead_or_drop_error_reported_s : FxHashSet < DefId > ,
304
+ /// This field keeps track of when borrow errors are reported in read or write passes
305
+ /// so that an error is not reported in both.
306
+ read_or_write_error_reported : FxHashSet < ( Place < ' tcx > , Span ) > ,
303
307
/// This field keeps track of when borrow conflict errors are reported
304
308
/// for reservations, so that we don't report seemingly duplicate
305
309
/// errors for corresponding activations
@@ -739,11 +743,23 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
739
743
}
740
744
}
741
745
746
+ if self . read_or_write_error_reported . contains ( & ( place_span. 0 . clone ( ) , place_span. 1 ) ) {
747
+ debug ! ( "suppressing access_place write for {:?}" , place_span) ;
748
+ return AccessErrorsReported {
749
+ mutability_error : false ,
750
+ conflict_error : true ,
751
+ } ;
752
+ }
753
+
742
754
let mutability_error =
743
755
self . check_access_permissions ( place_span, rw, is_local_mutation_allowed) ;
744
756
let conflict_error =
745
757
self . check_access_for_conflict ( context, place_span, sd, rw, flow_state) ;
746
758
759
+ if conflict_error {
760
+ self . read_or_write_error_reported . insert ( ( place_span. 0 . clone ( ) , place_span. 1 ) ) ;
761
+ }
762
+
747
763
AccessErrorsReported {
748
764
mutability_error,
749
765
conflict_error,
0 commit comments