diff options
| author | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-02-16 14:40:53 +0300 |
|---|---|---|
| committer | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-03-05 12:00:22 +0300 |
| commit | f3dfa52fd18b0cd684ef44b409891d6cd16fe553 (patch) | |
| tree | f67cb06c953e0ab6fad27044f9e5866a18f5845b /compiler/rustc_infer/src | |
| parent | 13471d3b2046cce78181dde6cfc146c09f55e29e (diff) | |
| download | rust-f3dfa52fd18b0cd684ef44b409891d6cd16fe553.tar.gz rust-f3dfa52fd18b0cd684ef44b409891d6cd16fe553.zip | |
resolve to universal regions when possible
Diffstat (limited to 'compiler/rustc_infer/src')
| -rw-r--r-- | compiler/rustc_infer/src/infer/canonical/canonicalizer.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/region_constraints/mod.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/resolve.rs | 15 |
3 files changed, 17 insertions, 36 deletions
diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 7ffd39de781..c6adc88bd12 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -352,19 +352,17 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> { } ty::ReVar(vid) => { - let resolved_vid = self + let resolved = self .infcx .inner .borrow_mut() .unwrap_region_constraints() - .opportunistic_resolve_var(vid); + .opportunistic_resolve_var(self.tcx, vid); debug!( - "canonical: region var found with vid {:?}, \ - opportunistically resolved to {:?}", - vid, resolved_vid + "canonical: region var found with vid {vid:?}, \ + opportunistically resolved to {resolved:?}", ); - let r = self.tcx.mk_re_var(resolved_vid); - self.canonicalize_mode.canonicalize_free_region(self, r) + self.canonicalize_mode.canonicalize_free_region(self, resolved) } ty::ReStatic diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 33514eedfc3..bf9e71b63fa 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -633,29 +633,15 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> { } } - /// Resolves the passed RegionVid to the root RegionVid in the unification table - pub(super) fn opportunistic_resolve_var(&mut self, rid: ty::RegionVid) -> ty::RegionVid { - self.unification_table().find(rid).vid - } - - /// If the Region is a `ReVar`, then resolves it either to the root value in - /// the unification table, if it exists, or to the root `ReVar` in the table. - /// If the Region is not a `ReVar`, just returns the Region itself. - pub fn opportunistic_resolve_region( + /// Resolves a region var to its value in the unification table, if it exists. + /// Otherwise, it is resolved to the root `ReVar` in the table. + pub fn opportunistic_resolve_var( &mut self, tcx: TyCtxt<'tcx>, - region: ty::Region<'tcx>, + vid: ty::RegionVid, ) -> ty::Region<'tcx> { - match *region { - ty::ReVar(rid) => { - let unified_region = self.unification_table().probe_value(rid); - unified_region.0.unwrap_or_else(|| { - let root = self.unification_table().find(rid).vid; - tcx.mk_re_var(root) - }) - } - _ => region, - } + let root_vid = self.unification_table().find(vid).vid; + self.unification_table().probe_value(root_vid).0.unwrap_or_else(|| tcx.mk_re_var(root_vid)) } fn combine_map(&mut self, t: CombineMapType) -> &mut CombineMap<'tcx> { diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index 5bb35832930..4f49f416507 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -85,15 +85,12 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticRegionResolver<'a, 'tcx fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { match *r { - ty::ReVar(rid) => { - let resolved = self - .infcx - .inner - .borrow_mut() - .unwrap_region_constraints() - .opportunistic_resolve_var(rid); - TypeFolder::interner(self).mk_re_var(resolved) - } + ty::ReVar(vid) => self + .infcx + .inner + .borrow_mut() + .unwrap_region_constraints() + .opportunistic_resolve_var(TypeFolder::interner(self), vid), _ => r, } } |
