From f92d679b78fc1e5db5d5fd6cbb9a5e076f8fee69 Mon Sep 17 00:00:00 2001 From: David Wood Date: Sat, 20 Jan 2018 02:15:57 +0000 Subject: [PATCH] Encompassed error deduplication of some existing sets in the ctxt. --- .../borrow_check/error_reporting.rs | 29 ++++--------- src/librustc_mir/borrow_check/mod.rs | 43 ++++++++----------- 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 7bd3b6e39f05..8ded245e13ff 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({:?}): ", - (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({:?}): ", - (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 1d630b280a59..6b84abbe266f 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, - /// Same as the above, but for statics (thread-locals) - storage_dead_or_drop_error_reported_s: FxHashSet, - /// 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 {