Skip to content

Commit 09eed28

Browse files
committed
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.
1 parent f30ee65 commit 09eed28

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs

+11-27
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6060
debug!(?concrete_type, ?substs);
6161

6262
let mut subst_regions = vec![self.universal_regions.fr_static];
63-
let universal_substs =
64-
infcx.tcx.fold_regions(substs, &mut false, |region, _| match *region {
65-
ty::ReVar(vid) => {
66-
subst_regions.push(vid);
67-
self.definitions[vid].external_name.unwrap_or_else(|| {
68-
infcx.tcx.sess.delay_span_bug(
69-
span,
70-
"opaque type with non-universal region substs",
71-
);
72-
infcx.tcx.lifetimes.re_static
73-
})
74-
}
75-
// We don't fold regions in the predicates of opaque
76-
// types to `ReVar`s. This means that in a case like
77-
//
78-
// fn f<'a: 'a>() -> impl Iterator<Item = impl Sized>
79-
//
80-
// The inner opaque type has `'static` in its substs.
81-
ty::ReStatic => region,
82-
_ => {
83-
infcx.tcx.sess.delay_span_bug(
84-
span,
85-
&format!("unexpected concrete region in borrowck: {:?}", region),
86-
);
87-
region
88-
}
89-
});
63+
let universal_substs = infcx.tcx.fold_regions(substs, &mut false, |region, _| {
64+
let vid = self.universal_regions.to_region_vid(region);
65+
subst_regions.push(vid);
66+
self.definitions[vid].external_name.unwrap_or_else(|| {
67+
infcx
68+
.tcx
69+
.sess
70+
.delay_span_bug(span, "opaque type with non-universal region substs");
71+
infcx.tcx.lifetimes.re_static
72+
})
73+
});
9074

9175
subst_regions.sort();
9276
subst_regions.dedup();

compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs

-4
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ struct UniversalRegionRelationsBuilder<'this, 'tcx> {
235235

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

compiler/rustc_mir/src/borrow_check/universal_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::borrow_check::nll::ToRegionVid;
3030

3131
#[derive(Debug)]
3232
pub struct UniversalRegions<'tcx> {
33-
pub(crate) indices: UniversalRegionIndices<'tcx>,
33+
indices: UniversalRegionIndices<'tcx>,
3434

3535
/// The vid assigned to `'static`
3636
pub fr_static: RegionVid,
@@ -162,7 +162,7 @@ impl<'tcx> DefiningTy<'tcx> {
162162
}
163163

164164
#[derive(Debug)]
165-
pub(crate) struct UniversalRegionIndices<'tcx> {
165+
struct UniversalRegionIndices<'tcx> {
166166
/// For those regions that may appear in the parameter environment
167167
/// ('static and early-bound regions), we maintain a map from the
168168
/// `ty::Region` to the internal `RegionVid` we are using. This is

0 commit comments

Comments
 (0)