From f05e40eb992fce44db348cfb1e8ecb4699e9cdd6 Mon Sep 17 00:00:00 2001 From: Mark Mansi Date: Wed, 1 Jan 2020 14:35:08 -0600 Subject: [PATCH] address review comments --- .../borrow_check/diagnostics/region_errors.rs | 15 +++++++-------- .../borrow_check/diagnostics/region_name.rs | 4 +--- src/librustc_mir/borrow_check/region_infer/mod.rs | 6 ++++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index 729a679e92a32..b999dfa303103 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -138,8 +138,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { if let DefiningTy::Closure(def_id, substs) = self.regioncx.universal_regions().defining_ty { - let closure_kind_ty = substs.as_closure().kind_ty(def_id, self.infcx.tcx); - return Some(ty::ClosureKind::FnMut) == closure_kind_ty.to_opt_closure_kind(); + return substs.as_closure().kind(def_id, self.infcx.tcx) + == ty::ClosureKind::FnMut; } } } @@ -160,7 +160,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { // Try to convert the lower-bound region into something named we can print for the user. let lower_bound_region = self.to_error_region(type_test.lower_bound); - // Skip duplicate-ish errors. let type_test_span = type_test.locations.span(&self.body); if let Some(lower_bound_region) = lower_bound_region { @@ -236,7 +235,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { RegionErrorKind::RegionError { fr_origin, longer_fr, shorter_fr, is_reported } => { if is_reported { - self.report_error( + self.report_region_error( longer_fr, fr_origin, shorter_fr, @@ -270,21 +269,21 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// ``` /// /// Here we would be invoked with `fr = 'a` and `outlived_fr = `'b`. - pub(in crate::borrow_check) fn report_error( + pub(in crate::borrow_check) fn report_region_error( &mut self, fr: RegionVid, fr_origin: NLLRegionVariableOrigin, outlived_fr: RegionVid, outlives_suggestion: &mut OutlivesSuggestionBuilder, ) { - debug!("report_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr); + debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr); let (category, _, span) = self.regioncx.best_blame_constraint(&self.body, fr, fr_origin, |r| { self.regioncx.provides_universal_region(r, fr, outlived_fr) }); - debug!("report_error: category={:?} {:?}", category, span); + debug!("report_region_error: category={:?} {:?}", category, span); // Check if we can use one of the "nice region errors". if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) { let tables = self.infcx.tcx.typeck_tables_of(self.mir_def_id); @@ -301,7 +300,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ); debug!( - "report_error: fr_is_local={:?} outlived_fr_is_local={:?} category={:?}", + "report_region_error: fr_is_local={:?} outlived_fr_is_local={:?} category={:?}", fr_is_local, outlived_fr_is_local, category ); diff --git a/src/librustc_mir/borrow_check/diagnostics/region_name.rs b/src/librustc_mir/borrow_check/diagnostics/region_name.rs index f7aeec5e76ee9..47eb2d8940af4 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_name.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_name.rs @@ -123,9 +123,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { /// /// This is _not_ idempotent. Call `give_region_a_name` when possible. fn synthesize_region_name(&self) -> Symbol { - let mut counter = self.next_region_name.try_borrow_mut().unwrap(); - let c = *counter; - *counter += 1; + let c = self.next_region_name.replace_with(|counter| *counter + 1); Symbol::intern(&format!("'{:?}", c)) } diff --git a/src/librustc_mir/borrow_check/region_infer/mod.rs b/src/librustc_mir/borrow_check/region_infer/mod.rs index 180bb95cab9f4..26d9cf2e0450f 100644 --- a/src/librustc_mir/borrow_check/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/region_infer/mod.rs @@ -846,6 +846,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Type-test failed. Report the error. let erased_generic_kind = infcx.tcx.erase_regions(&type_test.generic_kind); + + // Skip duplicate-ish errors. if deduplicate_errors.insert(( erased_generic_kind, type_test.lower_bound, @@ -1850,8 +1852,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { self.scc_values.contains(r_scc, upper) } - crate fn universal_regions(&self) -> Rc> { - self.universal_regions.clone() + crate fn universal_regions(&self) -> &UniversalRegions<'tcx> { + self.universal_regions.as_ref() } /// Tries to find the best constraint to blame for the fact that