about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2021-06-17 05:16:46 -0400
committerNiko Matsakis <niko@alum.mit.edu>2021-06-17 05:22:04 -0400
commit09eed2889a2b959e35b6bed30ca4f53cc5a3e578 (patch)
treee57c6f860ee22de369f0ddbed98f9cde83f3b8de
parentf30ee6508d3cbd385afc61a5b5993bdd50a849ae (diff)
downloadrust-09eed2889a2b959e35b6bed30ca4f53cc5a3e578.tar.gz
rust-09eed2889a2b959e35b6bed30ca4f53cc5a3e578.zip
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.
-rw-r--r--compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs38
-rw-r--r--compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs4
-rw-r--r--compiler/rustc_mir/src/borrow_check/universal_regions.rs4
3 files changed, 13 insertions, 33 deletions
diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs b/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs
index 0d1d2551042..5a334ed556d 100644
--- a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs
+++ b/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs
@@ -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();
diff --git a/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs b/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs
index 2aed6f8eb45..beee3181256 100644
--- a/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs
+++ b/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs
@@ -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)
diff --git a/compiler/rustc_mir/src/borrow_check/universal_regions.rs b/compiler/rustc_mir/src/borrow_check/universal_regions.rs
index a3845aedd40..c2ac1e289ce 100644
--- a/compiler/rustc_mir/src/borrow_check/universal_regions.rs
+++ b/compiler/rustc_mir/src/borrow_check/universal_regions.rs
@@ -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