address review comment
This commit is contained in:
parent
095b5fae1c
commit
228f40820d
@ -420,7 +420,7 @@ pub fn take_and_reset_data(&mut self) -> RegionConstraintData<'tcx> {
|
|||||||
// `RegionConstraintData` contains the relationship here.
|
// `RegionConstraintData` contains the relationship here.
|
||||||
if *any_unifications {
|
if *any_unifications {
|
||||||
*any_unifications = false;
|
*any_unifications = false;
|
||||||
self.unification_table_mut().reset_unifications(|_| UnifiedRegion(None));
|
self.unification_table_mut().reset_unifications(|_| UnifiedRegion::new(None));
|
||||||
}
|
}
|
||||||
|
|
||||||
data
|
data
|
||||||
@ -447,7 +447,7 @@ pub(super) fn new_region_var(
|
|||||||
) -> RegionVid {
|
) -> RegionVid {
|
||||||
let vid = self.var_infos.push(RegionVariableInfo { origin, universe });
|
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);
|
assert_eq!(vid, u_vid.vid);
|
||||||
self.undo_log.push(AddVar(vid));
|
self.undo_log.push(AddVar(vid));
|
||||||
debug!("created new region variable {:?} in {:?} with origin {:?}", vid, universe, origin);
|
debug!("created new region variable {:?} in {:?} with origin {:?}", vid, universe, origin);
|
||||||
@ -522,7 +522,7 @@ pub(super) fn make_eqregion(
|
|||||||
(Region(Interned(ReVar(vid), _)), value)
|
(Region(Interned(ReVar(vid), _)), value)
|
||||||
| (value, Region(Interned(ReVar(vid), _))) => {
|
| (value, Region(Interned(ReVar(vid), _))) => {
|
||||||
debug!("make_eqregion: unifying {:?} with {:?}", vid, value);
|
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;
|
self.any_unifications = true;
|
||||||
}
|
}
|
||||||
(_, _) => {}
|
(_, _) => {}
|
||||||
@ -642,7 +642,10 @@ pub fn opportunistic_resolve_var(
|
|||||||
) -> ty::Region<'tcx> {
|
) -> ty::Region<'tcx> {
|
||||||
let mut ut = self.unification_table_mut(); // FIXME(rust-lang/ena#42): unnecessary mut
|
let mut ut = self.unification_table_mut(); // FIXME(rust-lang/ena#42): unnecessary mut
|
||||||
let root_vid = ut.find(vid).vid;
|
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.
|
// Don't resolve a variable to a region that it cannot name.
|
||||||
if self.var_universe(vid).can_name(self.universe(resolved)) {
|
if self.var_universe(vid).can_name(self.universe(resolved)) {
|
||||||
|
@ -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_data_structures::unify::{NoError, UnifyKey, UnifyValue};
|
||||||
use rustc_span::def_id::DefId;
|
use rustc_span::def_id::DefId;
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
@ -11,7 +11,20 @@ pub trait ToType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
#[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)]
|
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||||
pub struct RegionVidKey<'tcx> {
|
pub struct RegionVidKey<'tcx> {
|
||||||
@ -44,7 +57,7 @@ impl<'tcx> UnifyValue for UnifiedRegion<'tcx> {
|
|||||||
type Error = NoError;
|
type Error = NoError;
|
||||||
|
|
||||||
fn unify_values(value1: &Self, value2: &Self) -> Result<Self, 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
|
// Here we can just pick one value, because the full constraints graph
|
||||||
// will be handled later. Ideally, we might want a `MultipleValues`
|
// will be handled later. Ideally, we might want a `MultipleValues`
|
||||||
// variant or something. For now though, this is fine.
|
// variant or something. For now though, this is fine.
|
||||||
|
Loading…
Reference in New Issue
Block a user