Skip to content

Commit f92d679

Browse files
committed
Encompassed error deduplication of some existing sets in the ctxt.
1 parent 3daa4d2 commit f92d679

File tree

2 files changed

+25
-47
lines changed

2 files changed

+25
-47
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -362,33 +362,20 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
362362
let scope_tree = borrows.0.scope_tree();
363363
let root_place = self.prefixes(&borrow.borrowed_place, PrefixSet::All).last().unwrap();
364364

365-
match root_place {
366-
&Place::Local(local) => {
367-
if let Some(_) = self.storage_dead_or_drop_error_reported_l.replace(local) {
368-
debug!("report_does_not_live_long_enough({:?}): <suppressed>",
369-
(borrow, drop_span));
370-
return
371-
}
372-
}
373-
&Place::Static(ref statik) => {
374-
if let Some(_) = self.storage_dead_or_drop_error_reported_s
375-
.replace(statik.def_id)
376-
{
377-
debug!("report_does_not_live_long_enough({:?}): <suppressed>",
378-
(borrow, drop_span));
379-
return
380-
}
381-
},
382-
&Place::Projection(_) =>
383-
unreachable!("root_place is an unreachable???")
384-
};
385-
386365
let borrow_span = self.mir.source_info(borrow.location).span;
387366
let proper_span = match *root_place {
388367
Place::Local(local) => self.mir.local_decls[local].source_info.span,
389368
_ => drop_span,
390369
};
391370

371+
if self.access_place_error_reported.contains(&(root_place.clone(), borrow_span)) {
372+
debug!("suppressing access_place error when borrow doesn't live long enough for {:?}",
373+
borrow_span);
374+
return;
375+
}
376+
377+
self.access_place_error_reported.insert((root_place.clone(), borrow_span));
378+
392379
match (borrow.region, &self.describe_place(&borrow.borrowed_place)) {
393380
(RegionKind::ReScope(_), Some(name)) => {
394381
self.report_scoped_local_value_does_not_live_long_enough(

src/librustc_mir/borrow_check/mod.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::hir::map::definitions::DefPathData;
1717
use rustc::infer::InferCtxt;
1818
use rustc::ty::{self, ParamEnv, TyCtxt};
1919
use rustc::ty::maps::Providers;
20-
use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Local, Location, Place};
20+
use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Location, Place};
2121
use rustc::mir::{Mir, Mutability, Operand, Projection, ProjectionElem, Rvalue};
2222
use rustc::mir::{Field, Statement, StatementKind, Terminator, TerminatorKind};
2323
use rustc::mir::ClosureRegionRequirements;
@@ -228,9 +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(),
233-
read_or_write_error_reported: FxHashSet(),
231+
access_place_error_reported: FxHashSet(),
234232
reservation_error_reported: FxHashSet(),
235233
nonlexical_regioncx: opt_regioncx.clone(),
236234
};
@@ -295,15 +293,12 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
295293
/// I'm not sure this is the right approach - @eddyb could you try and
296294
/// figure this out?
297295
locals_are_invalidated_at_exit: bool,
298-
/// This field keeps track of when storage dead or drop errors are reported
299-
/// in order to stop duplicate error reporting and identify the conditions required
300-
/// for a "temporary value dropped here while still borrowed" error. See #45360.
301-
storage_dead_or_drop_error_reported_l: FxHashSet<Local>,
302-
/// Same as the above, but for statics (thread-locals)
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)>,
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)>,
307302
/// This field keeps track of when borrow conflict errors are reported
308303
/// for reservations, so that we don't report seemingly duplicate
309304
/// errors for corresponding activations
@@ -730,21 +725,17 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
730725

731726
if let Activation(_, borrow_index) = rw {
732727
if self.reservation_error_reported.contains(&place_span.0) {
733-
debug!(
734-
"skipping access_place for activation of invalid reservation \
735-
place: {:?} borrow_index: {:?}",
736-
place_span.0,
737-
borrow_index
738-
);
728+
debug!("skipping access_place for activation of invalid reservation \
729+
place: {:?} borrow_index: {:?}", place_span.0, borrow_index);
739730
return AccessErrorsReported {
740731
mutability_error: false,
741732
conflict_error: true,
742733
};
743734
}
744735
}
745736

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);
737+
if self.access_place_error_reported.contains(&(place_span.0.clone(), place_span.1)) {
738+
debug!("suppressing access_place error for {:?}", place_span);
748739
return AccessErrorsReported {
749740
mutability_error: false,
750741
conflict_error: true,
@@ -756,8 +747,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
756747
let conflict_error =
757748
self.check_access_for_conflict(context, place_span, sd, rw, flow_state);
758749

759-
if conflict_error {
760-
self.read_or_write_error_reported.insert((place_span.0.clone(), place_span.1));
750+
if conflict_error || mutability_error {
751+
self.access_place_error_reported.insert((place_span.0.clone(), place_span.1));
761752
}
762753

763754
AccessErrorsReported {
@@ -845,15 +836,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
845836
place_span.0
846837
);
847838
this.reservation_error_reported.insert(place_span.0.clone());
848-
}
839+
},
849840
Activation(_, activating) => {
850841
debug!(
851842
"observing check_place for activation of \
852843
borrow_index: {:?}",
853844
activating
854845
);
855-
}
856-
Read(..) | Write(..) => {}
846+
},
847+
Read(..) | Write(..) => {},
857848
}
858849

859850
match kind {

0 commit comments

Comments
 (0)