Skip to content

Commit

Permalink
use to_region_vid in opaque type code
Browse files Browse the repository at this point in the history
Normalization can pull in named regions from the parameter
environment. We need to be prepared for that in the opaque
types code.
  • Loading branch information
nikomatsakis committed Jun 17, 2021
1 parent f30ee65 commit 09eed28
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
38 changes: 11 additions & 27 deletions compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs
Expand Up @@ -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();
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/borrow_check/universal_regions.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 09eed28

Please sign in to comment.