about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2018-01-20 02:15:57 +0000
committerDavid Wood <david@davidtw.co>2018-01-27 13:33:10 +0000
commitf92d679b78fc1e5db5d5fd6cbb9a5e076f8fee69 (patch)
tree7926d0fe117ff2f926872a447d9ee3bb89eb63c9 /src
parent3daa4d255f1ecc9d0a28deb9ca3d6da79f1df438 (diff)
Encompassed error deduplication of some existing sets in the ctxt.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/borrow_check/error_reporting.rs29
-rw-r--r--src/librustc_mir/borrow_check/mod.rs43
2 files changed, 25 insertions, 47 deletions
diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs
index 7bd3b6e39f0..8ded245e13f 100644
--- a/src/librustc_mir/borrow_check/error_reporting.rs
+++ b/src/librustc_mir/borrow_check/error_reporting.rs
@@ -362,33 +362,20 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
         let scope_tree = borrows.0.scope_tree();
         let root_place = self.prefixes(&borrow.borrowed_place, PrefixSet::All).last().unwrap();
 
-        match root_place {
-            &Place::Local(local) => {
-                if let Some(_) = self.storage_dead_or_drop_error_reported_l.replace(local) {
-                    debug!("report_does_not_live_long_enough({:?}): <suppressed>",
-                           (borrow, drop_span));
-                    return
-                }
-            }
-            &Place::Static(ref statik) => {
-                if let Some(_) = self.storage_dead_or_drop_error_reported_s
-                    .replace(statik.def_id)
-                {
-                    debug!("report_does_not_live_long_enough({:?}): <suppressed>",
-                           (borrow, drop_span));
-                    return
-                }
-            },
-            &Place::Projection(_) =>
-                unreachable!("root_place is an unreachable???")
-        };
-
         let borrow_span = self.mir.source_info(borrow.location).span;
         let proper_span = match *root_place {
             Place::Local(local) => self.mir.local_decls[local].source_info.span,
             _ => drop_span,
         };
 
+        if self.access_place_error_reported.contains(&(root_place.clone(), borrow_span)) {
+            debug!("suppressing access_place error when borrow doesn't live long enough for {:?}",
+                   borrow_span);
+            return;
+        }
+
+        self.access_place_error_reported.insert((root_place.clone(), borrow_span));
+
         match (borrow.region, &self.describe_place(&borrow.borrowed_place)) {
             (RegionKind::ReScope(_), Some(name)) => {
                 self.report_scoped_local_value_does_not_live_long_enough(
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index 1d630b280a5..6b84abbe266 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -17,7 +17,7 @@ use rustc::hir::map::definitions::DefPathData;
 use rustc::infer::InferCtxt;
 use rustc::ty::{self, ParamEnv, TyCtxt};
 use rustc::ty::maps::Providers;
-use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Local, Location, Place};
+use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Location, Place};
 use rustc::mir::{Mir, Mutability, Operand, Projection, ProjectionElem, Rvalue};
 use rustc::mir::{Field, Statement, StatementKind, Terminator, TerminatorKind};
 use rustc::mir::ClosureRegionRequirements;
@@ -228,9 +228,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
             hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => false,
             hir::BodyOwnerKind::Fn => true,
         },
-        storage_dead_or_drop_error_reported_l: FxHashSet(),
-        storage_dead_or_drop_error_reported_s: FxHashSet(),
-        read_or_write_error_reported: FxHashSet(),
+        access_place_error_reported: FxHashSet(),
         reservation_error_reported: FxHashSet(),
         nonlexical_regioncx: opt_regioncx.clone(),
     };
@@ -295,15 +293,12 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
     /// I'm not sure this is the right approach - @eddyb could you try and
     /// figure this out?
     locals_are_invalidated_at_exit: bool,
-    /// This field keeps track of when storage dead or drop errors are reported
-    /// in order to stop duplicate error reporting and identify the conditions required
-    /// for a "temporary value dropped here while still borrowed" error. See #45360.
-    storage_dead_or_drop_error_reported_l: FxHashSet<Local>,
-    /// Same as the above, but for statics (thread-locals)
-    storage_dead_or_drop_error_reported_s: FxHashSet<DefId>,
-    /// This field keeps track of when borrow errors are reported in read or write passes
-    /// so that an error is not reported in both.
-    read_or_write_error_reported: FxHashSet<(Place<'tcx>, Span)>,
+    /// This field keeps track of when borrow errors are reported in the access_place function
+    /// so that there is no duplicate reporting. This field cannot also be used for the conflicting
+    /// borrow errors that is handled by the `reservation_error_reported` field as the inclusion
+    /// of the `Span` type (while required to mute some errors) stops the muting of the reservation
+    /// errors.
+    access_place_error_reported: FxHashSet<(Place<'tcx>, Span)>,
     /// This field keeps track of when borrow conflict errors are reported
     /// for reservations, so that we don't report seemingly duplicate
     /// errors for corresponding activations
@@ -730,12 +725,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
 
         if let Activation(_, borrow_index) = rw {
             if self.reservation_error_reported.contains(&place_span.0) {
-                debug!(
-                    "skipping access_place for activation of invalid reservation \
-                     place: {:?} borrow_index: {:?}",
-                    place_span.0,
-                    borrow_index
-                );
+                debug!("skipping access_place for activation of invalid reservation \
+                     place: {:?} borrow_index: {:?}", place_span.0, borrow_index);
                 return AccessErrorsReported {
                     mutability_error: false,
                     conflict_error: true,
@@ -743,8 +734,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
             }
         }
 
-        if self.read_or_write_error_reported.contains(&(place_span.0.clone(), place_span.1)) {
-            debug!("suppressing access_place write for {:?}", place_span);
+        if self.access_place_error_reported.contains(&(place_span.0.clone(), place_span.1)) {
+            debug!("suppressing access_place error for {:?}", place_span);
             return AccessErrorsReported {
                 mutability_error: false,
                 conflict_error: true,
@@ -756,8 +747,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
         let conflict_error =
             self.check_access_for_conflict(context, place_span, sd, rw, flow_state);
 
-        if conflict_error {
-            self.read_or_write_error_reported.insert((place_span.0.clone(), place_span.1));
+        if conflict_error || mutability_error {
+            self.access_place_error_reported.insert((place_span.0.clone(), place_span.1));
         }
 
         AccessErrorsReported {
@@ -845,15 +836,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                                 place_span.0
                             );
                             this.reservation_error_reported.insert(place_span.0.clone());
-                        }
+                        },
                         Activation(_, activating) => {
                             debug!(
                                 "observing check_place for activation of \
                                  borrow_index: {:?}",
                                 activating
                             );
-                        }
-                        Read(..) | Write(..) => {}
+                        },
+                        Read(..) | Write(..) => {},
                     }
 
                     match kind {