Move outlives env computation into methods
This commit is contained in:
parent
2b8930c71c
commit
48b7e38c06
8 changed files with 71 additions and 49 deletions
|
@ -9,6 +9,46 @@ use rustc_middle::ty::{self, Ty};
|
|||
use crate::traits::ScrubbedTraitError;
|
||||
use crate::traits::outlives_bounds::InferCtxtExt;
|
||||
|
||||
#[extension(pub trait OutlivesEnvironmentBuildExt<'tcx>)]
|
||||
impl<'tcx> OutlivesEnvironment<'tcx> {
|
||||
fn new(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
body_id: LocalDefId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>,
|
||||
) -> Self {
|
||||
Self::new_with_implied_bounds_compat(
|
||||
infcx,
|
||||
body_id,
|
||||
param_env,
|
||||
assumed_wf_tys,
|
||||
!infcx.tcx.sess.opts.unstable_opts.no_implied_bounds_compat,
|
||||
)
|
||||
}
|
||||
|
||||
fn new_with_implied_bounds_compat(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
body_id: LocalDefId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>,
|
||||
implied_bounds_compat: bool,
|
||||
) -> Self {
|
||||
// FIXME: This needs to be modified so that we normalize the known type
|
||||
// outlives obligations then elaborate them into their region/type components.
|
||||
// Otherwise, `<W<'a> as Mirror>::Assoc: 'b` will not imply `'a: 'b` even
|
||||
// if we can normalize `'a`.
|
||||
OutlivesEnvironment::with_bounds(
|
||||
param_env,
|
||||
infcx.implied_bounds_tys_with_compat(
|
||||
body_id,
|
||||
param_env,
|
||||
assumed_wf_tys,
|
||||
implied_bounds_compat,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[extension(pub trait InferCtxtRegionExt<'tcx>)]
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
/// Resolve regions, using the deep normalizer to normalize any type-outlives
|
||||
|
@ -23,9 +63,11 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
param_env: ty::ParamEnv<'tcx>,
|
||||
assumed_wf_tys: impl IntoIterator<Item = Ty<'tcx>>,
|
||||
) -> Vec<RegionResolutionError<'tcx>> {
|
||||
self.resolve_regions_with_outlives_env(&OutlivesEnvironment::with_bounds(
|
||||
self.resolve_regions_with_outlives_env(&OutlivesEnvironment::new(
|
||||
self,
|
||||
body_id,
|
||||
param_env,
|
||||
self.implied_bounds_tys(body_id, param_env, assumed_wf_tys),
|
||||
assumed_wf_tys,
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::iter;
|
|||
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet, IndexEntry};
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
use rustc_hir::def_id::CRATE_DEF_ID;
|
||||
use rustc_infer::infer::DefineOpaqueTypes;
|
||||
use rustc_middle::ty::{Region, RegionVid};
|
||||
use tracing::debug;
|
||||
|
@ -13,6 +14,7 @@ use tracing::debug;
|
|||
use super::*;
|
||||
use crate::errors::UnableToConstructConstantValue;
|
||||
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
|
||||
use crate::regions::OutlivesEnvironmentBuildExt;
|
||||
use crate::traits::project::ProjectAndUnifyResult;
|
||||
|
||||
// FIXME(twk): this is obviously not nice to duplicate like that
|
||||
|
@ -158,7 +160,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
panic!("Unable to fulfill trait {trait_did:?} for '{ty:?}': {errors:?}");
|
||||
}
|
||||
|
||||
let outlives_env = OutlivesEnvironment::new(full_env);
|
||||
let outlives_env = OutlivesEnvironment::new(&infcx, CRATE_DEF_ID, full_env, []);
|
||||
let _ = infcx.process_registered_region_obligations(&outlives_env, |ty, _| Ok(ty));
|
||||
|
||||
let region_data = infcx.inner.borrow_mut().unwrap_region_constraints().data().clone();
|
||||
|
|
|
@ -108,8 +108,9 @@ fn implied_outlives_bounds<'a, 'tcx>(
|
|||
|
||||
#[extension(pub trait InferCtxtExt<'tcx>)]
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
/// Do *NOT* call this directly.
|
||||
fn implied_bounds_tys_compat<Tys: IntoIterator<Item = Ty<'tcx>>>(
|
||||
/// Do *NOT* call this directly. You probably want to construct a `OutlivesEnvironment`
|
||||
/// instead if you're interested in the implied bounds for a given signature.
|
||||
fn implied_bounds_tys_with_compat<Tys: IntoIterator<Item = Ty<'tcx>>>(
|
||||
&self,
|
||||
body_id: LocalDefId,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
|
@ -119,20 +120,4 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
tys.into_iter()
|
||||
.flat_map(move |ty| implied_outlives_bounds(self, param_env, body_id, ty, compat))
|
||||
}
|
||||
|
||||
/// If `-Z no-implied-bounds-compat` is set, calls `implied_bounds_tys_compat`
|
||||
/// with `compat` set to `true`, otherwise `false`.
|
||||
fn implied_bounds_tys(
|
||||
&self,
|
||||
body_id: LocalDefId,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
tys: impl IntoIterator<Item = Ty<'tcx>>,
|
||||
) -> impl Iterator<Item = OutlivesBound<'tcx>> {
|
||||
self.implied_bounds_tys_compat(
|
||||
body_id,
|
||||
param_env,
|
||||
tys,
|
||||
!self.tcx.sess.opts.unstable_opts.no_implied_bounds_compat,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue