diff --git a/src/librustc/infer/canonical/query_response.rs b/src/librustc/infer/canonical/query_response.rs index f0ea61cf9b4..d00da11d17d 100644 --- a/src/librustc/infer/canonical/query_response.rs +++ b/src/librustc/infer/canonical/query_response.rs @@ -654,14 +654,14 @@ pub fn make_query_outlives<'tcx>( constraints, verifys, givens, - in_constraints, + pick_constraints, } = region_constraints; assert!(verifys.is_empty()); assert!(givens.is_empty()); // FIXME(ndm) -- we have to think about what to do here, perhaps - assert!(in_constraints.is_empty()); + assert!(pick_constraints.is_empty()); let outlives: Vec<_> = constraints .into_iter() diff --git a/src/librustc/infer/lexical_region_resolve/mod.rs b/src/librustc/infer/lexical_region_resolve/mod.rs index 61c711967ad..a37eff82e6e 100644 --- a/src/librustc/infer/lexical_region_resolve/mod.rs +++ b/src/librustc/infer/lexical_region_resolve/mod.rs @@ -2,7 +2,7 @@ use crate::infer::region_constraints::Constraint; use crate::infer::region_constraints::GenericKind; -use crate::infer::region_constraints::InConstraint; +use crate::infer::region_constraints::PickConstraint; use crate::infer::region_constraints::RegionConstraintData; use crate::infer::region_constraints::VarInfos; use crate::infer::region_constraints::VerifyBound; @@ -118,7 +118,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { let graph = self.construct_graph(); self.expand_givens(&graph); - self.enforce_in_constraints(&graph, &mut var_data); + self.enforce_pick_constraints(&graph, &mut var_data); self.expansion(&mut var_data); self.collect_errors(&mut var_data, errors); self.collect_var_errors(&var_data, &graph, errors); @@ -200,63 +200,63 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { /// - if `'o[i] <= 'b` is false, then `'o[i]` is not an option /// /// Hopefully this narrows it down to just one option. - fn enforce_in_constraints( + fn enforce_pick_constraints( &self, graph: &RegionGraph<'tcx>, var_values: &mut LexicalRegionResolutions<'tcx>, ) { - for in_constraint in &self.data.in_constraints { - let _ = self.enforce_in_constraint(graph, in_constraint, var_values); + for pick_constraint in &self.data.pick_constraints { + let _ = self.enforce_pick_constraint(graph, pick_constraint, var_values); } } - fn enforce_in_constraint( + fn enforce_pick_constraint( &self, graph: &RegionGraph<'tcx>, - in_constraint: &InConstraint<'tcx>, + pick_constraint: &PickConstraint<'tcx>, var_values: &mut LexicalRegionResolutions<'tcx>, ) -> Result<(), ()> { - debug!("enforce_in_constraint(in_constraint={:#?})", in_constraint); + debug!("enforce_pick_constraint(pick_constraint={:#?})", pick_constraint); // the constraint is some inference variable (`vid`) which // must be equal to one of the options - let vid = match in_constraint.region { + let pick_vid = match pick_constraint.pick_region { ty::ReVar(vid) => *vid, _ => return Err(()), }; // find all the "bounds" -- that is, each region `b` such that // `r0 <= b` must hold. - let (bounds, _) = self.collect_concrete_regions(graph, vid, OUTGOING, None); + let (pick_bounds, _) = self.collect_concrete_regions(graph, pick_vid, OUTGOING, None); // get an iterator over the *available options* -- that is, // each constraint regions `o` where `o <= b` for all the // bounds `b`. - debug!("enforce_in_constraint: bounds={:#?}", bounds); - let mut options = in_constraint.in_regions.iter().filter(|option| { - bounds.iter().all(|bound| self.sub_concrete_regions(option, bound.region)) + debug!("enforce_pick_constraint: bounds={:#?}", pick_bounds); + let mut options = pick_constraint.option_regions.iter().filter(|option| { + pick_bounds.iter().all(|bound| self.sub_concrete_regions(option, bound.region)) }); // if there >1 option, we only make a choice if there is a // single *least* choice -- i.e., some available region that // is `<=` all the others. let mut least_choice = options.next().ok_or(())?; - debug!("enforce_in_constraint: least_choice={:?}", least_choice); + debug!("enforce_pick_constraint: least_choice={:?}", least_choice); for option in options { - debug!("enforce_in_constraint: option={:?}", option); + debug!("enforce_pick_constraint: option={:?}", option); if !self.sub_concrete_regions(least_choice, option) { if self.sub_concrete_regions(option, least_choice) { - debug!("enforce_in_constraint: new least choice"); + debug!("enforce_pick_constraint: new least choice"); least_choice = option; } else { - debug!("enforce_in_constraint: no least choice"); + debug!("enforce_pick_constraint: no least choice"); return Err(()); } } } - debug!("enforce_in_constraint: final least choice = {:?}", least_choice); - *var_values.value_mut(vid) = VarValue::Value(least_choice); + debug!("enforce_pick_constraint: final least choice = {:?}", least_choice); + *var_values.value_mut(pick_vid) = VarValue::Value(least_choice); Ok(()) } diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index d4386b321e3..ba42c7a5441 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -907,7 +907,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// Require that the region `r` be equal to one of the regions in /// the set `regions`. - pub fn in_constraint( + pub fn pick_constraint( &self, origin: SubregionOrigin<'tcx>, region: ty::Region<'tcx>, @@ -915,7 +915,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { ) { debug!("sub_regions({:?} <: {:?})", region, in_regions); self.borrow_region_constraints() - .in_constraint(origin, region, in_regions); + .pick_constraint(origin, region, in_regions); } pub fn subtype_predicate( diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index d4c6c8b99b5..733155ad501 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -421,7 +421,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor { tcx: self.tcx, - op: |r| self.in_constraint(infer::CallReturn(span), r, &in_regions), + op: |r| self.pick_constraint(infer::CallReturn(span), r, &in_regions), }); } diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index 14572c050b0..fa64690ded4 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -79,10 +79,10 @@ pub struct RegionConstraintData<'tcx> { /// be a region variable (or neither, as it happens). pub constraints: BTreeMap, SubregionOrigin<'tcx>>, - /// Constraints of the form `R0 in [R1, ..., Rn]`, meaning that + /// Constraints of the form `pick R0 from [R1, ..., Rn]`, meaning that /// `R0` must be equal to one of the regions `R1..Rn`. These occur /// with `impl Trait` quite frequently. - pub in_constraints: Vec>, + pub pick_constraints: Vec>, /// A "verify" is something that we need to verify after inference /// is done, but which does not directly affect inference in any @@ -143,12 +143,17 @@ impl Constraint<'_> { } } -/// Requires that `region` must be equal to one of the regions in `in_regions`. +/// Requires that `region` must be equal to one of the regions in `option_regions`. +/// We often denote this using the syntax: +/// +/// ``` +/// pick R0 from [O1..On] +/// ``` #[derive(Debug, Clone)] -pub struct InConstraint<'tcx> { +pub struct PickConstraint<'tcx> { pub origin: SubregionOrigin<'tcx>, - pub region: Region<'tcx>, - pub in_regions: Rc>>, + pub pick_region: Region<'tcx>, + pub option_regions: Rc>>, } /// `VerifyGenericBound(T, _, R, RS)`: the parameter type `T` (or @@ -657,20 +662,20 @@ impl<'tcx> RegionConstraintCollector<'tcx> { } } - pub fn in_constraint( + pub fn pick_constraint( &mut self, origin: SubregionOrigin<'tcx>, - region: ty::Region<'tcx>, - in_regions: &Rc>>, + pick_region: ty::Region<'tcx>, + option_regions: &Rc>>, ) { - debug!("in_constraint({:?} in {:#?})", region, in_regions); + debug!("pick_constraint({:?} in {:#?})", pick_region, option_regions); - if in_regions.iter().any(|&r| r == region) { + if option_regions.iter().any(|&r| r == pick_region) { return; } - self.data.in_constraints.push(InConstraint { - origin, region, in_regions: in_regions.clone() + self.data.pick_constraints.push(PickConstraint { + origin, pick_region, option_regions: option_regions.clone() }); } @@ -938,10 +943,10 @@ impl<'tcx> RegionConstraintData<'tcx> { pub fn is_empty(&self) -> bool { let RegionConstraintData { constraints, - in_constraints, + pick_constraints, verifys, givens, } = self; - constraints.is_empty() && in_constraints.is_empty() && verifys.is_empty() && givens.is_empty() + constraints.is_empty() && pick_constraints.is_empty() && verifys.is_empty() && givens.is_empty() } }