use to_region_vid in opaque type code

Normalization can pull in named regions from the parameter
environment. We need to be prepared for that in the opaque
types code.
This commit is contained in:
Niko Matsakis 2021-06-17 05:16:46 -04:00
parent f30ee6508d
commit 09eed2889a
3 changed files with 13 additions and 33 deletions

View File

@ -60,33 +60,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
debug!(?concrete_type, ?substs);
let mut subst_regions = vec![self.universal_regions.fr_static];
let universal_substs =
infcx.tcx.fold_regions(substs, &mut false, |region, _| match *region {
ty::ReVar(vid) => {
subst_regions.push(vid);
self.definitions[vid].external_name.unwrap_or_else(|| {
infcx.tcx.sess.delay_span_bug(
span,
"opaque type with non-universal region substs",
);
infcx.tcx.lifetimes.re_static
})
}
// We don't fold regions in the predicates of opaque
// types to `ReVar`s. This means that in a case like
//
// fn f<'a: 'a>() -> impl Iterator<Item = impl Sized>
//
// The inner opaque type has `'static` in its substs.
ty::ReStatic => region,
_ => {
infcx.tcx.sess.delay_span_bug(
span,
&format!("unexpected concrete region in borrowck: {:?}", region),
);
region
}
});
let universal_substs = infcx.tcx.fold_regions(substs, &mut false, |region, _| {
let vid = self.universal_regions.to_region_vid(region);
subst_regions.push(vid);
self.definitions[vid].external_name.unwrap_or_else(|| {
infcx
.tcx
.sess
.delay_span_bug(span, "opaque type with non-universal region substs");
infcx.tcx.lifetimes.re_static
})
});
subst_regions.sort();
subst_regions.dedup();

View File

@ -235,7 +235,6 @@ struct UniversalRegionRelationsBuilder<'this, 'tcx> {
impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
crate fn create(mut self) -> CreateResult<'tcx> {
let tcx = self.infcx.tcx;
let unnormalized_input_output_tys = self
.universal_regions
.unnormalized_input_tys
@ -267,9 +266,6 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
.delay_span_bug(DUMMY_SP, &format!("failed to normalize {:?}", ty));
(self.infcx.tcx.ty_error(), None)
});
// We need to replace bound regions in the substs of associated types (parent substs, not GATs)
// with inference vars, see issue #78450
let ty = self.universal_regions.indices.fold_to_region_vids(tcx, ty);
let constraints2 = self.add_implied_bounds(ty);
normalized_inputs_and_output.push(ty);
constraints1.into_iter().chain(constraints2)

View File

@ -30,7 +30,7 @@ use crate::borrow_check::nll::ToRegionVid;
#[derive(Debug)]
pub struct UniversalRegions<'tcx> {
pub(crate) indices: UniversalRegionIndices<'tcx>,
indices: UniversalRegionIndices<'tcx>,
/// The vid assigned to `'static`
pub fr_static: RegionVid,
@ -162,7 +162,7 @@ impl<'tcx> DefiningTy<'tcx> {
}
#[derive(Debug)]
pub(crate) struct UniversalRegionIndices<'tcx> {
struct UniversalRegionIndices<'tcx> {
/// For those regions that may appear in the parameter environment
/// ('static and early-bound regions), we maintain a map from the
/// `ty::Region` to the internal `RegionVid` we are using. This is