From 9c5a5c471aa9229b82bafa8ec18e55722d9ba8c3 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 1 Oct 2019 21:39:19 -0400 Subject: [PATCH] Rename to `was_placeholder` to `from_forall` --- src/librustc/infer/mod.rs | 12 +++++++++++- .../nll/region_infer/error_reporting/mod.rs | 4 ++-- .../borrow_check/nll/region_infer/mod.rs | 2 +- src/librustc_mir/borrow_check/nll/renumber.rs | 2 +- .../borrow_check/nll/type_check/relate_tys.rs | 6 +++--- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 99297d7222b07..35db82406ab46 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -419,7 +419,17 @@ pub enum NLLRegionVariableOrigin { Placeholder(ty::PlaceholderRegion), Existential { - was_placeholder: bool + /// If this is true, then this variable was created to represent a lifetime + /// bound in a `for` binder. For example, it might have been created to + /// represent the lifetime `'a` in a type like `for<'a> fn(&'a u32)`. + /// Such variables are created when we are trying to figure out if there + /// is any valid instantiation of `'a` that could fit into some scenario. + /// + /// This is used to inform error reporting: in the case that we are trying to + /// determine whether there is any valid instantiation of a `'a` variable that meets + /// some constraint C, we want to blame the "source" of that `for` type, + /// rather than blaming the source of the constraint C. + from_forall: bool }, } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index 826be88e36572..fa02e2dd234ef 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -159,11 +159,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { let should_reverse = match from_region_origin { NLLRegionVariableOrigin::FreeRegion - | NLLRegionVariableOrigin::Existential { was_placeholder: false } => { + | NLLRegionVariableOrigin::Existential { from_forall: false } => { true } NLLRegionVariableOrigin::Placeholder(_) - | NLLRegionVariableOrigin::Existential { was_placeholder: true } => { + | NLLRegionVariableOrigin::Existential { from_forall: true } => { false } }; diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 164f7b0627c2d..dbb810db555b4 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -1612,7 +1612,7 @@ impl<'tcx> RegionDefinition<'tcx> { let origin = match rv_origin { RegionVariableOrigin::NLL(origin) => origin, - _ => NLLRegionVariableOrigin::Existential { was_placeholder: false }, + _ => NLLRegionVariableOrigin::Existential { from_forall: false }, }; Self { origin, universe, external_name: None } diff --git a/src/librustc_mir/borrow_check/nll/renumber.rs b/src/librustc_mir/borrow_check/nll/renumber.rs index 6e4db36bdce03..315c369716e38 100644 --- a/src/librustc_mir/borrow_check/nll/renumber.rs +++ b/src/librustc_mir/borrow_check/nll/renumber.rs @@ -35,7 +35,7 @@ where infcx .tcx .fold_regions(value, &mut false, |_region, _depth| { - let origin = NLLRegionVariableOrigin::Existential { was_placeholder: false }; + let origin = NLLRegionVariableOrigin::Existential { from_forall: false }; infcx.next_nll_region_var(origin) }) } diff --git a/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs b/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs index 919fcdbd39ba0..80bf0478128c7 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/relate_tys.rs @@ -66,9 +66,9 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> { self.infcx.create_next_universe() } - fn next_existential_region_var(&mut self, was_placeholder: bool) -> ty::Region<'tcx> { + fn next_existential_region_var(&mut self, from_forall: bool) -> ty::Region<'tcx> { if let Some(_) = &mut self.borrowck_context { - let origin = NLLRegionVariableOrigin::Existential { was_placeholder }; + let origin = NLLRegionVariableOrigin::Existential { from_forall }; self.infcx.next_nll_region_var(origin) } else { self.infcx.tcx.lifetimes.re_erased @@ -89,7 +89,7 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> { fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> { self.infcx .next_nll_region_var_in_universe(NLLRegionVariableOrigin::Existential { - was_placeholder: false + from_forall: false }, universe) }