-pub trait ClosureRegionRequirementsExt<'tcx> {
- fn apply_requirements(
- &self,
- tcx: TyCtxt<'tcx>,
- closure_def_id: DefId,
- closure_substs: SubstsRef<'tcx>,
- ) -> Vec<QueryOutlivesConstraint<'tcx>>;
-}
-
-impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx> {
- /// Given an instance T of the closure type, this method
- /// instantiates the "extra" requirements that we computed for the
- /// closure into the inference context. This has the effect of
- /// adding new outlives obligations to existing variables.
- ///
- /// As described on `ClosureRegionRequirements`, the extra
- /// requirements are expressed in terms of regionvids that index
- /// into the free regions that appear on the closure type. So, to
- /// do this, we first copy those regions out from the type T into
- /// a vector. Then we can just index into that vector to extract
- /// out the corresponding region from T and apply the
- /// requirements.
- fn apply_requirements(
- &self,
- tcx: TyCtxt<'tcx>,
- closure_def_id: DefId,
- closure_substs: SubstsRef<'tcx>,
- ) -> Vec<QueryOutlivesConstraint<'tcx>> {
- debug!(
- "apply_requirements(closure_def_id={:?}, closure_substs={:?})",
- closure_def_id, closure_substs
- );
-
- // Extract the values of the free regions in `closure_substs`
- // into a vector. These are the regions that we will be
- // relating to one another.
- let closure_mapping = &UniversalRegions::closure_mapping(
- tcx,
- closure_substs,
- self.num_external_vids,
- tcx.typeck_root_def_id(closure_def_id),
- );
- debug!("apply_requirements: closure_mapping={:?}", closure_mapping);
-
- // Create the predicates.
- self.outlives_requirements
- .iter()
- .map(|outlives_requirement| {
- let outlived_region = closure_mapping[outlives_requirement.outlived_free_region];
-
- match outlives_requirement.subject {
- ClosureOutlivesSubject::Region(region) => {
- let region = closure_mapping[region];
- debug!(
- "apply_requirements: region={:?} \
- outlived_region={:?} \
- outlives_requirement={:?}",
- region, outlived_region, outlives_requirement,
- );
- (
- ty::Binder::dummy(ty::OutlivesPredicate(
- region.into(),
- outlived_region,
- )),
- ConstraintCategory::BoringNoLocation,
- )
- }
-
- ClosureOutlivesSubject::Ty(ty) => {
- debug!(
- "apply_requirements: ty={:?} \
- outlived_region={:?} \
- outlives_requirement={:?}",
- ty, outlived_region, outlives_requirement,
- );
- (
- ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region)),
- ConstraintCategory::BoringNoLocation,
- )
- }
- }
- })
- .collect()
- }
-}
-