diff options
| author | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-03-08 14:03:20 +0300 |
|---|---|---|
| committer | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-03-08 14:07:01 +0300 |
| commit | 228f40820d91423babd3ac2e5184c5a12109dc9b (patch) | |
| tree | 26c3fd0084650b309e6f8e04d37460e88e7c4605 | |
| parent | 095b5fae1c5fb1ff2433e6c15a092e7f267415ec (diff) | |
| download | rust-228f40820d91423babd3ac2e5184c5a12109dc9b.tar.gz rust-228f40820d91423babd3ac2e5184c5a12109dc9b.zip | |
address review comment
| -rw-r--r-- | compiler/rustc_infer/src/infer/region_constraints/mod.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/infer/unify_key.rs | 19 |
2 files changed, 23 insertions, 7 deletions
diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 022f435b9cb..21bd9243ad6 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -420,7 +420,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> { // `RegionConstraintData` contains the relationship here. if *any_unifications { *any_unifications = false; - self.unification_table_mut().reset_unifications(|_| UnifiedRegion(None)); + self.unification_table_mut().reset_unifications(|_| UnifiedRegion::new(None)); } data @@ -447,7 +447,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> { ) -> RegionVid { let vid = self.var_infos.push(RegionVariableInfo { origin, universe }); - let u_vid = self.unification_table_mut().new_key(UnifiedRegion(None)); + let u_vid = self.unification_table_mut().new_key(UnifiedRegion::new(None)); assert_eq!(vid, u_vid.vid); self.undo_log.push(AddVar(vid)); debug!("created new region variable {:?} in {:?} with origin {:?}", vid, universe, origin); @@ -522,7 +522,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> { (Region(Interned(ReVar(vid), _)), value) | (value, Region(Interned(ReVar(vid), _))) => { debug!("make_eqregion: unifying {:?} with {:?}", vid, value); - self.unification_table_mut().union_value(*vid, UnifiedRegion(Some(value))); + self.unification_table_mut().union_value(*vid, UnifiedRegion::new(Some(value))); self.any_unifications = true; } (_, _) => {} @@ -642,7 +642,10 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> { ) -> ty::Region<'tcx> { let mut ut = self.unification_table_mut(); // FIXME(rust-lang/ena#42): unnecessary mut let root_vid = ut.find(vid).vid; - let resolved = ut.probe_value(root_vid).0.unwrap_or_else(|| tcx.mk_re_var(root_vid)); + let resolved = ut + .probe_value(root_vid) + .get_value_ignoring_universes() + .unwrap_or_else(|| tcx.mk_re_var(root_vid)); // Don't resolve a variable to a region that it cannot name. if self.var_universe(vid).can_name(self.universe(resolved)) { diff --git a/compiler/rustc_middle/src/infer/unify_key.rs b/compiler/rustc_middle/src/infer/unify_key.rs index 41d8c7ffdb9..2ef6cf6f32d 100644 --- a/compiler/rustc_middle/src/infer/unify_key.rs +++ b/compiler/rustc_middle/src/infer/unify_key.rs @@ -1,4 +1,4 @@ -use crate::ty::{self, Ty, TyCtxt}; +use crate::ty::{self, Region, Ty, TyCtxt}; use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue}; use rustc_span::def_id::DefId; use rustc_span::symbol::Symbol; @@ -11,7 +11,20 @@ pub trait ToType { } #[derive(PartialEq, Copy, Clone, Debug)] -pub struct UnifiedRegion<'tcx>(pub Option<ty::Region<'tcx>>); +pub struct UnifiedRegion<'tcx> { + value: Option<ty::Region<'tcx>>, +} + +impl<'tcx> UnifiedRegion<'tcx> { + pub fn new(value: Option<Region<'tcx>>) -> Self { + Self { value } + } + + /// The caller is responsible for checking universe compatibility before using this value. + pub fn get_value_ignoring_universes(self) -> Option<Region<'tcx>> { + self.value + } +} #[derive(PartialEq, Copy, Clone, Debug)] pub struct RegionVidKey<'tcx> { @@ -44,7 +57,7 @@ impl<'tcx> UnifyValue for UnifiedRegion<'tcx> { type Error = NoError; fn unify_values(value1: &Self, value2: &Self) -> Result<Self, NoError> { - Ok(match (value1.0, value2.0) { + Ok(match (value1.value, value2.value) { // Here we can just pick one value, because the full constraints graph // will be handled later. Ideally, we might want a `MultipleValues` // variant or something. For now though, this is fine. |
