Skip to content

Commit 3daa4d2

Browse files
committed
Introduced a new set to stop duplicate errors from MIR passes on one place/span.
1 parent f1c1db6 commit 3daa4d2

File tree

1 file changed

+16
-0
lines changed
  • src/librustc_mir/borrow_check

1 file changed

+16
-0
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
230230
},
231231
storage_dead_or_drop_error_reported_l: FxHashSet(),
232232
storage_dead_or_drop_error_reported_s: FxHashSet(),
233+
read_or_write_error_reported: FxHashSet(),
233234
reservation_error_reported: FxHashSet(),
234235
nonlexical_regioncx: opt_regioncx.clone(),
235236
};
@@ -300,6 +301,9 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
300301
storage_dead_or_drop_error_reported_l: FxHashSet<Local>,
301302
/// Same as the above, but for statics (thread-locals)
302303
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)>,
303307
/// This field keeps track of when borrow conflict errors are reported
304308
/// for reservations, so that we don't report seemingly duplicate
305309
/// errors for corresponding activations
@@ -739,11 +743,23 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
739743
}
740744
}
741745

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+
742754
let mutability_error =
743755
self.check_access_permissions(place_span, rw, is_local_mutation_allowed);
744756
let conflict_error =
745757
self.check_access_for_conflict(context, place_span, sd, rw, flow_state);
746758

759+
if conflict_error {
760+
self.read_or_write_error_reported.insert((place_span.0.clone(), place_span.1));
761+
}
762+
747763
AccessErrorsReported {
748764
mutability_error,
749765
conflict_error,

0 commit comments

Comments
 (0)